1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
6 #include <vlibapi/api.h>
7 #include <vlibmemory/api.h>
8 #include <vppinfra/error.h>
9 #include <vpp/api/types.h>
12 #include <vnet/l2/l2_classify.h>
13 #include <vnet/l2/l2_vtr.h>
14 #include <vnet/ip/ip_types_api.h>
16 #define __plugin_msg_base l2_test_main.msg_id_base
17 #include <vlibapi/vat_helper_macros.h>
19 #include <vlibmemory/vlib.api_enum.h>
20 #include <vlibmemory/vlib.api_types.h>
22 /* Declare message IDs */
23 #include <vnet/format_fns.h>
24 #include <vnet/l2/l2.api_enum.h>
25 #include <vnet/l2/l2.api_types.h>
27 #define vl_endianfun /* define message structures */
28 #include <vnet/l2/l2.api.h>
31 #define vl_calcsizefun
32 #include <vnet/l2/l2.api.h>
37 /* API message ID base */
43 static l2_test_main_t l2_test_main;
46 vl_api_l2_fib_table_details_t_handler (vl_api_l2_fib_table_details_t *mp)
48 vat_main_t *vam = l2_test_main.vat_main;
51 vam->ofp, "%3" PRIu32 " %U %3" PRIu32 " %d %d %d",
52 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
53 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac, mp->bvi_mac);
57 api_l2_fib_table_dump (vat_main_t *vam)
59 unformat_input_t *i = vam->input;
60 vl_api_l2_fib_table_dump_t *mp;
61 vl_api_control_ping_t *mp_ping;
66 /* Parse args required to build the message */
67 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
69 if (unformat (i, "bd_id %d", &bd_id))
77 errmsg ("missing bridge domain");
81 fformat (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
83 /* Get list of l2 fib entries */
84 M (L2_FIB_TABLE_DUMP, mp);
86 mp->bd_id = ntohl (bd_id);
89 /* Use a control ping for synchronization */
90 PING (&l2_test_main, mp_ping);
98 vl_api_l2_xconnect_details_t_handler (vl_api_l2_xconnect_details_t *mp)
100 vat_main_t *vam = l2_test_main.vat_main;
101 fformat (vam->ofp, "%15d%15d", ntohl (mp->rx_sw_if_index),
102 ntohl (mp->tx_sw_if_index));
106 api_l2_xconnect_dump (vat_main_t *vam)
108 vl_api_l2_xconnect_dump_t *mp;
109 vl_api_control_ping_t *mp_ping;
112 if (!vam->json_output)
114 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
117 M (L2_XCONNECT_DUMP, mp);
121 /* Use a control ping for synchronization */
122 PING (&l2_test_main, mp_ping);
130 api_want_l2_arp_term_events (vat_main_t *vam)
136 api_want_l2_macs_events (vat_main_t *vam)
138 unformat_input_t *line_input = vam->input;
139 vl_api_want_l2_macs_events_t *mp;
140 u8 enable_disable = 1;
142 u32 max_macs_in_event = 0;
146 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
148 if (unformat (line_input, "learn-limit %d", &learn_limit))
150 else if (unformat (line_input, "scan-delay %d", &scan_delay))
152 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
154 else if (unformat (line_input, "disable"))
160 M (WANT_L2_MACS_EVENTS, mp);
161 mp->enable_disable = enable_disable;
162 mp->pid = htonl (getpid ());
163 mp->learn_limit = htonl (learn_limit);
164 mp->scan_delay = (u8) scan_delay;
165 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
172 api_l2fib_flush_all (vat_main_t *vam)
178 increment_mac_address (u8 *mac)
180 u64 tmp = *((u64 *) mac);
181 tmp = clib_net_to_host_u64 (tmp);
182 tmp += 1 << 16; /* skip unused (least significant) octets */
183 tmp = clib_host_to_net_u64 (tmp);
185 clib_memcpy (mac, &tmp, 6);
189 api_l2fib_add_del (vat_main_t *vam)
191 vnet_main_t *vnm = vnet_get_main ();
192 unformat_input_t *i = vam->input;
193 vl_api_l2fib_add_del_t *mp;
200 u8 sw_if_index_set = 0;
209 /* Parse args required to build the message */
210 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
212 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
214 else if (unformat (i, "bd_id %d", &bd_id))
216 else if (unformat (i, "sw_if_index %d", &sw_if_index))
218 else if (unformat (i, "sw_if"))
220 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
222 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
229 else if (unformat (i, "static"))
231 else if (unformat (i, "filter"))
236 else if (unformat (i, "bvi"))
241 else if (unformat (i, "del"))
243 else if (unformat (i, "count %d", &count))
251 errmsg ("missing mac address");
257 errmsg ("missing bridge domain");
261 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
263 errmsg ("missing interface name or sw_if_index");
269 /* Turn on async mode */
271 vam->async_errors = 0;
272 before = vat_time_now (vam);
275 for (j = 0; j < count; j++)
277 M (L2FIB_ADD_DEL, mp);
279 clib_memcpy (mp->mac, mac, 6);
280 mp->bd_id = ntohl (bd_id);
282 mp->sw_if_index = ntohl (sw_if_index);
286 mp->static_mac = static_mac;
287 mp->filter_mac = filter_mac;
288 mp->bvi_mac = bvi_mac;
290 increment_mac_address (mac);
297 vl_api_control_ping_t *mp_ping;
300 /* Shut off async mode */
303 PING (&l2_test_main, mp_ping);
306 timeout = vat_time_now (vam) + 1.0;
307 while (vat_time_now (vam) < timeout)
308 if (vam->result_ready == 1)
313 if (vam->retval == -99)
316 if (vam->async_errors > 0)
318 errmsg ("%d asynchronous errors", vam->async_errors);
321 vam->async_errors = 0;
322 after = vat_time_now (vam);
324 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec", count,
325 after - before, count / (after - before));
331 /* Wait for a reply... */
335 /* Return the good/bad news */
336 return (vam->retval);
340 api_l2fib_flush_int (vat_main_t *vam)
342 vnet_main_t *vnm = vnet_get_main ();
343 unformat_input_t *i = vam->input;
344 vl_api_l2fib_flush_int_t *mp;
345 u32 sw_if_index = ~0;
348 /* Parse args required to build the message */
349 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
351 if (unformat (i, "sw_if_index %d", &sw_if_index))
353 else if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
360 if (sw_if_index == ~0)
362 errmsg ("missing interface name or sw_if_index");
366 M (L2FIB_FLUSH_INT, mp);
368 mp->sw_if_index = ntohl (sw_if_index);
376 api_l2_fib_clear_table (vat_main_t *vam)
378 vl_api_l2_fib_clear_table_t *mp;
381 M (L2_FIB_CLEAR_TABLE, mp);
389 api_bridge_domain_set_mac_age (vat_main_t *vam)
391 unformat_input_t *i = vam->input;
392 vl_api_bridge_domain_set_mac_age_t *mp;
397 /* Parse args required to build the message */
398 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
400 if (unformat (i, "bd_id %d", &bd_id))
402 else if (unformat (i, "mac-age %d", &mac_age))
410 errmsg ("missing bridge domain");
416 errmsg ("mac age must be less than 256 ");
420 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
422 mp->bd_id = htonl (bd_id);
423 mp->mac_age = (u8) mac_age;
431 api_l2fib_set_scan_delay (vat_main_t *vam)
437 api_want_l2_macs_events2 (vat_main_t *vam)
443 api_l2_flags (vat_main_t *vam)
445 vnet_main_t *vnm = vnet_get_main ();
446 unformat_input_t *i = vam->input;
447 vl_api_l2_flags_t *mp;
450 u8 sw_if_index_set = 0;
454 /* Parse args required to build the message */
455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
457 if (unformat (i, "sw_if_index %d", &sw_if_index))
459 else if (unformat (i, "sw_if"))
461 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
463 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
470 else if (unformat (i, "learn"))
472 else if (unformat (i, "forward"))
474 else if (unformat (i, "flood"))
476 else if (unformat (i, "uu-flood"))
477 flags |= L2_UU_FLOOD;
478 else if (unformat (i, "arp-term"))
479 flags |= L2_ARP_TERM;
480 else if (unformat (i, "off"))
482 else if (unformat (i, "disable"))
488 if (sw_if_index_set == 0)
490 errmsg ("missing interface name or sw_if_index");
496 mp->sw_if_index = ntohl (sw_if_index);
497 mp->feature_bitmap = ntohl (flags);
506 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t *mp)
508 vat_main_t *vam = l2_test_main.vat_main;
509 i32 retval = ntohl (mp->retval);
512 vam->async_errors += (retval < 0);
516 vam->retval = retval;
517 vam->result_ready = 1;
522 api_l2fib_flush_bd (vat_main_t *vam)
524 unformat_input_t *i = vam->input;
525 vl_api_l2fib_flush_bd_t *mp;
529 /* Parse args required to build the message */
530 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
532 if (unformat (i, "bd_id %d", &bd_id))
540 errmsg ("missing bridge domain");
544 M (L2FIB_FLUSH_BD, mp);
546 mp->bd_id = htonl (bd_id);
554 api_bridge_domain_add_del (vat_main_t *vam)
556 unformat_input_t *i = vam->input;
557 vl_api_bridge_domain_add_del_t *mp;
560 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
565 /* Parse args required to build the message */
566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
568 if (unformat (i, "bd_id %d", &bd_id))
570 else if (unformat (i, "flood %d", &flood))
572 else if (unformat (i, "uu-flood %d", &uu_flood))
574 else if (unformat (i, "forward %d", &forward))
576 else if (unformat (i, "learn %d", &learn))
578 else if (unformat (i, "arp-term %d", &arp_term))
580 else if (unformat (i, "mac-age %d", &mac_age))
582 else if (unformat (i, "bd-tag %s", &bd_tag))
584 else if (unformat (i, "del"))
587 flood = uu_flood = forward = learn = 0;
595 errmsg ("missing bridge domain");
602 errmsg ("mac age must be less than 256 ");
607 if ((bd_tag) && (vec_len (bd_tag) > 63))
609 errmsg ("bd-tag cannot be longer than 63");
614 M (BRIDGE_DOMAIN_ADD_DEL, mp);
616 mp->bd_id = ntohl (bd_id);
618 mp->uu_flood = uu_flood;
619 mp->forward = forward;
621 mp->arp_term = arp_term;
623 mp->mac_age = (u8) mac_age;
626 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
627 mp->bd_tag[vec_len (bd_tag)] = 0;
637 #define foreach_pbb_vtr_op \
638 _ ("disable", L2_VTR_DISABLED) \
639 _ ("pop", L2_VTR_POP_2) \
640 _ ("push", L2_VTR_PUSH_2)
643 api_l2_interface_pbb_tag_rewrite (vat_main_t *vam)
645 vnet_main_t *vnm = vnet_get_main ();
646 unformat_input_t *i = vam->input;
647 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
648 u32 sw_if_index = ~0, vtr_op = ~0;
651 u8 dmac_set = 0, smac_set = 0;
657 /* Shut up coverity */
658 clib_memset (dmac, 0, sizeof (dmac));
659 clib_memset (smac, 0, sizeof (smac));
661 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
663 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
665 else if (unformat (i, "sw_if_index %d", &sw_if_index))
667 else if (unformat (i, "vtr_op %d", &vtr_op))
670 else if (unformat (i, n)) { vtr_op = v; }
673 else if (unformat (i, "translate_pbb_stag"))
675 if (unformat (i, "%d", &tmp))
677 vtr_op = L2_VTR_TRANSLATE_2_1;
683 "translate_pbb_stag operation requires outer tag definition");
687 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
689 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
691 else if (unformat (i, "sid %d", &sid));
692 else if (unformat (i, "vlanid %d", &tmp)) vlanid = tmp;
695 clib_warning ("parse error '%U'", format_unformat_error, i);
700 if ((sw_if_index == ~0) || (vtr_op == ~0))
702 errmsg ("missing sw_if_index or vtr operation");
705 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2)) &&
706 ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
708 errmsg ("push and translate_qinq operations require dmac, smac, sid and "
709 "optionally vlanid");
713 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
714 mp->sw_if_index = ntohl (sw_if_index);
715 mp->vtr_op = ntohl (vtr_op);
716 mp->outer_tag = ntohs (outer_tag);
717 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
718 clib_memcpy (mp->b_smac, smac, sizeof (smac));
719 mp->b_vlanid = ntohs (vlanid);
720 mp->i_sid = ntohl (sid);
728 api_sw_interface_set_l2_xconnect (vat_main_t *vam)
730 vnet_main_t *vnm = vnet_get_main ();
731 unformat_input_t *i = vam->input;
732 vl_api_sw_interface_set_l2_xconnect_t *mp;
734 u8 rx_sw_if_index_set = 0;
736 u8 tx_sw_if_index_set = 0;
740 /* Parse args required to build the message */
741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
743 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
744 rx_sw_if_index_set = 1;
745 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
746 tx_sw_if_index_set = 1;
747 else if (unformat (i, "rx"))
749 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
751 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
753 rx_sw_if_index_set = 1;
758 else if (unformat (i, "tx"))
760 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
762 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
764 tx_sw_if_index_set = 1;
769 else if (unformat (i, "enable"))
771 else if (unformat (i, "disable"))
777 if (rx_sw_if_index_set == 0)
779 errmsg ("missing rx interface name or rx_sw_if_index");
783 if (enable && (tx_sw_if_index_set == 0))
785 errmsg ("missing tx interface name or tx_sw_if_index");
789 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
791 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
792 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
801 api_l2_interface_efp_filter (vat_main_t *vam)
803 vnet_main_t *vnm = vnet_get_main ();
804 unformat_input_t *i = vam->input;
805 vl_api_l2_interface_efp_filter_t *mp;
808 u8 sw_if_index_set = 0;
811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
813 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
815 else if (unformat (i, "sw_if_index %d", &sw_if_index))
817 else if (unformat (i, "enable"))
819 else if (unformat (i, "disable"))
823 clib_warning ("parse error '%U'", format_unformat_error, i);
828 if (sw_if_index_set == 0)
830 errmsg ("missing sw_if_index");
834 M (L2_INTERFACE_EFP_FILTER, mp);
836 mp->sw_if_index = ntohl (sw_if_index);
837 mp->enable_disable = enable;
845 vl_api_bd_ip_mac_details_t_handler (vl_api_bd_ip_mac_details_t *mp)
847 vat_main_t *vam = &vat_main;
849 print (vam->ofp, "\n%-5d %U %U", ntohl (mp->entry.bd_id),
850 format_vl_api_mac_address, mp->entry.mac, format_vl_api_address,
855 vl_api_bvi_create_reply_t_handler (vl_api_bvi_create_reply_t *mp)
860 api_sw_interface_set_l2_bridge (vat_main_t *vam)
862 vnet_main_t *vnm = vnet_get_main ();
863 unformat_input_t *i = vam->input;
864 vl_api_sw_interface_set_l2_bridge_t *mp;
865 vl_api_l2_port_type_t port_type;
867 u8 rx_sw_if_index_set = 0;
874 port_type = L2_API_PORT_TYPE_NORMAL;
876 /* Parse args required to build the message */
877 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
879 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
880 rx_sw_if_index_set = 1;
881 else if (unformat (i, "bd_id %d", &bd_id))
883 else if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
885 rx_sw_if_index_set = 1;
886 else if (unformat (i, "shg %d", &shg))
888 else if (unformat (i, "bvi"))
889 port_type = L2_API_PORT_TYPE_BVI;
890 else if (unformat (i, "uu-fwd"))
891 port_type = L2_API_PORT_TYPE_UU_FWD;
892 else if (unformat (i, "enable"))
894 else if (unformat (i, "disable"))
900 if (rx_sw_if_index_set == 0)
902 errmsg ("missing rx interface name or sw_if_index");
906 if (enable && (bd_id_set == 0))
908 errmsg ("missing bridge domain");
912 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
914 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
915 mp->bd_id = ntohl (bd_id);
917 mp->port_type = ntohl (port_type);
926 api_sw_interface_set_vpath (vat_main_t *vam)
928 vnet_main_t *vnm = vnet_get_main ();
929 unformat_input_t *i = vam->input;
930 vl_api_sw_interface_set_vpath_t *mp;
932 u8 sw_if_index_set = 0;
936 /* Parse args required to build the message */
937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
939 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
941 else if (unformat (i, "sw_if_index %d", &sw_if_index))
943 else if (unformat (i, "enable"))
945 else if (unformat (i, "disable"))
951 if (sw_if_index_set == 0)
953 errmsg ("missing interface name or sw_if_index");
957 /* Construct the API message */
958 M (SW_INTERFACE_SET_VPATH, mp);
960 mp->sw_if_index = ntohl (sw_if_index);
961 mp->enable = is_enable;
966 /* Wait for a reply... */
972 api_l2_patch_add_del (vat_main_t *vam)
974 vnet_main_t *vnm = vnet_get_main ();
975 unformat_input_t *i = vam->input;
976 vl_api_l2_patch_add_del_t *mp;
978 u8 rx_sw_if_index_set = 0;
980 u8 tx_sw_if_index_set = 0;
984 /* Parse args required to build the message */
985 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
987 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
988 rx_sw_if_index_set = 1;
989 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
990 tx_sw_if_index_set = 1;
991 else if (unformat (i, "rx"))
993 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
995 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
997 rx_sw_if_index_set = 1;
1002 else if (unformat (i, "tx"))
1004 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1006 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm,
1008 tx_sw_if_index_set = 1;
1013 else if (unformat (i, "del"))
1019 if (rx_sw_if_index_set == 0)
1021 errmsg ("missing rx interface name or rx_sw_if_index");
1025 if (tx_sw_if_index_set == 0)
1027 errmsg ("missing tx interface name or tx_sw_if_index");
1031 M (L2_PATCH_ADD_DEL, mp);
1033 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
1034 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
1035 mp->is_add = is_add;
1043 vl_api_bridge_flags_reply_t_handler (vl_api_bridge_flags_reply_t *mp)
1045 vat_main_t *vam = &vat_main;
1046 i32 retval = ntohl (mp->retval);
1047 if (vam->async_mode)
1049 vam->async_errors += (retval < 0);
1053 vam->retval = retval;
1054 vam->result_ready = 1;
1058 #define foreach_vtr_op \
1059 _ ("disable", L2_VTR_DISABLED) \
1060 _ ("push-1", L2_VTR_PUSH_1) \
1061 _ ("push-2", L2_VTR_PUSH_2) \
1062 _ ("pop-1", L2_VTR_POP_1) \
1063 _ ("pop-2", L2_VTR_POP_2) \
1064 _ ("translate-1-1", L2_VTR_TRANSLATE_1_1) \
1065 _ ("translate-1-2", L2_VTR_TRANSLATE_1_2) \
1066 _ ("translate-2-1", L2_VTR_TRANSLATE_2_1) \
1067 _ ("translate-2-2", L2_VTR_TRANSLATE_2_2)
1070 api_l2_interface_vlan_tag_rewrite (vat_main_t *vam)
1072 vnet_main_t *vnm = vnet_get_main ();
1073 unformat_input_t *i = vam->input;
1074 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
1076 u8 sw_if_index_set = 0;
1084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1086 if (unformat (i, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1087 sw_if_index_set = 1;
1088 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1089 sw_if_index_set = 1;
1090 else if (unformat (i, "vtr_op %d", &vtr_op))
1093 else if (unformat (i, n)) \
1100 else if (unformat (i, "push_dot1q %d", &push_dot1q));
1101 else if (unformat (i, "tag1 %d", &tag1));
1102 else if (unformat (i, "tag2 %d", &tag2));
1105 clib_warning ("parse error '%U'", format_unformat_error, i);
1110 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
1112 errmsg ("missing vtr operation or sw_if_index");
1116 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
1117 mp->sw_if_index = ntohl (sw_if_index);
1118 mp->vtr_op = ntohl (vtr_op);
1119 mp->push_dot1q = ntohl (push_dot1q);
1120 mp->tag1 = ntohl (tag1);
1121 mp->tag2 = ntohl (tag2);
1129 api_bridge_domain_set_learn_limit (vat_main_t *vam)
1135 api_bd_ip_mac_add_del (vat_main_t *vam)
1137 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
1138 vl_api_mac_address_t mac = { 0 };
1139 unformat_input_t *i = vam->input;
1140 vl_api_bd_ip_mac_add_del_t *mp;
1148 /* Parse args required to build the message */
1149 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1151 if (unformat (i, "bd_id %d", &bd_id))
1155 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
1159 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
1163 else if (unformat (i, "del"))
1171 errmsg ("missing bridge domain");
1174 else if (ip_set == 0)
1176 errmsg ("missing IP address");
1179 else if (mac_set == 0)
1181 errmsg ("missing MAC address");
1185 M (BD_IP_MAC_ADD_DEL, mp);
1187 mp->entry.bd_id = ntohl (bd_id);
1188 mp->is_add = is_add;
1190 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
1191 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
1199 vl_api_bridge_domain_details_t_handler (vl_api_bridge_domain_details_t *mp)
1201 vat_main_t *vam = l2_test_main.vat_main;
1202 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1205 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s", " ID", "LRN", "FWD",
1206 "FLD", "BVI", "UU-FWD", "#IF");
1208 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d", ntohl (mp->bd_id), mp->learn,
1209 mp->forward, mp->flood, ntohl (mp->bvi_sw_if_index),
1210 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1214 vl_api_bridge_domain_sw_if_t *sw_ifs;
1215 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1218 sw_ifs = mp->sw_if_details;
1219 for (i = 0; i < n_sw_ifs; i++)
1225 sw_if_index = ntohl (sw_ifs->sw_if_index);
1227 hash_foreach_pair (p, vam->sw_if_index_by_interface_name, ({
1228 if ((u32) p->value[0] == sw_if_index)
1230 sw_if_name = (u8 *) (p->key);
1234 print (vam->ofp, "%7d %3d %s", sw_if_index, sw_ifs->shg,
1235 sw_if_name ? (char *) sw_if_name : "sw_if_index not found!");
1243 api_bridge_domain_dump (vat_main_t *vam)
1245 unformat_input_t *i = vam->input;
1246 vl_api_bridge_domain_dump_t *mp;
1247 vl_api_control_ping_t *mp_ping;
1251 /* Parse args required to build the message */
1252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1254 if (unformat (i, "bd_id %d", &bd_id))
1260 M (BRIDGE_DOMAIN_DUMP, mp);
1261 mp->bd_id = ntohl (bd_id);
1264 /* Use a control ping for synchronization */
1265 PING (&l2_test_main, mp_ping);
1273 api_bridge_domain_set_default_learn_limit (vat_main_t *vam)
1279 api_bd_ip_mac_flush (vat_main_t *vam)
1281 unformat_input_t *i = vam->input;
1282 vl_api_bd_ip_mac_flush_t *mp;
1287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1289 if (unformat (i, "bd_id %d", &bd_id))
1299 errmsg ("missing bridge domain");
1303 M (BD_IP_MAC_FLUSH, mp);
1305 mp->bd_id = ntohl (bd_id);
1313 api_bd_ip_mac_dump (vat_main_t *vam)
1315 unformat_input_t *i = vam->input;
1316 vl_api_bd_ip_mac_dump_t *mp;
1317 vl_api_control_ping_t *mp_ping;
1322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1324 if (unformat (i, "bd_id %d", &bd_id))
1332 fformat (vam->ofp, "\n%-5s %-7s %-20s %-30s", "bd_id", "is_ipv6",
1333 "mac_address", "ip_address");
1335 /* Dump Bridge Domain Ip to Mac entries */
1336 M (BD_IP_MAC_DUMP, mp);
1339 mp->bd_id = htonl (bd_id);
1345 /* Use a control ping for synchronization */
1346 PING (&l2_test_main, mp_ping);
1354 api_bvi_create (vat_main_t *vam)
1360 api_bvi_delete (vat_main_t *vam)
1366 api_bridge_flags (vat_main_t *vam)
1368 unformat_input_t *i = vam->input;
1369 vl_api_bridge_flags_t *mp;
1373 bd_flags_t flags = 0;
1376 /* Parse args required to build the message */
1377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1379 if (unformat (i, "bd_id %d", &bd_id))
1381 else if (unformat (i, "learn"))
1382 flags |= BRIDGE_API_FLAG_LEARN;
1383 else if (unformat (i, "forward"))
1384 flags |= BRIDGE_API_FLAG_FWD;
1385 else if (unformat (i, "flood"))
1386 flags |= BRIDGE_API_FLAG_FLOOD;
1387 else if (unformat (i, "uu-flood"))
1388 flags |= BRIDGE_API_FLAG_UU_FLOOD;
1389 else if (unformat (i, "arp-term"))
1390 flags |= BRIDGE_API_FLAG_ARP_TERM;
1391 else if (unformat (i, "off"))
1393 else if (unformat (i, "disable"))
1401 errmsg ("missing bridge domain");
1405 M (BRIDGE_FLAGS, mp);
1407 mp->bd_id = ntohl (bd_id);
1408 mp->flags = ntohl (flags);
1409 mp->is_set = is_set;
1416 #include <vnet/l2/l2.api_test.c>
1420 * eval: (c-set-style "gnu")