blob: 226e30ecfd4cdec9c52cf95c38ec7e8f8fbceccb [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.
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
Neale Rannsb4743802018-09-05 09:13:57 -070024typedef enum l2_bd_port_type_t_
25{
26 L2_BD_PORT_TYPE_NORMAL = 0,
27 L2_BD_PORT_TYPE_BVI = 1,
28 L2_BD_PORT_TYPE_UU_FWD = 2,
29} l2_bd_port_type_t;
30
Dave Barach97d8dc22016-08-15 15:31:15 -040031typedef struct
32{
33 /* hash bd_id -> bd_index */
34 uword *bd_index_by_bd_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070035
Dave Barach97d8dc22016-08-15 15:31:15 -040036 /* Busy bd_index bitmap */
37 uword *bd_index_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070038
Dave Barach97d8dc22016-08-15 15:31:15 -040039 /* convenience */
40 vlib_main_t *vlib_main;
41 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070042} bd_main_t;
43
Eyal Bari942402b2017-07-26 11:57:04 +030044extern bd_main_t bd_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070045
Dave Barach97d8dc22016-08-15 15:31:15 -040046/* Bridge domain member */
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
48#define L2_FLOOD_MEMBER_NORMAL 0
49#define L2_FLOOD_MEMBER_BVI 1
50
Dave Barach97d8dc22016-08-15 15:31:15 -040051typedef struct
52{
53 u32 sw_if_index; /* the output L2 interface */
54 u8 flags; /* 0=normal, 1=bvi */
55 u8 shg; /* split horizon group number */
56 u16 spare;
Ed Warnickecb9cada2015-12-08 15:45:58 -070057} l2_flood_member_t;
58
Dave Barach97d8dc22016-08-15 15:31:15 -040059/* Per-bridge domain configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -070060
Dave Barach97d8dc22016-08-15 15:31:15 -040061typedef struct
62{
Dave Barach97d8dc22016-08-15 15:31:15 -040063 /*
64 * Contains bit enables for flooding, learning, and forwarding.
65 * All other feature bits should always be set.
Neale Rannsb4743802018-09-05 09:13:57 -070066 */
67 u32 feature_bitmap;
68 /*
Dave Barach97d8dc22016-08-15 15:31:15 -040069 * identity of the bridge-domain's BVI interface
70 * set to ~0 if there is no BVI
71 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070072 u32 bvi_sw_if_index;
73
Neale Rannsb4743802018-09-05 09:13:57 -070074 /*
75 * identity of the bridge-domain's UU flood interface
76 * set to ~0 if there is no such configuration
77 */
78 u32 uu_fwd_sw_if_index;
79
Dave Barach97d8dc22016-08-15 15:31:15 -040080 /* bridge domain id, not to be confused with bd_index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 u32 bd_id;
82
Eyal Baric5b13602016-11-24 19:42:43 +020083 /* Vector of member ports */
Dave Barach97d8dc22016-08-15 15:31:15 -040084 l2_flood_member_t *members;
Ed Warnickecb9cada2015-12-08 15:45:58 -070085
Eyal Baric5b13602016-11-24 19:42:43 +020086 /* First flood_count member ports are flooded */
87 u32 flood_count;
88
89 /* Tunnel Master (Multicast vxlan) are always flooded */
90 u32 tun_master_count;
91
92 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
93 u32 tun_normal_count;
94
Neale Ranns87dad112018-04-09 01:53:01 -070095 /* Interface on which packets are not flooded */
96 u32 no_flood_count;
97
John Lo1edfba92016-08-27 01:11:57 -040098 /* hash ip4/ip6 -> mac for arp/nd termination */
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 uword *mac_by_ip4;
100 uword *mac_by_ip6;
101
Damjan Mariond171d482016-12-05 14:16:38 +0100102 /* mac aging */
103 u8 mac_age;
104
John Loda1f2c72017-03-24 20:11:15 -0400105 /* sequence number for bridge domain based flush of MACs */
106 u8 seq_num;
107
Jerome Tollet48304142017-09-05 12:13:22 +0100108 /* Bridge domain tag (C string NULL terminated) */
109 u8 *bd_tag;
110
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111} l2_bridge_domain_t;
112
John Lo97934772017-05-18 22:26:47 -0400113/* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
114#define L2_BD_ID_MAX ((1<<24)-1)
115
Choonho Son05480792017-03-29 20:07:45 +0900116typedef struct
117{
118 u32 bd_id;
119 u8 flood;
120 u8 uu_flood;
121 u8 forward;
122 u8 learn;
123 u8 arp_term;
124 u8 mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +0100125 u8 *bd_tag;
Choonho Son05480792017-03-29 20:07:45 +0900126 u8 is_add;
127} l2_bridge_domain_add_del_args_t;
128
Dave Barach97d8dc22016-08-15 15:31:15 -0400129/* Return 1 if bridge domain has been initialized */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130always_inline u32
Dave Barach97d8dc22016-08-15 15:31:15 -0400131bd_is_valid (l2_bridge_domain_t * bd_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132{
133 return (bd_config->feature_bitmap != 0);
134}
135
Dave Barach97d8dc22016-08-15 15:31:15 -0400136/* Init bridge domain if not done already */
137void bd_validate (l2_bridge_domain_t * bd_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138
139
140void
Dave Barach97d8dc22016-08-15 15:31:15 -0400141bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142
Dave Barach97d8dc22016-08-15 15:31:15 -0400143u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144
Neale Rannsb4743802018-09-05 09:13:57 -0700145typedef enum bd_flags_t_
146{
147 L2_NONE = 0,
148 L2_LEARN = (1 << 0),
149 L2_FWD = (1 << 1),
150 L2_FLOOD = (1 << 2),
151 L2_UU_FLOOD = (1 << 3),
152 L2_ARP_TERM = (1 << 4),
153} bd_flags_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
Neale Rannsb4743802018-09-05 09:13:57 -0700155u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, bd_flags_t flags,
156 u32 enable);
Damjan Mariond171d482016-12-05 14:16:38 +0100157void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
Eyal Barib1352ed2017-04-07 23:14:17 +0300158int bd_add_del (l2_bridge_domain_add_del_args_t * args);
159
160/**
161 * \brief Get a bridge domain.
162 *
163 * Get a bridge domain with the given bridge domain ID.
164 *
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.
168 */
169u32 bd_find_index (bd_main_t * bdm, u32 bd_id);
170
171/**
172 * \brief Create a bridge domain.
173 *
174 * Create a bridge domain with the given bridge domain ID
175 *
176 * \param bdm bd_main pointer.
177 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
178 */
179u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100181/**
182 * \brief Get or create a bridge domain.
183 *
Eyal Barib1352ed2017-04-07 23:14:17 +0300184 * 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..
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100186 *
187 * \param bdm bd_main pointer.
Eyal Barib1352ed2017-04-07 23:14:17 +0300188 * \param bd_id The bridge domain ID
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100189 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
190 */
Eyal Barib1352ed2017-04-07 23:14:17 +0300191static inline u32
192bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
193{
194 u32 bd_index = bd_find_index (bdm, bd_id);
195 if (bd_index == ~0)
196 return bd_add_bd_index (bdm, bd_id);
197 return bd_index;
198}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700199
Dave Barach97d8dc22016-08-15 15:31:15 -0400200u32 bd_add_del_ip_mac (u32 bd_index,
201 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
203#endif
204
Dave Barach97d8dc22016-08-15 15:31:15 -0400205/*
206 * fd.io coding-style-patch-verification: ON
207 *
208 * Local Variables:
209 * eval: (c-set-style "gnu")
210 * End:
211 */