blob: 5a93e5bc41d0f027439695ac4ba9b7ccb062ee76 [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) {
27
Yi Tseng1d842672017-11-28 16:06:52 -080028 action drop() {
29 mark_to_drop();
30 }
Yi Tsengbe342052017-11-03 10:21:23 -070031
32 action set_vlan(vlan_id_t new_vlan_id) {
33 hdr.vlan_tag.vlan_id = new_vlan_id;
34 }
35
36 action push_internal_vlan(vlan_id_t new_vlan_id) {
37 // Add internal VLAN header, will be removed before packet emission.
38 // cfi and pri values are dummy.
39 hdr.vlan_tag.setValid();
40 hdr.vlan_tag.cfi = 0;
41 hdr.vlan_tag.pri = 0;
Yi Tseng1d842672017-11-28 16:06:52 -080042 hdr.vlan_tag.ether_type = hdr.ethernet.ether_type;
43 hdr.ethernet.ether_type = ETHERTYPE_VLAN;
Yi Tsengbe342052017-11-03 10:21:23 -070044 set_vlan(new_vlan_id);
45
46 // pop internal vlan before output
47 fabric_metadata.pop_vlan_at_egress = true;
48 }
49
50 action set_forwarding_type(fwd_type_t fwd_type) {
51 fabric_metadata.fwd_type = fwd_type;
52 }
53
54 // Originally Ingress port and Vlan table in OF-DPA pipeline
55 table ingress_port_vlan {
56 key = {
57 standard_metadata.ingress_port: exact;
58 hdr.vlan_tag.isValid(): exact @name("hdr.vlan_tag.is_valid");
59 hdr.vlan_tag.vlan_id: ternary;
60 }
61
62 actions = {
63 push_internal_vlan;
64 set_vlan;
65 nop;
66 drop;
67 }
68 const default_action = drop();
Yi Tsengbe342052017-11-03 10:21:23 -070069 }
70
71 // Originally TMAC table in OF-DPA pipeline
72 table fwd_classifier {
73 key = {
74 standard_metadata.ingress_port: exact;
75 hdr.ethernet.dst_addr: exact;
Yi Tseng1d842672017-11-28 16:06:52 -080076 fabric_metadata.original_ether_type: exact;
Yi Tsengbe342052017-11-03 10:21:23 -070077 }
78
79 actions = {
80 set_forwarding_type;
81 }
82
83 const default_action = set_forwarding_type(FWD_BRIDGING);
Yi Tsengbe342052017-11-03 10:21:23 -070084 }
85
86 apply {
87 ingress_port_vlan.apply();
88 fwd_classifier.apply();
89 }
90}