FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
l2_bd.h
Go to the documentation of this file.
1 /*
2  * l2_bd.h : layer 2 bridge domain
3  *
4  * Copyright (c) 2013 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef included_l2bd_h
19 #define included_l2bd_h
20 
21 #include <vlib/vlib.h>
22 #include <vnet/vnet.h>
23 #include <vnet/ip/ip6_packet.h>
25 
26 typedef enum l2_bd_port_type_t_
27 {
32 
33 typedef struct
34 {
35  /* hash bd_id -> bd_index */
37 
38  /* Busy bd_index bitmap */
40 
41  /* convenience */
44 } bd_main_t;
45 
46 extern bd_main_t bd_main;
47 
48 /* Bridge domain member */
49 
50 #define L2_FLOOD_MEMBER_NORMAL 0
51 #define L2_FLOOD_MEMBER_BVI 1
52 
53 typedef struct
54 {
55  u32 sw_if_index; /* the output L2 interface */
56  u8 flags; /* 0=normal, 1=bvi */
57  u8 shg; /* split horizon group number */
60 
61 /* Per-bridge domain configuration */
62 
63 typedef struct
64 {
65  /*
66  * Contains bit enables for flooding, learning, and forwarding.
67  * All other feature bits should always be set.
68  */
70  /*
71  * identity of the bridge-domain's BVI interface
72  * set to ~0 if there is no BVI
73  */
75 
76  /*
77  * identity of the bridge-domain's UU flood interface
78  * set to ~0 if there is no such configuration
79  */
81 
82  /* bridge domain id, not to be confused with bd_index */
84 
85  /* Vector of member ports */
87 
88  /* First flood_count member ports are flooded */
90 
91  /* Tunnel Master (Multicast vxlan) are always flooded */
93 
94  /* Tunnels (Unicast vxlan) are flooded if there are no masters */
96 
97  /* Interface on which packets are not flooded */
99 
100  /* hash ip4/ip6 -> mac for arp/nd termination */
103 
104  /* mac aging */
106 
107  /* sequence number for bridge domain based flush of MACs */
109 
110  /* Bridge domain tag (C string NULL terminated) */
112 
114 
115 /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
116 #define L2_BD_ID_MAX ((1<<24)-1)
117 
118 typedef struct
119 {
130 
131 /* Return 1 if bridge domain has been initialized */
134 {
135  return (bd_config->feature_bitmap != 0);
136 }
137 
138 /* Init bridge domain if not done already */
139 void bd_validate (l2_bridge_domain_t * bd_config);
140 
141 
142 void
143 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
144 
146 
147 typedef enum bd_flags_t_
148 {
149  L2_NONE = 0,
150  L2_LEARN = (1 << 0),
151  L2_FWD = (1 << 1),
152  L2_FLOOD = (1 << 2),
153  L2_UU_FLOOD = (1 << 3),
154  L2_ARP_TERM = (1 << 4),
155 } bd_flags_t;
156 
158  u32 enable);
159 void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
161 
162 /**
163  * \brief Get a bridge domain.
164  *
165  * Get a bridge domain with the given bridge domain ID.
166  *
167  * \param bdm bd_main pointer.
168  * \param bd_id The bridge domain ID
169  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
170  */
172 
173 /**
174  * \brief Create a bridge domain.
175  *
176  * Create a bridge domain with the given bridge domain ID
177  *
178  * \param bdm bd_main pointer.
179  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
180  */
182 
183 /**
184  * \brief Get or create a bridge domain.
185  *
186  * Get a bridge domain with the given bridge domain ID, if one exists, otherwise
187  * create one with the given ID, or the first unused ID if the given ID is ~0..
188  *
189  * \param bdm bd_main pointer.
190  * \param bd_id The bridge domain ID
191  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
192  */
193 static inline u32
195 {
196  u32 bd_index = bd_find_index (bdm, bd_id);
197  if (bd_index == ~0)
198  return bd_add_bd_index (bdm, bd_id);
199  return bd_index;
200 }
201 
202 u32 bd_add_del_ip_mac (u32 bd_index,
203  ip46_type_t type,
204  const ip46_address_t * ip_addr,
205  const mac_address_t * mac, u8 is_add);
206 
207 void bd_flush_ip_mac (u32 bd_index);
208 
209 #endif
210 
211 /*
212  * fd.io coding-style-patch-verification: ON
213  *
214  * Local Variables:
215  * eval: (c-set-style "gnu")
216  * End:
217  */
u32 sw_if_index
Definition: ipsec_gre.api:37
u32 flags
Definition: vhost_user.h:115
u32 uu_fwd_sw_if_index
Definition: l2_bd.h:80
void bd_flush_ip_mac(u32 bd_index)
Flush IP address to MAC address mapping tables in a BD.
Definition: l2_bd.c:819
u32 bvi_sw_if_index
Definition: l2_bd.h:74
Definition: l2_bd.h:151
l2_flood_member_t * members
Definition: l2_bd.h:86
void bd_add_member(l2_bridge_domain_t *bd_config, l2_flood_member_t *member)
Definition: l2_bd.c:147
unsigned char u8
Definition: types.h:56
int bd_add_del(l2_bridge_domain_add_del_args_t *args)
Definition: l2_bd.c:1188
#define always_inline
Definition: clib.h:98
bd_main_t bd_main
Definition: l2_bd.c:44
u32 bd_set_flags(vlib_main_t *vm, u32 bd_index, bd_flags_t flags, u32 enable)
Set the learn/forward/flood flags for the bridge domain.
Definition: l2_bd.c:251
u32 bd_add_bd_index(bd_main_t *bdm, u32 bd_id)
Create a bridge domain.
Definition: l2_bd.c:78
unsigned int u32
Definition: types.h:88
uword * bd_index_by_bd_id
Definition: l2_bd.h:36
vnet_main_t * vnet_main
Definition: l2_bd.h:43
u32 bd_add_del_ip_mac(u32 bd_index, ip46_type_t type, const ip46_address_t *ip_addr, const mac_address_t *mac, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:742
u32 bd_id
Definition: gbp.api:269
unsigned short u16
Definition: types.h:57
enum l2_bd_port_type_t_ l2_bd_port_type_t
uword * bd_index_bitmap
Definition: l2_bd.h:39
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:133
Definition: l2_bd.h:149
u32 no_flood_count
Definition: l2_bd.h:98
vlib_main_t * vm
Definition: buffer.c:312
u32 tun_master_count
Definition: l2_bd.h:92
u32 bd_remove_member(l2_bridge_domain_t *bd_config, u32 sw_if_index)
Definition: l2_bd.c:192
uword * mac_by_ip6
Definition: l2_bd.h:102
static u32 bd_find_or_add_bd_index(bd_main_t *bdm, u32 bd_id)
Get or create a bridge domain.
Definition: l2_bd.h:194
ip46_type_t
Definition: ip6_packet.h:70
bd_flags_t_
Definition: l2_bd.h:147
u32 tun_normal_count
Definition: l2_bd.h:95
void bd_set_mac_age(vlib_main_t *vm, u32 bd_index, u8 age)
Set the mac age for the bridge domain.
Definition: l2_bd.c:295
vlib_main_t * vlib_main
Definition: l2_bd.h:42
l2_bd_port_type_t_
Definition: l2_bd.h:26
u32 feature_bitmap
Definition: l2_bd.h:69
u64 uword
Definition: types.h:112
u32 bd_find_index(bd_main_t *bdm, u32 bd_id)
Get a bridge domain.
Definition: l2_bd.c:69
uword * mac_by_ip4
Definition: l2_bd.h:101
u32 sw_if_index
Definition: l2_bd.h:55
void bd_validate(l2_bridge_domain_t *bd_config)
Init bridge domain if not done already.
Definition: l2_bd.c:51
enum bd_flags_t_ bd_flags_t