blob: c5030d7f2d3a28390efefbd9ada407b4472f23d3 [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 Tseng47eac892018-07-11 02:17:04 +080027
28 /*
29 * Ingress Port VLAN Table.
30 * Process packets for different interfaces (Port number + VLAN).
31 * For example, an untagged packet will be tagged when it entered to an
32 * interface with untagged VLAN configuration.
33 */
Yi Tseng3a5731e2018-01-22 11:38:58 -080034 direct_counter(CounterType.packets_and_bytes) ingress_port_vlan_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070035
Yi Tseng1d842672017-11-28 16:06:52 -080036 action drop() {
37 mark_to_drop();
Yi Tseng47eac892018-07-11 02:17:04 +080038 ingress_port_vlan_counter.count();
Yi Tseng1d842672017-11-28 16:06:52 -080039 }
Yi Tsengbe342052017-11-03 10:21:23 -070040
41 action set_vlan(vlan_id_t new_vlan_id) {
42 hdr.vlan_tag.vlan_id = new_vlan_id;
Yi Tseng47eac892018-07-11 02:17:04 +080043 ingress_port_vlan_counter.count();
Yi Tsengbe342052017-11-03 10:21:23 -070044 }
45
46 action push_internal_vlan(vlan_id_t new_vlan_id) {
47 // Add internal VLAN header, will be removed before packet emission.
48 // cfi and pri values are dummy.
49 hdr.vlan_tag.setValid();
50 hdr.vlan_tag.cfi = 0;
51 hdr.vlan_tag.pri = 0;
Yi Tseng1d842672017-11-28 16:06:52 -080052 hdr.vlan_tag.ether_type = hdr.ethernet.ether_type;
53 hdr.ethernet.ether_type = ETHERTYPE_VLAN;
Yi Tseng47eac892018-07-11 02:17:04 +080054 hdr.vlan_tag.vlan_id = new_vlan_id;
Yi Tsengbe342052017-11-03 10:21:23 -070055
Yi Tseng20f9e7b2018-05-24 23:27:39 +080056 // pop internal vlan before packet in
Carmelo Cascone35d9b332018-06-15 16:27:22 +020057 fabric_metadata.pop_vlan_when_packet_in = _TRUE;
Yi Tseng47eac892018-07-11 02:17:04 +080058 ingress_port_vlan_counter.count();
Yi Tsengbe342052017-11-03 10:21:23 -070059 }
60
Yi Tsengbe342052017-11-03 10:21:23 -070061 table ingress_port_vlan {
62 key = {
63 standard_metadata.ingress_port: exact;
64 hdr.vlan_tag.isValid(): exact @name("hdr.vlan_tag.is_valid");
65 hdr.vlan_tag.vlan_id: ternary;
66 }
67
68 actions = {
69 push_internal_vlan;
70 set_vlan;
Yi Tseng47eac892018-07-11 02:17:04 +080071 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -070072 drop;
73 }
Yi Tseng3a5731e2018-01-22 11:38:58 -080074
75 const default_action = nop();
76 counters = ingress_port_vlan_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070077 }
78
Yi Tseng47eac892018-07-11 02:17:04 +080079 /*
80 * Forwarding Classifier.
81 * Setup Forwarding Type metadata for Forwarding control block.
82 * There are six types of tables in Forwarding control block:
83 * - Bridging: default forwarding type
84 * - MPLS: destination mac address is the router mac and ethernet type is
85 * MPLS(0x8847)
86 * - IP Multicast: destination mac address is multicast address and ethernet
87 * type is IP(0x0800 or 0x86dd)
88 * - IP Unicast: destination mac address is router mac and ethernet type is
89 * IP(0x0800 or 0x86dd)
90 */
91 direct_counter(CounterType.packets_and_bytes) fwd_classifier_counter;
92
93 action set_forwarding_type(fwd_type_t fwd_type) {
94 fabric_metadata.fwd_type = fwd_type;
95 fwd_classifier_counter.count();
96 }
97
Yi Tsengbe342052017-11-03 10:21:23 -070098 table fwd_classifier {
99 key = {
100 standard_metadata.ingress_port: exact;
101 hdr.ethernet.dst_addr: exact;
Yi Tseng8235a1a2018-07-24 20:57:28 +0800102 hdr.vlan_tag.ether_type: exact;
Yi Tsengbe342052017-11-03 10:21:23 -0700103 }
104
105 actions = {
106 set_forwarding_type;
107 }
108
109 const default_action = set_forwarding_type(FWD_BRIDGING);
Yi Tseng3a5731e2018-01-22 11:38:58 -0800110 counters = fwd_classifier_counter;
Yi Tsengbe342052017-11-03 10:21:23 -0700111 }
112
113 apply {
114 ingress_port_vlan.apply();
115 fwd_classifier.apply();
116 }
117}