blob: 1a4e3f28da4625896917f1ddeff2d10633d7d5d5 [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
Carmelo Cascone70e816b2019-03-19 16:15:47 -070043 // FIXME: using ternary for eth_dst prevents our ability to scale in
44 // bridging heavy environments. Do we really need ternary? Can we come up
45 // with a multi-table/algorithmic approach?
Yi Tsengbe342052017-11-03 10:21:23 -070046 table bridging {
47 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080048 fabric_metadata.vlan_id: exact @name("vlan_id");
49 hdr.ethernet.dst_addr: ternary @name("eth_dst");
Yi Tsengbe342052017-11-03 10:21:23 -070050 }
Yi Tsengbe342052017-11-03 10:21:23 -070051 actions = {
Yi Tseng47eac892018-07-11 02:17:04 +080052 set_next_id_bridging;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080053 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -070054 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080055 const default_action = nop();
Yi Tseng3a5731e2018-01-22 11:38:58 -080056 counters = bridging_counter;
Carmelo Cascone70e816b2019-03-19 16:15:47 -070057 size = BRIDGING_TABLE_SIZE;
Yi Tsengbe342052017-11-03 10:21:23 -070058 }
59
Yi Tseng47eac892018-07-11 02:17:04 +080060 /*
61 * MPLS Table.
Yi Tseng47eac892018-07-11 02:17:04 +080062 */
63 direct_counter(CounterType.packets_and_bytes) mpls_counter;
64
65 action pop_mpls_and_next(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080066 fabric_metadata.mpls_label = 0;
67 set_next_id(next_id);
Yi Tseng47eac892018-07-11 02:17:04 +080068 mpls_counter.count();
69 }
70
Yi Tsengbe342052017-11-03 10:21:23 -070071 table mpls {
72 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080073 fabric_metadata.mpls_label: exact @name("mpls_label");
Yi Tsengbe342052017-11-03 10:21:23 -070074 }
Yi Tsengbe342052017-11-03 10:21:23 -070075 actions = {
76 pop_mpls_and_next;
Carmelo Casconeb5324e72018-11-25 02:26:32 -080077 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -070078 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -080079 const default_action = nop();
Yi Tseng3a5731e2018-01-22 11:38:58 -080080 counters = mpls_counter;
Carmelo Cascone70e816b2019-03-19 16:15:47 -070081 size = MPLS_TABLE_SIZE;
Yi Tsengbe342052017-11-03 10:21:23 -070082 }
83
Yi Tseng47eac892018-07-11 02:17:04 +080084 /*
Charles Chan384aea22018-08-23 22:08:02 -070085 * IPv4 Routing Table.
Yi Tseng47eac892018-07-11 02:17:04 +080086 */
Daniele Moro5a2de712019-09-24 14:34:07 -070087#ifdef WTIH_DEBUG
Charles Chan384aea22018-08-23 22:08:02 -070088 direct_counter(CounterType.packets_and_bytes) routing_v4_counter;
Daniele Moro5a2de712019-09-24 14:34:07 -070089#endif // WITH_DEBUG
Yi Tseng47eac892018-07-11 02:17:04 +080090
Charles Chan384aea22018-08-23 22:08:02 -070091 action set_next_id_routing_v4(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -080092 set_next_id(next_id);
Daniele Moro5a2de712019-09-24 14:34:07 -070093#ifdef WTIH_DEBUG
Charles Chan384aea22018-08-23 22:08:02 -070094 routing_v4_counter.count();
Daniele Moro5a2de712019-09-24 14:34:07 -070095#endif // WITH_DEBUG
Yi Tseng47eac892018-07-11 02:17:04 +080096 }
97
Charles Chancd03f072018-08-31 17:46:37 -070098 action nop_routing_v4() {
Daniele Moro5a2de712019-09-24 14:34:07 -070099 // no-op
100#ifdef WTIH_DEBUG
Charles Chancd03f072018-08-31 17:46:37 -0700101 routing_v4_counter.count();
Daniele Moro5a2de712019-09-24 14:34:07 -0700102#endif // WITH_DEBUG
Charles Chancd03f072018-08-31 17:46:37 -0700103 }
104
Carmelo Cascone70e816b2019-03-19 16:15:47 -0700105 #ifdef _ROUTING_V4_TABLE_ANNOT
106 _ROUTING_V4_TABLE_ANNOT
107 #endif
Charles Chan384aea22018-08-23 22:08:02 -0700108 table routing_v4 {
Yi Tsengbe342052017-11-03 10:21:23 -0700109 key = {
Robert MacDavidbec6b6a2020-05-21 21:32:38 -0400110 fabric_metadata.ipv4_dst_addr: lpm @name("ipv4_dst");
Yi Tsengbe342052017-11-03 10:21:23 -0700111 }
Yi Tsengbe342052017-11-03 10:21:23 -0700112 actions = {
Charles Chan384aea22018-08-23 22:08:02 -0700113 set_next_id_routing_v4;
Charles Chancd03f072018-08-31 17:46:37 -0700114 nop_routing_v4;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800115 @defaultonly nop;
Yi Tsengbe342052017-11-03 10:21:23 -0700116 }
CyberHasHe9ba39c2019-10-11 05:59:12 +0800117 default_action = nop();
Daniele Moro5a2de712019-09-24 14:34:07 -0700118#ifdef WTIH_DEBUG
Charles Chan384aea22018-08-23 22:08:02 -0700119 counters = routing_v4_counter;
Daniele Moro5a2de712019-09-24 14:34:07 -0700120#endif // WITH_DEBUG
Carmelo Cascone70e816b2019-03-19 16:15:47 -0700121 size = ROUTING_V4_TABLE_SIZE;
Yi Tsengbe342052017-11-03 10:21:23 -0700122 }
123
Yi Tseng47eac892018-07-11 02:17:04 +0800124#ifdef WITH_IPV6
125 /*
Charles Chan384aea22018-08-23 22:08:02 -0700126 * IPv6 Routing Table.
Yi Tseng47eac892018-07-11 02:17:04 +0800127 */
Charles Chan384aea22018-08-23 22:08:02 -0700128 direct_counter(CounterType.packets_and_bytes) routing_v6_counter;
Yi Tseng47eac892018-07-11 02:17:04 +0800129
Charles Chan384aea22018-08-23 22:08:02 -0700130 action set_next_id_routing_v6(next_id_t next_id) {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800131 set_next_id(next_id);
Charles Chan384aea22018-08-23 22:08:02 -0700132 routing_v6_counter.count();
Yi Tseng47eac892018-07-11 02:17:04 +0800133 }
134
Charles Chan384aea22018-08-23 22:08:02 -0700135 table routing_v6 {
Yi Tseng47eac892018-07-11 02:17:04 +0800136 key = {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800137 hdr.ipv6.dst_addr: lpm @name("ipv6_dst");
Yi Tseng47eac892018-07-11 02:17:04 +0800138 }
Yi Tseng47eac892018-07-11 02:17:04 +0800139 actions = {
Charles Chan384aea22018-08-23 22:08:02 -0700140 set_next_id_routing_v6;
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800141 @defaultonly nop;
Yi Tseng47eac892018-07-11 02:17:04 +0800142 }
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800143 const default_action = nop();
Charles Chan384aea22018-08-23 22:08:02 -0700144 counters = routing_v6_counter;
Carmelo Cascone70e816b2019-03-19 16:15:47 -0700145 size = ROUTING_V6_TABLE_SIZE;
Yi Tseng47eac892018-07-11 02:17:04 +0800146 }
Yi Tseng47eac892018-07-11 02:17:04 +0800147#endif // WITH_IPV6
148
Yi Tsengbe342052017-11-03 10:21:23 -0700149 apply {
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800150 if (fabric_metadata.fwd_type == FWD_BRIDGING) bridging.apply();
151 else if (fabric_metadata.fwd_type == FWD_MPLS) mpls.apply();
Charles Chan384aea22018-08-23 22:08:02 -0700152 else if (fabric_metadata.fwd_type == FWD_IPV4_UNICAST) routing_v4.apply();
Carmelo Casconeed88f2b2018-01-26 17:36:34 -0800153#ifdef WITH_IPV6
Charles Chan384aea22018-08-23 22:08:02 -0700154 else if (fabric_metadata.fwd_type == FWD_IPV6_UNICAST) routing_v6.apply();
Carmelo Casconeed88f2b2018-01-26 17:36:34 -0800155#endif // WITH_IPV6
Yi Tsengbe342052017-11-03 10:21:23 -0700156 }
157}