blob: e5f89cb53bb0d792688ab05cdec2fa9f074fb860 [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"
Yi Tsengbe342052017-11-03 10:21:23 -070022
23
Carmelo Casconeb5324e72018-11-25 02:26:32 -080024control Forwarding (inout parsed_headers_t hdr,
25 inout fabric_metadata_t fabric_metadata,
26 inout standard_metadata_t standard_metadata) {
27
28 @hidden
29 action set_next_id(next_id_t next_id) {
30 fabric_metadata.next_id = next_id;
31 }
Yi Tsengbe342052017-11-03 10:21:23 -070032
Yi Tseng47eac892018-07-11 02:17:04 +080033 /*
34 * Bridging Table.
Yi Tseng47eac892018-07-11 02:17:04 +080035 */
Yi Tseng3a5731e2018-01-22 11:38:58 -080036 direct_counter(CounterType.packets_and_bytes) bridging_counter;
Yi Tseng3a5731e2018-01-22 11:38:58 -080037
Yi Tseng47eac892018-07-11 02:17:04 +080038 action set_next_id_bridging(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080039 set_next_id(next_id);
Yi Tseng47eac892018-07-11 02:17:04 +080040 bridging_counter.count();
Yi Tsengbe342052017-11-03 10:21:23 -070041 }
42
Yi Tsengbe342052017-11-03 10:21:23 -070043 table bridging {
44 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080045 fabric_metadata.vlan_id: exact @name("vlan_id");
46 hdr.ethernet.dst_addr: ternary @name("eth_dst");
Yi Tsengbe342052017-11-03 10:21:23 -070047 }
Yi Tsengbe342052017-11-03 10:21:23 -070048 actions = {
Yi Tseng47eac892018-07-11 02:17:04 +080049 set_next_id_bridging;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080050 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -070051 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080052 const default_action = nop();
Yi Tseng3a5731e2018-01-22 11:38:58 -080053 counters = bridging_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070054 }
55
Yi Tseng47eac892018-07-11 02:17:04 +080056 /*
57 * MPLS Table.
Yi Tseng47eac892018-07-11 02:17:04 +080058 */
59 direct_counter(CounterType.packets_and_bytes) mpls_counter;
60
61 action pop_mpls_and_next(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080062 fabric_metadata.mpls_label = 0;
63 set_next_id(next_id);
Yi Tseng47eac892018-07-11 02:17:04 +080064 mpls_counter.count();
65 }
66
Yi Tsengbe342052017-11-03 10:21:23 -070067 table mpls {
68 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080069 fabric_metadata.mpls_label: exact @name("mpls_label");
Yi Tsengbe342052017-11-03 10:21:23 -070070 }
Yi Tsengbe342052017-11-03 10:21:23 -070071 actions = {
72 pop_mpls_and_next;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080073 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -070074 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080075 const default_action = nop();
Yi Tseng3a5731e2018-01-22 11:38:58 -080076 counters = mpls_counter;
Yi Tsengbe342052017-11-03 10:21:23 -070077 }
78
Yi Tseng47eac892018-07-11 02:17:04 +080079 /*
Charles Chan384aea22018-08-23 22:08:02 -070080 * IPv4 Routing Table.
Yi Tseng47eac892018-07-11 02:17:04 +080081 */
Charles Chan384aea22018-08-23 22:08:02 -070082 direct_counter(CounterType.packets_and_bytes) routing_v4_counter;
Yi Tseng47eac892018-07-11 02:17:04 +080083
Charles Chan384aea22018-08-23 22:08:02 -070084 action set_next_id_routing_v4(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080085 set_next_id(next_id);
Charles Chan384aea22018-08-23 22:08:02 -070086 routing_v4_counter.count();
Yi Tseng47eac892018-07-11 02:17:04 +080087 }
88
Charles Chancd03f072018-08-31 17:46:37 -070089 action nop_routing_v4() {
90 routing_v4_counter.count();
91 }
92
Charles Chan384aea22018-08-23 22:08:02 -070093 table routing_v4 {
Yi Tsengbe342052017-11-03 10:21:23 -070094 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080095 hdr.ipv4.dst_addr: lpm @name("ipv4_dst");
Yi Tsengbe342052017-11-03 10:21:23 -070096 }
Yi Tsengbe342052017-11-03 10:21:23 -070097 actions = {
Charles Chan384aea22018-08-23 22:08:02 -070098 set_next_id_routing_v4;
Charles Chancd03f072018-08-31 17:46:37 -070099 nop_routing_v4;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800100 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -0700101 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800102 const default_action = nop();
Charles Chan384aea22018-08-23 22:08:02 -0700103 counters = routing_v4_counter;
Yi Tsengbe342052017-11-03 10:21:23 -0700104 }
105
Yi Tseng47eac892018-07-11 02:17:04 +0800106#ifdef WITH_IPV6
107 /*
Charles Chan384aea22018-08-23 22:08:02 -0700108 * IPv6 Routing Table.
Yi Tseng47eac892018-07-11 02:17:04 +0800109 */
Charles Chan384aea22018-08-23 22:08:02 -0700110 direct_counter(CounterType.packets_and_bytes) routing_v6_counter;
Yi Tseng47eac892018-07-11 02:17:04 +0800111
Charles Chan384aea22018-08-23 22:08:02 -0700112 action set_next_id_routing_v6(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800113 set_next_id(next_id);
Charles Chan384aea22018-08-23 22:08:02 -0700114 routing_v6_counter.count();
Yi Tseng47eac892018-07-11 02:17:04 +0800115 }
116
Charles Chan384aea22018-08-23 22:08:02 -0700117 table routing_v6 {
Yi Tseng47eac892018-07-11 02:17:04 +0800118 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800119 hdr.ipv6.dst_addr: lpm @name("ipv6_dst");
Yi Tseng47eac892018-07-11 02:17:04 +0800120 }
Yi Tseng47eac892018-07-11 02:17:04 +0800121 actions = {
Charles Chan384aea22018-08-23 22:08:02 -0700122 set_next_id_routing_v6;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800123 @defaultonly nop;
Yi Tseng47eac892018-07-11 02:17:04 +0800124 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800125 const default_action = nop();
Charles Chan384aea22018-08-23 22:08:02 -0700126 counters = routing_v6_counter;
Yi Tseng47eac892018-07-11 02:17:04 +0800127 }
Yi Tseng47eac892018-07-11 02:17:04 +0800128#endif // WITH_IPV6
129
Yi Tsengbe342052017-11-03 10:21:23 -0700130 apply {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800131 if (fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply();
132 else if (fabric_metadata.fwd_type == FWD_MPLS) mpls.apply();
Charles Chan384aea22018-08-23 22:08:02 -0700133 else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) routing_v4.apply();
Carmelo Casconeed88f2b2018-01-26 17:36:34 -0800134#ifdef WITH_IPV6
Charles Chan384aea22018-08-23 22:08:02 -0700135 else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) routing_v6.apply();
Carmelo Casconeed88f2b2018-01-26 17:36:34 -0800136#endif // WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700137 }
138}