blob: c1368d84cb7416e268c5aa79601d89b18d6a1767 [file] [log] [blame]
Carmelo Cascone79a3a312018-08-16 17:14:43 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* -*- P4_16 -*- */
18#ifndef __INT_MAIN__
19#define __INT_MAIN__
20
21#ifdef WITH_INT_SOURCE
22#include "int_source.p4"
23#endif // WITH_INT_SOURCE
24
25#ifdef WITH_INT_TRANSIT
26#include "int_transit.p4"
27#endif // WITH_INT_TRANSIT
28
29#ifdef WITH_INT_SINK
30#include "int_sink.p4"
31#include "int_report.p4"
32#endif // WITH_INT_SINK
33
34control process_set_source_sink (
35 inout parsed_headers_t hdr,
36 inout fabric_metadata_t fabric_metadata,
37 inout standard_metadata_t standard_metadata) {
38
39 direct_counter(CounterType.packets_and_bytes) counter_set_source;
40
41 action int_set_source () {
42 fabric_metadata.int_meta.source = _TRUE;
43 counter_set_source.count();
44 }
45
46 table tb_set_source {
47 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080048 standard_metadata.ingress_port: exact @name("ig_port");
Carmelo Cascone79a3a312018-08-16 17:14:43 -070049 }
50 actions = {
51 int_set_source;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080052 @defaultonly nop();
Carmelo Cascone79a3a312018-08-16 17:14:43 -070053 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080054 const default_action = nop();
Carmelo Cascone79a3a312018-08-16 17:14:43 -070055 counters = counter_set_source;
56 size = MAX_PORTS;
57 }
58
59#ifdef WITH_INT_SINK
60 direct_counter(CounterType.packets_and_bytes) counter_set_sink;
61
62 action int_set_sink () {
63 fabric_metadata.int_meta.sink = _TRUE;
64 counter_set_sink.count();
65 }
66
67 table tb_set_sink {
68 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080069 standard_metadata.egress_spec: exact @name("eg_spec");
Carmelo Cascone79a3a312018-08-16 17:14:43 -070070 }
71 actions = {
72 int_set_sink;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080073 @defaultonly nop();
Carmelo Cascone79a3a312018-08-16 17:14:43 -070074 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080075 const default_action = nop();
Carmelo Cascone79a3a312018-08-16 17:14:43 -070076 counters = counter_set_sink;
77 size = MAX_PORTS;
78 }
79#endif // WITH_INT_SINK
80
81 apply {
82 tb_set_source.apply();
83
84#ifdef WITH_INT_SINK
85 tb_set_sink.apply();
86 if(fabric_metadata.int_meta.sink == _TRUE) {
87 // FIXME: this works only on BMv2
88 #ifdef __TARGET_BMV2__
89 clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID);
90 #endif
91 }
92#endif // WITH_INT_SINK
93 }
94}
95
96control process_int_main (
97 inout parsed_headers_t hdr,
98 inout fabric_metadata_t fabric_metadata,
99 inout standard_metadata_t standard_metadata) {
100
101 apply {
102 if (standard_metadata.ingress_port != CPU_PORT &&
103 standard_metadata.egress_port != CPU_PORT &&
104 (hdr.udp.isValid() || hdr.tcp.isValid())) {
105#ifdef WITH_INT_SOURCE
106 if (fabric_metadata.int_meta.source == _TRUE) {
107 process_int_source.apply(hdr, fabric_metadata, standard_metadata);
108 }
109#endif // WITH_INT_SOURCE
110 if(hdr.int_header.isValid()) {
111#ifdef WITH_INT_TRANSIT
112 process_int_transit.apply(hdr, fabric_metadata, standard_metadata);
113#endif // WITH_INT_TRANSIT
114#ifdef WITH_INT_SINK
115 if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) {
116 /* send int report */
117 process_int_report.apply(hdr, fabric_metadata, standard_metadata);
118 }
119 if (fabric_metadata.int_meta.sink == _TRUE) {
120 // int sink
121 process_int_sink.apply(hdr, fabric_metadata);
122 }
123#endif // WITH_INT_SINK
124 }
125 }
126 }
127}
128#endif