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 "../define.p4" | ||||
21 | #include "../header.p4" | ||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 22 | |
23 | |||||
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 24 | control Forwarding (inout parsed_headers_t hdr, |
25 | inout fabric_metadata_t fabric_metadata, | ||||
26 | inout standard_metadata_t standard_metadata) { | ||||
27 | |||||
28 | @hidden | ||||
29 | action set_next_id(next_id_t next_id) { | ||||
30 | fabric_metadata.next_id = next_id; | ||||
31 | } | ||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 32 | |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 33 | /* |
34 | * Bridging Table. | ||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 35 | */ |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 36 | direct_counter(CounterType.packets_and_bytes) bridging_counter; |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 37 | |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 38 | action set_next_id_bridging(next_id_t next_id) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 39 | set_next_id(next_id); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 40 | bridging_counter.count(); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 41 | } |
42 | |||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 43 | table bridging { |
44 | key = { | ||||
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 45 | fabric_metadata.vlan_id: exact @name("vlan_id"); |
46 | hdr.ethernet.dst_addr: ternary @name("eth_dst"); | ||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 47 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 48 | actions = { |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 49 | set_next_id_bridging; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 50 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 51 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 52 | const default_action = nop(); |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 53 | counters = bridging_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 54 | } |
55 | |||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 56 | /* |
57 | * MPLS Table. | ||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 58 | */ |
59 | direct_counter(CounterType.packets_and_bytes) mpls_counter; | ||||
60 | |||||
61 | action pop_mpls_and_next(next_id_t next_id) { | ||||
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 62 | fabric_metadata.mpls_label = 0; |
63 | set_next_id(next_id); | ||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 64 | mpls_counter.count(); |
65 | } | ||||
66 | |||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 67 | table mpls { |
68 | key = { | ||||
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 69 | fabric_metadata.mpls_label: exact @name("mpls_label"); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 70 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 71 | actions = { |
72 | pop_mpls_and_next; | ||||
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 73 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 74 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 75 | const default_action = nop(); |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 76 | counters = mpls_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 77 | } |
78 | |||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 79 | /* |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 80 | * IPv4 Routing Table. |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 81 | */ |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 82 | direct_counter(CounterType.packets_and_bytes) routing_v4_counter; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 83 | |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 84 | action set_next_id_routing_v4(next_id_t next_id) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 85 | set_next_id(next_id); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 86 | routing_v4_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 87 | } |
88 | |||||
Charles Chan | cd03f07 | 2018-08-31 17:46:37 -0700 | [diff] [blame] | 89 | action nop_routing_v4() { |
90 | routing_v4_counter.count(); | ||||
91 | } | ||||
92 | |||||
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 93 | table routing_v4 { |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 94 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 95 | hdr.ipv4.dst_addr: lpm @name("ipv4_dst"); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 96 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 97 | actions = { |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 98 | set_next_id_routing_v4; |
Charles Chan | cd03f07 | 2018-08-31 17:46:37 -0700 | [diff] [blame] | 99 | nop_routing_v4; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 100 | @defaultonly nop; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 101 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 102 | const default_action = nop(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 103 | counters = routing_v4_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 104 | } |
105 | |||||
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 106 | #ifdef WITH_IPV6 |
107 | /* | ||||
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 108 | * IPv6 Routing Table. |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 109 | */ |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 110 | direct_counter(CounterType.packets_and_bytes) routing_v6_counter; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 111 | |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 112 | action set_next_id_routing_v6(next_id_t next_id) { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 113 | set_next_id(next_id); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 114 | routing_v6_counter.count(); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 115 | } |
116 | |||||
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 117 | table routing_v6 { |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 118 | key = { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 119 | hdr.ipv6.dst_addr: lpm @name("ipv6_dst"); |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 120 | } |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 121 | actions = { |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 122 | set_next_id_routing_v6; |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 123 | @defaultonly nop; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 124 | } |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 125 | const default_action = nop(); |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 126 | counters = routing_v6_counter; |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 127 | } |
Yi Tseng | 47eac89 | 2018-07-11 02:17:04 +0800 | [diff] [blame] | 128 | #endif // WITH_IPV6 |
129 | |||||
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 130 | apply { |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame^] | 131 | if (fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply(); |
132 | else if (fabric_metadata.fwd_type == FWD_MPLS) mpls.apply(); | ||||
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 133 | else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) routing_v4.apply(); |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 134 | #ifdef WITH_IPV6 |
Charles Chan | 384aea2 | 2018-08-23 22:08:02 -0700 | [diff] [blame] | 135 | else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) routing_v6.apply(); |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 136 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 137 | } |
138 | } |