blob: 22ad209eee3f47c965d30f6d486486ffc5330846 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -07001/*
2 * Copyright 2017-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#include <core.p4>
18#include <v1model.p4>
19
20#include "include/control/filtering.p4"
21#include "include/control/forwarding.p4"
22#include "include/control/next.p4"
23#include "include/control/packetio.p4"
24#include "include/control/port_counter.p4"
25#include "include/header.p4"
26#include "include/checksum.p4"
27#include "include/parser.p4"
28
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080029#ifdef WITH_SPGW
30#include "include/spgw.p4"
31#endif // WITH_SPGW
32
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090033#ifdef WITH_INT
34#include "include/int_source.p4"
35#include "include/int_transit.p4"
36#include "include/int_sink.p4"
37#include "include/int_report.p4"
38#endif // WITH_INT
39
Yi Tsengbe342052017-11-03 10:21:23 -070040control FabricIngress (
41inout parsed_headers_t hdr,
42inout fabric_metadata_t fabric_metadata,
43inout standard_metadata_t standard_metadata) {
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070044 PacketIoIngress() pkt_io_ingress;
Yi Tsengbe342052017-11-03 10:21:23 -070045 Filtering() filtering;
46 Forwarding() forwarding;
47 Next() next;
48 PortCountersControl() port_counters_control;
49
50 apply {
Carmelo Cascone9b0171b2018-08-14 01:43:57 -070051#ifdef WITH_SPGW
52 spgw_normalizer.apply(hdr.gtpu.isValid(), hdr.gtpu_ipv4, hdr.gtpu_udp,
53 hdr.ipv4, hdr.udp, hdr.inner_ipv4, hdr.inner_udp);
54#endif // WITH_SPGW
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070055 pkt_io_ingress.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080056#ifdef WITH_SPGW
Carmelo Casconeb757dbc2018-01-25 17:53:17 -080057#ifdef WITH_SPGW_PCC_GATING
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080058 fabric_metadata.spgw.l4_src_port = fabric_metadata.l4_src_port;
59 fabric_metadata.spgw.l4_dst_port = fabric_metadata.l4_dst_port;
Carmelo Casconeb757dbc2018-01-25 17:53:17 -080060#endif // WITH_SPGW_PCC_GATING
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080061 spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
Carmelo Casconeb757dbc2018-01-25 17:53:17 -080062 hdr.ipv4, hdr.udp, fabric_metadata.spgw);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080063#endif // WITH_SPGW
Yi Tsengbe342052017-11-03 10:21:23 -070064 filtering.apply(hdr, fabric_metadata, standard_metadata);
65 forwarding.apply(hdr, fabric_metadata, standard_metadata);
66 next.apply(hdr, fabric_metadata, standard_metadata);
67 port_counters_control.apply(hdr, fabric_metadata, standard_metadata);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090068#ifdef WITH_INT
69 process_set_source_sink.apply(hdr, fabric_metadata, standard_metadata);
70 if(fabric_metadata.int_meta.sink == 1) {
71 // clone packet for Telemetry Report
72 #ifdef __TARGET_BMV2__
73 clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID);
74 #endif
75 }
76#endif
Yi Tsengbe342052017-11-03 10:21:23 -070077 }
78}
79
80control FabricEgress (inout parsed_headers_t hdr,
81 inout fabric_metadata_t fabric_metadata,
82 inout standard_metadata_t standard_metadata) {
Yi Tseng1d842672017-11-28 16:06:52 -080083 PacketIoEgress() pkt_io_egress;
Yi Tseng20f9e7b2018-05-24 23:27:39 +080084 EgressNextControl() egress_next;
85
Yi Tsengbe342052017-11-03 10:21:23 -070086 apply {
Yi Tseng1d842672017-11-28 16:06:52 -080087 pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070088 egress_next.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080089#ifdef WITH_SPGW
Carmelo Cascone33e85c02018-02-01 13:30:18 -080090 spgw_egress.apply(hdr.ipv4, hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080091 fabric_metadata.spgw, standard_metadata);
92#endif // WITH_SPGW
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090093#ifdef WITH_INT
94 if (standard_metadata.ingress_port != CPU_PORT &&
95 standard_metadata.egress_port != CPU_PORT &&
96 (hdr.udp.isValid() || hdr.tcp.isValid())) {
97 if (fabric_metadata.int_meta.source == 1) {
98 process_int_source.apply(hdr, fabric_metadata, standard_metadata);
99 }
100 if(hdr.int_header.isValid()) {
101 process_int_transit.apply(hdr, fabric_metadata, standard_metadata);
102 // update underlay header based on INT information inserted
103 process_int_outer_encap.apply(hdr, fabric_metadata, standard_metadata);
104 if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) {
105 /* send int report */
106 process_int_report.apply(hdr, fabric_metadata, standard_metadata);
107 }
108 if (fabric_metadata.int_meta.sink == 1) {
109 // int sink
110 process_int_sink.apply(hdr, fabric_metadata, standard_metadata);
111 }
112 }
113 }
114#endif
Yi Tsengbe342052017-11-03 10:21:23 -0700115 }
116}
117
118V1Switch(
119 FabricParser(),
120 FabricVerifyChecksum(),
121 FabricIngress(),
122 FabricEgress(),
123 FabricComputeChecksum(),
124 FabricDeparser()
125) main;