-static int
-get_locator_set (vat_main_t * vam)
-{
- vl_api_lisp_locator_set_dump_t *mp;
- f64 timeout = ~0;
-
- M (LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
- /* send it... */
- S;
-
- /* Use a control ping for synchronization */
- {
- vl_api_noprint_control_ping_t *mp;
- M (NOPRINT_CONTROL_PING, noprint_control_ping);
- S;
- }
-
- /* Wait for a reply... */
- W;
-
- /* NOTREACHED */
- return 0;
-}
-
-static inline u8 *
-format_eid_for_eid_table (vat_main_t * vam, u8 * str, eid_table_t * eid_table,
- int *ret)
-{
- u8 *(*format_eid) (u8 *, va_list *) = 0;
-
- ASSERT (vam != NULL);
- ASSERT (eid_table != NULL);
-
- if (ret)
- {
- *ret = 0;
- }
-
- switch (eid_table->eid_type)
- {
- case 0:
- case 1:
- format_eid = (eid_table->eid_type ? format_ip6_address :
- format_ip4_address);
- str = format (0, "[%d] %U/%d",
- clib_net_to_host_u32 (eid_table->vni),
- format_eid, eid_table->eid, eid_table->eid_prefix_len);
- break;
- case 2:
- str = format (0, "[%d] %U",
- clib_net_to_host_u32 (eid_table->vni),
- format_ethernet_address, eid_table->eid);
- break;
- default:
- errmsg ("unknown EID type %d!", eid_table->eid_type);
- if (ret)
- {
- *ret = -99;
- }
- return 0;
- }
-
- return str;
-}
-
-static inline u8 *
-format_locator_set_for_eid_table (vat_main_t * vam, u8 * str,
- eid_table_t * eid_table)
-{
- locator_set_msg_t *ls = 0;
-
- ASSERT (vam != NULL);
- ASSERT (eid_table != NULL);
-
- if (eid_table->is_local)
- {
- vec_foreach (ls, vam->locator_set_msg)
- {
- if (ls->locator_set_index == eid_table->locator_set_index)
- {
- str = format (0, "local(%s)", ls->locator_set_name);
- return str;
- }
- }
-
- str = format (0, "local(N/A)");
- }
- else
- {
- str = format (0, "remote");
- }
-
- return str;
-}
-
-static inline u8 *
-format_locator_for_eid_table (vat_main_t * vam, u8 * str,
- eid_table_t * eid_table)
-{
- locator_msg_t *loc = 0;
- int first_line = 1;
-
- ASSERT (vam != NULL);
- ASSERT (eid_table != NULL);
-
- vec_foreach (loc, vam->locator_msg)
- {
- if (!first_line)
- {
- if (loc->local)
- {
- str = format (str, "%-55s%-d\n", " ", loc->sw_if_index);
- }
- else
- {
- str = format (str, "%=55s%-U\n", " ",
- loc->is_ipv6 ? format_ip6_address :
- format_ip4_address, loc->ip_address);
- }
-
- continue;
- }
-
- if (loc->local)
- {
- str = format (str, "%-30d%-20u%-u\n", loc->sw_if_index,
- eid_table->ttl, eid_table->authoritative);
- }
- else
- {
- str = format (str, "%-30U%-20u%-u\n",
- loc->is_ipv6 ? format_ip6_address :
- format_ip4_address,
- loc->ip_address, eid_table->ttl,
- eid_table->authoritative);
- }
- first_line = 0;
- }
-
- return str;
-}
-
-static int
-print_lisp_eid_table_dump (vat_main_t * vam)
-{
- eid_table_t *eid_table = 0;
- u8 *tmp_str = 0, *tmp_str2 = 0;
- int ret = 0;
-
- ASSERT (vam != NULL);
-
- ret = get_locator_set (vam);
- if (ret)
- {
- vec_free (vam->eid_tables);
- return ret;
- }
-
- fformat (vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type", "locators",
- "ttl", "authoritative");
-
- vec_foreach (eid_table, vam->eid_tables)
- {
- ret = lisp_locator_dump_send_msg (vam, eid_table->locator_set_index, 0);
- if (ret)
- {
- vec_free (vam->locator_msg);
- clean_locator_set_message (vam);
- vec_free (vam->eid_tables);
- return ret;
- }
-
- tmp_str2 = format_eid_for_eid_table (vam, tmp_str2, eid_table, &ret);
- if (ret)
- {
- vec_free (vam->locator_msg);
- clean_locator_set_message (vam);
- vec_free (vam->eid_tables);
- return ret;
- }
-
- tmp_str = format (0, "%-35s", tmp_str2);
- vec_free (tmp_str2);
-
- tmp_str2 = format_locator_set_for_eid_table (vam, tmp_str2, eid_table);
- tmp_str = format (tmp_str, "%-20s", tmp_str2);
- vec_free (tmp_str2);
-
- tmp_str2 = format_locator_for_eid_table (vam, tmp_str2, eid_table);
- tmp_str = format (tmp_str, "%-s", tmp_str2);
- vec_free (tmp_str2);
-
- fformat (vam->ofp, "%s", tmp_str);
- vec_free (tmp_str);
- vec_free (vam->locator_msg);
- }
-
- clean_locator_set_message (vam);
- vec_free (vam->eid_tables);
-
- return ret;
-}
-
-static inline void
-json_locator_set_for_eid_table (vat_main_t * vam, vat_json_node_t * node,
- eid_table_t * eid_table)
-{
- locator_set_msg_t *ls = 0;
- u8 *s = 0;
-
- ASSERT (vam != NULL);
- ASSERT (node != NULL);
- ASSERT (eid_table != NULL);
-
- if (eid_table->is_local)
- {
- vec_foreach (ls, vam->locator_set_msg)
- {
- if (ls->locator_set_index == eid_table->locator_set_index)
- {
- vat_json_object_add_string_copy (node, "locator-set",
- ls->locator_set_name);
- return;
- }
- }
-
- s = format (0, "N/A");
- vec_add1 (s, 0);
- vat_json_object_add_string_copy (node, "locator-set", s);
- vec_free (s);
- }
- else
- {
- s = format (0, "remote");
- vec_add1 (s, 0);
- vat_json_object_add_string_copy (node, "locator-set", s);
- vec_free (s);
- }
-}
-
-static inline int
-json_eid_for_eid_table (vat_main_t * vam, vat_json_node_t * node,
- eid_table_t * eid_table)
-{
- u8 *s = 0;
- struct in6_addr ip6;
- struct in_addr ip4;
-
- ASSERT (vam != NULL);
- ASSERT (node != NULL);
- ASSERT (eid_table != NULL);
-
- switch (eid_table->eid_type)
- {
- case 0:
- clib_memcpy (&ip4, eid_table->eid, sizeof (ip4));
- vat_json_object_add_ip4 (node, "eid", ip4);
- vat_json_object_add_uint (node, "eid-prefix-len",
- eid_table->eid_prefix_len);
- break;
- case 1:
- clib_memcpy (&ip6, eid_table->eid, sizeof (ip6));
- vat_json_object_add_ip6 (node, "eid", ip6);
- vat_json_object_add_uint (node, "eid-prefix-len",
- eid_table->eid_prefix_len);
- break;
- case 2:
- s = format (0, "%U", format_ethernet_address, eid_table->eid);
- vec_add1 (s, 0);
- vat_json_object_add_string_copy (node, "eid", s);
- vec_free (s);
- break;
- default:
- errmsg ("unknown EID type %d!", eid_table->eid_type);
- return -99;
- }
-
- return 0;
-}
-
-static inline void
-json_locator_for_eid_table (vat_main_t * vam, vat_json_node_t * node,
- eid_table_t * eid_table)
-{
- locator_msg_t *loc = 0;
- vat_json_node_t *locator_array = 0;
- vat_json_node_t *locator = 0;
- struct in6_addr ip6;
- struct in_addr ip4;
-
- ASSERT (vam != NULL);
- ASSERT (node != NULL);
- ASSERT (eid_table != NULL);
-
- locator_array = vat_json_object_add_list (node, "locator");
- vec_foreach (loc, vam->locator_msg)
- {
- locator = vat_json_array_add (locator_array);
- vat_json_init_object (locator);
- if (loc->local)
- {
- vat_json_object_add_uint (locator, "locator-index", loc->sw_if_index);
- }
- else
- {
- if (loc->is_ipv6)
- {
- clib_memcpy (&ip6, loc->ip_address, sizeof (ip6));
- vat_json_object_add_ip6 (locator, "locator", ip6);
- }
- else
- {
- clib_memcpy (&ip4, loc->ip_address, sizeof (ip4));
- vat_json_object_add_ip4 (locator, "locator", ip4);
- }
- }
- }
-}
-
-static int
-json_lisp_eid_table_dump (vat_main_t * vam)
-{
- eid_table_t *eid_table;
- vat_json_node_t *node = 0;
- int ret = 0;
-
- ASSERT (vam != NULL);
-
- ret = get_locator_set (vam);
- if (ret)
- {
- vec_free (vam->eid_tables);
- return ret;
- }
-
- if (!vec_len (vam->eid_tables))
- {
- /* just print [] */
- vat_json_init_array (&vam->json_tree);
- vat_json_print (vam->ofp, &vam->json_tree);
- vam->json_tree.type = VAT_JSON_NONE;
- return ret;
- }
-
- if (VAT_JSON_ARRAY != vam->json_tree.type)
- {
- ASSERT (VAT_JSON_NONE == vam->json_tree.type);
- vat_json_init_array (&vam->json_tree);
- }
-
- vec_foreach (eid_table, vam->eid_tables)
- {
- ret = lisp_locator_dump_send_msg (vam, eid_table->locator_set_index, 0);
- if (ret)
- {
- vec_free (vam->locator_msg);
- vec_free (vam->eid_tables);
- clean_locator_set_message (vam);
- vat_json_free (&vam->json_tree);
- vam->json_tree.type = VAT_JSON_NONE;
- return ret;
- }
-
- node = vat_json_array_add (&vam->json_tree);
- vat_json_init_object (node);
-
- vat_json_object_add_uint (node, "vni", eid_table->vni);
-
- json_locator_set_for_eid_table (vam, node, eid_table);
- ret = json_eid_for_eid_table (vam, node, eid_table);
- if (ret)
- {
- vec_free (vam->locator_msg);
- vec_free (vam->eid_tables);
- clean_locator_set_message (vam);
- vat_json_free (&vam->json_tree);
- vam->json_tree.type = VAT_JSON_NONE;
- return ret;
- }
-
- json_locator_for_eid_table (vam, node, eid_table);
-
- vat_json_object_add_uint (node, "ttl", eid_table->ttl);
- vat_json_object_add_uint (node, "authoritative",
- eid_table->authoritative);
-
- vec_free (vam->locator_msg);
- }
-
- vat_json_print (vam->ofp, &vam->json_tree);
- vat_json_free (&vam->json_tree);
- vam->json_tree.type = VAT_JSON_NONE;
-
- clean_locator_set_message (vam);
- vec_free (vam->eid_tables);
-
- return ret;
-}
-