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" |
| 21 | #include "../action.p4" |
| 22 | |
| 23 | control Filtering ( |
| 24 | inout parsed_headers_t hdr, |
| 25 | inout fabric_metadata_t fabric_metadata, |
| 26 | inout standard_metadata_t standard_metadata) { |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 27 | direct_counter(CounterType.packets_and_bytes) ingress_port_vlan_counter; |
| 28 | direct_counter(CounterType.packets_and_bytes) fwd_classifier_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 29 | |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 30 | action drop() { |
| 31 | mark_to_drop(); |
| 32 | } |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 33 | |
| 34 | action set_vlan(vlan_id_t new_vlan_id) { |
| 35 | hdr.vlan_tag.vlan_id = new_vlan_id; |
| 36 | } |
| 37 | |
| 38 | action push_internal_vlan(vlan_id_t new_vlan_id) { |
| 39 | // Add internal VLAN header, will be removed before packet emission. |
| 40 | // cfi and pri values are dummy. |
| 41 | hdr.vlan_tag.setValid(); |
| 42 | hdr.vlan_tag.cfi = 0; |
| 43 | hdr.vlan_tag.pri = 0; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 44 | hdr.vlan_tag.ether_type = hdr.ethernet.ether_type; |
| 45 | hdr.ethernet.ether_type = ETHERTYPE_VLAN; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 46 | set_vlan(new_vlan_id); |
| 47 | |
Yi Tseng | 20f9e7b | 2018-05-24 23:27:39 +0800 | [diff] [blame] | 48 | // pop internal vlan before packet in |
| 49 | fabric_metadata.pop_vlan_when_packet_in = true; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | action set_forwarding_type(fwd_type_t fwd_type) { |
| 53 | fabric_metadata.fwd_type = fwd_type; |
| 54 | } |
| 55 | |
| 56 | // Originally Ingress port and Vlan table in OF-DPA pipeline |
| 57 | table ingress_port_vlan { |
| 58 | key = { |
| 59 | standard_metadata.ingress_port: exact; |
| 60 | hdr.vlan_tag.isValid(): exact @name("hdr.vlan_tag.is_valid"); |
| 61 | hdr.vlan_tag.vlan_id: ternary; |
| 62 | } |
| 63 | |
| 64 | actions = { |
| 65 | push_internal_vlan; |
| 66 | set_vlan; |
| 67 | nop; |
| 68 | drop; |
| 69 | } |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 70 | |
| 71 | const default_action = nop(); |
| 72 | counters = ingress_port_vlan_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // Originally TMAC table in OF-DPA pipeline |
| 76 | table fwd_classifier { |
| 77 | key = { |
| 78 | standard_metadata.ingress_port: exact; |
| 79 | hdr.ethernet.dst_addr: exact; |
Yi Tseng | 1d84267 | 2017-11-28 16:06:52 -0800 | [diff] [blame] | 80 | fabric_metadata.original_ether_type: exact; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | actions = { |
| 84 | set_forwarding_type; |
| 85 | } |
| 86 | |
| 87 | const default_action = set_forwarding_type(FWD_BRIDGING); |
Yi Tseng | 3a5731e | 2018-01-22 11:38:58 -0800 | [diff] [blame] | 88 | counters = fwd_classifier_counter; |
Yi Tseng | be34205 | 2017-11-03 10:21:23 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | apply { |
| 92 | ingress_port_vlan.apply(); |
| 93 | fwd_classifier.apply(); |
| 94 | } |
| 95 | } |