blob: 055f77b87f2cabc55c3d4b8232ddb9b0b131e969 [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 "../define.p4"
21#include "../header.p4"
22#include "../action.p4"
23
24
25control Forwarding (
26 inout parsed_headers_t hdr,
27 inout fabric_metadata_t fabric_metadata,
28 inout standard_metadata_t standard_metadata) {
29
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_next_id(next_id_t next_id) {
35 fabric_metadata.next_id = next_id;
36 }
37
38 action pop_mpls_and_next(next_id_t next_id) {
39 hdr.mpls.setInvalid();
Yi Tsengbe342052017-11-03 10:21:23 -070040 fabric_metadata.next_id = next_id;
41 }
42
Yi Tsengbe342052017-11-03 10:21:23 -070043 action duplicate_to_controller() {
Yi Tsengbe342052017-11-03 10:21:23 -070044 standard_metadata.egress_spec = CPU_PORT;
45 }
46
Yi Tsengbe342052017-11-03 10:21:23 -070047 table bridging {
48 key = {
49 hdr.vlan_tag.vlan_id: exact;
50 hdr.ethernet.dst_addr: ternary;
51 }
52
53 actions = {
54 set_next_id;
55 }
Yi Tsengbe342052017-11-03 10:21:23 -070056 }
57
58 table mpls {
59 key = {
60 hdr.mpls.label: exact;
61 }
62
63 actions = {
64 pop_mpls_and_next;
65 }
Yi Tsengbe342052017-11-03 10:21:23 -070066 }
67
68 table unicast_v4 {
69 key = {
70 hdr.ipv4.dst_addr: lpm;
71 }
72
73 actions = {
74 set_next_id;
Yi Tsengbe342052017-11-03 10:21:23 -070075 }
Yi Tsengbe342052017-11-03 10:21:23 -070076 }
77
78 table multicast_v4 {
79 key = {
80 hdr.vlan_tag.vlan_id: exact;
81 hdr.ipv4.dst_addr: lpm;
82 }
83
84 actions = {
85 set_next_id;
86 }
Yi Tsengbe342052017-11-03 10:21:23 -070087 }
88
89 table unicast_v6 {
90 key = {
91 hdr.ipv6.dst_addr: lpm;
92 }
93
94 actions = {
95 set_next_id;
Yi Tsengbe342052017-11-03 10:21:23 -070096 }
Yi Tsengbe342052017-11-03 10:21:23 -070097 }
98
99 table multicast_v6 {
100 key = {
101 hdr.vlan_tag.vlan_id: exact;
102 hdr.ipv6.dst_addr: lpm;
103 }
104
105 actions = {
106 set_next_id;
107 }
Yi Tsengbe342052017-11-03 10:21:23 -0700108 }
109
110 table acl {
111 key = {
Yi Tseng1d842672017-11-28 16:06:52 -0800112 standard_metadata.ingress_port: ternary; // 9
113 fabric_metadata.ip_proto: ternary; // 8
114 fabric_metadata.l4_src_port: ternary; // 16
115 fabric_metadata.l4_dst_port: ternary; // 16
116
117 hdr.ethernet.dst_addr: ternary; // 48
118 hdr.ethernet.src_addr: ternary; // 48
119 fabric_metadata.original_ether_type: ternary; //16
120 hdr.vlan_tag.vlan_id: ternary; // 12
121 hdr.mpls.bos: ternary; // 1
122 hdr.mpls.label: ternary; // 20
123 hdr.ipv4.src_addr: ternary; // 32
124 hdr.ipv4.dst_addr: ternary; // 32
125 hdr.ipv6.src_addr: ternary; // 128
126 hdr.ipv6.dst_addr: ternary; // 128
127 hdr.icmp.icmp_type: ternary; // 8
128 hdr.icmp.icmp_code: ternary; // 8
Yi Tsengbe342052017-11-03 10:21:23 -0700129 }
130
131 actions = {
132 set_next_id;
133 duplicate_to_controller;
134 drop;
135 nop;
136 }
137
138 const default_action = nop();
Yi Tseng1d842672017-11-28 16:06:52 -0800139 size = 256;
Yi Tsengbe342052017-11-03 10:21:23 -0700140 }
141
142 apply {
143 if(fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply();
Yi Tseng1d842672017-11-28 16:06:52 -0800144 else if (fabric_metadata.fwd_type == FWD_MPLS) {
145 mpls.apply();
146 if (hdr.ipv4.isValid()) {
147 hdr.ethernet.ether_type = ETHERTYPE_IPV4;
148 fabric_metadata.original_ether_type = ETHERTYPE_IPV4;
149 } else {
150 hdr.ethernet.ether_type = ETHERTYPE_IPV6;
151 fabric_metadata.original_ether_type = ETHERTYPE_IPV6;
152 }
153 }
Yi Tsengbe342052017-11-03 10:21:23 -0700154 else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) unicast_v4.apply();
155 else if (fabric_metadata.fwd_type == FWD_IPV4_MULTICAST) multicast_v4.apply();
156 else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) unicast_v6.apply();
157 else if (fabric_metadata.fwd_type == FWD_IPV6_MULTICAST) multicast_v6.apply();
158 acl.apply();
159 }
160}