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 "../header.p4" |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 21 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 22 | control Next (inout parsed_headers_t hdr, |
| 23 | inout fabric_metadata_t fabric_metadata, |
| 24 | inout standard_metadata_t standard_metadata) { |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 25 | |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 26 | /* |
| 27 | * General actions. |
| 28 | */ |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 29 | @hidden |
| 30 | action output(port_num_t port_num) { |
| 31 | standard_metadata.egress_spec = port_num; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 32 | } |
| 33 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 34 | @hidden |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 35 | action rewrite_smac(mac_addr_t smac) { |
| 36 | hdr.ethernet.src_addr = smac; |
| 37 | } |
| 38 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 39 | @hidden |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 40 | action rewrite_dmac(mac_addr_t dmac) { |
| 41 | hdr.ethernet.dst_addr = dmac; |
| 42 | } |
| 43 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 44 | @hidden |
| 45 | action set_mpls_label(mpls_label_t label) { |
| 46 | fabric_metadata.mpls_label = label; |
| 47 | } |
| 48 | |
| 49 | @hidden |
| 50 | action routing(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac) { |
| 51 | rewrite_smac(smac); |
| 52 | rewrite_dmac(dmac); |
| 53 | output(port_num); |
| 54 | } |
| 55 | |
| 56 | @hidden |
| 57 | action mpls_routing(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac, |
| 58 | mpls_label_t label) { |
| 59 | set_mpls_label(label); |
| 60 | routing(port_num, smac, dmac); |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 63 | /* |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 64 | * Next VLAN table. |
| 65 | * Modify VLAN ID based on next ID. |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 66 | */ |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 67 | direct_counter(CounterType.packets_and_bytes) next_vlan_counter; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 68 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 69 | action set_vlan(vlan_id_t vlan_id) { |
| 70 | fabric_metadata.vlan_id = vlan_id; |
| 71 | next_vlan_counter.count(); |
Yi Tseng | 1b154bd | 2017-11-20 17:48:19 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 74 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 75 | action set_double_vlan(vlan_id_t outer_vlan_id, vlan_id_t inner_vlan_id) { |
| 76 | set_vlan(outer_vlan_id); |
| 77 | fabric_metadata.push_double_vlan = _TRUE; |
| 78 | fabric_metadata.inner_vlan_id = inner_vlan_id; |
| 79 | } |
| 80 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
| 81 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 82 | table next_vlan { |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 83 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 84 | fabric_metadata.next_id: exact @name("next_id"); |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 85 | } |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 86 | actions = { |
| 87 | set_vlan; |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 88 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 89 | set_double_vlan; |
| 90 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 91 | @defaultonly nop; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 92 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 93 | const default_action = nop(); |
| 94 | counters = next_vlan_counter; |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 95 | size = NEXT_VLAN_TABLE_SIZE; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 96 | } |
| 97 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 98 | #ifdef WITH_XCONNECT |
| 99 | /* |
| 100 | * Cross-connect table. |
| 101 | * Bidirectional forwarding for the same next id. |
| 102 | */ |
| 103 | direct_counter(CounterType.packets_and_bytes) xconnect_counter; |
| 104 | |
| 105 | action output_xconnect(port_num_t port_num) { |
| 106 | output(port_num); |
| 107 | xconnect_counter.count(); |
| 108 | } |
| 109 | |
| 110 | action set_next_id_xconnect(next_id_t next_id) { |
| 111 | fabric_metadata.next_id = next_id; |
| 112 | xconnect_counter.count(); |
| 113 | } |
| 114 | |
| 115 | table xconnect { |
| 116 | key = { |
| 117 | standard_metadata.ingress_port: exact @name("ig_port"); |
| 118 | fabric_metadata.next_id: exact @name("next_id"); |
| 119 | } |
| 120 | actions = { |
| 121 | output_xconnect; |
| 122 | set_next_id_xconnect; |
| 123 | @defaultonly nop; |
| 124 | } |
| 125 | counters = xconnect_counter; |
| 126 | const default_action = nop(); |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 127 | size = XCONNECT_NEXT_TABLE_SIZE; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 128 | } |
| 129 | #endif // WITH_XCONNECT |
| 130 | |
| 131 | #ifdef WITH_SIMPLE_NEXT |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 132 | /* |
| 133 | * Simple Table. |
| 134 | * Do a single egress action based on next id. |
| 135 | */ |
| 136 | direct_counter(CounterType.packets_and_bytes) simple_counter; |
| 137 | |
| 138 | action output_simple(port_num_t port_num) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 139 | output(port_num); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 140 | simple_counter.count(); |
| 141 | } |
| 142 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 143 | action routing_simple(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac) { |
| 144 | routing(port_num, smac, dmac); |
| 145 | simple_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 146 | } |
| 147 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 148 | action mpls_routing_simple(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac, |
| 149 | mpls_label_t label) { |
| 150 | mpls_routing(port_num, smac, dmac, label); |
| 151 | simple_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 152 | } |
| 153 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 154 | table simple { |
| 155 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 156 | fabric_metadata.next_id: exact @name("next_id"); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 157 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 158 | actions = { |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 159 | output_simple; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 160 | routing_simple; |
| 161 | mpls_routing_simple; |
| 162 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 163 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 164 | const default_action = nop(); |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 165 | counters = simple_counter; |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 166 | size = SIMPLE_NEXT_TABLE_SIZE; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 167 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 168 | #endif // WITH_SIMPLE_NEXT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 169 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 170 | #ifdef WITH_HASHED_NEXT |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 171 | /* |
| 172 | * Hashed table. |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 173 | * Execute an action profile selector based on next id. |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 174 | */ |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 175 | @max_group_size(HASHED_SELECTOR_MAX_GROUP_SIZE) |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 176 | #ifdef _CUSTOM_HASHED_SELECTOR_ANNOTATION |
| 177 | _CUSTOM_HASHED_SELECTOR_ANNOTATION |
| 178 | #endif |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 179 | action_selector(HashAlgorithm.crc16, HASHED_ACT_PROFILE_SIZE, 32w16) hashed_selector; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 180 | direct_counter(CounterType.packets_and_bytes) hashed_counter; |
| 181 | |
| 182 | action output_hashed(port_num_t port_num) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 183 | output(port_num); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 184 | hashed_counter.count(); |
| 185 | } |
| 186 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 187 | action routing_hashed(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac) { |
| 188 | routing(port_num, smac, dmac); |
| 189 | hashed_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 190 | } |
| 191 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 192 | action mpls_routing_hashed(port_num_t port_num, mac_addr_t smac, mac_addr_t dmac, |
| 193 | mpls_label_t label) { |
| 194 | mpls_routing(port_num, smac, dmac, label); |
| 195 | hashed_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 196 | } |
| 197 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 198 | table hashed { |
| 199 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 200 | fabric_metadata.next_id: exact @name("next_id"); |
Yi Tseng | 3d3956d | 2018-01-31 17:28:05 -0800 | [diff] [blame] | 201 | hdr.ipv4.dst_addr: selector; |
| 202 | hdr.ipv4.src_addr: selector; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 203 | fabric_metadata.ip_proto: selector; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 204 | fabric_metadata.l4_sport: selector; |
| 205 | fabric_metadata.l4_dport: selector; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 206 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 207 | actions = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 208 | output_hashed; |
| 209 | routing_hashed; |
| 210 | mpls_routing_hashed; |
| 211 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 212 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 213 | implementation = hashed_selector; |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 214 | counters = hashed_counter; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 215 | const default_action = nop(); |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 216 | size = HASHED_NEXT_TABLE_SIZE; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 217 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 218 | #endif // WITH_HASHED_NEXT |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 221 | * Multicast |
| 222 | * Maps next IDs to PRE multicat group IDs. |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 223 | */ |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 224 | direct_counter(CounterType.packets_and_bytes) multicast_counter; |
| 225 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 226 | action set_mcast_group_id(mcast_group_id_t group_id) { |
| 227 | standard_metadata.mcast_grp = group_id; |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 228 | fabric_metadata.is_multicast = _TRUE; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 229 | multicast_counter.count(); |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame] | 232 | table multicast { |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 233 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 234 | fabric_metadata.next_id: exact @name("next_id"); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 235 | } |
| 236 | actions = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 237 | set_mcast_group_id; |
| 238 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 239 | } |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame] | 240 | counters = multicast_counter; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 241 | const default_action = nop(); |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 242 | size = MULTICAST_NEXT_TABLE_SIZE; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | apply { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 246 | #ifdef WITH_XCONNECT |
| 247 | // xconnect might set a new next_id. |
| 248 | xconnect.apply(); |
| 249 | #endif // WITH_XCONNECT |
| 250 | #ifdef WITH_SIMPLE_NEXT |
| 251 | simple.apply(); |
| 252 | #endif // WITH_SIMPLE_NEXT |
| 253 | #ifdef WITH_HASHED_NEXT |
| 254 | hashed.apply(); |
| 255 | #endif // WITH_HASHED_NEXT |
| 256 | multicast.apply(); |
| 257 | next_vlan.apply(); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 261 | control EgressNextControl (inout parsed_headers_t hdr, |
| 262 | inout fabric_metadata_t fabric_metadata, |
| 263 | inout standard_metadata_t standard_metadata) { |
| 264 | @hidden |
| 265 | action pop_mpls_if_present() { |
| 266 | hdr.mpls.setInvalid(); |
| 267 | // Assuming there's an IP header after the MPLS one. |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 268 | hdr.eth_type.value = fabric_metadata.ip_eth_type; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @hidden |
| 272 | action set_mpls() { |
| 273 | hdr.mpls.setValid(); |
| 274 | hdr.mpls.label = fabric_metadata.mpls_label; |
| 275 | hdr.mpls.tc = 3w0; |
| 276 | hdr.mpls.bos = 1w1; // BOS = TRUE |
| 277 | hdr.mpls.ttl = fabric_metadata.mpls_ttl; // Decrement after push. |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 278 | hdr.eth_type.value = ETHERTYPE_MPLS; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @hidden |
| 282 | action push_vlan() { |
| 283 | // If VLAN is already valid, we overwrite it with a potentially new VLAN |
| 284 | // ID, and same CFI, PRI, and eth_type values found in ingress. |
| 285 | hdr.vlan_tag.setValid(); |
| 286 | hdr.vlan_tag.cfi = fabric_metadata.vlan_cfi; |
| 287 | hdr.vlan_tag.pri = fabric_metadata.vlan_pri; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 288 | hdr.vlan_tag.eth_type = ETHERTYPE_VLAN; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 289 | hdr.vlan_tag.vlan_id = fabric_metadata.vlan_id; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 290 | } |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 291 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 292 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 293 | @hidden |
| 294 | action push_inner_vlan() { |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 295 | // Push inner VLAN TAG, rewriting correclty the outer vlan eth_type |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 296 | hdr.inner_vlan_tag.setValid(); |
| 297 | hdr.inner_vlan_tag.cfi = fabric_metadata.inner_vlan_cfi; |
| 298 | hdr.inner_vlan_tag.pri = fabric_metadata.inner_vlan_pri; |
| 299 | hdr.inner_vlan_tag.vlan_id = fabric_metadata.inner_vlan_id; |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame^] | 300 | hdr.inner_vlan_tag.eth_type = ETHERTYPE_VLAN; |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 301 | hdr.vlan_tag.eth_type = ETHERTYPE_VLAN; |
| 302 | } |
| 303 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
| 304 | |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 305 | /* |
| 306 | * Egress VLAN Table. |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 307 | * Pops the VLAN tag if the pair egress port and VLAN ID is matched. |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 308 | */ |
| 309 | direct_counter(CounterType.packets_and_bytes) egress_vlan_counter; |
| 310 | |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 311 | action pop_vlan() { |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 312 | hdr.vlan_tag.setInvalid(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 313 | egress_vlan_counter.count(); |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | table egress_vlan { |
| 317 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 318 | fabric_metadata.vlan_id: exact @name("vlan_id"); |
| 319 | standard_metadata.egress_port: exact @name("eg_port"); |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 320 | } |
| 321 | actions = { |
| 322 | pop_vlan; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 323 | @defaultonly nop; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 324 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 325 | const default_action = nop(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 326 | counters = egress_vlan_counter; |
Carmelo Cascone | 70e816b | 2019-03-19 16:15:47 -0700 | [diff] [blame] | 327 | size = EGRESS_VLAN_TABLE_SIZE; |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 328 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 329 | |
| 330 | apply { |
Carmelo Cascone | 1e8843f | 2018-07-19 19:01:12 +0200 | [diff] [blame] | 331 | if (fabric_metadata.is_multicast == _TRUE |
Carmelo Cascone | a5400af | 2018-07-17 22:11:54 +0200 | [diff] [blame] | 332 | && standard_metadata.ingress_port == standard_metadata.egress_port) { |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 333 | mark_to_drop(standard_metadata); |
Carmelo Cascone | a5400af | 2018-07-17 22:11:54 +0200 | [diff] [blame] | 334 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 335 | |
| 336 | if (fabric_metadata.mpls_label == 0) { |
| 337 | if (hdr.mpls.isValid()) pop_mpls_if_present(); |
| 338 | } else { |
| 339 | set_mpls(); |
| 340 | } |
| 341 | |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 342 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
| 343 | if (fabric_metadata.push_double_vlan == _TRUE) { |
| 344 | // Double VLAN termination. |
| 345 | push_vlan(); |
| 346 | push_inner_vlan(); |
| 347 | } else { |
| 348 | // If no push double vlan, inner_vlan_tag must be popped |
| 349 | hdr.inner_vlan_tag.setInvalid(); |
| 350 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
| 351 | // Port-based VLAN tagging (by default all |
| 352 | // ports are assumed tagged) |
| 353 | if (!egress_vlan.apply().hit) { |
| 354 | // Push VLAN tag if not the default one. |
| 355 | if (fabric_metadata.vlan_id != DEFAULT_VLAN_ID) { |
| 356 | push_vlan(); |
| 357 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 358 | } |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 359 | #ifdef WITH_DOUBLE_VLAN_TERMINATION |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 360 | } |
Daniele Moro | 7c3a002 | 2019-07-12 13:38:34 -0700 | [diff] [blame] | 361 | #endif // WITH_DOUBLE_VLAN_TERMINATION |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 362 | |
| 363 | // TTL decrement and check. |
| 364 | if (hdr.mpls.isValid()) { |
| 365 | hdr.mpls.ttl = hdr.mpls.ttl - 1; |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 366 | if (hdr.mpls.ttl == 0) mark_to_drop(standard_metadata); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 367 | } else { |
| 368 | if(hdr.ipv4.isValid()) { |
| 369 | hdr.ipv4.ttl = hdr.ipv4.ttl - 1; |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 370 | if (hdr.ipv4.ttl == 0) mark_to_drop(standard_metadata); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 371 | } |
| 372 | #ifdef WITH_IPV6 |
| 373 | else if (hdr.ipv6.isValid()) { |
| 374 | hdr.ipv6.hop_limit = hdr.ipv6.hop_limit - 1; |
Carmelo Cascone | 9b607da | 2019-05-08 14:03:01 -0700 | [diff] [blame] | 375 | if (hdr.ipv6.hop_limit == 0) mark_to_drop(standard_metadata); |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 376 | } |
| 377 | #endif // WITH_IPV6 |
| 378 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 379 | } |
| 380 | } |