blob: 83733411a420b19d66dc09a6f0f673c432266b8a [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
37bd_main_t bd_main;
38
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
52
Dave Barach97d8dc22016-08-15 15:31:15 -040053/* Per-bridge domain configuration */
Ed Warnickecb9cada2015-12-08 15:45:58 -070054
Dave Barach97d8dc22016-08-15 15:31:15 -040055typedef struct
56{
57 u32 feature_bitmap;
58 /*
59 * Contains bit enables for flooding, learning, and forwarding.
60 * All other feature bits should always be set.
61 *
62 * identity of the bridge-domain's BVI interface
63 * set to ~0 if there is no BVI
64 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070065 u32 bvi_sw_if_index;
66
Dave Barach97d8dc22016-08-15 15:31:15 -040067 /* bridge domain id, not to be confused with bd_index */
Ed Warnickecb9cada2015-12-08 15:45:58 -070068 u32 bd_id;
69
Eyal Baric5b13602016-11-24 19:42:43 +020070 /* Vector of member ports */
Dave Barach97d8dc22016-08-15 15:31:15 -040071 l2_flood_member_t *members;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072
Eyal Baric5b13602016-11-24 19:42:43 +020073 /* First flood_count member ports are flooded */
74 u32 flood_count;
75
76 /* Tunnel Master (Multicast vxlan) are always flooded */
77 u32 tun_master_count;
78
79 /* Tunnels (Unicast vxlan) are flooded if there are no masters */
80 u32 tun_normal_count;
81
John Lo1edfba92016-08-27 01:11:57 -040082 /* hash ip4/ip6 -> mac for arp/nd termination */
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 uword *mac_by_ip4;
84 uword *mac_by_ip6;
85
Damjan Mariond171d482016-12-05 14:16:38 +010086 /* mac aging */
87 u8 mac_age;
88
John Loda1f2c72017-03-24 20:11:15 -040089 /* sequence number for bridge domain based flush of MACs */
90 u8 seq_num;
91
Ed Warnickecb9cada2015-12-08 15:45:58 -070092} l2_bridge_domain_t;
93
Choonho Son05480792017-03-29 20:07:45 +090094typedef struct
95{
96 u32 bd_id;
97 u8 flood;
98 u8 uu_flood;
99 u8 forward;
100 u8 learn;
101 u8 arp_term;
102 u8 mac_age;
103 u8 is_add;
104} l2_bridge_domain_add_del_args_t;
105
Dave Barach97d8dc22016-08-15 15:31:15 -0400106/* Return 1 if bridge domain has been initialized */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107always_inline u32
Dave Barach97d8dc22016-08-15 15:31:15 -0400108bd_is_valid (l2_bridge_domain_t * bd_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109{
110 return (bd_config->feature_bitmap != 0);
111}
112
Dave Barach97d8dc22016-08-15 15:31:15 -0400113/* Init bridge domain if not done already */
114void bd_validate (l2_bridge_domain_t * bd_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
116
117void
Dave Barach97d8dc22016-08-15 15:31:15 -0400118bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700119
Dave Barach97d8dc22016-08-15 15:31:15 -0400120u32 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121
122
123#define L2_LEARN (1<<0)
124#define L2_FWD (1<<1)
125#define L2_FLOOD (1<<2)
126#define L2_UU_FLOOD (1<<3)
127#define L2_ARP_TERM (1<<4)
128
Dave Barach97d8dc22016-08-15 15:31:15 -0400129u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable);
Damjan Mariond171d482016-12-05 14:16:38 +0100130void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100132/**
133 * \brief Get or create a bridge domain.
134 *
135 * Get or create a bridge domain with the given bridge domain ID.
136 *
137 * \param bdm bd_main pointer.
138 * \param bd_id The bridge domain ID or ~0 if an arbitrary unused bridge domain should be used.
139 * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector.
140 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141u32 bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id);
Pierre Pfister530bd8e2016-05-10 17:11:22 +0100142
143/**
144 * \brief Delete a bridge domain.
145 *
146 * Delete an existing bridge domain with the given bridge domain ID.
147 *
148 * \param bdm bd_main pointer.
149 * \param bd_id The bridge domain ID.
150 * \return 0 on success and -1 if the bridge domain does not exist.
151 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152int bd_delete_bd_index (bd_main_t * bdm, u32 bd_id);
153
Dave Barach97d8dc22016-08-15 15:31:15 -0400154u32 bd_add_del_ip_mac (u32 bd_index,
155 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
157#endif
158
Dave Barach97d8dc22016-08-15 15:31:15 -0400159/*
160 * fd.io coding-style-patch-verification: ON
161 *
162 * Local Variables:
163 * eval: (c-set-style "gnu")
164 * End:
165 */