blob: 58bf147295d5f0a3369c36366cf0f20744993cd8 [file] [log] [blame]
Yi Tsengbe342052017-11-03 10:21:23 -07001/*
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
23control Filtering (
24 inout parsed_headers_t hdr,
25 inout fabric_metadata_t fabric_metadata,
26 inout standard_metadata_t standard_metadata) {
Yi Tseng3a5731e2018-01-22 11:38:58 -080027 direct_counter(CounterType.packets_and_bytes) ingress_port_vlan_counter;
28 direct_counter(CounterType.packets_and_bytes) fwd_classifier_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070029
Yi Tseng1d842672017-11-28 16:06:52 -080030 action drop() {
31 mark_to_drop();
32 }
Yi Tsengbe342052017-11-03 10:21:23 -070033
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 Tseng1d842672017-11-28 16:06:52 -080044 hdr.vlan_tag.ether_type = hdr.ethernet.ether_type;
45 hdr.ethernet.ether_type = ETHERTYPE_VLAN;
Yi Tsengbe342052017-11-03 10:21:23 -070046 set_vlan(new_vlan_id);
47
48 // pop internal vlan before output
49 fabric_metadata.pop_vlan_at_egress = true;
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 Tseng3a5731e2018-01-22 11:38:58 -080070
71 const default_action = nop();
72 counters = ingress_port_vlan_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070073 }
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 Tseng1d842672017-11-28 16:06:52 -080080 fabric_metadata.original_ether_type: exact;
Yi Tsengbe342052017-11-03 10:21:23 -070081 }
82
83 actions = {
84 set_forwarding_type;
85 }
86
87 const default_action = set_forwarding_type(FWD_BRIDGING);
Yi Tseng3a5731e2018-01-22 11:38:58 -080088 counters = fwd_classifier_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070089 }
90
91 apply {
92 ingress_port_vlan.apply();
93 fwd_classifier.apply();
94 }
95}