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" |
| 22 | #include "../action.p4" |
| 23 | |
| 24 | |
| 25 | control Forwarding ( |
| 26 | inout parsed_headers_t hdr, |
| 27 | inout fabric_metadata_t fabric_metadata, |
| 28 | inout standard_metadata_t standard_metadata) { |
| 29 | |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 30 | direct_counter(CounterType.packets_and_bytes) bridging_counter; |
| 31 | direct_counter(CounterType.packets_and_bytes) mpls_counter; |
| 32 | direct_counter(CounterType.packets_and_bytes) unicast_v4_counter; |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 33 | direct_counter(CounterType.packets_and_bytes) acl_counter; |
| 34 | |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 35 | action drop() { |
| 36 | mark_to_drop(); |
| 37 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 38 | |
| 39 | action set_next_id(next_id_t next_id) { |
| 40 | fabric_metadata.next_id = next_id; |
| 41 | } |
| 42 | |
| 43 | action pop_mpls_and_next(next_id_t next_id) { |
| 44 | hdr.mpls.setInvalid(); |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 45 | fabric_metadata.next_id = next_id; |
| 46 | } |
| 47 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 48 | action duplicate_to_controller() { |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 49 | standard_metadata.egress_spec = CPU_PORT; |
| 50 | } |
| 51 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 52 | table bridging { |
| 53 | key = { |
| 54 | hdr.vlan_tag.vlan_id: exact; |
| 55 | hdr.ethernet.dst_addr: ternary; |
| 56 | } |
| 57 | |
| 58 | actions = { |
| 59 | set_next_id; |
| 60 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 61 | counters = bridging_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | table mpls { |
| 65 | key = { |
| 66 | hdr.mpls.label: exact; |
| 67 | } |
| 68 | |
| 69 | actions = { |
| 70 | pop_mpls_and_next; |
| 71 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 72 | counters = mpls_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | table unicast_v4 { |
| 76 | key = { |
| 77 | hdr.ipv4.dst_addr: lpm; |
| 78 | } |
| 79 | |
| 80 | actions = { |
| 81 | set_next_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 82 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 83 | counters = unicast_v4_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 86 | #ifdef WITH_MULTICAST |
| 87 | direct_counter(CounterType.packets_and_bytes) multicast_v4_counter; |
| 88 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 89 | table multicast_v4 { |
| 90 | key = { |
| 91 | hdr.vlan_tag.vlan_id: exact; |
| 92 | hdr.ipv4.dst_addr: lpm; |
| 93 | } |
| 94 | |
| 95 | actions = { |
| 96 | set_next_id; |
| 97 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 98 | counters = multicast_v4_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 99 | } |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 100 | #endif // WITH_MULTICAST |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 101 | |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 102 | #ifdef WITH_IPV6 |
| 103 | direct_counter(CounterType.packets_and_bytes) unicast_v6_counter; |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 104 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 105 | table unicast_v6 { |
| 106 | key = { |
| 107 | hdr.ipv6.dst_addr: lpm; |
| 108 | } |
| 109 | |
| 110 | actions = { |
| 111 | set_next_id; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 112 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 113 | counters = unicast_v6_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 116 | #ifdef WITH_MULTICAST |
| 117 | direct_counter(CounterType.packets_and_bytes) multicast_v6_counter; |
| 118 | |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 119 | table multicast_v6 { |
| 120 | key = { |
| 121 | hdr.vlan_tag.vlan_id: exact; |
| 122 | hdr.ipv6.dst_addr: lpm; |
| 123 | } |
| 124 | |
| 125 | actions = { |
| 126 | set_next_id; |
| 127 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 128 | counters = multicast_v6_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 129 | } |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 130 | #endif // WITH_MULTICAST |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 131 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 132 | |
| 133 | table acl { |
| 134 | key = { |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 135 | standard_metadata.ingress_port: ternary; // 9 |
| 136 | fabric_metadata.ip_proto: ternary; // 8 |
| 137 | fabric_metadata.l4_src_port: ternary; // 16 |
| 138 | fabric_metadata.l4_dst_port: ternary; // 16 |
Yi Tseng | c6844f5 | 2017-12-19 11:58:25 -0800 | [diff] [blame] | 139 | fabric_metadata.original_ether_type: ternary; //16 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 140 | |
| 141 | hdr.ethernet.dst_addr: ternary; // 48 |
| 142 | hdr.ethernet.src_addr: ternary; // 48 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 143 | hdr.vlan_tag.vlan_id: ternary; // 12 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 144 | hdr.ipv4.src_addr: ternary; // 32 |
| 145 | hdr.ipv4.dst_addr: ternary; // 32 |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 146 | hdr.icmp.icmp_type: ternary; // 8 |
| 147 | hdr.icmp.icmp_code: ternary; // 8 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | actions = { |
| 151 | set_next_id; |
| 152 | duplicate_to_controller; |
| 153 | drop; |
| 154 | nop; |
| 155 | } |
| 156 | |
| 157 | const default_action = nop(); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 158 | size = 256; |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 159 | counters = acl_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | apply { |
| 163 | if(fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply(); |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 164 | else if (fabric_metadata.fwd_type == FWD_MPLS) { |
| 165 | mpls.apply(); |
Yi Tseng | bd46d05 | 2018-01-22 17:18:16 -0800 | [diff] [blame] | 166 | |
| 167 | // TODO: IPv6 |
| 168 | hdr.vlan_tag.ether_type = ETHERTYPE_IPV4; |
| 169 | fabric_metadata.original_ether_type = ETHERTYPE_IPV4; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 170 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 171 | else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) unicast_v4.apply(); |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 172 | #ifdef WITH_MULTICAST |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 173 | else if (fabric_metadata.fwd_type == FWD_IPV4_MULTICAST) multicast_v4.apply(); |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 174 | #endif // WITH_MULTICAST |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 175 | #ifdef WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 176 | else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) unicast_v6.apply(); |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 177 | #ifdef WITH_MULTICAST |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 178 | else if (fabric_metadata.fwd_type == FWD_IPV6_MULTICAST) multicast_v6.apply(); |
Carmelo Cascone | a106140 | 2018-02-03 17:39:59 -0800 | [diff] [blame^] | 179 | #endif // WITH_MULTICAST |
Carmelo Cascone | ed88f2b | 2018-01-26 17:36:34 -0800 | [diff] [blame] | 180 | #endif // WITH_IPV6 |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 181 | acl.apply(); |
| 182 | } |
| 183 | } |