FD.io VPP  v18.07.1-19-g511ce25
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 
24 typedef struct
25 {
26  /* hash bd_id -> bd_index */
28 
29  /* Busy bd_index bitmap */
31 
32  /* convenience */
35 } bd_main_t;
36 
37 extern bd_main_t bd_main;
38 
39 /* Bridge domain member */
40 
41 #define L2_FLOOD_MEMBER_NORMAL 0
42 #define L2_FLOOD_MEMBER_BVI 1
43 
44 typedef struct
45 {
46  u32 sw_if_index; /* the output L2 interface */
47  u8 flags; /* 0=normal, 1=bvi */
48  u8 shg; /* split horizon group number */
51 
52 /* Per-bridge domain configuration */
53 
54 typedef struct
55 {
57  /*
58  * Contains bit enables for flooding, learning, and forwarding.
59  * All other feature bits should always be set.
60  *
61  * identity of the bridge-domain's BVI interface
62  * set to ~0 if there is no BVI
63  */
65 
66  /* bridge domain id, not to be confused with bd_index */
68 
69  /* Vector of member ports */
71 
72  /* First flood_count member ports are flooded */
74 
75  /* Tunnel Master (Multicast vxlan) are always flooded */
77 
78  /* Tunnels (Unicast vxlan) are flooded if there are no masters */
80 
81  /* Interface on which packets are not flooded */
83 
84  /* hash ip4/ip6 -> mac for arp/nd termination */
87 
88  /* mac aging */
90 
91  /* sequence number for bridge domain based flush of MACs */
93 
94  /* Bridge domain tag (C string NULL terminated) */
96 
98 
99 /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
100 #define L2_BD_ID_MAX ((1<<24)-1)
101 
102 typedef struct
103 {
114 
115 /* Return 1 if bridge domain has been initialized */
118 {
119  return (bd_config->feature_bitmap != 0);
120 }
121 
122 /* Init bridge domain if not done already */
123 void bd_validate (l2_bridge_domain_t * bd_config);
124 
125 
126 void
127 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
128 
129 u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
130 
131 
132 #define L2_LEARN (1<<0)
133 #define L2_FWD (1<<1)
134 #define L2_FLOOD (1<<2)
135 #define L2_UU_FLOOD (1<<3)
136 #define L2_ARP_TERM (1<<4)
137 
138 u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable);
139 void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
141 
142 /**
143  * \brief Get a bridge domain.
144  *
145  * Get a bridge domain with the given bridge domain ID.
146  *
147  * \param bdm bd_main pointer.
148  * \param bd_id The bridge domain ID
149  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
150  */
151 u32 bd_find_index (bd_main_t * bdm, u32 bd_id);
152 
153 /**
154  * \brief Create a bridge domain.
155  *
156  * Create a bridge domain with the given bridge domain ID
157  *
158  * \param bdm bd_main pointer.
159  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
160  */
161 u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
162 
163 /**
164  * \brief Get or create a bridge domain.
165  *
166  * Get a bridge domain with the given bridge domain ID, if one exists, otherwise
167  * create one with the given ID, or the first unused ID if the given ID is ~0..
168  *
169  * \param bdm bd_main pointer.
170  * \param bd_id The bridge domain ID
171  * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
172  */
173 static inline u32
175 {
176  u32 bd_index = bd_find_index (bdm, bd_id);
177  if (bd_index == ~0)
178  return bd_add_bd_index (bdm, bd_id);
179  return bd_index;
180 }
181 
182 u32 bd_add_del_ip_mac (u32 bd_index,
183  u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add);
184 
185 #endif
186 
187 /*
188  * fd.io coding-style-patch-verification: ON
189  *
190  * Local Variables:
191  * eval: (c-set-style "gnu")
192  * End:
193  */
u32 bvi_sw_if_index
Definition: l2_bd.h:64
l2_flood_member_t * members
Definition: l2_bd.h:70
void bd_add_member(l2_bridge_domain_t *bd_config, l2_flood_member_t *member)
Definition: l2_bd.c:139
unsigned char u8
Definition: types.h:56
int bd_add_del(l2_bridge_domain_add_del_args_t *args)
Definition: l2_bd.c:1138
#define always_inline
Definition: clib.h:92
bd_main_t bd_main
Definition: l2_bd.c:44
u32 bd_add_bd_index(bd_main_t *bdm, u32 bd_id)
Create a bridge domain.
Definition: l2_bd.c:77
unsigned int u32
Definition: types.h:88
uword * bd_index_by_bd_id
Definition: l2_bd.h:27
vnet_main_t * vnet_main
Definition: l2_bd.h:34
u32 bd_set_flags(vlib_main_t *vm, u32 bd_index, u32 flags, u32 enable)
Set the learn/forward/flood flags for the bridge domain.
Definition: l2_bd.c:243
unsigned short u16
Definition: types.h:57
uword * bd_index_bitmap
Definition: l2_bd.h:30
static u32 bd_is_valid(l2_bridge_domain_t *bd_config)
Definition: l2_bd.h:117
u32 flags
Definition: vhost_user.h:110
u32 no_flood_count
Definition: l2_bd.h:82
vlib_main_t * vm
Definition: buffer.c:294
u32 tun_master_count
Definition: l2_bd.h:76
u32 bd_remove_member(l2_bridge_domain_t *bd_config, u32 sw_if_index)
Definition: l2_bd.c:184
uword * mac_by_ip6
Definition: l2_bd.h:86
u32 bd_add_del_ip_mac(u32 bd_index, u8 *ip_addr, u8 *mac_addr, u8 is_ip6, u8 is_add)
Add/delete IP address to MAC address mapping.
Definition: l2_bd.c:734
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:174
u32 tun_normal_count
Definition: l2_bd.h:79
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:287
vlib_main_t * vlib_main
Definition: l2_bd.h:33
u32 feature_bitmap
Definition: l2_bd.h:56
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:68
uword * mac_by_ip4
Definition: l2_bd.h:85
u32 sw_if_index
Definition: l2_bd.h:46
void bd_validate(l2_bridge_domain_t *bd_config)
Init bridge domain if not done already.
Definition: l2_bd.c:51