Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 1 | /* |
| 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 Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 20 | #include "include/size.p4" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 21 | #include "include/control/filtering.p4" |
| 22 | #include "include/control/forwarding.p4" |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 23 | #include "include/control/acl.p4" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 24 | #include "include/control/next.p4" |
| 25 | #include "include/control/packetio.p4" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 26 | #include "include/header.p4" |
| 27 | #include "include/checksum.p4" |
| 28 | #include "include/parser.p4" |
| 29 | |
Carmelo Cascone | 0c8d73e | 2018-09-07 16:31:06 -0700 | [diff] [blame] | 30 | #ifdef WITH_PORT_COUNTER |
| 31 | #include "include/control/port_counter.p4" |
| 32 | #endif // WITH_PORT_COUNTER |
| 33 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 34 | #ifdef WITH_SPGW |
| 35 | #include "include/spgw.p4" |
| 36 | #endif // WITH_SPGW |
| 37 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 38 | #ifdef WITH_INT |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 39 | #include "include/int/int_main.p4" |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 40 | #endif // WITH_INT |
| 41 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 42 | control FabricIngress (inout parsed_headers_t hdr, |
| 43 | inout fabric_metadata_t fabric_metadata, |
| 44 | inout standard_metadata_t standard_metadata) { |
| 45 | |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 46 | PacketIoIngress() pkt_io_ingress; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 47 | Filtering() filtering; |
| 48 | Forwarding() forwarding; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 49 | Acl() acl; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 50 | Next() next; |
Carmelo Cascone | 0c8d73e | 2018-09-07 16:31:06 -0700 | [diff] [blame] | 51 | #ifdef WITH_PORT_COUNTER |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 52 | PortCountersControl() port_counters_control; |
Carmelo Cascone | 0c8d73e | 2018-09-07 16:31:06 -0700 | [diff] [blame] | 53 | #endif // WITH_PORT_COUNTER |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 54 | |
| 55 | apply { |
Carmelo Cascone | fa42158 | 2018-09-13 10:05:57 -0700 | [diff] [blame] | 56 | _PRE_INGRESS |
Carmelo Cascone | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 57 | #ifdef WITH_SPGW |
| 58 | spgw_normalizer.apply(hdr.gtpu.isValid(), hdr.gtpu_ipv4, hdr.gtpu_udp, |
| 59 | hdr.ipv4, hdr.udp, hdr.inner_ipv4, hdr.inner_udp); |
| 60 | #endif // WITH_SPGW |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 61 | pkt_io_ingress.apply(hdr, fabric_metadata, standard_metadata); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 62 | filtering.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 63 | #ifdef WITH_SPGW |
| 64 | spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 65 | hdr.ipv4, hdr.udp, fabric_metadata, standard_metadata); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 66 | #endif // WITH_SPGW |
| 67 | if (fabric_metadata.skip_forwarding == _FALSE) { |
| 68 | forwarding.apply(hdr, fabric_metadata, standard_metadata); |
| 69 | } |
| 70 | acl.apply(hdr, fabric_metadata, standard_metadata); |
| 71 | if (fabric_metadata.skip_next == _FALSE) { |
| 72 | next.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | 0c8d73e | 2018-09-07 16:31:06 -0700 | [diff] [blame] | 73 | #ifdef WITH_PORT_COUNTER |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 74 | // FIXME: we're not counting pkts punted to cpu or forwarded via |
| 75 | // multicast groups. Remove when gNMI support will be there. |
| 76 | port_counters_control.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | 0c8d73e | 2018-09-07 16:31:06 -0700 | [diff] [blame] | 77 | #endif // WITH_PORT_COUNTER |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 78 | #if defined(WITH_INT_SOURCE) || defined(WITH_INT_SINK) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 79 | process_set_source_sink.apply(hdr, fabric_metadata, standard_metadata); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 80 | #endif |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 81 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | control FabricEgress (inout parsed_headers_t hdr, |
| 86 | inout fabric_metadata_t fabric_metadata, |
| 87 | inout standard_metadata_t standard_metadata) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 88 | |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 89 | PacketIoEgress() pkt_io_egress; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 90 | EgressNextControl() egress_next; |
| 91 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 92 | apply { |
Carmelo Cascone | fa42158 | 2018-09-13 10:05:57 -0700 | [diff] [blame] | 93 | _PRE_EGRESS |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 94 | pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | 8d2d1b2 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 95 | egress_next.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 96 | #ifdef WITH_SPGW |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 97 | spgw_egress.apply(hdr.ipv4, hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 98 | fabric_metadata, standard_metadata); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 99 | #endif // WITH_SPGW |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 100 | #ifdef WITH_INT |
Carmelo Cascone | 79a3a31 | 2018-08-16 17:14:43 -0700 | [diff] [blame] | 101 | process_int_main.apply(hdr, fabric_metadata, standard_metadata); |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 102 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | V1Switch( |
| 107 | FabricParser(), |
| 108 | FabricVerifyChecksum(), |
| 109 | FabricIngress(), |
| 110 | FabricEgress(), |
| 111 | FabricComputeChecksum(), |
| 112 | FabricDeparser() |
| 113 | ) main; |