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" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 24 | #include "include/header.p4" |
| 25 | #include "include/checksum.p4" |
| 26 | #include "include/parser.p4" |
| 27 | |
Carmelo Cascone | d9afb71 | 2018-09-07 16:31:06 -0700 | [diff] [blame^] | 28 | #ifdef WITH_PORT_COUNTER |
| 29 | #include "include/control/port_counter.p4" |
| 30 | #endif // WITH_PORT_COUNTER |
| 31 | |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 32 | #ifdef WITH_SPGW |
| 33 | #include "include/spgw.p4" |
| 34 | #endif // WITH_SPGW |
| 35 | |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 36 | #ifdef WITH_INT |
| 37 | #include "include/int_source.p4" |
| 38 | #include "include/int_transit.p4" |
| 39 | #include "include/int_sink.p4" |
| 40 | #include "include/int_report.p4" |
| 41 | #endif // WITH_INT |
| 42 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 43 | control FabricIngress ( |
| 44 | inout parsed_headers_t hdr, |
| 45 | inout fabric_metadata_t fabric_metadata, |
| 46 | inout standard_metadata_t standard_metadata) { |
Carmelo Cascone | 3e5c745 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 47 | PacketIoIngress() pkt_io_ingress; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 48 | Filtering() filtering; |
| 49 | Forwarding() forwarding; |
| 50 | Next() next; |
Carmelo Cascone | d9afb71 | 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 | d9afb71 | 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 | 9b0171b | 2018-08-14 01:43:57 -0700 | [diff] [blame] | 56 | #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 Cascone | 3e5c745 | 2018-08-27 18:33:53 -0700 | [diff] [blame] | 60 | pkt_io_ingress.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 61 | #ifdef WITH_SPGW |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 62 | #ifdef WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 63 | fabric_metadata.spgw.l4_src_port = fabric_metadata.l4_src_port; |
| 64 | fabric_metadata.spgw.l4_dst_port = fabric_metadata.l4_dst_port; |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 65 | #endif // WITH_SPGW_PCC_GATING |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 66 | spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu, |
Carmelo Cascone | b757dbc | 2018-01-25 17:53:17 -0800 | [diff] [blame] | 67 | hdr.ipv4, hdr.udp, fabric_metadata.spgw); |
Carmelo Cascone | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 68 | #endif // WITH_SPGW |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 69 | filtering.apply(hdr, fabric_metadata, standard_metadata); |
| 70 | forwarding.apply(hdr, fabric_metadata, standard_metadata); |
| 71 | next.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | d9afb71 | 2018-09-07 16:31:06 -0700 | [diff] [blame^] | 72 | #ifdef WITH_PORT_COUNTER |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 73 | port_counters_control.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | d9afb71 | 2018-09-07 16:31:06 -0700 | [diff] [blame^] | 74 | #endif // WITH_PORT_COUNTER |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 75 | #ifdef WITH_INT |
| 76 | process_set_source_sink.apply(hdr, fabric_metadata, standard_metadata); |
| 77 | if(fabric_metadata.int_meta.sink == 1) { |
| 78 | // clone packet for Telemetry Report |
| 79 | #ifdef __TARGET_BMV2__ |
| 80 | clone(CloneType.I2E, REPORT_MIRROR_SESSION_ID); |
| 81 | #endif |
| 82 | } |
| 83 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
| 87 | control FabricEgress (inout parsed_headers_t hdr, |
| 88 | inout fabric_metadata_t fabric_metadata, |
| 89 | inout standard_metadata_t standard_metadata) { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 90 | PacketIoEgress() pkt_io_egress; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 91 | EgressNextControl() egress_next; |
| 92 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 93 | apply { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 94 | pkt_io_egress.apply(hdr, fabric_metadata, standard_metadata); |
Carmelo Cascone | 3e5c745 | 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 | b81f4be | 2018-01-16 23:24:01 -0800 | [diff] [blame] | 98 | fabric_metadata.spgw, standard_metadata); |
| 99 | #endif // WITH_SPGW |
Jonghwan Hyun | ed478dc | 2018-08-06 15:35:18 +0900 | [diff] [blame] | 100 | #ifdef WITH_INT |
| 101 | if (standard_metadata.ingress_port != CPU_PORT && |
| 102 | standard_metadata.egress_port != CPU_PORT && |
| 103 | (hdr.udp.isValid() || hdr.tcp.isValid())) { |
| 104 | if (fabric_metadata.int_meta.source == 1) { |
| 105 | process_int_source.apply(hdr, fabric_metadata, standard_metadata); |
| 106 | } |
| 107 | if(hdr.int_header.isValid()) { |
| 108 | process_int_transit.apply(hdr, fabric_metadata, standard_metadata); |
| 109 | // update underlay header based on INT information inserted |
| 110 | process_int_outer_encap.apply(hdr, fabric_metadata, standard_metadata); |
| 111 | if (standard_metadata.instance_type == PKT_INSTANCE_TYPE_INGRESS_CLONE) { |
| 112 | /* send int report */ |
| 113 | process_int_report.apply(hdr, fabric_metadata, standard_metadata); |
| 114 | } |
| 115 | if (fabric_metadata.int_meta.sink == 1) { |
| 116 | // int sink |
| 117 | process_int_sink.apply(hdr, fabric_metadata, standard_metadata); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | #endif |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | V1Switch( |
| 126 | FabricParser(), |
| 127 | FabricVerifyChecksum(), |
| 128 | FabricIngress(), |
| 129 | FabricEgress(), |
| 130 | FabricComputeChecksum(), |
| 131 | FabricDeparser() |
| 132 | ) main; |