2 * l2_bd.c : 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 #include <vlib/vlib.h>
19 #include <vnet/vnet.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>
26 #include <vnet/l2/l2_learn.h>
27 #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>
32 #include <vppinfra/error.h>
33 #include <vppinfra/hash.h>
34 #include <vppinfra/vec.h>
38 * @brief Ethernet Bridge Domain.
40 * Code in this file manages Layer 2 bridge domains.
47 Init bridge domain if not done already.
48 For feature bitmap, set all bits except ARP termination
51 bd_validate (l2_bridge_domain_t * bd_config)
53 if (!bd_is_valid (bd_config))
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;
61 bd_config->mac_by_ip4 = 0;
62 bd_config->mac_by_ip6 = hash_create_mem (0, sizeof (ip6_address_t),
68 bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id)
76 while (hash_get (bdm->bd_index_by_bd_id, bd_id))
81 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
86 rv = clib_bitmap_first_clear (bdm->bd_index_bitmap);
88 /* mark this index busy */
89 bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, rv, 1);
91 hash_set (bdm->bd_index_by_bd_id, bd_id, rv);
93 vec_validate (l2input_main.bd_configs, rv);
94 l2input_main.bd_configs[rv].bd_id = bd_id;
100 bd_delete_bd_index (bd_main_t * bdm, u32 bd_id)
105 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
111 /* mark this index clear */
112 bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, bd_index, 0);
113 hash_unset (bdm->bd_index_by_bd_id, bd_id);
115 l2input_main.bd_configs[bd_index].bd_id = ~0;
116 l2input_main.bd_configs[bd_index].feature_bitmap = 0;
122 update_flood_count (l2_bridge_domain_t * bd_config)
124 bd_config->flood_count = vec_len (bd_config->members) -
125 (bd_config->tun_master_count ? bd_config->tun_normal_count : 0);
129 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member)
132 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
133 (vnet_get_main (), member->sw_if_index);
136 * Add one element to the vector
137 * vector is ordered [ bvi, normal/tun_masters..., tun_normals... ]
138 * When flooding, the bvi interface (if present) must be the last member
139 * processed due to how BVI processing can change the packet. To enable
140 * this order, we make the bvi interface the first in the vector and
141 * flooding walks the vector in reverse.
143 switch (sw_if->flood_class)
145 case VNET_FLOOD_CLASS_TUNNEL_MASTER:
146 bd_config->tun_master_count++;
150 case VNET_FLOOD_CLASS_NORMAL:
151 ix = (member->flags & L2_FLOOD_MEMBER_BVI) ? 0 :
152 vec_len (bd_config->members) - bd_config->tun_normal_count;
154 case VNET_FLOOD_CLASS_TUNNEL_NORMAL:
155 ix = vec_len (bd_config->members);
156 bd_config->tun_normal_count++;
160 vec_insert_elts (bd_config->members, member, 1, ix);
161 update_flood_count (bd_config);
164 #define BD_REMOVE_ERROR_OK 0
165 #define BD_REMOVE_ERROR_NOT_FOUND 1
168 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index)
172 /* Find and delete the member */
173 vec_foreach_index (ix, bd_config->members)
175 l2_flood_member_t *m = vec_elt_at_index (bd_config->members, ix);
176 if (m->sw_if_index == sw_if_index)
178 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
179 (vnet_get_main (), sw_if_index);
181 if (sw_if->flood_class != VNET_FLOOD_CLASS_NORMAL)
183 if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_MASTER)
184 bd_config->tun_master_count--;
185 else if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_NORMAL)
186 bd_config->tun_normal_count--;
188 vec_del1 (bd_config->members, ix);
189 update_flood_count (bd_config);
191 return BD_REMOVE_ERROR_OK;
195 return BD_REMOVE_ERROR_NOT_FOUND;
200 l2bd_init (vlib_main_t * vm)
202 bd_main_t *bdm = &bd_main;
204 bdm->bd_index_by_bd_id = hash_create (0, sizeof (uword));
206 * create a dummy bd with bd_id of 0 and bd_index of 0 with feature set
207 * to packet drop only. Thus, packets received from any L2 interface with
208 * uninitialized bd_index of 0 can be dropped safely.
210 bd_index = bd_find_or_add_bd_index (bdm, 0);
211 ASSERT (bd_index == 0);
212 l2input_main.bd_configs[0].feature_bitmap = L2INPUT_FEAT_DROP;
216 VLIB_INIT_FUNCTION (l2bd_init);
220 Set the learn/forward/flood flags for the bridge domain.
221 Return 0 if ok, non-zero if for an error.
224 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable)
227 l2_bridge_domain_t *bd_config;
228 u32 feature_bitmap = 0;
230 vec_validate (l2input_main.bd_configs, bd_index);
231 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
233 bd_validate (bd_config);
235 if (flags & L2_LEARN)
237 feature_bitmap |= L2INPUT_FEAT_LEARN;
241 feature_bitmap |= L2INPUT_FEAT_FWD;
243 if (flags & L2_FLOOD)
245 feature_bitmap |= L2INPUT_FEAT_FLOOD;
247 if (flags & L2_UU_FLOOD)
249 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
251 if (flags & L2_ARP_TERM)
253 feature_bitmap |= L2INPUT_FEAT_ARP_TERM;
258 bd_config->feature_bitmap |= feature_bitmap;
262 bd_config->feature_bitmap &= ~feature_bitmap;
269 Set the mac age for the bridge domain.
272 bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age)
274 l2_bridge_domain_t *bd_config;
277 vec_validate (l2input_main.bd_configs, bd_index);
278 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
279 bd_config->mac_age = age;
281 /* check if there is at least one bd with mac aging enabled */
282 vec_foreach (bd_config, l2input_main.bd_configs)
283 if (bd_config->bd_id != ~0 && bd_config->mac_age != 0)
286 vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index,
287 enable ? L2_MAC_AGE_PROCESS_EVENT_START :
288 L2_MAC_AGE_PROCESS_EVENT_STOP, 0);
292 Set bridge-domain learn enable/disable.
294 set bridge-domain learn <bd_id> [disable]
296 static clib_error_t *
297 bd_learn (vlib_main_t * vm,
298 unformat_input_t * input, vlib_cli_command_t * cmd)
300 bd_main_t *bdm = &bd_main;
301 clib_error_t *error = 0;
306 if (!unformat (input, "%d", &bd_id))
308 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
309 format_unformat_error, input);
313 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
316 return clib_error_return (0, "No such bridge domain %d", bd_id);
321 if (unformat (input, "disable"))
326 /* set the bridge domain flag */
327 if (bd_set_flags (vm, bd_index, L2_LEARN, enable))
330 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
339 * Layer 2 learning can be enabled and disabled on each
340 * interface and on each bridge-domain. Use this command to
341 * manage bridge-domains. It is enabled by default.
344 * Example of how to enable learning (where 200 is the bridge-domain-id):
345 * @cliexcmd{set bridge-domain learn 200}
346 * Example of how to disable learning (where 200 is the bridge-domain-id):
347 * @cliexcmd{set bridge-domain learn 200 disable}
350 VLIB_CLI_COMMAND (bd_learn_cli, static) = {
351 .path = "set bridge-domain learn",
352 .short_help = "set bridge-domain learn <bridge-domain-id> [disable]",
353 .function = bd_learn,
358 Set bridge-domain forward enable/disable.
360 set bridge-domain forward <bd_index> [disable]
362 static clib_error_t *
363 bd_fwd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
365 bd_main_t *bdm = &bd_main;
366 clib_error_t *error = 0;
371 if (!unformat (input, "%d", &bd_id))
373 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
374 format_unformat_error, input);
378 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
381 return clib_error_return (0, "No such bridge domain %d", bd_id);
386 if (unformat (input, "disable"))
391 /* set the bridge domain flag */
392 if (bd_set_flags (vm, bd_index, L2_FWD, enable))
395 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
405 * Layer 2 unicast forwarding can be enabled and disabled on each
406 * interface and on each bridge-domain. Use this command to
407 * manage bridge-domains. It is enabled by default.
410 * Example of how to enable forwarding (where 200 is the bridge-domain-id):
411 * @cliexcmd{set bridge-domain forward 200}
412 * Example of how to disable forwarding (where 200 is the bridge-domain-id):
413 * @cliexcmd{set bridge-domain forward 200 disable}
416 VLIB_CLI_COMMAND (bd_fwd_cli, static) = {
417 .path = "set bridge-domain forward",
418 .short_help = "set bridge-domain forward <bridge-domain-id> [disable]",
424 Set bridge-domain flood enable/disable.
426 set bridge-domain flood <bd_index> [disable]
428 static clib_error_t *
429 bd_flood (vlib_main_t * vm,
430 unformat_input_t * input, vlib_cli_command_t * cmd)
432 bd_main_t *bdm = &bd_main;
433 clib_error_t *error = 0;
438 if (!unformat (input, "%d", &bd_id))
440 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
441 format_unformat_error, input);
445 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
448 return clib_error_return (0, "No such bridge domain %d", bd_id);
453 if (unformat (input, "disable"))
458 /* set the bridge domain flag */
459 if (bd_set_flags (vm, bd_index, L2_FLOOD, enable))
462 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
471 * Layer 2 flooding can be enabled and disabled on each
472 * interface and on each bridge-domain. Use this command to
473 * manage bridge-domains. It is enabled by default.
476 * Example of how to enable flooding (where 200 is the bridge-domain-id):
477 * @cliexcmd{set bridge-domain flood 200}
478 * Example of how to disable flooding (where 200 is the bridge-domain-id):
479 * @cliexcmd{set bridge-domain flood 200 disable}
482 VLIB_CLI_COMMAND (bd_flood_cli, static) = {
483 .path = "set bridge-domain flood",
484 .short_help = "set bridge-domain flood <bridge-domain-id> [disable]",
485 .function = bd_flood,
490 Set bridge-domain unkown-unicast flood enable/disable.
492 set bridge-domain uu-flood <bd_index> [disable]
494 static clib_error_t *
495 bd_uu_flood (vlib_main_t * vm,
496 unformat_input_t * input, vlib_cli_command_t * cmd)
498 bd_main_t *bdm = &bd_main;
499 clib_error_t *error = 0;
504 if (!unformat (input, "%d", &bd_id))
506 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
507 format_unformat_error, input);
511 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
514 return clib_error_return (0, "No such bridge domain %d", bd_id);
519 if (unformat (input, "disable"))
524 /* set the bridge domain flag */
525 if (bd_set_flags (vm, bd_index, L2_UU_FLOOD, enable))
528 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
537 * Layer 2 unknown-unicast flooding can be enabled and disabled on each
538 * bridge-domain. It is enabled by default.
541 * Example of how to enable unknown-unicast flooding (where 200 is the
543 * @cliexcmd{set bridge-domain uu-flood 200}
544 * Example of how to disable unknown-unicast flooding (where 200 is the bridge-domain-id):
545 * @cliexcmd{set bridge-domain uu-flood 200 disable}
548 VLIB_CLI_COMMAND (bd_uu_flood_cli, static) = {
549 .path = "set bridge-domain uu-flood",
550 .short_help = "set bridge-domain uu-flood <bridge-domain-id> [disable]",
551 .function = bd_uu_flood,
556 Set bridge-domain arp term enable/disable.
558 set bridge-domain arp term <bridge-domain-id> [disable]
560 static clib_error_t *
561 bd_arp_term (vlib_main_t * vm,
562 unformat_input_t * input, vlib_cli_command_t * cmd)
564 bd_main_t *bdm = &bd_main;
565 clib_error_t *error = 0;
570 if (!unformat (input, "%d", &bd_id))
572 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
573 format_unformat_error, input);
577 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
581 return clib_error_return (0, "No such bridge domain %d", bd_id);
584 if (unformat (input, "disable"))
587 /* set the bridge domain flag */
588 if (bd_set_flags (vm, bd_index, L2_ARP_TERM, enable))
591 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
599 static clib_error_t *
600 bd_mac_age (vlib_main_t * vm,
601 unformat_input_t * input, vlib_cli_command_t * cmd)
603 bd_main_t *bdm = &bd_main;
604 clib_error_t *error = 0;
609 if (!unformat (input, "%d", &bd_id))
611 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
612 format_unformat_error, input);
616 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
619 return clib_error_return (0, "No such bridge domain %d", bd_id);
623 if (!unformat (input, "%u", &age))
626 clib_error_return (0, "expecting ageing time in minutes but got `%U'",
627 format_unformat_error, input);
631 /* set the bridge domain flag */
635 clib_error_return (0, "mac aging time cannot be bigger than 255");
638 bd_set_mac_age (vm, bd_index, (u8) age);
645 * Layer 2 mac aging can be enabled and disabled on each
646 * bridge-domain. Use this command to set or disable mac aging
647 * on specific bridge-domains. It is disabled by default.
650 * Example of how to set mac aging (where 200 is the bridge-domain-id and
651 * 5 is aging time in minutes):
652 * @cliexcmd{set bridge-domain mac-age 200 5}
653 * Example of how to disable mac aging (where 200 is the bridge-domain-id):
654 * @cliexcmd{set bridge-domain flood 200 0}
657 VLIB_CLI_COMMAND (bd_mac_age_cli, static) = {
658 .path = "set bridge-domain mac-age",
659 .short_help = "set bridge-domain mac-age <bridge-domain-id> <mins>",
660 .function = bd_mac_age,
665 * Modify whether or not an existing bridge-domain should terminate and respond
666 * to ARP Requests. ARP Termination is disabled by default.
669 * Example of how to enable ARP termination (where 200 is the bridge-domain-id):
670 * @cliexcmd{set bridge-domain arp term 200}
671 * Example of how to disable ARP termination (where 200 is the bridge-domain-id):
672 * @cliexcmd{set bridge-domain arp term 200 disable}
675 VLIB_CLI_COMMAND (bd_arp_term_cli, static) = {
676 .path = "set bridge-domain arp term",
677 .short_help = "set bridge-domain arp term <bridge-domain-id> [disable]",
678 .function = bd_arp_term,
684 * Add/delete IP address to MAC address mapping.
686 * The clib hash implementation stores uword entries in the hash table.
687 * The hash table mac_by_ip4 is keyed via IP4 address and store the
688 * 6-byte MAC address directly in the hash table entry uword.
690 * @warning This only works for 64-bit processor with 8-byte uword;
691 * which means this code *WILL NOT WORK* for a 32-bit prcessor with
695 bd_add_del_ip_mac (u32 bd_index,
696 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add)
698 l2input_main_t *l2im = &l2input_main;
699 l2_bridge_domain_t *bd_cfg = l2input_bd_config_from_index (l2im, bd_index);
700 u64 new_mac = *(u64 *) mac_addr;
702 u16 *mac16 = (u16 *) & new_mac;
704 ASSERT (sizeof (uword) == sizeof (u64)); /* make sure uword is 8 bytes */
706 mac16[3] = 0; /* Clear last 2 unsed bytes of the 8-byte MAC address */
709 ip6_address_t *ip6_addr_key;
711 old_mac = (u64 *) hash_get_mem (bd_cfg->mac_by_ip6, ip_addr);
715 { /* new entry - allocate and craete ip6 address key */
716 ip6_addr_key = clib_mem_alloc (sizeof (ip6_address_t));
717 clib_memcpy (ip6_addr_key, ip_addr, sizeof (ip6_address_t));
719 else if (*old_mac == new_mac)
720 { /* same mac entry already exist for ip6 address */
724 { /* updat mac for ip6 address */
725 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
726 ip6_addr_key = (ip6_address_t *) hp->key;
728 hash_set_mem (bd_cfg->mac_by_ip6, ip6_addr_key, new_mac);
732 if (old_mac && (*old_mac == new_mac))
734 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
735 ip6_addr_key = (ip6_address_t *) hp->key;
736 hash_unset_mem (bd_cfg->mac_by_ip6, ip_addr);
737 clib_mem_free (ip6_addr_key);
745 ip4_address_t ip4_addr = *(ip4_address_t *) ip_addr;
746 old_mac = (u64 *) hash_get (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
749 if (old_mac && (*old_mac == new_mac))
750 return 0; /* mac entry already exist */
751 hash_set (bd_cfg->mac_by_ip4, ip4_addr.as_u32, new_mac);
755 if (old_mac && (*old_mac == new_mac))
756 hash_unset (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
765 Set bridge-domain arp entry add/delete.
767 set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]
769 static clib_error_t *
770 bd_arp_entry (vlib_main_t * vm,
771 unformat_input_t * input, vlib_cli_command_t * cmd)
773 bd_main_t *bdm = &bd_main;
774 clib_error_t *error = 0;
782 if (!unformat (input, "%d", &bd_id))
784 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
785 format_unformat_error, input);
789 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
794 return clib_error_return (0, "No such bridge domain %d", bd_id);
796 if (unformat (input, "%U", unformat_ip4_address, ip_addr))
800 else if (unformat (input, "%U", unformat_ip6_address, ip_addr))
806 error = clib_error_return (0, "expecting IP address but got `%U'",
807 format_unformat_error, input);
811 if (!unformat (input, "%U", unformat_ethernet_address, mac_addr))
813 error = clib_error_return (0, "expecting MAC address but got `%U'",
814 format_unformat_error, input);
818 if (unformat (input, "del"))
823 /* set the bridge domain flagAdd IP-MAC entry into bridge domain */
824 if (bd_add_del_ip_mac (bd_index, ip_addr, mac_addr, is_ip6, is_add))
826 error = clib_error_return (0, "MAC %s for IP %U and MAC %U failed",
827 is_add ? "add" : "del",
829 format_ip4_address : format_ip6_address,
830 ip_addr, format_ethernet_address, mac_addr);
838 * Add an ARP entry to an existing bridge-domain.
841 * Example of how to add an ARP entry (where 200 is the bridge-domain-id):
842 * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a}
843 * Example of how to delete an ARP entry (where 200 is the bridge-domain-id):
844 * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a del}
847 VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = {
848 .path = "set bridge-domain arp entry",
849 .short_help = "set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]",
850 .function = bd_arp_entry,
855 format_vtr (u8 * s, va_list * args)
857 u32 vtr_op = va_arg (*args, u32);
858 u32 dot1q = va_arg (*args, u32);
859 u32 tag1 = va_arg (*args, u32);
860 u32 tag2 = va_arg (*args, u32);
863 case L2_VTR_DISABLED:
864 return format (s, "none");
866 return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
868 return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1,
871 return format (s, "pop-1");
873 return format (s, "pop-2");
874 case L2_VTR_TRANSLATE_1_1:
875 return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
876 case L2_VTR_TRANSLATE_1_2:
877 return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
879 case L2_VTR_TRANSLATE_2_1:
880 return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
881 case L2_VTR_TRANSLATE_2_2:
882 return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
885 return format (s, "none");
890 Show bridge-domain state.
892 show bridge-domain [<bd_index>]
894 static clib_error_t *
895 bd_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
897 vnet_main_t *vnm = vnet_get_main ();
898 bd_main_t *bdm = &bd_main;
899 clib_error_t *error = 0;
901 l2_bridge_domain_t *bd_config;
911 end = vec_len (l2input_main.bd_configs);
913 if (unformat (input, "%d", &bd_id))
915 if (unformat (input, "detail"))
917 else if (unformat (input, "det"))
919 if (unformat (input, "int"))
921 if (unformat (input, "arp"))
924 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
928 return clib_error_return (0, "No such bridge domain %d", bd_id);
930 vec_validate (l2input_main.bd_configs, bd_index);
931 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
932 if (bd_is_valid (bd_config))
939 vlib_cli_output (vm, "bridge-domain %d not in use", bd_id);
944 /* Show all bridge-domains that have been initialized */
946 for (bd_index = start; bd_index < end; bd_index++)
948 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
949 if (bd_is_valid (bd_config))
955 "%=5s %=7s %=10s %=10s %=10s %=10s %=10s %=14s",
956 "ID", "Index", "Learning", "U-Forwrd",
957 "UU-Flood", "Flooding", "ARP-Term",
962 "%=5d %=7d %=10s %=10s %=10s %=10s %=10s %=14U",
963 bd_config->bd_id, bd_index,
964 bd_config->feature_bitmap & L2INPUT_FEAT_LEARN ?
966 bd_config->feature_bitmap & L2INPUT_FEAT_FWD ? "on"
968 bd_config->feature_bitmap & L2INPUT_FEAT_UU_FLOOD ?
970 bd_config->feature_bitmap & L2INPUT_FEAT_FLOOD ?
972 bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM ?
973 "on" : "off", format_vnet_sw_if_index_name_with_NA,
974 vnm, bd_config->bvi_sw_if_index);
978 /* Show all member interfaces */
980 vec_foreach_index (i, bd_config->members)
982 l2_flood_member_t *member =
983 vec_elt_at_index (bd_config->members, i);
984 u32 vtr_opr, dot1q, tag1, tag2;
987 vlib_cli_output (vm, "\n%=30s%=7s%=5s%=5s%=9s%=30s",
988 "Interface", "Index", "SHG", "BVI",
989 "TxFlood", "VLAN-Tag-Rewrite");
991 l2vtr_get (vm, vnm, member->sw_if_index, &vtr_opr, &dot1q,
993 vlib_cli_output (vm, "%=30U%=7d%=5d%=5s%=9s%=30U",
994 format_vnet_sw_if_index_name, vnm,
995 member->sw_if_index, member->sw_if_index,
997 member->flags & L2_FLOOD_MEMBER_BVI ? "*" :
998 "-", i < bd_config->flood_count ? "*" : "-",
999 format_vtr, vtr_opr, dot1q, tag1, tag2);
1003 if ((detail || arp) &&
1004 (bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM))
1007 ip6_address_t *ip6_addr;
1009 vlib_cli_output (vm,
1010 "\n IP4/IP6 to MAC table for ARP Termination");
1013 hash_foreach (ip4_addr, mac_addr, bd_config->mac_by_ip4,
1015 vlib_cli_output (vm, "%=40U => %=20U",
1016 format_ip4_address, &ip4_addr,
1017 format_ethernet_address, &mac_addr);
1020 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
1022 vlib_cli_output (vm, "%=40U => %=20U",
1023 format_ip6_address, ip6_addr,
1024 format_ethernet_address, &mac_addr);
1033 vlib_cli_output (vm, "no bridge-domains in use");
1041 * Show a summary of all the bridge-domain instances or detailed view of a
1042 * single bridge-domain. Bridge-domains are created by adding an interface
1043 * to a bridge using the '<em>set interface l2 bridge</em>' command.
1047 * Example of displaying all bridge-domains:
1048 * @cliexstart{show bridge-domain}
1049 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1050 * 0 0 off off off off off local0
1051 * 200 1 on on on on off N/A
1054 * Example of displaying details of a single bridge-domains:
1055 * @cliexstart{show bridge-domain 200 detail}
1056 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1057 * 200 1 on on on on off N/A
1059 * Interface Index SHG BVI VLAN-Tag-Rewrite
1060 * GigabitEthernet0/8/0.200 3 0 - none
1061 * GigabitEthernet0/9/0.200 4 0 - none
1066 VLIB_CLI_COMMAND (bd_show_cli, static) = {
1067 .path = "show bridge-domain",
1068 .short_help = "show bridge-domain [bridge-domain-id [detail|int|arp]]",
1069 .function = bd_show,
1074 * fd.io coding-style-patch-verification: ON
1077 * eval: (c-set-style "gnu")