blob: 6c60d52a513c9a0f9d8080811c3b98085750bdea [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"
Carmelo Casconeb5324e72018-11-25 02:26:32 -080022#include "include/control/acl.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070023#include "include/control/next.p4"
24#include "include/control/packetio.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070025#include "include/header.p4"
26#include "include/checksum.p4"
27#include "include/parser.p4"
28
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070029#ifdef WITH_PORT_COUNTER
30#include "include/control/port_counter.p4"
31#endif // WITH_PORT_COUNTER
32
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080033#ifdef WITH_SPGW
34#include "include/spgw.p4"
35#endif // WITH_SPGW
36
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090037#ifdef WITH_INT
Carmelo Cascone79a3a312018-08-16 17:14:43 -070038#include "include/int/int_main.p4"
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090039#endif // WITH_INT
40
Carmelo Casconeb5324e72018-11-25 02:26:32 -080041control FabricIngress (inout parsed_headers_t hdr,
42 inout fabric_metadata_t fabric_metadata,
43 inout standard_metadata_t standard_metadata) {
44
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070045 PacketIoIngress() pkt_io_ingress;
Yi Tsengbe342052017-11-03 10:21:23 -070046 Filtering() filtering;
47 Forwarding() forwarding;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080048 Acl() acl;
Yi Tsengbe342052017-11-03 10:21:23 -070049 Next() next;
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070050#ifdef WITH_PORT_COUNTER
Yi Tsengbe342052017-11-03 10:21:23 -070051 PortCountersControl() port_counters_control;
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070052#endif // WITH_PORT_COUNTER
Yi Tsengbe342052017-11-03 10:21:23 -070053
54 apply {
Carmelo Casconefa421582018-09-13 10:05:57 -070055 _PRE_INGRESS
Carmelo Cascone9b0171b2018-08-14 01:43:57 -070056#ifdef WITH_SPGW
57 spgw_normalizer.apply(hdr.gtpu.isValid(), hdr.gtpu_ipv4, hdr.gtpu_udp,
58 hdr.ipv4, hdr.udp, hdr.inner_ipv4, hdr.inner_udp);
59#endif // WITH_SPGW
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070060 pkt_io_ingress.apply(hdr, fabric_metadata, standard_metadata);
Yi Tsengbe342052017-11-03 10:21:23 -070061 filtering.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb5324e72018-11-25 02:26:32 -080062#ifdef WITH_SPGW
63 spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
64 hdr.ipv4, hdr.udp, fabric_metadata);
65#endif // WITH_SPGW
66 if (fabric_metadata.skip_forwarding == _FALSE) {
67 forwarding.apply(hdr, fabric_metadata, standard_metadata);
68 }
69 acl.apply(hdr, fabric_metadata, standard_metadata);
70 if (fabric_metadata.skip_next == _FALSE) {
71 next.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070072#ifdef WITH_PORT_COUNTER
Carmelo Casconeb5324e72018-11-25 02:26:32 -080073 // FIXME: we're not counting pkts punted to cpu or forwarded via
74 // multicast groups. Remove when gNMI support will be there.
75 port_counters_control.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070076#endif // WITH_PORT_COUNTER
Carmelo Cascone79a3a312018-08-16 17:14:43 -070077#if defined(WITH_INT_SOURCE) || defined(WITH_INT_SINK)
Carmelo Casconeb5324e72018-11-25 02:26:32 -080078 process_set_source_sink.apply(hdr, fabric_metadata, standard_metadata);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090079#endif
Carmelo Casconeb5324e72018-11-25 02:26:32 -080080 }
Yi Tsengbe342052017-11-03 10:21:23 -070081 }
82}
83
84control FabricEgress (inout parsed_headers_t hdr,
85 inout fabric_metadata_t fabric_metadata,
86 inout standard_metadata_t standard_metadata) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080087
Yi Tseng1d842672017-11-28 16:06:52 -080088 PacketIoEgress() pkt_io_egress;
Yi Tseng20f9e7b2018-05-24 23:27:39 +080089 EgressNextControl() egress_next;
90
Yi Tsengbe342052017-11-03 10:21:23 -070091 apply {
Carmelo Casconefa421582018-09-13 10:05:57 -070092 _PRE_EGRESS
Yi Tseng1d842672017-11-28 16:06:52 -080093 pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070094 egress_next.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080095#ifdef WITH_SPGW
Carmelo Cascone33e85c02018-02-01 13:30:18 -080096 spgw_egress.apply(hdr.ipv4, hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
Carmelo Casconeb5324e72018-11-25 02:26:32 -080097 fabric_metadata, standard_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080098#endif // WITH_SPGW
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090099#ifdef WITH_INT
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700100 process_int_main.apply(hdr, fabric_metadata, standard_metadata);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900101#endif
Yi Tsengbe342052017-11-03 10:21:23 -0700102 }
103}
104
105V1Switch(
106 FabricParser(),
107 FabricVerifyChecksum(),
108 FabricIngress(),
109 FabricEgress(),
110 FabricComputeChecksum(),
111 FabricDeparser()
112) main;