blob: 082d210b9725c0976b7ee56309b283b98ccc2d7b [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * l2_bd.h : layer 2 bridge domain
3 *
4 * Copyright (c) 2013 Cisco and/or its affiliates.
Laszlo Kiraly0f8f4352022-09-16 13:20:07 +02005 * Copyright (c) 2022 Nordix Foundation.
Ed Warnickecb9cada2015-12-08 15:45:58 -07006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef included_l2bd_h
20#define included_l2bd_h
21
22#include <vlib/vlib.h>
23#include <vnet/vnet.h>
Neale Rannscbe25aa2019-09-30 10:53:31 +000024#include <vnet/ip/ip46_address.h>
Neale Ranns4d5b9172018-10-24 02:57:49 -070025#include <vnet/ethernet/mac_address.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
Neale Rannsb4743802018-09-05 09:13:57 -070027typedef enum l2_bd_port_type_t_
28{
29 L2_BD_PORT_TYPE_NORMAL = 0,
30 L2_BD_PORT_TYPE_BVI = 1,
31 L2_BD_PORT_TYPE_UU_FWD = 2,
32} l2_bd_port_type_t;
33
Dave Barach97d8dc22016-08-15 15:31:15 -040034typedef struct
35{
36 /* hash bd_id -> bd_index */
37 uword *bd_index_by_bd_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070038
Dave Barach97d8dc22016-08-15 15:31:15 -040039 /* Busy bd_index bitmap */
40 uword *bd_index_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070041
Dave Barach97d8dc22016-08-15 15:31:15 -040042 /* convenience */
43 vlib_main_t *vlib_main;
44 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070045} bd_main_t;
46
Eyal Bari942402b2017-07-26 11:57:04 +030047extern bd_main_t bd_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070048
Dave Barach97d8dc22016-08-15 15:31:15 -040049/* Bridge domain member */
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
51#define L2_FLOOD_MEMBER_NORMAL 0
52#define L2_FLOOD_MEMBER_BVI 1
53
Dave Barach97d8dc22016-08-15 15:31:15 -040054typedef struct
55{
56 u32 sw_if_index; /* the output L2 interface */
57 u8 flags; /* 0=normal, 1=bvi */
58 u8 shg; /* split horizon group number */
59 u16 spare;
Ed Warnickecb9cada2015-12-08 15:45:58 -070060} l2_flood_member_t;
61
Dave Barach97d8dc22016-08-15 15:31:15 -040062/* Per-bridge domain configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -070063
Dave Barach97d8dc22016-08-15 15:31:15 -040064typedef struct
65{
Dave Barach97d8dc22016-08-15 15:31:15 -040066 /*
67 * Contains bit enables for flooding, learning, and forwarding.
68 * All other feature bits should always be set.
Neale Rannsb4743802018-09-05 09:13:57 -070069 */
70 u32 feature_bitmap;
71 /*
Dave Barach97d8dc22016-08-15 15:31:15 -040072 * identity of the bridge-domain's BVI interface
73 * set to ~0 if there is no BVI
74 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070075 u32 bvi_sw_if_index;
76
Neale Rannsb4743802018-09-05 09:13:57 -070077 /*
78 * identity of the bridge-domain's UU flood interface
79 * set to ~0 if there is no such configuration
80 */
81 u32 uu_fwd_sw_if_index;
82
Dave Barach97d8dc22016-08-15 15:31:15 -040083 /* bridge domain id, not to be confused with bd_index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 u32 bd_id;
85
Eyal Baric5b13602016-11-24 19:42:43 +020086 /* Vector of member ports */
Dave Barach97d8dc22016-08-15 15:31:15 -040087 l2_flood_member_t *members;
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
Eyal Baric5b13602016-11-24 19:42:43 +020089 /* First flood_count member ports are flooded */
90 u32 flood_count;
91
92 /* Tunnel Master (Multicast vxlan) are always flooded */
93 u32 tun_master_count;
94
95 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
96 u32 tun_normal_count;
97
Neale Ranns87dad112018-04-09 01:53:01 -070098 /* Interface on which packets are not flooded */
99 u32 no_flood_count;
100
John Lo1edfba92016-08-27 01:11:57 -0400101 /* hash ip4/ip6 -> mac for arp/nd termination */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 uword *mac_by_ip4;
103 uword *mac_by_ip6;
104
Damjan Mariond171d482016-12-05 14:16:38 +0100105 /* mac aging */
106 u8 mac_age;
107
John Loda1f2c72017-03-24 20:11:15 -0400108 /* sequence number for bridge domain based flush of MACs */
109 u8 seq_num;
110
Jerome Tollet48304142017-09-05 12:13:22 +0100111 /* Bridge domain tag (C string NULL terminated) */
112 u8 *bd_tag;
113
Jerome Tollet5f93e3b2020-12-18 09:44:24 +0100114 /* Maximum number of learned entries */
115 u32 learn_limit;
116
117 /* Current number of learned entries */
118 u32 learn_count;
119
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120} l2_bridge_domain_t;
121
John Lo97934772017-05-18 22:26:47 -0400122/* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
123#define L2_BD_ID_MAX ((1<<24)-1)
124
Choonho Son05480792017-03-29 20:07:45 +0900125typedef struct
126{
127 u32 bd_id;
128 u8 flood;
129 u8 uu_flood;
130 u8 forward;
131 u8 learn;
132 u8 arp_term;
Mohsin Kazmi5e6f7342019-04-05 17:40:20 +0200133 u8 arp_ufwd;
Choonho Son05480792017-03-29 20:07:45 +0900134 u8 mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +0100135 u8 *bd_tag;
Choonho Son05480792017-03-29 20:07:45 +0900136 u8 is_add;
137} l2_bridge_domain_add_del_args_t;
138
Dave Barach97d8dc22016-08-15 15:31:15 -0400139/* Return 1 if bridge domain has been initialized */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140always_inline u32
Dave Barach97d8dc22016-08-15 15:31:15 -0400141bd_is_valid (l2_bridge_domain_t * bd_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142{
143 return (bd_config->feature_bitmap != 0);
144}
145
Dave Barach97d8dc22016-08-15 15:31:15 -0400146/* Init bridge domain if not done already */
147void bd_validate (l2_bridge_domain_t * bd_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148
Ed Warnickecb9cada2015-12-08 15:45:58 -0700149void
Dave Barach97d8dc22016-08-15 15:31:15 -0400150bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151
Dave Barach97d8dc22016-08-15 15:31:15 -0400152u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700153
Neale Rannsb4743802018-09-05 09:13:57 -0700154typedef enum bd_flags_t_
155{
156 L2_NONE = 0,
157 L2_LEARN = (1 << 0),
158 L2_FWD = (1 << 1),
159 L2_FLOOD = (1 << 2),
160 L2_UU_FLOOD = (1 << 3),
161 L2_ARP_TERM = (1 << 4),
Mohsin Kazmi5e6f7342019-04-05 17:40:20 +0200162 L2_ARP_UFWD = (1 << 5),
Neale Rannsb4743802018-09-05 09:13:57 -0700163} bd_flags_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
Neale Rannsb4743802018-09-05 09:13:57 -0700165u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags,
166 u32 enable);
Damjan Mariond171d482016-12-05 14:16:38 +0100167void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
Jerome Tollet5f93e3b2020-12-18 09:44:24 +0100168void bd_set_learn_limit (vlib_main_t *vm, u32 bd_index, u32 learn_limit);
Eyal Barib1352ed2017-04-07 23:14:17 +0300169int bd_add_del (l2_bridge_domain_add_del_args_t * args);
Laszlo Kiraly0f8f4352022-09-16 13:20:07 +0200170u32 bd_get_unused_id (void);
Eyal Barib1352ed2017-04-07 23:14:17 +0300171/**
172 * \brief Get a bridge domain.
173 *
174 * Get a bridge domain with the given bridge domain ID.
175 *
176 * \param bdm bd_main pointer.
177 * \param bd_id The bridge domain ID
178 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
179 */
180u32 bd_find_index (bd_main_t * bdm, u32 bd_id);
181
182/**
183 * \brief Create a bridge domain.
184 *
185 * Create a bridge domain with the given bridge domain ID
186 *
187 * \param bdm bd_main pointer.
188 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
189 */
190u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100192/**
193 * \brief Get or create a bridge domain.
194 *
Eyal Barib1352ed2017-04-07 23:14:17 +0300195 * Get a bridge domain with the given bridge domain ID, if one exists, otherwise
196 * create one with the given ID, or the first unused ID if the given ID is ~0..
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100197 *
198 * \param bdm bd_main pointer.
Eyal Barib1352ed2017-04-07 23:14:17 +0300199 * \param bd_id The bridge domain ID
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100200 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
201 */
Eyal Barib1352ed2017-04-07 23:14:17 +0300202static inline u32
203bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
204{
205 u32 bd_index = bd_find_index (bdm, bd_id);
206 if (bd_index == ~0)
207 return bd_add_bd_index (bdm, bd_id);
208 return bd_index;
209}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210
Neale Ranns47a3d992020-09-29 15:38:51 +0000211/**
212 * \brief Walk all the input interfaces in the BD
213 */
214typedef walk_rc_t (*bd_input_walk_fn_t) (u32 bd_index, u32 sw_if_index);
215
216u32 bd_input_walk (u32 bd_index, bd_input_walk_fn_t fn, void *data);
217
218l2_bridge_domain_t *bd_get (u32 bd_index);
219l2_bridge_domain_t *bd_get_by_table_id (u32 table_id);
220
Dave Barach97d8dc22016-08-15 15:31:15 -0400221u32 bd_add_del_ip_mac (u32 bd_index,
Neale Ranns4d5b9172018-10-24 02:57:49 -0700222 ip46_type_t type,
223 const ip46_address_t * ip_addr,
224 const mac_address_t * mac, u8 is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225
John Loe26c81f2019-01-07 15:16:33 -0500226void bd_flush_ip_mac (u32 bd_index);
227
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228#endif
229
Dave Barach97d8dc22016-08-15 15:31:15 -0400230/*
231 * fd.io coding-style-patch-verification: ON
232 *
233 * Local Variables:
234 * eval: (c-set-style "gnu")
235 * End:
236 */