blob: ad3857d05b1209a9a5a2b1c1a3d55440cbe0c4cf [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
Carmelo Cascone70e816b2019-03-19 16:15:47 -070020#include "include/size.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070021#include "include/control/filtering.p4"
22#include "include/control/forwarding.p4"
Carmelo Casconeb5324e72018-11-25 02:26:32 -080023#include "include/control/acl.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070024#include "include/control/next.p4"
25#include "include/control/packetio.p4"
Yi Tsengbe342052017-11-03 10:21:23 -070026#include "include/header.p4"
27#include "include/checksum.p4"
28#include "include/parser.p4"
29
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070030#ifdef WITH_PORT_COUNTER
31#include "include/control/port_counter.p4"
32#endif // WITH_PORT_COUNTER
33
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080034#ifdef WITH_SPGW
Robert MacDavidde12b982020-07-15 18:38:59 -070035#include "include/control/spgw.p4"
Carmelo Casconeb81f4be2018-01-16 23:24:01 -080036#endif // WITH_SPGW
37
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070038#ifdef WITH_BNG
39#include "include/bng.p4"
40#endif // WITH_BNG
41
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090042#ifdef WITH_INT
Carmelo Cascone79a3a312018-08-16 17:14:43 -070043#include "include/int/int_main.p4"
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090044#endif // WITH_INT
45
Carmelo Casconeb5324e72018-11-25 02:26:32 -080046control FabricIngress (inout parsed_headers_t hdr,
47 inout fabric_metadata_t fabric_metadata,
48 inout standard_metadata_t standard_metadata) {
49
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070050 PacketIoIngress() pkt_io_ingress;
Yi Tsengbe342052017-11-03 10:21:23 -070051 Filtering() filtering;
52 Forwarding() forwarding;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080053 Acl() acl;
Yi Tsengbe342052017-11-03 10:21:23 -070054 Next() next;
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070055#ifdef WITH_PORT_COUNTER
Yi Tsengbe342052017-11-03 10:21:23 -070056 PortCountersControl() port_counters_control;
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070057#endif // WITH_PORT_COUNTER
Robert MacDavidde12b982020-07-15 18:38:59 -070058#ifdef WITH_SPGW
Carmelo Cascone2102bfb2020-12-04 16:54:24 -080059 SpgwIngress() spgw;
Robert MacDavidde12b982020-07-15 18:38:59 -070060#endif // WITH_SPGW
Yi Tsengbe342052017-11-03 10:21:23 -070061
62 apply {
Carmelo Casconefa421582018-09-13 10:05:57 -070063 _PRE_INGRESS
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -070064 pkt_io_ingress.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb5324e72018-11-25 02:26:32 -080065#ifdef WITH_SPGW
Carmelo Cascone2102bfb2020-12-04 16:54:24 -080066 spgw.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb5324e72018-11-25 02:26:32 -080067#endif // WITH_SPGW
Robert MacDavidde12b982020-07-15 18:38:59 -070068 filtering.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb5324e72018-11-25 02:26:32 -080069 if (fabric_metadata.skip_forwarding == _FALSE) {
70 forwarding.apply(hdr, fabric_metadata, standard_metadata);
71 }
72 acl.apply(hdr, fabric_metadata, standard_metadata);
73 if (fabric_metadata.skip_next == _FALSE) {
74 next.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070075#ifdef WITH_PORT_COUNTER
Carmelo Casconeb5324e72018-11-25 02:26:32 -080076 // FIXME: we're not counting pkts punted to cpu or forwarded via
77 // multicast groups. Remove when gNMI support will be there.
78 port_counters_control.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone0c8d73e2018-09-07 16:31:06 -070079#endif // WITH_PORT_COUNTER
Carmelo Cascone79a3a312018-08-16 17:14:43 -070080#if defined(WITH_INT_SOURCE) || defined(WITH_INT_SINK)
Carmelo Casconeb5324e72018-11-25 02:26:32 -080081 process_set_source_sink.apply(hdr, fabric_metadata, standard_metadata);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090082#endif
Carmelo Casconeb5324e72018-11-25 02:26:32 -080083 }
Daniele Moro7c3a0022019-07-12 13:38:34 -070084#ifdef WITH_BNG
85 bng_ingress.apply(hdr, fabric_metadata, standard_metadata);
86#endif // WITH_BNG
87
Yi Tsengbe342052017-11-03 10:21:23 -070088 }
89}
90
91control FabricEgress (inout parsed_headers_t hdr,
92 inout fabric_metadata_t fabric_metadata,
93 inout standard_metadata_t standard_metadata) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080094
Yi Tseng1d842672017-11-28 16:06:52 -080095 PacketIoEgress() pkt_io_egress;
Yi Tseng20f9e7b2018-05-24 23:27:39 +080096 EgressNextControl() egress_next;
Robert MacDavidde12b982020-07-15 18:38:59 -070097#ifdef WITH_SPGW
Carmelo Cascone2102bfb2020-12-04 16:54:24 -080098 SpgwEgress() spgw;
Robert MacDavidde12b982020-07-15 18:38:59 -070099#endif // WITH_SPGW
Yi Tseng20f9e7b2018-05-24 23:27:39 +0800100
Yi Tsengbe342052017-11-03 10:21:23 -0700101 apply {
Carmelo Casconefa421582018-09-13 10:05:57 -0700102 _PRE_EGRESS
Yi Tseng1d842672017-11-28 16:06:52 -0800103 pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Cascone8d2d1b22018-08-27 18:33:53 -0700104 egress_next.apply(hdr, fabric_metadata, standard_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800105#ifdef WITH_SPGW
Carmelo Cascone2102bfb2020-12-04 16:54:24 -0800106 spgw.apply(hdr, fabric_metadata);
Carmelo Casconeb81f4be2018-01-16 23:24:01 -0800107#endif // WITH_SPGW
Carmelo Cascone4d8785b2019-05-31 17:11:26 -0700108#ifdef WITH_BNG
109 bng_egress.apply(hdr, fabric_metadata, standard_metadata);
110#endif // WITH_BNG
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900111#ifdef WITH_INT
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700112 process_int_main.apply(hdr, fabric_metadata, standard_metadata);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900113#endif
Yi Tsengbe342052017-11-03 10:21:23 -0700114 }
115}
116
117V1Switch(
118 FabricParser(),
119 FabricVerifyChecksum(),
120 FabricIngress(),
121 FabricEgress(),
122 FabricComputeChecksum(),
123 FabricDeparser()
124) main;