2 * l2_bd.h : layer 2 bridge domain
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef included_l2bd_h
19 #define included_l2bd_h
21 #include <vlib/vlib.h>
22 #include <vnet/vnet.h>
24 typedef enum l2_bd_port_type_t_
26 L2_BD_PORT_TYPE_NORMAL = 0,
27 L2_BD_PORT_TYPE_BVI = 1,
28 L2_BD_PORT_TYPE_UU_FWD = 2,
33 /* hash bd_id -> bd_index */
34 uword *bd_index_by_bd_id;
36 /* Busy bd_index bitmap */
37 uword *bd_index_bitmap;
40 vlib_main_t *vlib_main;
41 vnet_main_t *vnet_main;
44 extern bd_main_t bd_main;
46 /* Bridge domain member */
48 #define L2_FLOOD_MEMBER_NORMAL 0
49 #define L2_FLOOD_MEMBER_BVI 1
53 u32 sw_if_index; /* the output L2 interface */
54 u8 flags; /* 0=normal, 1=bvi */
55 u8 shg; /* split horizon group number */
59 /* Per-bridge domain configuration */
64 * Contains bit enables for flooding, learning, and forwarding.
65 * All other feature bits should always be set.
69 * identity of the bridge-domain's BVI interface
70 * set to ~0 if there is no BVI
75 * identity of the bridge-domain's UU flood interface
76 * set to ~0 if there is no such configuration
78 u32 uu_fwd_sw_if_index;
80 /* bridge domain id, not to be confused with bd_index */
83 /* Vector of member ports */
84 l2_flood_member_t *members;
86 /* First flood_count member ports are flooded */
89 /* Tunnel Master (Multicast vxlan) are always flooded */
92 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
95 /* Interface on which packets are not flooded */
98 /* hash ip4/ip6 -> mac for arp/nd termination */
105 /* sequence number for bridge domain based flush of MACs */
108 /* Bridge domain tag (C string NULL terminated) */
111 } l2_bridge_domain_t;
113 /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
114 #define L2_BD_ID_MAX ((1<<24)-1)
127 } l2_bridge_domain_add_del_args_t;
129 /* Return 1 if bridge domain has been initialized */
131 bd_is_valid (l2_bridge_domain_t * bd_config)
133 return (bd_config->feature_bitmap != 0);
136 /* Init bridge domain if not done already */
137 void bd_validate (l2_bridge_domain_t * bd_config);
141 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
143 u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
145 typedef enum bd_flags_t_
151 L2_UU_FLOOD = (1 << 3),
152 L2_ARP_TERM = (1 << 4),
155 u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags,
157 void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
158 int bd_add_del (l2_bridge_domain_add_del_args_t * args);
161 * \brief Get a bridge domain.
163 * Get a bridge domain with the given bridge domain ID.
165 * \param bdm bd_main pointer.
166 * \param bd_id The bridge domain ID
167 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
169 u32 bd_find_index (bd_main_t * bdm, u32 bd_id);
172 * \brief Create a bridge domain.
174 * Create a bridge domain with the given bridge domain ID
176 * \param bdm bd_main pointer.
177 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
179 u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
182 * \brief Get or create a bridge domain.
184 * Get a bridge domain with the given bridge domain ID, if one exists, otherwise
185 * create one with the given ID, or the first unused ID if the given ID is ~0..
187 * \param bdm bd_main pointer.
188 * \param bd_id The bridge domain ID
189 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
192 bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
194 u32 bd_index = bd_find_index (bdm, bd_id);
196 return bd_add_bd_index (bdm, bd_id);
200 u32 bd_add_del_ip_mac (u32 bd_index,
201 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add);
206 * fd.io coding-style-patch-verification: ON
209 * eval: (c-set-style "gnu")