blob: 4e9ada19348a041762e3ab6f5f61fc312518a097 [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
Yi Tsengc6844f52017-12-19 11:58:25 -0800116 fabric_metadata.original_ether_type: ternary; //16
Yi Tseng1d842672017-11-28 16:06:52 -0800117
118 hdr.ethernet.dst_addr: ternary; // 48
119 hdr.ethernet.src_addr: ternary; // 48
Yi Tseng1d842672017-11-28 16:06:52 -0800120 hdr.vlan_tag.vlan_id: ternary; // 12
Yi Tseng1d842672017-11-28 16:06:52 -0800121 hdr.ipv4.src_addr: ternary; // 32
122 hdr.ipv4.dst_addr: ternary; // 32
Yi Tseng1d842672017-11-28 16:06:52 -0800123 hdr.icmp.icmp_type: ternary; // 8
124 hdr.icmp.icmp_code: ternary; // 8
Yi Tsengbe342052017-11-03 10:21:23 -0700125 }
126
127 actions = {
128 set_next_id;
129 duplicate_to_controller;
130 drop;
131 nop;
132 }
133
134 const default_action = nop();
Yi Tseng1d842672017-11-28 16:06:52 -0800135 size = 256;
Yi Tsengbe342052017-11-03 10:21:23 -0700136 }
137
138 apply {
139 if(fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply();
Yi Tseng1d842672017-11-28 16:06:52 -0800140 else if (fabric_metadata.fwd_type == FWD_MPLS) {
141 mpls.apply();
142 if (hdr.ipv4.isValid()) {
143 hdr.ethernet.ether_type = ETHERTYPE_IPV4;
144 fabric_metadata.original_ether_type = ETHERTYPE_IPV4;
145 } else {
146 hdr.ethernet.ether_type = ETHERTYPE_IPV6;
147 fabric_metadata.original_ether_type = ETHERTYPE_IPV6;
148 }
149 }
Yi Tsengbe342052017-11-03 10:21:23 -0700150 else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) unicast_v4.apply();
151 else if (fabric_metadata.fwd_type == FWD_IPV4_MULTICAST) multicast_v4.apply();
152 else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) unicast_v6.apply();
153 else if (fabric_metadata.fwd_type == FWD_IPV6_MULTICAST) multicast_v6.apply();
154 acl.apply();
155 }
156}