blob: ffc75339e9729e7209cf25213ce5eec0de994fd6 [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
Dave Barach97d8dc22016-08-15 15:31:15 -040024typedef struct
25{
26 /* hash bd_id -> bd_index */
27 uword *bd_index_by_bd_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -070028
Dave Barach97d8dc22016-08-15 15:31:15 -040029 /* Busy bd_index bitmap */
30 uword *bd_index_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070031
Dave Barach97d8dc22016-08-15 15:31:15 -040032 /* convenience */
33 vlib_main_t *vlib_main;
34 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070035} bd_main_t;
36
Eyal Bari942402b2017-07-26 11:57:04 +030037extern bd_main_t bd_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070038
Dave Barach97d8dc22016-08-15 15:31:15 -040039/* Bridge domain member */
Ed Warnickecb9cada2015-12-08 15:45:58 -070040
41#define L2_FLOOD_MEMBER_NORMAL 0
42#define L2_FLOOD_MEMBER_BVI 1
43
Dave Barach97d8dc22016-08-15 15:31:15 -040044typedef 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 */
49 u16 spare;
Ed Warnickecb9cada2015-12-08 15:45:58 -070050} l2_flood_member_t;
51
Dave Barach97d8dc22016-08-15 15:31:15 -040052/* Per-bridge domain configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -070053
Dave Barach97d8dc22016-08-15 15:31:15 -040054typedef struct
55{
56 u32 feature_bitmap;
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 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070064 u32 bvi_sw_if_index;
65
Dave Barach97d8dc22016-08-15 15:31:15 -040066 /* bridge domain id, not to be confused with bd_index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070067 u32 bd_id;
68
Eyal Baric5b13602016-11-24 19:42:43 +020069 /* Vector of member ports */
Dave Barach97d8dc22016-08-15 15:31:15 -040070 l2_flood_member_t *members;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
Eyal Baric5b13602016-11-24 19:42:43 +020072 /* First flood_count member ports are flooded */
73 u32 flood_count;
74
75 /* Tunnel Master (Multicast vxlan) are always flooded */
76 u32 tun_master_count;
77
78 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
79 u32 tun_normal_count;
80
Neale Ranns87dad112018-04-09 01:53:01 -070081 /* Interface on which packets are not flooded */
82 u32 no_flood_count;
83
John Lo1edfba92016-08-27 01:11:57 -040084 /* hash ip4/ip6 -> mac for arp/nd termination */
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 uword *mac_by_ip4;
86 uword *mac_by_ip6;
87
Damjan Mariond171d482016-12-05 14:16:38 +010088 /* mac aging */
89 u8 mac_age;
90
John Loda1f2c72017-03-24 20:11:15 -040091 /* sequence number for bridge domain based flush of MACs */
92 u8 seq_num;
93
Jerome Tollet48304142017-09-05 12:13:22 +010094 /* Bridge domain tag (C string NULL terminated) */
95 u8 *bd_tag;
96
Ed Warnickecb9cada2015-12-08 15:45:58 -070097} l2_bridge_domain_t;
98
John Lo97934772017-05-18 22:26:47 -040099/* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */
100#define L2_BD_ID_MAX ((1<<24)-1)
101
Choonho Son05480792017-03-29 20:07:45 +0900102typedef struct
103{
104 u32 bd_id;
105 u8 flood;
106 u8 uu_flood;
107 u8 forward;
108 u8 learn;
109 u8 arp_term;
110 u8 mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +0100111 u8 *bd_tag;
Choonho Son05480792017-03-29 20:07:45 +0900112 u8 is_add;
113} l2_bridge_domain_add_del_args_t;
114
Dave Barach97d8dc22016-08-15 15:31:15 -0400115/* Return 1 if bridge domain has been initialized */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116always_inline u32
Dave Barach97d8dc22016-08-15 15:31:15 -0400117bd_is_valid (l2_bridge_domain_t * bd_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118{
119 return (bd_config->feature_bitmap != 0);
120}
121
Dave Barach97d8dc22016-08-15 15:31:15 -0400122/* Init bridge domain if not done already */
123void bd_validate (l2_bridge_domain_t * bd_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
125
126void
Dave Barach97d8dc22016-08-15 15:31:15 -0400127bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Dave Barach97d8dc22016-08-15 15:31:15 -0400129u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
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
Dave Barach97d8dc22016-08-15 15:31:15 -0400138u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable);
Damjan Mariond171d482016-12-05 14:16:38 +0100139void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
Eyal Barib1352ed2017-04-07 23:14:17 +0300140int bd_add_del (l2_bridge_domain_add_del_args_t * args);
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 */
151u32 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 */
161u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100163/**
164 * \brief Get or create a bridge domain.
165 *
Eyal Barib1352ed2017-04-07 23:14:17 +0300166 * 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..
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100168 *
169 * \param bdm bd_main pointer.
Eyal Barib1352ed2017-04-07 23:14:17 +0300170 * \param bd_id The bridge domain ID
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100171 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
172 */
Eyal Barib1352ed2017-04-07 23:14:17 +0300173static inline u32
174bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
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}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700181
Dave Barach97d8dc22016-08-15 15:31:15 -0400182u32 bd_add_del_ip_mac (u32 bd_index,
183 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700184
185#endif
186
Dave Barach97d8dc22016-08-15 15:31:15 -0400187/*
188 * fd.io coding-style-patch-verification: ON
189 *
190 * Local Variables:
191 * eval: (c-set-style "gnu")
192 * End:
193 */