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 | |
| 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 Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 29 | #ifdef WITH_SPGW |
| 30 | #include "include/spgw.p4" |
| 31 | #endif // WITH_SPGW |
| 32 | |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame] | 33 | #ifdef WITH_INT_TRANSIT |
| 34 | #include "include/int_transit.p4" |
| 35 | #endif // WITH_INT_TRANSIT |
| 36 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 37 | control FabricIngress ( |
| 38 | inout parsed_headers_t hdr, |
| 39 | inout fabric_metadata_t fabric_metadata, |
| 40 | inout standard_metadata_t standard_metadata) { |
| 41 | PacketIoIngress() packet_io_ingress; |
| 42 | Filtering() filtering; |
| 43 | Forwarding() forwarding; |
| 44 | Next() next; |
| 45 | PortCountersControl() port_counters_control; |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 46 | EgressNextControl() egress_next; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 47 | |
| 48 | apply { |
Carmelo Cascone | a14a5d3 | 2018-05-30 16:56:04 -0700 | [diff] [blame] | 49 | #ifdef WITH_INT_TRANSIT |
Carmelo Cascone | e2c568f | 2018-03-24 15:03:40 -0700 | [diff] [blame] | 50 | fabric_metadata.int_metadata.ingress_tstamp = |
| 51 | (bit<32>) standard_metadata.ingress_global_timestamp; |
Carmelo Cascone | a14a5d3 | 2018-05-30 16:56:04 -0700 | [diff] [blame] | 52 | #endif // WITH_INT_TRANSIT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 53 | packet_io_ingress.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 54 | #ifdef WITH_SPGW |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 55 | #ifdef WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 56 | fabric_metadata.spgw.l4_src_port = fabric_metadata.l4_src_port; |
| 57 | fabric_metadata.spgw.l4_dst_port = fabric_metadata.l4_dst_port; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 58 | #endif // WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 59 | spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 60 | hdr.ipv4, hdr.udp, fabric_metadata.spgw); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 61 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 62 | filtering.apply(hdr, fabric_metadata, standard_metadata); |
| 63 | forwarding.apply(hdr, fabric_metadata, standard_metadata); |
| 64 | next.apply(hdr, fabric_metadata, standard_metadata); |
| 65 | port_counters_control.apply(hdr, fabric_metadata, standard_metadata); |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 66 | egress_next.apply(hdr, fabric_metadata, standard_metadata); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | control FabricEgress (inout parsed_headers_t hdr, |
| 71 | inout fabric_metadata_t fabric_metadata, |
| 72 | inout standard_metadata_t standard_metadata) { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 73 | PacketIoEgress() pkt_io_egress; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 74 | apply { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 75 | pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | 0488822 | 2018-03-19 22:18:12 -0700 | [diff] [blame] | 76 | #ifdef WITH_INT_TRANSIT |
| 77 | int_egress.apply(hdr, fabric_metadata.int_metadata, standard_metadata); |
| 78 | #endif // WITH_INT_TRANSIT |
| 79 | // gtpu encap needs to happen after INT to ensure length fields are set |
| 80 | // correctly |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 81 | #ifdef WITH_SPGW |
Carmelo Cascone | 33e85c0 | 2018-02-01 13:30:18 -0800 | [diff] [blame] | 82 | spgw_egress.apply(hdr.ipv4, hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 83 | fabric_metadata.spgw, standard_metadata); |
| 84 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | V1Switch( |
| 89 | FabricParser(), |
| 90 | FabricVerifyChecksum(), |
| 91 | FabricIngress(), |
| 92 | FabricEgress(), |
| 93 | FabricComputeChecksum(), |
| 94 | FabricDeparser() |
| 95 | ) main; |