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