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;
118 l2fib_flush_bd_mac (vlib_get_main (), bd_index);
124 update_flood_count (l2_bridge_domain_t * bd_config)
126 bd_config->flood_count = vec_len (bd_config->members) -
127 (bd_config->tun_master_count ? bd_config->tun_normal_count : 0);
131 bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member)
134 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
135 (vnet_get_main (), member->sw_if_index);
138 * Add one element to the vector
139 * vector is ordered [ bvi, normal/tun_masters..., tun_normals... ]
140 * When flooding, the bvi interface (if present) must be the last member
141 * processed due to how BVI processing can change the packet. To enable
142 * this order, we make the bvi interface the first in the vector and
143 * flooding walks the vector in reverse.
145 switch (sw_if->flood_class)
147 case VNET_FLOOD_CLASS_TUNNEL_MASTER:
148 bd_config->tun_master_count++;
152 case VNET_FLOOD_CLASS_NORMAL:
153 ix = (member->flags & L2_FLOOD_MEMBER_BVI) ? 0 :
154 vec_len (bd_config->members) - bd_config->tun_normal_count;
156 case VNET_FLOOD_CLASS_TUNNEL_NORMAL:
157 ix = vec_len (bd_config->members);
158 bd_config->tun_normal_count++;
162 vec_insert_elts (bd_config->members, member, 1, ix);
163 update_flood_count (bd_config);
166 #define BD_REMOVE_ERROR_OK 0
167 #define BD_REMOVE_ERROR_NOT_FOUND 1
170 bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index)
174 /* Find and delete the member */
175 vec_foreach_index (ix, bd_config->members)
177 l2_flood_member_t *m = vec_elt_at_index (bd_config->members, ix);
178 if (m->sw_if_index == sw_if_index)
180 vnet_sw_interface_t *sw_if = vnet_get_sw_interface
181 (vnet_get_main (), sw_if_index);
183 if (sw_if->flood_class != VNET_FLOOD_CLASS_NORMAL)
185 if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_MASTER)
186 bd_config->tun_master_count--;
187 else if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_NORMAL)
188 bd_config->tun_normal_count--;
190 vec_delete (bd_config->members, 1, ix);
191 update_flood_count (bd_config);
193 return BD_REMOVE_ERROR_OK;
197 return BD_REMOVE_ERROR_NOT_FOUND;
202 l2bd_init (vlib_main_t * vm)
204 bd_main_t *bdm = &bd_main;
206 bdm->bd_index_by_bd_id = hash_create (0, sizeof (uword));
208 * create a dummy bd with bd_id of 0 and bd_index of 0 with feature set
209 * to packet drop only. Thus, packets received from any L2 interface with
210 * uninitialized bd_index of 0 can be dropped safely.
212 bd_index = bd_find_or_add_bd_index (bdm, 0);
213 ASSERT (bd_index == 0);
214 l2input_main.bd_configs[0].feature_bitmap = L2INPUT_FEAT_DROP;
218 VLIB_INIT_FUNCTION (l2bd_init);
222 Set the learn/forward/flood flags for the bridge domain.
223 Return 0 if ok, non-zero if for an error.
226 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable)
229 l2_bridge_domain_t *bd_config;
230 u32 feature_bitmap = 0;
232 vec_validate (l2input_main.bd_configs, bd_index);
233 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
235 bd_validate (bd_config);
237 if (flags & L2_LEARN)
239 feature_bitmap |= L2INPUT_FEAT_LEARN;
243 feature_bitmap |= L2INPUT_FEAT_FWD;
245 if (flags & L2_FLOOD)
247 feature_bitmap |= L2INPUT_FEAT_FLOOD;
249 if (flags & L2_UU_FLOOD)
251 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
253 if (flags & L2_ARP_TERM)
255 feature_bitmap |= L2INPUT_FEAT_ARP_TERM;
260 bd_config->feature_bitmap |= feature_bitmap;
264 bd_config->feature_bitmap &= ~feature_bitmap;
271 Set the mac age for the bridge domain.
274 bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age)
276 l2_bridge_domain_t *bd_config;
279 vec_validate (l2input_main.bd_configs, bd_index);
280 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
281 bd_config->mac_age = age;
283 /* check if there is at least one bd with mac aging enabled */
284 vec_foreach (bd_config, l2input_main.bd_configs)
285 if (bd_config->bd_id != ~0 && bd_config->mac_age != 0)
288 vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index,
289 enable ? L2_MAC_AGE_PROCESS_EVENT_START :
290 L2_MAC_AGE_PROCESS_EVENT_STOP, 0);
294 Set bridge-domain learn enable/disable.
296 set bridge-domain learn <bd_id> [disable]
298 static clib_error_t *
299 bd_learn (vlib_main_t * vm,
300 unformat_input_t * input, vlib_cli_command_t * cmd)
302 bd_main_t *bdm = &bd_main;
303 clib_error_t *error = 0;
308 if (!unformat (input, "%d", &bd_id))
310 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
311 format_unformat_error, input);
315 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
318 return clib_error_return (0, "No such bridge domain %d", bd_id);
323 if (unformat (input, "disable"))
328 /* set the bridge domain flag */
329 if (bd_set_flags (vm, bd_index, L2_LEARN, enable))
332 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
341 * Layer 2 learning can be enabled and disabled on each
342 * interface and on each bridge-domain. Use this command to
343 * manage bridge-domains. It is enabled by default.
346 * Example of how to enable learning (where 200 is the bridge-domain-id):
347 * @cliexcmd{set bridge-domain learn 200}
348 * Example of how to disable learning (where 200 is the bridge-domain-id):
349 * @cliexcmd{set bridge-domain learn 200 disable}
352 VLIB_CLI_COMMAND (bd_learn_cli, static) = {
353 .path = "set bridge-domain learn",
354 .short_help = "set bridge-domain learn <bridge-domain-id> [disable]",
355 .function = bd_learn,
360 Set bridge-domain forward enable/disable.
362 set bridge-domain forward <bd_index> [disable]
364 static clib_error_t *
365 bd_fwd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
367 bd_main_t *bdm = &bd_main;
368 clib_error_t *error = 0;
373 if (!unformat (input, "%d", &bd_id))
375 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
376 format_unformat_error, input);
380 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
383 return clib_error_return (0, "No such bridge domain %d", bd_id);
388 if (unformat (input, "disable"))
393 /* set the bridge domain flag */
394 if (bd_set_flags (vm, bd_index, L2_FWD, enable))
397 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
407 * Layer 2 unicast forwarding can be enabled and disabled on each
408 * interface and on each bridge-domain. Use this command to
409 * manage bridge-domains. It is enabled by default.
412 * Example of how to enable forwarding (where 200 is the bridge-domain-id):
413 * @cliexcmd{set bridge-domain forward 200}
414 * Example of how to disable forwarding (where 200 is the bridge-domain-id):
415 * @cliexcmd{set bridge-domain forward 200 disable}
418 VLIB_CLI_COMMAND (bd_fwd_cli, static) = {
419 .path = "set bridge-domain forward",
420 .short_help = "set bridge-domain forward <bridge-domain-id> [disable]",
426 Set bridge-domain flood enable/disable.
428 set bridge-domain flood <bd_index> [disable]
430 static clib_error_t *
431 bd_flood (vlib_main_t * vm,
432 unformat_input_t * input, vlib_cli_command_t * cmd)
434 bd_main_t *bdm = &bd_main;
435 clib_error_t *error = 0;
440 if (!unformat (input, "%d", &bd_id))
442 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
443 format_unformat_error, input);
447 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
450 return clib_error_return (0, "No such bridge domain %d", bd_id);
455 if (unformat (input, "disable"))
460 /* set the bridge domain flag */
461 if (bd_set_flags (vm, bd_index, L2_FLOOD, enable))
464 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
473 * Layer 2 flooding can be enabled and disabled on each
474 * interface and on each bridge-domain. Use this command to
475 * manage bridge-domains. It is enabled by default.
478 * Example of how to enable flooding (where 200 is the bridge-domain-id):
479 * @cliexcmd{set bridge-domain flood 200}
480 * Example of how to disable flooding (where 200 is the bridge-domain-id):
481 * @cliexcmd{set bridge-domain flood 200 disable}
484 VLIB_CLI_COMMAND (bd_flood_cli, static) = {
485 .path = "set bridge-domain flood",
486 .short_help = "set bridge-domain flood <bridge-domain-id> [disable]",
487 .function = bd_flood,
492 Set bridge-domain unkown-unicast flood enable/disable.
494 set bridge-domain uu-flood <bd_index> [disable]
496 static clib_error_t *
497 bd_uu_flood (vlib_main_t * vm,
498 unformat_input_t * input, vlib_cli_command_t * cmd)
500 bd_main_t *bdm = &bd_main;
501 clib_error_t *error = 0;
506 if (!unformat (input, "%d", &bd_id))
508 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
509 format_unformat_error, input);
513 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
516 return clib_error_return (0, "No such bridge domain %d", bd_id);
521 if (unformat (input, "disable"))
526 /* set the bridge domain flag */
527 if (bd_set_flags (vm, bd_index, L2_UU_FLOOD, enable))
530 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
539 * Layer 2 unknown-unicast flooding can be enabled and disabled on each
540 * bridge-domain. It is enabled by default.
543 * Example of how to enable unknown-unicast flooding (where 200 is the
545 * @cliexcmd{set bridge-domain uu-flood 200}
546 * Example of how to disable unknown-unicast flooding (where 200 is the bridge-domain-id):
547 * @cliexcmd{set bridge-domain uu-flood 200 disable}
550 VLIB_CLI_COMMAND (bd_uu_flood_cli, static) = {
551 .path = "set bridge-domain uu-flood",
552 .short_help = "set bridge-domain uu-flood <bridge-domain-id> [disable]",
553 .function = bd_uu_flood,
558 Set bridge-domain arp term enable/disable.
560 set bridge-domain arp term <bridge-domain-id> [disable]
562 static clib_error_t *
563 bd_arp_term (vlib_main_t * vm,
564 unformat_input_t * input, vlib_cli_command_t * cmd)
566 bd_main_t *bdm = &bd_main;
567 clib_error_t *error = 0;
572 if (!unformat (input, "%d", &bd_id))
574 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
575 format_unformat_error, input);
579 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
583 return clib_error_return (0, "No such bridge domain %d", bd_id);
586 if (unformat (input, "disable"))
589 /* set the bridge domain flag */
590 if (bd_set_flags (vm, bd_index, L2_ARP_TERM, enable))
593 clib_error_return (0, "bridge-domain id %d out of range", bd_index);
601 static clib_error_t *
602 bd_mac_age (vlib_main_t * vm,
603 unformat_input_t * input, vlib_cli_command_t * cmd)
605 bd_main_t *bdm = &bd_main;
606 clib_error_t *error = 0;
611 if (!unformat (input, "%d", &bd_id))
613 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
614 format_unformat_error, input);
618 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
621 return clib_error_return (0, "No such bridge domain %d", bd_id);
625 if (!unformat (input, "%u", &age))
628 clib_error_return (0, "expecting ageing time in minutes but got `%U'",
629 format_unformat_error, input);
633 /* set the bridge domain flag */
637 clib_error_return (0, "mac aging time cannot be bigger than 255");
640 bd_set_mac_age (vm, bd_index, (u8) age);
647 * Layer 2 mac aging can be enabled and disabled on each
648 * bridge-domain. Use this command to set or disable mac aging
649 * on specific bridge-domains. It is disabled by default.
652 * Example of how to set mac aging (where 200 is the bridge-domain-id and
653 * 5 is aging time in minutes):
654 * @cliexcmd{set bridge-domain mac-age 200 5}
655 * Example of how to disable mac aging (where 200 is the bridge-domain-id):
656 * @cliexcmd{set bridge-domain flood 200 0}
659 VLIB_CLI_COMMAND (bd_mac_age_cli, static) = {
660 .path = "set bridge-domain mac-age",
661 .short_help = "set bridge-domain mac-age <bridge-domain-id> <mins>",
662 .function = bd_mac_age,
667 * Modify whether or not an existing bridge-domain should terminate and respond
668 * to ARP Requests. ARP Termination is disabled by default.
671 * Example of how to enable ARP termination (where 200 is the bridge-domain-id):
672 * @cliexcmd{set bridge-domain arp term 200}
673 * Example of how to disable ARP termination (where 200 is the bridge-domain-id):
674 * @cliexcmd{set bridge-domain arp term 200 disable}
677 VLIB_CLI_COMMAND (bd_arp_term_cli, static) = {
678 .path = "set bridge-domain arp term",
679 .short_help = "set bridge-domain arp term <bridge-domain-id> [disable]",
680 .function = bd_arp_term,
686 * Add/delete IP address to MAC address mapping.
688 * The clib hash implementation stores uword entries in the hash table.
689 * The hash table mac_by_ip4 is keyed via IP4 address and store the
690 * 6-byte MAC address directly in the hash table entry uword.
692 * @warning This only works for 64-bit processor with 8-byte uword;
693 * which means this code *WILL NOT WORK* for a 32-bit prcessor with
697 bd_add_del_ip_mac (u32 bd_index,
698 u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add)
700 l2input_main_t *l2im = &l2input_main;
701 l2_bridge_domain_t *bd_cfg = l2input_bd_config_from_index (l2im, bd_index);
702 u64 new_mac = *(u64 *) mac_addr;
704 u16 *mac16 = (u16 *) & new_mac;
706 ASSERT (sizeof (uword) == sizeof (u64)); /* make sure uword is 8 bytes */
708 mac16[3] = 0; /* Clear last 2 unsed bytes of the 8-byte MAC address */
711 ip6_address_t *ip6_addr_key;
713 old_mac = (u64 *) hash_get_mem (bd_cfg->mac_by_ip6, ip_addr);
717 { /* new entry - allocate and craete ip6 address key */
718 ip6_addr_key = clib_mem_alloc (sizeof (ip6_address_t));
719 clib_memcpy (ip6_addr_key, ip_addr, sizeof (ip6_address_t));
721 else if (*old_mac == new_mac)
722 { /* same mac entry already exist for ip6 address */
726 { /* updat mac for ip6 address */
727 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
728 ip6_addr_key = (ip6_address_t *) hp->key;
730 hash_set_mem (bd_cfg->mac_by_ip6, ip6_addr_key, new_mac);
734 if (old_mac && (*old_mac == new_mac))
736 hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr);
737 ip6_addr_key = (ip6_address_t *) hp->key;
738 hash_unset_mem (bd_cfg->mac_by_ip6, ip_addr);
739 clib_mem_free (ip6_addr_key);
747 ip4_address_t ip4_addr = *(ip4_address_t *) ip_addr;
748 old_mac = (u64 *) hash_get (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
751 if (old_mac && (*old_mac == new_mac))
752 return 0; /* mac entry already exist */
753 hash_set (bd_cfg->mac_by_ip4, ip4_addr.as_u32, new_mac);
757 if (old_mac && (*old_mac == new_mac))
758 hash_unset (bd_cfg->mac_by_ip4, ip4_addr.as_u32);
767 Set bridge-domain arp entry add/delete.
769 set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]
771 static clib_error_t *
772 bd_arp_entry (vlib_main_t * vm,
773 unformat_input_t * input, vlib_cli_command_t * cmd)
775 bd_main_t *bdm = &bd_main;
776 clib_error_t *error = 0;
784 if (!unformat (input, "%d", &bd_id))
786 error = clib_error_return (0, "expecting bridge-domain id but got `%U'",
787 format_unformat_error, input);
791 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
796 return clib_error_return (0, "No such bridge domain %d", bd_id);
798 if (unformat (input, "%U", unformat_ip4_address, ip_addr))
802 else if (unformat (input, "%U", unformat_ip6_address, ip_addr))
808 error = clib_error_return (0, "expecting IP address but got `%U'",
809 format_unformat_error, input);
813 if (!unformat (input, "%U", unformat_ethernet_address, mac_addr))
815 error = clib_error_return (0, "expecting MAC address but got `%U'",
816 format_unformat_error, input);
820 if (unformat (input, "del"))
825 /* set the bridge domain flagAdd IP-MAC entry into bridge domain */
826 if (bd_add_del_ip_mac (bd_index, ip_addr, mac_addr, is_ip6, is_add))
828 error = clib_error_return (0, "MAC %s for IP %U and MAC %U failed",
829 is_add ? "add" : "del",
831 format_ip4_address : format_ip6_address,
832 ip_addr, format_ethernet_address, mac_addr);
840 * Add an ARP entry to an existing bridge-domain.
843 * Example of how to add 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}
845 * Example of how to delete an ARP entry (where 200 is the bridge-domain-id):
846 * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a del}
849 VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = {
850 .path = "set bridge-domain arp entry",
851 .short_help = "set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]",
852 .function = bd_arp_entry,
857 format_vtr (u8 * s, va_list * args)
859 u32 vtr_op = va_arg (*args, u32);
860 u32 dot1q = va_arg (*args, u32);
861 u32 tag1 = va_arg (*args, u32);
862 u32 tag2 = va_arg (*args, u32);
865 case L2_VTR_DISABLED:
866 return format (s, "none");
868 return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
870 return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1,
873 return format (s, "pop-1");
875 return format (s, "pop-2");
876 case L2_VTR_TRANSLATE_1_1:
877 return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
878 case L2_VTR_TRANSLATE_1_2:
879 return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
881 case L2_VTR_TRANSLATE_2_1:
882 return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
883 case L2_VTR_TRANSLATE_2_2:
884 return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
887 return format (s, "none");
892 Show bridge-domain state.
894 show bridge-domain [<bd_index>]
896 static clib_error_t *
897 bd_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
899 vnet_main_t *vnm = vnet_get_main ();
900 bd_main_t *bdm = &bd_main;
901 clib_error_t *error = 0;
903 l2_bridge_domain_t *bd_config;
912 end = vec_len (l2input_main.bd_configs);
914 if (unformat (input, "%d", &bd_id))
916 if (unformat (input, "detail"))
918 else if (unformat (input, "det"))
920 if (unformat (input, "int"))
922 if (unformat (input, "arp"))
925 p = hash_get (bdm->bd_index_by_bd_id, bd_id);
929 return clib_error_return (0, "No such bridge domain %d", bd_id);
931 vec_validate (l2input_main.bd_configs, bd_index);
932 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
933 if (bd_is_valid (bd_config))
940 vlib_cli_output (vm, "bridge-domain %d not in use", bd_id);
945 /* Show all bridge-domains that have been initialized */
948 for (bd_index = start; bd_index < end; bd_index++)
950 bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index);
951 if (bd_is_valid (bd_config))
957 "%=5s %=7s %=4s %=9s %=9s %=9s %=9s %=9s %=9s %=9s",
958 "ID", "Index", "BSN", "Age(min)", "Learning",
959 "U-Forwrd", "UU-Flood", "Flooding", "ARP-Term",
963 if (bd_config->mac_age)
964 as = format (as, "%d", bd_config->mac_age);
966 as = format (as, "off");
968 "%=5d %=7d %=4d %=9v %=9s %=9s %=9s %=9s %=9s %=9U",
969 bd_config->bd_id, bd_index, bd_config->seq_num, as,
970 bd_config->feature_bitmap & L2INPUT_FEAT_LEARN ?
972 bd_config->feature_bitmap & L2INPUT_FEAT_FWD ?
974 bd_config->feature_bitmap & L2INPUT_FEAT_UU_FLOOD ?
976 bd_config->feature_bitmap & L2INPUT_FEAT_FLOOD ?
978 bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM ?
980 format_vnet_sw_if_index_name_with_NA,
981 vnm, bd_config->bvi_sw_if_index);
982 vec_reset_length (as);
986 /* Show all member interfaces */
988 vec_foreach_index (i, bd_config->members)
990 l2_flood_member_t *member =
991 vec_elt_at_index (bd_config->members, i);
992 l2_input_config_t *int_config =
993 l2input_intf_config (member->sw_if_index);
994 u32 vtr_opr, dot1q, tag1, tag2;
997 vlib_cli_output (vm, "\n%=30s%=7s%=5s%=5s%=5s%=9s%=30s",
998 "Interface", "If-idx", "ISN", "SHG",
999 "BVI", "TxFlood", "VLAN-Tag-Rewrite");
1001 l2vtr_get (vm, vnm, member->sw_if_index, &vtr_opr, &dot1q,
1003 vlib_cli_output (vm, "%=30U%=7d%=5d%=5d%=5s%=9s%=30U",
1004 format_vnet_sw_if_index_name, vnm,
1005 member->sw_if_index, member->sw_if_index,
1006 int_config->seq_num, member->shg,
1007 member->flags & L2_FLOOD_MEMBER_BVI ? "*" :
1008 "-", i < bd_config->flood_count ? "*" : "-",
1009 format_vtr, vtr_opr, dot1q, tag1, tag2);
1013 if ((detail || arp) &&
1014 (bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM))
1017 ip6_address_t *ip6_addr;
1019 vlib_cli_output (vm,
1020 "\n IP4/IP6 to MAC table for ARP Termination");
1023 hash_foreach (ip4_addr, mac_addr, bd_config->mac_by_ip4,
1025 vlib_cli_output (vm, "%=40U => %=20U",
1026 format_ip4_address, &ip4_addr,
1027 format_ethernet_address, &mac_addr);
1030 hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6,
1032 vlib_cli_output (vm, "%=40U => %=20U",
1033 format_ip6_address, ip6_addr,
1034 format_ethernet_address, &mac_addr);
1044 vlib_cli_output (vm, "no bridge-domains in use");
1052 * Show a summary of all the bridge-domain instances or detailed view of a
1053 * single bridge-domain. Bridge-domains are created by adding an interface
1054 * to a bridge using the '<em>set interface l2 bridge</em>' command.
1058 * Example of displaying all bridge-domains:
1059 * @cliexstart{show bridge-domain}
1060 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1061 * 0 0 off off off off off local0
1062 * 200 1 on on on on off N/A
1065 * Example of displaying details of a single bridge-domains:
1066 * @cliexstart{show bridge-domain 200 detail}
1067 * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf
1068 * 200 1 on on on on off N/A
1070 * Interface Index SHG BVI VLAN-Tag-Rewrite
1071 * GigabitEthernet0/8/0.200 3 0 - none
1072 * GigabitEthernet0/9/0.200 4 0 - none
1077 VLIB_CLI_COMMAND (bd_show_cli, static) = {
1078 .path = "show bridge-domain",
1079 .short_help = "show bridge-domain [bridge-domain-id [detail|int|arp]]",
1080 .function = bd_show,
1085 * fd.io coding-style-patch-verification: ON
1088 * eval: (c-set-style "gnu")