blob: 29931918bc5c1edf381aecd95cf777dc289bc368 [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 Tseng3a5731e2018-01-22 11:38:58 -080030 direct_counter(CounterType.packets_and_bytes) bridging_counter;
31 direct_counter(CounterType.packets_and_bytes) mpls_counter;
32 direct_counter(CounterType.packets_and_bytes) unicast_v4_counter;
33 direct_counter(CounterType.packets_and_bytes) multicast_v4_counter;
34 direct_counter(CounterType.packets_and_bytes) unicast_v6_counter;
35 direct_counter(CounterType.packets_and_bytes) multicast_v6_counter;
36 direct_counter(CounterType.packets_and_bytes) acl_counter;
37
Yi Tseng1d842672017-11-28 16:06:52 -080038 action drop() {
39 mark_to_drop();
40 }
Yi Tsengbe342052017-11-03 10:21:23 -070041
42 action set_next_id(next_id_t next_id) {
43 fabric_metadata.next_id = next_id;
44 }
45
46 action pop_mpls_and_next(next_id_t next_id) {
47 hdr.mpls.setInvalid();
Yi Tsengbe342052017-11-03 10:21:23 -070048 fabric_metadata.next_id = next_id;
49 }
50
Yi Tsengbe342052017-11-03 10:21:23 -070051 action duplicate_to_controller() {
Yi Tsengbe342052017-11-03 10:21:23 -070052 standard_metadata.egress_spec = CPU_PORT;
53 }
54
Yi Tsengbe342052017-11-03 10:21:23 -070055 table bridging {
56 key = {
57 hdr.vlan_tag.vlan_id: exact;
58 hdr.ethernet.dst_addr: ternary;
59 }
60
61 actions = {
62 set_next_id;
63 }
Yi Tseng3a5731e2018-01-22 11:38:58 -080064 counters = bridging_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070065 }
66
67 table mpls {
68 key = {
69 hdr.mpls.label: exact;
70 }
71
72 actions = {
73 pop_mpls_and_next;
74 }
Yi Tseng3a5731e2018-01-22 11:38:58 -080075 counters = mpls_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070076 }
77
78 table unicast_v4 {
79 key = {
80 hdr.ipv4.dst_addr: lpm;
81 }
82
83 actions = {
84 set_next_id;
Yi Tsengbe342052017-11-03 10:21:23 -070085 }
Yi Tseng3a5731e2018-01-22 11:38:58 -080086 counters = unicast_v4_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070087 }
88
89 table multicast_v4 {
90 key = {
91 hdr.vlan_tag.vlan_id: exact;
92 hdr.ipv4.dst_addr: lpm;
93 }
94
95 actions = {
96 set_next_id;
97 }
Yi Tseng3a5731e2018-01-22 11:38:58 -080098 counters = multicast_v4_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070099 }
100
101 table unicast_v6 {
102 key = {
103 hdr.ipv6.dst_addr: lpm;
104 }
105
106 actions = {
107 set_next_id;
Yi Tsengbe342052017-11-03 10:21:23 -0700108 }
Yi Tseng3a5731e2018-01-22 11:38:58 -0800109 counters = unicast_v6_counter;
Yi Tsengbe342052017-11-03 10:21:23 -0700110 }
111
112 table multicast_v6 {
113 key = {
114 hdr.vlan_tag.vlan_id: exact;
115 hdr.ipv6.dst_addr: lpm;
116 }
117
118 actions = {
119 set_next_id;
120 }
Yi Tseng3a5731e2018-01-22 11:38:58 -0800121 counters = multicast_v6_counter;
Yi Tsengbe342052017-11-03 10:21:23 -0700122 }
123
124 table acl {
125 key = {
Yi Tseng1d842672017-11-28 16:06:52 -0800126 standard_metadata.ingress_port: ternary; // 9
127 fabric_metadata.ip_proto: ternary; // 8
128 fabric_metadata.l4_src_port: ternary; // 16
129 fabric_metadata.l4_dst_port: ternary; // 16
Yi Tsengc6844f52017-12-19 11:58:25 -0800130 fabric_metadata.original_ether_type: ternary; //16
Yi Tseng1d842672017-11-28 16:06:52 -0800131
132 hdr.ethernet.dst_addr: ternary; // 48
133 hdr.ethernet.src_addr: ternary; // 48
Yi Tseng1d842672017-11-28 16:06:52 -0800134 hdr.vlan_tag.vlan_id: ternary; // 12
Yi Tseng1d842672017-11-28 16:06:52 -0800135 hdr.ipv4.src_addr: ternary; // 32
136 hdr.ipv4.dst_addr: ternary; // 32
Yi Tseng1d842672017-11-28 16:06:52 -0800137 hdr.icmp.icmp_type: ternary; // 8
138 hdr.icmp.icmp_code: ternary; // 8
Yi Tsengbe342052017-11-03 10:21:23 -0700139 }
140
141 actions = {
142 set_next_id;
143 duplicate_to_controller;
144 drop;
145 nop;
146 }
147
148 const default_action = nop();
Yi Tseng1d842672017-11-28 16:06:52 -0800149 size = 256;
Yi Tseng3a5731e2018-01-22 11:38:58 -0800150 counters = acl_counter;
Yi Tsengbe342052017-11-03 10:21:23 -0700151 }
152
153 apply {
154 if(fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply();
Yi Tseng1d842672017-11-28 16:06:52 -0800155 else if (fabric_metadata.fwd_type == FWD_MPLS) {
156 mpls.apply();
Yi Tsengbd46d052018-01-22 17:18:16 -0800157
158 // TODO: IPv6
159 hdr.vlan_tag.ether_type = ETHERTYPE_IPV4;
160 fabric_metadata.original_ether_type = ETHERTYPE_IPV4;
Yi Tseng1d842672017-11-28 16:06:52 -0800161 }
Yi Tsengbe342052017-11-03 10:21:23 -0700162 else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) unicast_v4.apply();
163 else if (fabric_metadata.fwd_type == FWD_IPV4_MULTICAST) multicast_v4.apply();
164 else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) unicast_v6.apply();
165 else if (fabric_metadata.fwd_type == FWD_IPV6_MULTICAST) multicast_v6.apply();
166 acl.apply();
167 }
168}