diff options
-rw-r--r-- | src/vat/api_format.c | 96 | ||||
-rw-r--r-- | src/vnet/l2/l2.api | 26 | ||||
-rw-r--r-- | src/vnet/l2/l2_api.c | 80 | ||||
-rw-r--r-- | src/vpp/api/custom_dump.c | 10 |
4 files changed, 212 insertions, 0 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 8be83ba7cae..850fe56609d 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -5684,6 +5684,7 @@ _(IKEV2_INITIATE_DEL_CHILD_SA_REPLY, ikev2_initiate_del_child_sa_reply) \ _(IKEV2_INITIATE_REKEY_CHILD_SA_REPLY, ikev2_initiate_rekey_child_sa_reply) \ _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \ _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \ +_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \ _(DHCP_COMPL_EVENT, dhcp_compl_event) \ _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \ _(WANT_STATS_REPLY, want_stats_reply) \ @@ -7667,6 +7668,100 @@ api_bd_ip_mac_add_del (vat_main_t * vam) return ret; } +static void vl_api_bd_ip_mac_details_t_handler + (vl_api_bd_ip_mac_details_t * mp) +{ + vat_main_t *vam = &vat_main; + u8 *ip = 0; + + if (!mp->is_ipv6) + ip = + format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address); + else + ip = + format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address); + + print (vam->ofp, + "\n%-5d %-7s %-20U %-30s", + ntohl (mp->bd_id), mp->is_ipv6 ? "ip6" : "ip4", + format_ethernet_address, mp->mac_address, ip); + + vec_free (ip); +} + +static void vl_api_bd_ip_mac_details_t_handler_json + (vl_api_bd_ip_mac_details_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t *node = NULL; + + if (VAT_JSON_ARRAY != vam->json_tree.type) + { + ASSERT (VAT_JSON_NONE == vam->json_tree.type); + vat_json_init_array (&vam->json_tree); + } + node = vat_json_array_add (&vam->json_tree); + + vat_json_init_object (node); + vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id)); + vat_json_object_add_uint (node, "is_ipv6", ntohl (mp->is_ipv6)); + vat_json_object_add_string_copy (node, "mac_address", + format (0, "%U", format_ethernet_address, + &mp->mac_address)); + u8 *ip = 0; + + if (!mp->is_ipv6) + ip = + format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address); + else + ip = + format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address); + vat_json_object_add_string_copy (node, "ip_address", ip); + vec_free (ip); +} + +static int +api_bd_ip_mac_dump (vat_main_t * vam) +{ + unformat_input_t *i = vam->input; + vl_api_bd_ip_mac_dump_t *mp; + vl_api_control_ping_t *mp_ping; + int ret; + u32 bd_id; + u8 bd_id_set = 0; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "bd_id %d", &bd_id)) + { + bd_id_set++; + } + else + break; + } + + print (vam->ofp, + "\n%-5s %-7s %-20s %-30s", + "bd_id", "is_ipv6", "mac_address", "ip_address"); + + /* Dump Bridge Domain Ip to Mac entries */ + M (BD_IP_MAC_DUMP, mp); + + if (bd_id_set) + mp->bd_id = htonl (bd_id); + else + mp->bd_id = ~0; + + S (mp); + + /* Use a control ping for synchronization */ + MPING (CONTROL_PING, mp_ping); + S (mp_ping); + + W (ret); + return ret; +} + static int api_tap_connect (vat_main_t * vam) { @@ -23397,6 +23492,7 @@ _(ikev2_initiate_del_child_sa, "<ispi>") \ _(ikev2_initiate_rekey_child_sa, "<ispi>") \ _(delete_loopback,"sw_if_index <nn>") \ _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \ +_(bd_ip_mac_dump, "[bd_id] <id>") \ _(want_interface_events, "enable|disable") \ _(want_stats,"enable|disable") \ _(get_first_msg_id, "client <name>") \ diff --git a/src/vnet/l2/l2.api b/src/vnet/l2/l2.api index 05b250bd885..ae639682a38 100644 --- a/src/vnet/l2/l2.api +++ b/src/vnet/l2/l2.api @@ -459,6 +459,32 @@ autoreply define bd_ip_mac_add_del u8 mac_address[6]; }; +/** \brief bridge domain IP to MAC entry details structure + @param bd_id - bridge domain table id + @param is_ipv6 - if non-zero, ipv6 address, else ipv4 address + @param ip_address - ipv4 or ipv6 address + @param mac_address - MAC address +*/ +define bd_ip_mac_details +{ + u32 context; + u32 bd_id; + u8 is_ipv6; + u8 ip_address[16]; + u8 mac_address[6]; +}; + +/** \brief Dump bridge domain IP to MAC entries + @param client_index - opaque cookie to identify the sender + @param bd_id - bridge domain identifier +*/ +define bd_ip_mac_dump +{ + u32 client_index; + u32 context; + u32 bd_id; +}; + /** \brief L2 interface ethernet flow point filtering enable/disable request @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request diff --git a/src/vnet/l2/l2_api.c b/src/vnet/l2/l2_api.c index be3b75e9658..5ec7581ff3b 100644 --- a/src/vnet/l2/l2_api.c +++ b/src/vnet/l2/l2_api.c @@ -63,6 +63,7 @@ _(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge) \ _(L2_PATCH_ADD_DEL, l2_patch_add_del) \ _(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter) \ _(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \ +_(BD_IP_MAC_DUMP, bd_ip_mac_dump) \ _(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del) \ _(BRIDGE_DOMAIN_DUMP, bridge_domain_dump) \ _(BRIDGE_FLAGS, bridge_flags) \ @@ -702,6 +703,85 @@ static void } static void +send_bd_ip_mac_entry (vpe_api_main_t * am, + vl_api_registration_t * reg, + u32 bd_id, u8 is_ipv6, + u8 * ip_address, u8 * mac_address, u32 context) +{ + vl_api_bd_ip_mac_details_t *mp; + + mp = vl_msg_api_alloc (sizeof (*mp)); + memset (mp, 0, sizeof (*mp)); + mp->_vl_msg_id = ntohs (VL_API_BD_IP_MAC_DETAILS); + + mp->bd_id = ntohl (bd_id); + + clib_memcpy (mp->mac_address, mac_address, 6); + mp->is_ipv6 = is_ipv6; + clib_memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4); + mp->context = context; + + vl_api_send_msg (reg, (u8 *) mp); +} + +static void +vl_api_bd_ip_mac_dump_t_handler (vl_api_bd_ip_mac_dump_t * mp) +{ + vpe_api_main_t *am = &vpe_api_main; + bd_main_t *bdm = &bd_main; + l2_bridge_domain_t *bd_config; + u32 bd_id = ntohl (mp->bd_id); + u32 bd_index, start = 1, end; + vl_api_registration_t *reg; + uword *p; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + end = vec_len (l2input_main.bd_configs); + + /* see bd_id: ~0 means "any" */ + if (bd_id == ~0) + bd_index = ~0; + else + { + p = hash_get (bdm->bd_index_by_bd_id, bd_id); + if (p == 0) + return; + + bd_index = p[0]; + vec_validate (l2input_main.bd_configs, bd_index); + start = bd_index; + end = start + 1; + } + + for (bd_index = start; bd_index < end; bd_index++) + { + bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); + if (bd_is_valid (bd_config)) + { + ip4_address_t ip4_addr; + ip6_address_t *ip6_addr; + u64 mac_addr; + bd_id = bd_config->bd_id; + + /* *INDENT-OFF* */ + hash_foreach (ip4_addr.as_u32, mac_addr, bd_config->mac_by_ip4, + ({ + send_bd_ip_mac_entry (am, reg, bd_id, 0, (u8 *) &(ip4_addr.as_u8), (u8 *) &mac_addr, mp->context); + })); + + hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6, + ({ + send_bd_ip_mac_entry (am, reg, bd_id, 1, (u8 *) &(ip6_addr->as_u8), (u8 *) &mac_addr, mp->context); + })); + /* *INDENT-ON* */ + } + } +} + +static void vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp) { bd_main_t *bdm = &bd_main; diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index 0bd4fb8c467..b4fa22189b4 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -486,6 +486,16 @@ static void *vl_api_bd_ip_mac_add_del_t_print FINISH; } +static void *vl_api_bd_ip_mac_dump_t_print + (vl_api_bd_ip_mac_dump_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: bd_ip_mac_dump "); + + FINISH; +} + static void *vl_api_tap_connect_t_print (vl_api_tap_connect_t * mp, void *handle) { |