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) { |
| 27 | |
| 28 | direct_counter(CounterType.packets_and_bytes) ingress_port_vlan_counter; |
| 29 | direct_counter(CounterType.packets_and_bytes) fwd_classifier_counter; |
| 30 | |
| 31 | action set_vlan(vlan_id_t new_vlan_id) { |
| 32 | hdr.vlan_tag.vlan_id = new_vlan_id; |
| 33 | } |
| 34 | |
| 35 | action push_internal_vlan(vlan_id_t new_vlan_id) { |
| 36 | // Add internal VLAN header, will be removed before packet emission. |
| 37 | // cfi and pri values are dummy. |
| 38 | hdr.vlan_tag.setValid(); |
| 39 | hdr.vlan_tag.cfi = 0; |
| 40 | hdr.vlan_tag.pri = 0; |
| 41 | hdr.vlan_tag.ether_type = ETHERTYPE_VLAN; |
| 42 | set_vlan(new_vlan_id); |
| 43 | |
| 44 | // pop internal vlan before output |
| 45 | fabric_metadata.pop_vlan_at_egress = true; |
| 46 | } |
| 47 | |
| 48 | action set_forwarding_type(fwd_type_t fwd_type) { |
| 49 | fabric_metadata.fwd_type = fwd_type; |
| 50 | } |
| 51 | |
| 52 | // Originally Ingress port and Vlan table in OF-DPA pipeline |
| 53 | table ingress_port_vlan { |
| 54 | key = { |
| 55 | standard_metadata.ingress_port: exact; |
| 56 | hdr.vlan_tag.isValid(): exact @name("hdr.vlan_tag.is_valid"); |
| 57 | hdr.vlan_tag.vlan_id: ternary; |
| 58 | } |
| 59 | |
| 60 | actions = { |
| 61 | push_internal_vlan; |
| 62 | set_vlan; |
| 63 | nop; |
| 64 | drop; |
| 65 | } |
| 66 | const default_action = drop(); |
| 67 | counters = ingress_port_vlan_counter; |
| 68 | } |
| 69 | |
| 70 | // Originally TMAC table in OF-DPA pipeline |
| 71 | table fwd_classifier { |
| 72 | key = { |
| 73 | standard_metadata.ingress_port: exact; |
| 74 | hdr.ethernet.dst_addr: exact; |
| 75 | hdr.ethernet.ether_type: exact; |
| 76 | } |
| 77 | |
| 78 | actions = { |
| 79 | set_forwarding_type; |
| 80 | } |
| 81 | |
| 82 | const default_action = set_forwarding_type(FWD_BRIDGING); |
| 83 | counters = fwd_classifier_counter; |
| 84 | } |
| 85 | |
| 86 | apply { |
| 87 | ingress_port_vlan.apply(); |
| 88 | fwd_classifier.apply(); |
| 89 | } |
| 90 | } |