blob: 3a71091a4f39b3f355527e5d7757136b8861bba9 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * l2_bd.c : 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#include <vlib/vlib.h>
19#include <vnet/vnet.h>
20#include <vlib/cli.h>
21#include <vnet/ethernet/ethernet.h>
22#include <vnet/ip/format.h>
23#include <vnet/l2/l2_input.h>
24#include <vnet/l2/feat_bitmap.h>
25#include <vnet/l2/l2_bd.h>
Damjan Mariond171d482016-12-05 14:16:38 +010026#include <vnet/l2/l2_learn.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070027#include <vnet/l2/l2_fib.h>
28#include <vnet/l2/l2_vtr.h>
29#include <vnet/ip/ip4_packet.h>
30#include <vnet/ip/ip6_packet.h>
31
32#include <vppinfra/error.h>
33#include <vppinfra/hash.h>
34#include <vppinfra/vec.h>
35
Billy McFall22aa3e92016-09-09 08:46:40 -040036/**
37 * @file
38 * @brief Ethernet Bridge Domain.
39 *
40 * Code in this file manages Layer 2 bridge domains.
41 *
42 */
43
Ed Warnickecb9cada2015-12-08 15:45:58 -070044bd_main_t bd_main;
45
Dave Barach97d8dc22016-08-15 15:31:15 -040046/**
Chris Luke16bcf7d2016-09-01 14:31:46 -040047 Init bridge domain if not done already.
Dave Barach97d8dc22016-08-15 15:31:15 -040048 For feature bitmap, set all bits except ARP termination
49*/
Damjan Marion99d8c762015-12-14 15:01:56 +010050void
Dave Barach97d8dc22016-08-15 15:31:15 -040051bd_validate (l2_bridge_domain_t * bd_config)
Ed Warnickecb9cada2015-12-08 15:45:58 -070052{
Eyal Barib1352ed2017-04-07 23:14:17 +030053 if (bd_is_valid (bd_config))
54 return;
55 bd_config->feature_bitmap = ~L2INPUT_FEAT_ARP_TERM;
56 bd_config->bvi_sw_if_index = ~0;
57 bd_config->members = 0;
58 bd_config->flood_count = 0;
59 bd_config->tun_master_count = 0;
60 bd_config->tun_normal_count = 0;
Eyal Barib6b04f02018-07-11 14:01:36 +030061 bd_config->no_flood_count = 0;
Eyal Barib1352ed2017-04-07 23:14:17 +030062 bd_config->mac_by_ip4 = 0;
63 bd_config->mac_by_ip6 = hash_create_mem (0, sizeof (ip6_address_t),
64 sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -070065}
66
Dave Barach97d8dc22016-08-15 15:31:15 -040067u32
Eyal Barib1352ed2017-04-07 23:14:17 +030068bd_find_index (bd_main_t * bdm, u32 bd_id)
Ed Warnickecb9cada2015-12-08 15:45:58 -070069{
Eyal Barib1352ed2017-04-07 23:14:17 +030070 u32 *p = (u32 *) hash_get (bdm->bd_index_by_bd_id, bd_id);
71 if (!p)
72 return ~0;
73 return p[0];
74}
Ed Warnickecb9cada2015-12-08 15:45:58 -070075
Eyal Barib1352ed2017-04-07 23:14:17 +030076u32
77bd_add_bd_index (bd_main_t * bdm, u32 bd_id)
78{
79 ASSERT (!hash_get (bdm->bd_index_by_bd_id, bd_id));
80 u32 rv = clib_bitmap_first_clear (bdm->bd_index_bitmap);
Dave Barach97d8dc22016-08-15 15:31:15 -040081
Eyal Barib1352ed2017-04-07 23:14:17 +030082 /* mark this index taken */
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, rv, 1);
84
85 hash_set (bdm->bd_index_by_bd_id, bd_id, rv);
86
87 vec_validate (l2input_main.bd_configs, rv);
88 l2input_main.bd_configs[rv].bd_id = bd_id;
89
90 return rv;
91}
92
Eyal Barib1352ed2017-04-07 23:14:17 +030093static int
94bd_delete (bd_main_t * bdm, u32 bd_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -070095{
John Lod77630a2017-04-28 00:33:36 -040096 l2_bridge_domain_t *bd = &l2input_main.bd_configs[bd_index];
97 u32 bd_id = bd->bd_id;
John Lod48c8eb2017-05-05 12:35:25 -040098 u64 mac_addr;
99 ip6_address_t *ip6_addr_key;
Eyal Bariafc47aa2017-04-20 14:45:17 +0300100
John Lod48c8eb2017-05-05 12:35:25 -0400101 /* flush non-static MACs in BD and removed bd_id from hash table */
102 l2fib_flush_bd_mac (vlib_get_main (), bd_index);
Eyal Barib1352ed2017-04-07 23:14:17 +0300103 hash_unset (bdm->bd_index_by_bd_id, bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400104
105 /* mark this index clear */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106 bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, bd_index, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107
John Lod77630a2017-04-28 00:33:36 -0400108 /* clear BD config for reuse: bd_id to -1 and clear feature_bitmap */
109 bd->bd_id = ~0;
110 bd->feature_bitmap = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111
Jerome Tollet48304142017-09-05 12:13:22 +0100112 /* free BD tag */
113 vec_free (bd->bd_tag);
114
John Lod48c8eb2017-05-05 12:35:25 -0400115 /* free memory used by BD */
John Lod77630a2017-04-28 00:33:36 -0400116 vec_free (bd->members);
117 hash_free (bd->mac_by_ip4);
John Lod48c8eb2017-05-05 12:35:25 -0400118 /* *INDENT-OFF* */
119 hash_foreach_mem (ip6_addr_key, mac_addr, bd->mac_by_ip6,
120 ({
121 clib_mem_free (ip6_addr_key); /* free memory used for ip6 addr key */
122 }));
123 /* *INDENT-ON* */
John Lod77630a2017-04-28 00:33:36 -0400124 hash_free (bd->mac_by_ip6);
John Loda1f2c72017-03-24 20:11:15 -0400125
Ed Warnickecb9cada2015-12-08 15:45:58 -0700126 return 0;
127}
128
Eyal Baric5b13602016-11-24 19:42:43 +0200129static void
130update_flood_count (l2_bridge_domain_t * bd_config)
131{
Neale Ranns87dad112018-04-09 01:53:01 -0700132 bd_config->flood_count = (vec_len (bd_config->members) -
133 (bd_config->tun_master_count ?
134 bd_config->tun_normal_count : 0));
135 bd_config->flood_count -= bd_config->no_flood_count;
Eyal Baric5b13602016-11-24 19:42:43 +0200136}
137
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138void
Dave Barach97d8dc22016-08-15 15:31:15 -0400139bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140{
Neale Ranns87dad112018-04-09 01:53:01 -0700141 u32 ix = 0;
Eyal Baric5b13602016-11-24 19:42:43 +0200142 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
143 (vnet_get_main (), member->sw_if_index);
144
Dave Barach97d8dc22016-08-15 15:31:15 -0400145 /*
146 * Add one element to the vector
Neale Ranns87dad112018-04-09 01:53:01 -0700147 * vector is ordered [ bvi, normal/tun_masters..., tun_normals... no_flood]
Dave Barach97d8dc22016-08-15 15:31:15 -0400148 * When flooding, the bvi interface (if present) must be the last member
149 * processed due to how BVI processing can change the packet. To enable
150 * this order, we make the bvi interface the first in the vector and
Neale Ranns87dad112018-04-09 01:53:01 -0700151 * flooding walks the vector in reverse. The flood-count determines where
152 * in the member list to start the walk from.
Dave Barach97d8dc22016-08-15 15:31:15 -0400153 */
Eyal Baric5b13602016-11-24 19:42:43 +0200154 switch (sw_if->flood_class)
Dave Barach97d8dc22016-08-15 15:31:15 -0400155 {
Neale Ranns87dad112018-04-09 01:53:01 -0700156 case VNET_FLOOD_CLASS_NO_FLOOD:
157 bd_config->no_flood_count++;
158 ix = vec_len (bd_config->members);
159 break;
160 case VNET_FLOOD_CLASS_BVI:
161 ix = 0;
162 break;
Eyal Baric5b13602016-11-24 19:42:43 +0200163 case VNET_FLOOD_CLASS_TUNNEL_MASTER:
164 bd_config->tun_master_count++;
165 /* Fall through */
Eyal Baric5b13602016-11-24 19:42:43 +0200166 case VNET_FLOOD_CLASS_NORMAL:
Neale Ranns87dad112018-04-09 01:53:01 -0700167 ix = (vec_len (bd_config->members) -
168 bd_config->tun_normal_count - bd_config->no_flood_count);
Eyal Baric5b13602016-11-24 19:42:43 +0200169 break;
170 case VNET_FLOOD_CLASS_TUNNEL_NORMAL:
Neale Ranns87dad112018-04-09 01:53:01 -0700171 ix = (vec_len (bd_config->members) - bd_config->no_flood_count);
Eyal Baric5b13602016-11-24 19:42:43 +0200172 bd_config->tun_normal_count++;
173 break;
174 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175
Eyal Baric5b13602016-11-24 19:42:43 +0200176 vec_insert_elts (bd_config->members, member, 1, ix);
177 update_flood_count (bd_config);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178}
179
Ed Warnickecb9cada2015-12-08 15:45:58 -0700180#define BD_REMOVE_ERROR_OK 0
181#define BD_REMOVE_ERROR_NOT_FOUND 1
182
183u32
Dave Barach97d8dc22016-08-15 15:31:15 -0400184bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185{
186 u32 ix;
Dave Barach97d8dc22016-08-15 15:31:15 -0400187
188 /* Find and delete the member */
189 vec_foreach_index (ix, bd_config->members)
190 {
Eyal Baric5b13602016-11-24 19:42:43 +0200191 l2_flood_member_t *m = vec_elt_at_index (bd_config->members, ix);
192 if (m->sw_if_index == sw_if_index)
Dave Barach97d8dc22016-08-15 15:31:15 -0400193 {
Eyal Baric5b13602016-11-24 19:42:43 +0200194 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
195 (vnet_get_main (), sw_if_index);
196
197 if (sw_if->flood_class != VNET_FLOOD_CLASS_NORMAL)
198 {
199 if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_MASTER)
200 bd_config->tun_master_count--;
201 else if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_NORMAL)
202 bd_config->tun_normal_count--;
Eyal Barib6b04f02018-07-11 14:01:36 +0300203 else if (sw_if->flood_class == VNET_FLOOD_CLASS_NO_FLOOD)
204 bd_config->no_flood_count--;
Eyal Baric5b13602016-11-24 19:42:43 +0200205 }
Eyal Bari25b36672017-03-02 10:43:19 +0200206 vec_delete (bd_config->members, 1, ix);
Eyal Baric5b13602016-11-24 19:42:43 +0200207 update_flood_count (bd_config);
208
Dave Barach97d8dc22016-08-15 15:31:15 -0400209 return BD_REMOVE_ERROR_OK;
210 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211 }
212
213 return BD_REMOVE_ERROR_NOT_FOUND;
214}
215
216
Dave Barach97d8dc22016-08-15 15:31:15 -0400217clib_error_t *
218l2bd_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219{
220 bd_main_t *bdm = &bd_main;
Dave Barach97d8dc22016-08-15 15:31:15 -0400221 bdm->bd_index_by_bd_id = hash_create (0, sizeof (uword));
222 /*
223 * create a dummy bd with bd_id of 0 and bd_index of 0 with feature set
224 * to packet drop only. Thus, packets received from any L2 interface with
225 * uninitialized bd_index of 0 can be dropped safely.
226 */
Eyal Barib1352ed2017-04-07 23:14:17 +0300227 u32 bd_index = bd_add_bd_index (bdm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228 ASSERT (bd_index == 0);
Dave Barach97d8dc22016-08-15 15:31:15 -0400229 l2input_main.bd_configs[0].feature_bitmap = L2INPUT_FEAT_DROP;
Choonho Son05480792017-03-29 20:07:45 +0900230
231 bdm->vlib_main = vm;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232 return 0;
233}
234
235VLIB_INIT_FUNCTION (l2bd_init);
236
237
Dave Barach97d8dc22016-08-15 15:31:15 -0400238/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400239 Set the learn/forward/flood flags for the bridge domain.
Dave Barach97d8dc22016-08-15 15:31:15 -0400240 Return 0 if ok, non-zero if for an error.
241*/
242u32
243bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable)
244{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700245
Eyal Bariafc47aa2017-04-20 14:45:17 +0300246 l2_bridge_domain_t *bd_config = l2input_bd_config (bd_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700247 bd_validate (bd_config);
Eyal Bariafc47aa2017-04-20 14:45:17 +0300248 u32 feature_bitmap = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249
Dave Barach97d8dc22016-08-15 15:31:15 -0400250 if (flags & L2_LEARN)
251 {
252 feature_bitmap |= L2INPUT_FEAT_LEARN;
253 }
254 if (flags & L2_FWD)
255 {
256 feature_bitmap |= L2INPUT_FEAT_FWD;
257 }
258 if (flags & L2_FLOOD)
259 {
260 feature_bitmap |= L2INPUT_FEAT_FLOOD;
261 }
262 if (flags & L2_UU_FLOOD)
263 {
264 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
265 }
266 if (flags & L2_ARP_TERM)
267 {
268 feature_bitmap |= L2INPUT_FEAT_ARP_TERM;
269 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270
Dave Barach97d8dc22016-08-15 15:31:15 -0400271 if (enable)
272 {
273 bd_config->feature_bitmap |= feature_bitmap;
274 }
275 else
276 {
277 bd_config->feature_bitmap &= ~feature_bitmap;
278 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279
John Lo8d00fff2017-08-03 00:35:36 -0400280 return bd_config->feature_bitmap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281}
282
Dave Barach97d8dc22016-08-15 15:31:15 -0400283/**
Damjan Mariond171d482016-12-05 14:16:38 +0100284 Set the mac age for the bridge domain.
285*/
286void
287bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age)
288{
289 l2_bridge_domain_t *bd_config;
290 int enable = 0;
291
292 vec_validate (l2input_main.bd_configs, bd_index);
293 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
294 bd_config->mac_age = age;
295
296 /* check if there is at least one bd with mac aging enabled */
297 vec_foreach (bd_config, l2input_main.bd_configs)
Eyal Barifead6702017-04-04 04:46:32 +0300298 enable |= bd_config->bd_id != ~0 && bd_config->mac_age != 0;
Damjan Mariond171d482016-12-05 14:16:38 +0100299
300 vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index,
301 enable ? L2_MAC_AGE_PROCESS_EVENT_START :
302 L2_MAC_AGE_PROCESS_EVENT_STOP, 0);
303}
304
Jerome Tollet50570ec2017-09-14 12:53:56 +0100305/**
306 Set the tag for the bridge domain.
307*/
Jerome Tollet48304142017-09-05 12:13:22 +0100308
Jerome Tollet50570ec2017-09-14 12:53:56 +0100309static void
Jerome Tollet48304142017-09-05 12:13:22 +0100310bd_set_bd_tag (vlib_main_t * vm, u32 bd_index, u8 * bd_tag)
311{
312 u8 *old;
313 l2_bridge_domain_t *bd_config;
314 vec_validate (l2input_main.bd_configs, bd_index);
315 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
316
317 old = bd_config->bd_tag;
318
319 if (bd_tag[0])
320 {
321 bd_config->bd_tag = format (0, "%s%c", bd_tag, 0);
322 }
323 else
324 {
325 bd_config->bd_tag = NULL;
326 }
327
328 vec_free (old);
329}
330
Damjan Mariond171d482016-12-05 14:16:38 +0100331/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400332 Set bridge-domain learn enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400333 The CLI format is:
334 set bridge-domain learn <bd_id> [disable]
335*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336static clib_error_t *
337bd_learn (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400338 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339{
Dave Barach97d8dc22016-08-15 15:31:15 -0400340 bd_main_t *bdm = &bd_main;
341 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342 u32 bd_index, bd_id;
343 u32 enable;
Dave Barach97d8dc22016-08-15 15:31:15 -0400344 uword *p;
345
346 if (!unformat (input, "%d", &bd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700347 {
348 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
Dave Barach97d8dc22016-08-15 15:31:15 -0400349 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 goto done;
351 }
352
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500353 if (bd_id == 0)
354 return clib_error_return (0,
355 "No operations on the default bridge domain are supported");
356
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
358
359 if (p == 0)
360 return clib_error_return (0, "No such bridge domain %d", bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400361
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362 bd_index = p[0];
363
364 enable = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400365 if (unformat (input, "disable"))
366 {
367 enable = 0;
368 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700369
Dave Barach97d8dc22016-08-15 15:31:15 -0400370 /* set the bridge domain flag */
John Lo8d00fff2017-08-03 00:35:36 -0400371 bd_set_flags (vm, bd_index, L2_LEARN, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372
Dave Barach97d8dc22016-08-15 15:31:15 -0400373done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374 return error;
375}
376
Billy McFall22aa3e92016-09-09 08:46:40 -0400377/*?
378 * Layer 2 learning can be enabled and disabled on each
379 * interface and on each bridge-domain. Use this command to
380 * manage bridge-domains. It is enabled by default.
381 *
382 * @cliexpar
383 * Example of how to enable learning (where 200 is the bridge-domain-id):
384 * @cliexcmd{set bridge-domain learn 200}
385 * Example of how to disable learning (where 200 is the bridge-domain-id):
386 * @cliexcmd{set bridge-domain learn 200 disable}
387?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400388/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700389VLIB_CLI_COMMAND (bd_learn_cli, static) = {
390 .path = "set bridge-domain learn",
391 .short_help = "set bridge-domain learn <bridge-domain-id> [disable]",
392 .function = bd_learn,
393};
Dave Barach97d8dc22016-08-15 15:31:15 -0400394/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700395
Dave Barach97d8dc22016-08-15 15:31:15 -0400396/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400397 Set bridge-domain forward enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400398 The CLI format is:
399 set bridge-domain forward <bd_index> [disable]
400*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401static clib_error_t *
Dave Barach97d8dc22016-08-15 15:31:15 -0400402bd_fwd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403{
Dave Barach97d8dc22016-08-15 15:31:15 -0400404 bd_main_t *bdm = &bd_main;
405 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406 u32 bd_index, bd_id;
407 u32 enable;
Dave Barach97d8dc22016-08-15 15:31:15 -0400408 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700409
Dave Barach97d8dc22016-08-15 15:31:15 -0400410 if (!unformat (input, "%d", &bd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 {
412 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
Dave Barach97d8dc22016-08-15 15:31:15 -0400413 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414 goto done;
415 }
416
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500417 if (bd_id == 0)
418 return clib_error_return (0,
419 "No operations on the default bridge domain are supported");
420
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
422
423 if (p == 0)
424 return clib_error_return (0, "No such bridge domain %d", bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400425
Ed Warnickecb9cada2015-12-08 15:45:58 -0700426 bd_index = p[0];
427
428 enable = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400429 if (unformat (input, "disable"))
430 {
431 enable = 0;
432 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700433
Dave Barach97d8dc22016-08-15 15:31:15 -0400434 /* set the bridge domain flag */
John Lo8d00fff2017-08-03 00:35:36 -0400435 bd_set_flags (vm, bd_index, L2_FWD, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436
Dave Barach97d8dc22016-08-15 15:31:15 -0400437done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438 return error;
439}
440
Billy McFall22aa3e92016-09-09 08:46:40 -0400441
442/*?
443 * Layer 2 unicast forwarding can be enabled and disabled on each
444 * interface and on each bridge-domain. Use this command to
445 * manage bridge-domains. It is enabled by default.
446 *
447 * @cliexpar
448 * Example of how to enable forwarding (where 200 is the bridge-domain-id):
449 * @cliexcmd{set bridge-domain forward 200}
450 * Example of how to disable forwarding (where 200 is the bridge-domain-id):
451 * @cliexcmd{set bridge-domain forward 200 disable}
452?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400453/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454VLIB_CLI_COMMAND (bd_fwd_cli, static) = {
455 .path = "set bridge-domain forward",
456 .short_help = "set bridge-domain forward <bridge-domain-id> [disable]",
457 .function = bd_fwd,
458};
Dave Barach97d8dc22016-08-15 15:31:15 -0400459/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460
Dave Barach97d8dc22016-08-15 15:31:15 -0400461/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400462 Set bridge-domain flood enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400463 The CLI format is:
464 set bridge-domain flood <bd_index> [disable]
465*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700466static clib_error_t *
467bd_flood (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400468 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700469{
Dave Barach97d8dc22016-08-15 15:31:15 -0400470 bd_main_t *bdm = &bd_main;
471 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472 u32 bd_index, bd_id;
473 u32 enable;
Dave Barach97d8dc22016-08-15 15:31:15 -0400474 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475
Dave Barach97d8dc22016-08-15 15:31:15 -0400476 if (!unformat (input, "%d", &bd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700477 {
478 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
Dave Barach97d8dc22016-08-15 15:31:15 -0400479 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480 goto done;
481 }
482
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500483 if (bd_id == 0)
484 return clib_error_return (0,
485 "No operations on the default bridge domain are supported");
486
Ed Warnickecb9cada2015-12-08 15:45:58 -0700487 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
488
489 if (p == 0)
490 return clib_error_return (0, "No such bridge domain %d", bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400491
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492 bd_index = p[0];
493
494 enable = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400495 if (unformat (input, "disable"))
496 {
497 enable = 0;
498 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499
Dave Barach97d8dc22016-08-15 15:31:15 -0400500 /* set the bridge domain flag */
John Lo8d00fff2017-08-03 00:35:36 -0400501 bd_set_flags (vm, bd_index, L2_FLOOD, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502
Dave Barach97d8dc22016-08-15 15:31:15 -0400503done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504 return error;
505}
506
Billy McFall22aa3e92016-09-09 08:46:40 -0400507/*?
508 * Layer 2 flooding can be enabled and disabled on each
509 * interface and on each bridge-domain. Use this command to
510 * manage bridge-domains. It is enabled by default.
511 *
512 * @cliexpar
513 * Example of how to enable flooding (where 200 is the bridge-domain-id):
514 * @cliexcmd{set bridge-domain flood 200}
515 * Example of how to disable flooding (where 200 is the bridge-domain-id):
516 * @cliexcmd{set bridge-domain flood 200 disable}
517?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400518/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519VLIB_CLI_COMMAND (bd_flood_cli, static) = {
520 .path = "set bridge-domain flood",
521 .short_help = "set bridge-domain flood <bridge-domain-id> [disable]",
522 .function = bd_flood,
523};
Dave Barach97d8dc22016-08-15 15:31:15 -0400524/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525
Dave Barach97d8dc22016-08-15 15:31:15 -0400526/**
Andrey "Zed" Zaikin701625b2018-04-18 17:07:07 +0300527 Set bridge-domain unknown-unicast flood enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400528 The CLI format is:
529 set bridge-domain uu-flood <bd_index> [disable]
530*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700531static clib_error_t *
532bd_uu_flood (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400533 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534{
Dave Barach97d8dc22016-08-15 15:31:15 -0400535 bd_main_t *bdm = &bd_main;
536 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700537 u32 bd_index, bd_id;
538 u32 enable;
Dave Barach97d8dc22016-08-15 15:31:15 -0400539 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700540
Dave Barach97d8dc22016-08-15 15:31:15 -0400541 if (!unformat (input, "%d", &bd_id))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700542 {
543 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
Dave Barach97d8dc22016-08-15 15:31:15 -0400544 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700545 goto done;
546 }
547
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500548 if (bd_id == 0)
549 return clib_error_return (0,
550 "No operations on the default bridge domain are supported");
551
Ed Warnickecb9cada2015-12-08 15:45:58 -0700552 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
553
554 if (p == 0)
555 return clib_error_return (0, "No such bridge domain %d", bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400556
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557 bd_index = p[0];
558
559 enable = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400560 if (unformat (input, "disable"))
561 {
562 enable = 0;
563 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700564
Dave Barach97d8dc22016-08-15 15:31:15 -0400565 /* set the bridge domain flag */
John Lo8d00fff2017-08-03 00:35:36 -0400566 bd_set_flags (vm, bd_index, L2_UU_FLOOD, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700567
Dave Barach97d8dc22016-08-15 15:31:15 -0400568done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569 return error;
570}
571
Billy McFall22aa3e92016-09-09 08:46:40 -0400572/*?
573 * Layer 2 unknown-unicast flooding can be enabled and disabled on each
574 * bridge-domain. It is enabled by default.
575 *
576 * @cliexpar
577 * Example of how to enable unknown-unicast flooding (where 200 is the
578 * bridge-domain-id):
579 * @cliexcmd{set bridge-domain uu-flood 200}
580 * Example of how to disable unknown-unicast flooding (where 200 is the bridge-domain-id):
581 * @cliexcmd{set bridge-domain uu-flood 200 disable}
582?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400583/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700584VLIB_CLI_COMMAND (bd_uu_flood_cli, static) = {
585 .path = "set bridge-domain uu-flood",
586 .short_help = "set bridge-domain uu-flood <bridge-domain-id> [disable]",
587 .function = bd_uu_flood,
588};
Dave Barach97d8dc22016-08-15 15:31:15 -0400589/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700590
Dave Barach97d8dc22016-08-15 15:31:15 -0400591/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400592 Set bridge-domain arp term enable/disable.
Dave Barach97d8dc22016-08-15 15:31:15 -0400593 The CLI format is:
594 set bridge-domain arp term <bridge-domain-id> [disable]
595*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700596static clib_error_t *
597bd_arp_term (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400598 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599{
Dave Barach97d8dc22016-08-15 15:31:15 -0400600 bd_main_t *bdm = &bd_main;
601 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700602 u32 bd_index, bd_id;
603 u32 enable;
Dave Barach97d8dc22016-08-15 15:31:15 -0400604 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700605
Dave Barach97d8dc22016-08-15 15:31:15 -0400606 if (!unformat (input, "%d", &bd_id))
607 {
608 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
609 format_unformat_error, input);
610 goto done;
611 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700612
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500613 if (bd_id == 0)
614 return clib_error_return (0,
615 "No operations on the default bridge domain are supported");
616
Ed Warnickecb9cada2015-12-08 15:45:58 -0700617 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
Dave Barach97d8dc22016-08-15 15:31:15 -0400618 if (p)
619 bd_index = *p;
620 else
621 return clib_error_return (0, "No such bridge domain %d", bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700622
Dave Barach97d8dc22016-08-15 15:31:15 -0400623 enable = 1;
624 if (unformat (input, "disable"))
625 enable = 0;
626
627 /* set the bridge domain flag */
John Lo8d00fff2017-08-03 00:35:36 -0400628 bd_set_flags (vm, bd_index, L2_ARP_TERM, enable);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700629
630done:
631 return error;
632}
633
Damjan Mariond171d482016-12-05 14:16:38 +0100634static clib_error_t *
635bd_mac_age (vlib_main_t * vm,
636 unformat_input_t * input, vlib_cli_command_t * cmd)
637{
638 bd_main_t *bdm = &bd_main;
639 clib_error_t *error = 0;
640 u32 bd_index, bd_id;
641 u32 age;
642 uword *p;
643
644 if (!unformat (input, "%d", &bd_id))
645 {
646 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
647 format_unformat_error, input);
648 goto done;
649 }
650
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500651 if (bd_id == 0)
652 return clib_error_return (0,
653 "No operations on the default bridge domain are supported");
654
Damjan Mariond171d482016-12-05 14:16:38 +0100655 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
656
657 if (p == 0)
658 return clib_error_return (0, "No such bridge domain %d", bd_id);
659
660 bd_index = p[0];
661
662 if (!unformat (input, "%u", &age))
663 {
664 error =
665 clib_error_return (0, "expecting ageing time in minutes but got `%U'",
666 format_unformat_error, input);
667 goto done;
668 }
669
670 /* set the bridge domain flag */
671 if (age > 255)
672 {
673 error =
674 clib_error_return (0, "mac aging time cannot be bigger than 255");
675 goto done;
676 }
677 bd_set_mac_age (vm, bd_index, (u8) age);
678
679done:
680 return error;
681}
682
683/*?
684 * Layer 2 mac aging can be enabled and disabled on each
685 * bridge-domain. Use this command to set or disable mac aging
686 * on specific bridge-domains. It is disabled by default.
687 *
688 * @cliexpar
689 * Example of how to set mac aging (where 200 is the bridge-domain-id and
690 * 5 is aging time in minutes):
691 * @cliexcmd{set bridge-domain mac-age 200 5}
692 * Example of how to disable mac aging (where 200 is the bridge-domain-id):
693 * @cliexcmd{set bridge-domain flood 200 0}
694?*/
695/* *INDENT-OFF* */
696VLIB_CLI_COMMAND (bd_mac_age_cli, static) = {
697 .path = "set bridge-domain mac-age",
698 .short_help = "set bridge-domain mac-age <bridge-domain-id> <mins>",
699 .function = bd_mac_age,
700};
701/* *INDENT-ON* */
702
Billy McFall22aa3e92016-09-09 08:46:40 -0400703/*?
704 * Modify whether or not an existing bridge-domain should terminate and respond
705 * to ARP Requests. ARP Termination is disabled by default.
706 *
707 * @cliexpar
708 * Example of how to enable ARP termination (where 200 is the bridge-domain-id):
709 * @cliexcmd{set bridge-domain arp term 200}
710 * Example of how to disable ARP termination (where 200 is the bridge-domain-id):
711 * @cliexcmd{set bridge-domain arp term 200 disable}
712?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400713/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714VLIB_CLI_COMMAND (bd_arp_term_cli, static) = {
715 .path = "set bridge-domain arp term",
716 .short_help = "set bridge-domain arp term <bridge-domain-id> [disable]",
717 .function = bd_arp_term,
718};
Dave Barach97d8dc22016-08-15 15:31:15 -0400719/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700720
721
Dave Barach97d8dc22016-08-15 15:31:15 -0400722/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400723 * Add/delete IP address to MAC address mapping.
724 *
Dave Barach97d8dc22016-08-15 15:31:15 -0400725 * The clib hash implementation stores uword entries in the hash table.
726 * The hash table mac_by_ip4 is keyed via IP4 address and store the
727 * 6-byte MAC address directly in the hash table entry uword.
Chris Luke16bcf7d2016-09-01 14:31:46 -0400728 *
729 * @warning This only works for 64-bit processor with 8-byte uword;
730 * which means this code *WILL NOT WORK* for a 32-bit prcessor with
731 * 4-byte uword.
Dave Barach97d8dc22016-08-15 15:31:15 -0400732 */
733u32
734bd_add_del_ip_mac (u32 bd_index,
735 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736{
Eyal Bariafc47aa2017-04-20 14:45:17 +0300737 l2_bridge_domain_t *bd_cfg = l2input_bd_config (bd_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738 u64 new_mac = *(u64 *) mac_addr;
Dave Barach97d8dc22016-08-15 15:31:15 -0400739 u64 *old_mac;
740 u16 *mac16 = (u16 *) & new_mac;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741
Dave Barach97d8dc22016-08-15 15:31:15 -0400742 ASSERT (sizeof (uword) == sizeof (u64)); /* make sure uword is 8 bytes */
Eyal Bariafc47aa2017-04-20 14:45:17 +0300743 ASSERT (bd_is_valid (bd_cfg));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744
John Lo1edfba92016-08-27 01:11:57 -0400745 mac16[3] = 0; /* Clear last 2 unsed bytes of the 8-byte MAC address */
Dave Barach97d8dc22016-08-15 15:31:15 -0400746 if (is_ip6)
747 {
John Lo1edfba92016-08-27 01:11:57 -0400748 ip6_address_t *ip6_addr_key;
749 hash_pair_t *hp;
750 old_mac = (u64 *) hash_get_mem (bd_cfg->mac_by_ip6, ip_addr);
751 if (is_add)
752 {
753 if (old_mac == 0)
754 { /* new entry - allocate and craete ip6 address key */
755 ip6_addr_key = clib_mem_alloc (sizeof (ip6_address_t));
756 clib_memcpy (ip6_addr_key, ip_addr, sizeof (ip6_address_t));
757 }
758 else if (*old_mac == new_mac)
759 { /* same mac entry already exist for ip6 address */
760 return 0;
761 }
762 else
763 { /* updat mac for ip6 address */
764 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
765 ip6_addr_key = (ip6_address_t *) hp->key;
766 }
767 hash_set_mem (bd_cfg->mac_by_ip6, ip6_addr_key, new_mac);
768 }
769 else
770 {
771 if (old_mac && (*old_mac == new_mac))
772 {
773 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
774 ip6_addr_key = (ip6_address_t *) hp->key;
775 hash_unset_mem (bd_cfg->mac_by_ip6, ip_addr);
776 clib_mem_free (ip6_addr_key);
777 }
778 else
779 return 1;
780 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781 }
Dave Barach97d8dc22016-08-15 15:31:15 -0400782 else
783 {
784 ip4_address_t ip4_addr = *(ip4_address_t *) ip_addr;
785 old_mac = (u64 *) hash_get (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
786 if (is_add)
787 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400788 if (old_mac && (*old_mac == new_mac))
John Lo1edfba92016-08-27 01:11:57 -0400789 return 0; /* mac entry already exist */
Dave Barach97d8dc22016-08-15 15:31:15 -0400790 hash_set (bd_cfg->mac_by_ip4, ip4_addr.as_u32, new_mac);
791 }
792 else
793 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400794 if (old_mac && (*old_mac == new_mac))
John Lo1edfba92016-08-27 01:11:57 -0400795 hash_unset (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
Dave Barach97d8dc22016-08-15 15:31:15 -0400796 else
John Lo1edfba92016-08-27 01:11:57 -0400797 return 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400798 }
Dave Barach97d8dc22016-08-15 15:31:15 -0400799 }
John Lo1edfba92016-08-27 01:11:57 -0400800 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801}
802
Dave Barach97d8dc22016-08-15 15:31:15 -0400803/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400804 Set bridge-domain arp entry add/delete.
Dave Barach97d8dc22016-08-15 15:31:15 -0400805 The CLI format is:
Billy McFall22aa3e92016-09-09 08:46:40 -0400806 set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]
Dave Barach97d8dc22016-08-15 15:31:15 -0400807*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700808static clib_error_t *
809bd_arp_entry (vlib_main_t * vm,
Dave Barach97d8dc22016-08-15 15:31:15 -0400810 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700811{
Dave Barach97d8dc22016-08-15 15:31:15 -0400812 bd_main_t *bdm = &bd_main;
813 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700814 u32 bd_index, bd_id;
815 u8 is_add = 1;
816 u8 is_ip6 = 0;
817 u8 ip_addr[16];
818 u8 mac_addr[6];
Dave Barach97d8dc22016-08-15 15:31:15 -0400819 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700820
Dave Barach97d8dc22016-08-15 15:31:15 -0400821 if (!unformat (input, "%d", &bd_id))
822 {
823 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
824 format_unformat_error, input);
825 goto done;
826 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700827
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500828 if (bd_id == 0)
829 return clib_error_return (0,
830 "No operations on the default bridge domain are supported");
831
Ed Warnickecb9cada2015-12-08 15:45:58 -0700832 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
833
Dave Barach97d8dc22016-08-15 15:31:15 -0400834 if (p)
835 bd_index = *p;
836 else
837 return clib_error_return (0, "No such bridge domain %d", bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838
Dave Barach97d8dc22016-08-15 15:31:15 -0400839 if (unformat (input, "%U", unformat_ip4_address, ip_addr))
840 {
841 is_ip6 = 0;
842 }
843 else if (unformat (input, "%U", unformat_ip6_address, ip_addr))
844 {
845 is_ip6 = 1;
846 }
847 else
848 {
849 error = clib_error_return (0, "expecting IP address but got `%U'",
850 format_unformat_error, input);
851 goto done;
852 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700853
Dave Barach97d8dc22016-08-15 15:31:15 -0400854 if (!unformat (input, "%U", unformat_ethernet_address, mac_addr))
855 {
856 error = clib_error_return (0, "expecting MAC address but got `%U'",
857 format_unformat_error, input);
858 goto done;
859 }
860
861 if (unformat (input, "del"))
862 {
863 is_add = 0;
864 }
865
866 /* set the bridge domain flagAdd IP-MAC entry into bridge domain */
867 if (bd_add_del_ip_mac (bd_index, ip_addr, mac_addr, is_ip6, is_add))
868 {
869 error = clib_error_return (0, "MAC %s for IP %U and MAC %U failed",
870 is_add ? "add" : "del",
John Lo1edfba92016-08-27 01:11:57 -0400871 is_ip6 ?
872 format_ip4_address : format_ip6_address,
873 ip_addr, format_ethernet_address, mac_addr);
Dave Barach97d8dc22016-08-15 15:31:15 -0400874 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700875
876done:
877 return error;
878}
879
Billy McFall22aa3e92016-09-09 08:46:40 -0400880/*?
881 * Add an ARP entry to an existing bridge-domain.
882 *
883 * @cliexpar
884 * Example of how to add an ARP entry (where 200 is the bridge-domain-id):
885 * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a}
886 * Example of how to delete an ARP entry (where 200 is the bridge-domain-id):
887 * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a del}
888?*/
Dave Barach97d8dc22016-08-15 15:31:15 -0400889/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700890VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = {
891 .path = "set bridge-domain arp entry",
Billy McFall22aa3e92016-09-09 08:46:40 -0400892 .short_help = "set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700893 .function = bd_arp_entry,
894};
Dave Barach97d8dc22016-08-15 15:31:15 -0400895/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700896
Dave Barach97d8dc22016-08-15 15:31:15 -0400897u8 *
898format_vtr (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899{
Dave Barach97d8dc22016-08-15 15:31:15 -0400900 u32 vtr_op = va_arg (*args, u32);
901 u32 dot1q = va_arg (*args, u32);
902 u32 tag1 = va_arg (*args, u32);
903 u32 tag2 = va_arg (*args, u32);
904 switch (vtr_op)
905 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700906 case L2_VTR_DISABLED:
Dave Barach97d8dc22016-08-15 15:31:15 -0400907 return format (s, "none");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700908 case L2_VTR_PUSH_1:
Dave Barach97d8dc22016-08-15 15:31:15 -0400909 return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700910 case L2_VTR_PUSH_2:
Dave Barach97d8dc22016-08-15 15:31:15 -0400911 return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1,
912 tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913 case L2_VTR_POP_1:
Dave Barach97d8dc22016-08-15 15:31:15 -0400914 return format (s, "pop-1");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700915 case L2_VTR_POP_2:
Dave Barach97d8dc22016-08-15 15:31:15 -0400916 return format (s, "pop-2");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700917 case L2_VTR_TRANSLATE_1_1:
Dave Barach97d8dc22016-08-15 15:31:15 -0400918 return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919 case L2_VTR_TRANSLATE_1_2:
Dave Barach97d8dc22016-08-15 15:31:15 -0400920 return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
921 tag1, tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700922 case L2_VTR_TRANSLATE_2_1:
Dave Barach97d8dc22016-08-15 15:31:15 -0400923 return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924 case L2_VTR_TRANSLATE_2_2:
Dave Barach97d8dc22016-08-15 15:31:15 -0400925 return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
926 tag1, tag2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700927 default:
Dave Barach97d8dc22016-08-15 15:31:15 -0400928 return format (s, "none");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 }
930}
931
Dave Barach97d8dc22016-08-15 15:31:15 -0400932/**
Chris Luke16bcf7d2016-09-01 14:31:46 -0400933 Show bridge-domain state.
Dave Barach97d8dc22016-08-15 15:31:15 -0400934 The CLI format is:
935 show bridge-domain [<bd_index>]
936*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937static clib_error_t *
Dave Barach97d8dc22016-08-15 15:31:15 -0400938bd_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700939{
Dave Barach97d8dc22016-08-15 15:31:15 -0400940 vnet_main_t *vnm = vnet_get_main ();
941 bd_main_t *bdm = &bd_main;
942 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700943 u32 bd_index = ~0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400944 l2_bridge_domain_t *bd_config;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700945 u32 start, end;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700946 u32 detail = 0;
947 u32 intf = 0;
948 u32 arp = 0;
Jerome Tollet48304142017-09-05 12:13:22 +0100949 u32 bd_tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700950 u32 bd_id = ~0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400951 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700952
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500953 start = 1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400954 end = vec_len (l2input_main.bd_configs);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700955
Dave Barach97d8dc22016-08-15 15:31:15 -0400956 if (unformat (input, "%d", &bd_id))
957 {
958 if (unformat (input, "detail"))
959 detail = 1;
960 else if (unformat (input, "det"))
961 detail = 1;
962 if (unformat (input, "int"))
963 intf = 1;
964 if (unformat (input, "arp"))
965 arp = 1;
Jerome Tollet48304142017-09-05 12:13:22 +0100966 if (unformat (input, "bd-tag"))
967 bd_tag = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
Jon Loeliger1c7d4852017-05-02 11:06:23 -0500969 if (bd_id == 0)
970 return clib_error_return (0,
971 "No operations on the default bridge domain are supported");
972
Dave Barach97d8dc22016-08-15 15:31:15 -0400973 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
974 if (p)
975 bd_index = *p;
976 else
977 return clib_error_return (0, "No such bridge domain %d", bd_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700978
Dave Barach97d8dc22016-08-15 15:31:15 -0400979 vec_validate (l2input_main.bd_configs, bd_index);
980 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
981 if (bd_is_valid (bd_config))
982 {
983 start = bd_index;
984 end = start + 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985 }
Dave Barach97d8dc22016-08-15 15:31:15 -0400986 else
987 {
988 vlib_cli_output (vm, "bridge-domain %d not in use", bd_id);
989 goto done;
990 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700991 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992
Dave Barach97d8dc22016-08-15 15:31:15 -0400993 /* Show all bridge-domains that have been initialized */
John Loda1f2c72017-03-24 20:11:15 -0400994 u32 printed = 0;
995 u8 *as = 0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400996 for (bd_index = start; bd_index < end; bd_index++)
997 {
998 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
999 if (bd_is_valid (bd_config))
1000 {
1001 if (!printed)
1002 {
1003 printed = 1;
1004 vlib_cli_output (vm,
John Lo97934772017-05-18 22:26:47 -04001005 "%=8s %=7s %=4s %=9s %=9s %=9s %=9s %=9s %=9s %=9s",
1006 "BD-ID", "Index", "BSN", "Age(min)",
1007 "Learning", "U-Forwrd", "UU-Flood", "Flooding",
1008 "ARP-Term", "BVI-Intf");
Dave Barach97d8dc22016-08-15 15:31:15 -04001009 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001010
John Loda1f2c72017-03-24 20:11:15 -04001011 if (bd_config->mac_age)
1012 as = format (as, "%d", bd_config->mac_age);
1013 else
1014 as = format (as, "off");
Dave Barach97d8dc22016-08-15 15:31:15 -04001015 vlib_cli_output (vm,
John Lo97934772017-05-18 22:26:47 -04001016 "%=8d %=7d %=4d %=9v %=9s %=9s %=9s %=9s %=9s %=9U",
John Loda1f2c72017-03-24 20:11:15 -04001017 bd_config->bd_id, bd_index, bd_config->seq_num, as,
Dave Barach97d8dc22016-08-15 15:31:15 -04001018 bd_config->feature_bitmap & L2INPUT_FEAT_LEARN ?
1019 "on" : "off",
John Loda1f2c72017-03-24 20:11:15 -04001020 bd_config->feature_bitmap & L2INPUT_FEAT_FWD ?
1021 "on" : "off",
Dave Barach97d8dc22016-08-15 15:31:15 -04001022 bd_config->feature_bitmap & L2INPUT_FEAT_UU_FLOOD ?
1023 "on" : "off",
1024 bd_config->feature_bitmap & L2INPUT_FEAT_FLOOD ?
1025 "on" : "off",
1026 bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM ?
John Loda1f2c72017-03-24 20:11:15 -04001027 "on" : "off",
1028 format_vnet_sw_if_index_name_with_NA,
Dave Barach97d8dc22016-08-15 15:31:15 -04001029 vnm, bd_config->bvi_sw_if_index);
John Loda1f2c72017-03-24 20:11:15 -04001030 vec_reset_length (as);
Dave Barach97d8dc22016-08-15 15:31:15 -04001031
1032 if (detail || intf)
1033 {
1034 /* Show all member interfaces */
Eyal Baric5b13602016-11-24 19:42:43 +02001035 int i;
1036 vec_foreach_index (i, bd_config->members)
Dave Barach97d8dc22016-08-15 15:31:15 -04001037 {
Eyal Baric5b13602016-11-24 19:42:43 +02001038 l2_flood_member_t *member =
1039 vec_elt_at_index (bd_config->members, i);
Eyal Bari0f360dc2017-06-14 13:11:20 +03001040 u8 swif_seq_num = *l2fib_swif_seq_num (member->sw_if_index);
Dave Barach97d8dc22016-08-15 15:31:15 -04001041 u32 vtr_opr, dot1q, tag1, tag2;
Eyal Baric5b13602016-11-24 19:42:43 +02001042 if (i == 0)
Dave Barach97d8dc22016-08-15 15:31:15 -04001043 {
John Loda1f2c72017-03-24 20:11:15 -04001044 vlib_cli_output (vm, "\n%=30s%=7s%=5s%=5s%=5s%=9s%=30s",
1045 "Interface", "If-idx", "ISN", "SHG",
1046 "BVI", "TxFlood", "VLAN-Tag-Rewrite");
Dave Barach97d8dc22016-08-15 15:31:15 -04001047 }
1048 l2vtr_get (vm, vnm, member->sw_if_index, &vtr_opr, &dot1q,
1049 &tag1, &tag2);
John Loda1f2c72017-03-24 20:11:15 -04001050 vlib_cli_output (vm, "%=30U%=7d%=5d%=5d%=5s%=9s%=30U",
Dave Barach97d8dc22016-08-15 15:31:15 -04001051 format_vnet_sw_if_index_name, vnm,
1052 member->sw_if_index, member->sw_if_index,
Eyal Bari0f360dc2017-06-14 13:11:20 +03001053 swif_seq_num, member->shg,
Dave Barach97d8dc22016-08-15 15:31:15 -04001054 member->flags & L2_FLOOD_MEMBER_BVI ? "*" :
Eyal Baric5b13602016-11-24 19:42:43 +02001055 "-", i < bd_config->flood_count ? "*" : "-",
1056 format_vtr, vtr_opr, dot1q, tag1, tag2);
Dave Barach97d8dc22016-08-15 15:31:15 -04001057 }
1058 }
1059
1060 if ((detail || arp) &&
1061 (bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM))
1062 {
1063 u32 ip4_addr;
John Lo1edfba92016-08-27 01:11:57 -04001064 ip6_address_t *ip6_addr;
Dave Barach97d8dc22016-08-15 15:31:15 -04001065 u64 mac_addr;
1066 vlib_cli_output (vm,
John Lo1edfba92016-08-27 01:11:57 -04001067 "\n IP4/IP6 to MAC table for ARP Termination");
Dave Barach97d8dc22016-08-15 15:31:15 -04001068
1069 /* *INDENT-OFF* */
1070 hash_foreach (ip4_addr, mac_addr, bd_config->mac_by_ip4,
1071 ({
John Lo1edfba92016-08-27 01:11:57 -04001072 vlib_cli_output (vm, "%=40U => %=20U",
Dave Barach97d8dc22016-08-15 15:31:15 -04001073 format_ip4_address, &ip4_addr,
1074 format_ethernet_address, &mac_addr);
1075 }));
John Lo1edfba92016-08-27 01:11:57 -04001076
1077 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
1078 ({
1079 vlib_cli_output (vm, "%=40U => %=20U",
1080 format_ip6_address, ip6_addr,
1081 format_ethernet_address, &mac_addr);
1082 }));
Dave Barach97d8dc22016-08-15 15:31:15 -04001083 /* *INDENT-ON* */
1084 }
Jerome Tollet48304142017-09-05 12:13:22 +01001085
1086 if ((detail || bd_tag) && (bd_config->bd_tag))
1087 {
1088 vlib_cli_output (vm, "\n BD-Tag: %s", bd_config->bd_tag);
1089
1090 }
Dave Barach97d8dc22016-08-15 15:31:15 -04001091 }
1092 }
John Loda1f2c72017-03-24 20:11:15 -04001093 vec_free (as);
Dave Barach97d8dc22016-08-15 15:31:15 -04001094
1095 if (!printed)
1096 {
1097 vlib_cli_output (vm, "no bridge-domains in use");
1098 }
1099
1100done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001101 return error;
1102}
1103
Billy McFall22aa3e92016-09-09 08:46:40 -04001104/*?
1105 * Show a summary of all the bridge-domain instances or detailed view of a
1106 * single bridge-domain. Bridge-domains are created by adding an interface
1107 * to a bridge using the '<em>set interface l2 bridge</em>' command.
1108 *
1109 * @cliexpar
1110 * @parblock
1111 * Example of displaying all bridge-domains:
1112 * @cliexstart{show bridge-domain}
1113 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1114 * 0 0 off off off off off local0
1115 * 200 1 on on on on off N/A
1116 * @cliexend
1117 *
1118 * Example of displaying details of a single bridge-domains:
1119 * @cliexstart{show bridge-domain 200 detail}
1120 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1121 * 200 1 on on on on off N/A
1122 *
1123 * Interface Index SHG BVI VLAN-Tag-Rewrite
1124 * GigabitEthernet0/8/0.200 3 0 - none
1125 * GigabitEthernet0/9/0.200 4 0 - none
1126 * @cliexend
1127 * @endparblock
1128?*/
Dave Barach97d8dc22016-08-15 15:31:15 -04001129/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001130VLIB_CLI_COMMAND (bd_show_cli, static) = {
1131 .path = "show bridge-domain",
Jerome Tollet48304142017-09-05 12:13:22 +01001132 .short_help = "show bridge-domain [bridge-domain-id [detail|int|arp|bd-tag]]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001133 .function = bd_show,
1134};
Dave Barach97d8dc22016-08-15 15:31:15 -04001135/* *INDENT-ON* */
1136
Choonho Son05480792017-03-29 20:07:45 +09001137int
1138bd_add_del (l2_bridge_domain_add_del_args_t * a)
1139{
1140 bd_main_t *bdm = &bd_main;
1141 vlib_main_t *vm = bdm->vlib_main;
Choonho Son05480792017-03-29 20:07:45 +09001142 int rv = 0;
1143
Eyal Barib1352ed2017-04-07 23:14:17 +03001144 u32 bd_index = bd_find_index (bdm, a->bd_id);
Choonho Son05480792017-03-29 20:07:45 +09001145 if (a->is_add)
1146 {
Eyal Barib1352ed2017-04-07 23:14:17 +03001147 if (bd_index != ~0)
1148 return VNET_API_ERROR_BD_ALREADY_EXISTS;
John Lo97934772017-05-18 22:26:47 -04001149 if (a->bd_id > L2_BD_ID_MAX)
1150 return VNET_API_ERROR_BD_ID_EXCEED_MAX;
Eyal Barib1352ed2017-04-07 23:14:17 +03001151 bd_index = bd_add_bd_index (bdm, a->bd_id);
Choonho Son05480792017-03-29 20:07:45 +09001152
Eyal Barib1352ed2017-04-07 23:14:17 +03001153 u32 enable_flags = 0, disable_flags = 0;
Choonho Son05480792017-03-29 20:07:45 +09001154 if (a->flood)
1155 enable_flags |= L2_FLOOD;
1156 else
1157 disable_flags |= L2_FLOOD;
1158
1159 if (a->uu_flood)
1160 enable_flags |= L2_UU_FLOOD;
1161 else
1162 disable_flags |= L2_UU_FLOOD;
1163
1164 if (a->forward)
1165 enable_flags |= L2_FWD;
1166 else
1167 disable_flags |= L2_FWD;
1168
1169 if (a->learn)
1170 enable_flags |= L2_LEARN;
1171 else
1172 disable_flags |= L2_LEARN;
1173
1174 if (a->arp_term)
1175 enable_flags |= L2_ARP_TERM;
1176 else
1177 disable_flags |= L2_ARP_TERM;
1178
1179 if (enable_flags)
1180 bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ );
1181
1182 if (disable_flags)
1183 bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ );
1184
1185 bd_set_mac_age (vm, bd_index, a->mac_age);
Jerome Tollet48304142017-09-05 12:13:22 +01001186
1187 if (a->bd_tag)
1188 bd_set_bd_tag (vm, bd_index, a->bd_tag);
1189
Choonho Son05480792017-03-29 20:07:45 +09001190 }
1191 else
Eyal Barib1352ed2017-04-07 23:14:17 +03001192 {
1193 if (bd_index == ~0)
1194 return VNET_API_ERROR_NO_SUCH_ENTRY;
Jon Loeliger1c7d4852017-05-02 11:06:23 -05001195 if (bd_index == 0)
1196 return VNET_API_ERROR_BD_NOT_MODIFIABLE;
Eyal Barib1352ed2017-04-07 23:14:17 +03001197 if (vec_len (l2input_main.bd_configs[bd_index].members))
1198 return VNET_API_ERROR_BD_IN_USE;
1199 rv = bd_delete (bdm, bd_index);
1200 }
Choonho Son05480792017-03-29 20:07:45 +09001201
1202 return rv;
1203}
1204
1205/**
1206 Create or delete bridge-domain.
Choonho Son5ee51f82017-04-05 19:09:52 +09001207 The CLI format:
Jerome Tollet50570ec2017-09-14 12:53:56 +01001208 create bridge-domain <bd_index> [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] [flood <0|1>]
1209 [arp-term <0|1>] [mac-age <nn>] [bd-tag <tag>] [del]
Choonho Son05480792017-03-29 20:07:45 +09001210*/
1211
1212static clib_error_t *
1213bd_add_del_command_fn (vlib_main_t * vm, unformat_input_t * input,
1214 vlib_cli_command_t * cmd)
1215{
1216 unformat_input_t _line_input, *line_input = &_line_input;
1217 clib_error_t *error = 0;
1218 u8 is_add = 1;
1219 u32 bd_id = ~0;
Choonho Son5ee51f82017-04-05 19:09:52 +09001220 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Choonho Son05480792017-03-29 20:07:45 +09001221 u32 mac_age = 0;
Jerome Tollet48304142017-09-05 12:13:22 +01001222 u8 *bd_tag = NULL;
Choonho Son05480792017-03-29 20:07:45 +09001223 l2_bridge_domain_add_del_args_t _a, *a = &_a;
1224 int rv;
1225
1226 /* Get a line of input. */
1227 if (!unformat_user (input, unformat_line_input, line_input))
1228 return 0;
1229
1230 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1231 {
1232 if (unformat (line_input, "%d", &bd_id))
1233 ;
1234 else if (unformat (line_input, "flood %d", &flood))
1235 ;
1236 else if (unformat (line_input, "uu-flood %d", &uu_flood))
1237 ;
1238 else if (unformat (line_input, "forward %d", &forward))
1239 ;
Choonho Son5ee51f82017-04-05 19:09:52 +09001240 else if (unformat (line_input, "learn %d", &learn))
1241 ;
Choonho Son05480792017-03-29 20:07:45 +09001242 else if (unformat (line_input, "arp-term %d", &arp_term))
1243 ;
1244 else if (unformat (line_input, "mac-age %d", &mac_age))
1245 ;
Jerome Tollet48304142017-09-05 12:13:22 +01001246 else if (unformat (line_input, "bd-tag %s", &bd_tag))
1247 ;
Choonho Son05480792017-03-29 20:07:45 +09001248 else if (unformat (line_input, "del"))
1249 {
1250 is_add = 0;
1251 flood = uu_flood = forward = learn = 0;
1252 }
1253 else
1254 break;
1255 }
1256
1257 if (bd_id == ~0)
1258 {
1259 error = clib_error_return (0, "bridge-domain-id not specified");
1260 goto done;
1261 }
1262
Jon Loeliger1c7d4852017-05-02 11:06:23 -05001263 if (bd_id == 0)
1264 {
1265 error = clib_error_return (0, "bridge domain 0 can not be modified");
1266 goto done;
1267 }
1268
Choonho Son05480792017-03-29 20:07:45 +09001269 if (mac_age > 255)
1270 {
1271 error = clib_error_return (0, "mac age must be less than 256");
1272 goto done;
1273 }
Jerome Tollet48304142017-09-05 12:13:22 +01001274 if ((bd_tag) && (strlen ((char *) bd_tag) > 63))
1275 {
1276 error = clib_error_return (0, "bd-tag cannot be longer than 63");
1277 goto done;
1278 }
Choonho Son05480792017-03-29 20:07:45 +09001279
1280 memset (a, 0, sizeof (*a));
1281 a->is_add = is_add;
1282 a->bd_id = bd_id;
1283 a->flood = (u8) flood;
1284 a->uu_flood = (u8) uu_flood;
1285 a->forward = (u8) forward;
1286 a->learn = (u8) learn;
1287 a->arp_term = (u8) arp_term;
1288 a->mac_age = (u8) mac_age;
Jerome Tollet48304142017-09-05 12:13:22 +01001289 a->bd_tag = bd_tag;
Choonho Son05480792017-03-29 20:07:45 +09001290
1291 rv = bd_add_del (a);
1292
1293 switch (rv)
1294 {
1295 case 0:
1296 if (is_add)
1297 vlib_cli_output (vm, "bridge-domain %d", bd_id);
1298 break;
Eyal Barib1352ed2017-04-07 23:14:17 +03001299 case VNET_API_ERROR_BD_IN_USE:
1300 error = clib_error_return (0, "bridge domain in use - remove members");
1301 goto done;
Choonho Son05480792017-03-29 20:07:45 +09001302 case VNET_API_ERROR_NO_SUCH_ENTRY:
John Lo97934772017-05-18 22:26:47 -04001303 error = clib_error_return (0, "bridge domain ID does not exist");
Choonho Son05480792017-03-29 20:07:45 +09001304 goto done;
Jon Loeliger1c7d4852017-05-02 11:06:23 -05001305 case VNET_API_ERROR_BD_NOT_MODIFIABLE:
1306 error = clib_error_return (0, "bridge domain 0 can not be modified");
1307 goto done;
John Lo97934772017-05-18 22:26:47 -04001308 case VNET_API_ERROR_BD_ID_EXCEED_MAX:
1309 error = clib_error_return (0, "bridge domain ID exceed 16M limit");
1310 goto done;
Choonho Son05480792017-03-29 20:07:45 +09001311 default:
1312 error = clib_error_return (0, "bd_add_del returned %d", rv);
1313 goto done;
1314 }
1315
1316done:
Jerome Tollet48304142017-09-05 12:13:22 +01001317 vec_free (bd_tag);
Choonho Son05480792017-03-29 20:07:45 +09001318 unformat_free (line_input);
1319
1320 return error;
1321}
1322
1323
1324/*?
1325 * Create/Delete bridge-domain instance
1326 *
1327 * @cliexpar
1328 * @parblock
1329 * Example of creating bridge-domain 1:
1330 * @cliexstart{create bridge-domain 1}
1331 * bridge-domain 1
1332 * @cliexend
1333 *
1334 * Example of creating bridge-domain 2 with enabling arp-term, mac-age 60:
1335 * @cliexstart{create bridge-domain 2 arp-term 1 mac-age 60}
1336 * bridge-domain 2
1337 *
1338 * vpp# show bridge-domain
1339 * ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1340 * 0 0 0 off off off off off off local0
1341 * 1 1 0 off on on off on off N/A
1342 * 2 2 0 60 on on off on on N/A
1343 *
1344 * @cliexend
1345 *
1346 * Example of delete bridge-domain 1:
1347 * @cliexstart{create bridge-domain 1 del}
1348 * @cliexend
1349 * @endparblock
1350?*/
1351
1352/* *INDENT-OFF* */
1353VLIB_CLI_COMMAND (bd_create_cli, static) = {
1354 .path = "create bridge-domain",
1355 .short_help = "create bridge-domain <bridge-domain-id>"
1356 " [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] [flood <0|1>] [arp-term <0|1>]"
Jerome Tollet48304142017-09-05 12:13:22 +01001357 " [mac-age <nn>] [bd-tag <tag>] [del]",
Choonho Son05480792017-03-29 20:07:45 +09001358 .function = bd_add_del_command_fn,
1359};
1360/* *INDENT-ON* */
1361
1362
1363
Dave Barach97d8dc22016-08-15 15:31:15 -04001364/*
1365 * fd.io coding-style-patch-verification: ON
1366 *
1367 * Local Variables:
1368 * eval: (c-set-style "gnu")
1369 * End:
1370 */