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