diff options
author | 2016-09-02 12:14:31 +0200 | |
---|---|---|
committer | 2016-09-13 07:26:17 +0000 | |
commit | c5bb0d6667ca36affe9fb30e58c852e4f1b47f93 (patch) | |
tree | 685a3956fa65dc287914bc860be1b8845d21593e /vpp | |
parent | 22aa3e970da0f0c772c5a16103a5dcf1f2875285 (diff) |
VPP-376: Refactor LISP dump API + VAT
- refactor VAT so it won't cache data
- remove unused filter flag from locator dump API call
- json structure changed for locator and EID table dump calls
- remote mapping VAT cli now accepts string for negative mapping action
Change-Id: I776fb50659aaa7e98ad93715d282a83f78287344
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'vpp')
-rw-r--r-- | vpp/vpp-api/api.c | 126 | ||||
-rw-r--r-- | vpp/vpp-api/custom_dump.c | 49 | ||||
-rw-r--r-- | vpp/vpp-api/vpe.api | 66 |
3 files changed, 136 insertions, 105 deletions
diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c index 44afd674..c1da5aa9 100644 --- a/vpp/vpp-api/api.c +++ b/vpp/vpp-api/api.c @@ -283,7 +283,6 @@ _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ _(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered) \ _(CREATE_LOOPBACK, create_loopback) \ _(CONTROL_PING, control_ping) \ -_(NOPRINT_CONTROL_PING, noprint_control_ping) \ _(CLI_REQUEST, cli_request) \ _(CLI_INBAND, cli_inband) \ _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \ @@ -3636,20 +3635,6 @@ vl_api_control_ping_t_handler (vl_api_control_ping_t * mp) /* *INDENT-ON* */ } -static void vl_api_noprint_control_ping_t_handler - (vl_api_noprint_control_ping_t * mp) -{ - vl_api_noprint_control_ping_reply_t *rmp; - int rv = 0; - - /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_NOPRINT_CONTROL_PING_REPLY, - ({ - rmp->vpe_pid = ntohl (getpid()); - })); - /* *INDENT-ON* */ -} - static void shmem_cli_output (uword arg, u8 * buffer, uword buffer_bytes) { @@ -5711,12 +5696,13 @@ send_lisp_locator_details (lisp_cp_main_t * lcm, static void vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp) { + u8 *ls_name = 0; unix_shared_memory_queue_t *q = 0; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); locator_set_t *lsit = 0; locator_t *loc = 0; u32 ls_index = ~0, *locit = 0; - u8 filter; + uword *p = 0; q = vl_api_client_index_to_input_queue (mp->client_index); if (q == 0) @@ -5724,22 +5710,29 @@ vl_api_lisp_locator_dump_t_handler (vl_api_lisp_locator_dump_t * mp) return; } - ls_index = htonl (mp->locator_set_index); - - lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); - - filter = mp->filter; - if (filter && !((1 == filter && lsit->local) || - (2 == filter && !lsit->local))) + if (mp->is_index_set) + ls_index = htonl (mp->ls_index); + else { - return; + ls_name = format (0, "%s", mp->ls_name); + p = hash_get_mem (lcm->locator_set_index_by_name, ls_name); + if (!p) + goto out; + ls_index = p[0]; } + if (pool_is_free_index (lcm->locator_set_pool, ls_index)) + return; + + lsit = pool_elt_at_index (lcm->locator_set_pool, ls_index); + vec_foreach (locit, lsit->locator_indices) { loc = pool_elt_at_index (lcm->locator_pool, locit[0]); send_lisp_locator_details (lcm, loc, q, mp->context); }; +out: + vec_free (ls_name); } static void @@ -5756,19 +5749,17 @@ send_lisp_locator_set_details (lisp_cp_main_t * lcm, rmp->_vl_msg_id = ntohs (VL_API_LISP_LOCATOR_SET_DETAILS); rmp->context = context; - rmp->local = lsit->local; - rmp->locator_set_index = htonl (ls_index); + rmp->ls_index = htonl (ls_index); if (lsit->local) { ASSERT (lsit->name != NULL); - strncpy ((char *) rmp->locator_set_name, - (char *) lsit->name, ARRAY_LEN (rmp->locator_set_name) - 1); + strncpy ((char *) rmp->ls_name, (char *) lsit->name, + vec_len (lsit->name)); } else { - str = format (0, "remote-%d", ls_index); - strncpy ((char *) rmp->locator_set_name, (char *) str, - ARRAY_LEN (rmp->locator_set_name) - 1); + str = format (0, "<remote-%d>", ls_index); + strncpy ((char *) rmp->ls_name, (char *) str, vec_len (str)); vec_free (str); } @@ -5781,7 +5772,6 @@ vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp) unix_shared_memory_queue_t *q = NULL; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); locator_set_t *lsit = NULL; - u32 index; u8 filter; q = vl_api_client_index_to_input_queue (mp->client_index); @@ -5791,25 +5781,76 @@ vl_api_lisp_locator_set_dump_t_handler (vl_api_lisp_locator_set_dump_t * mp) } filter = mp->filter; - index = 0; /* *INDENT-OFF* */ pool_foreach (lsit, lcm->locator_set_pool, ({ if (filter && !((1 == filter && lsit->local) || - (2 == filter && !lsit->local))) { - index++; - continue; - } - send_lisp_locator_set_details(lcm, lsit, q, mp->context, index++); + (2 == filter && !lsit->local))) + { + continue; + } + send_lisp_locator_set_details (lcm, lsit, q, mp->context, + lsit - lcm->locator_set_pool); })); /* *INDENT-ON* */ } static void +lisp_fid_put_api (u8 * dst, fid_address_t * src, u8 * prefix_length) +{ + ASSERT (prefix_length); + ip_prefix_t *ippref = &fid_addr_ippref (src); + + switch (fid_addr_type (src)) + { + case FID_ADDR_IP_PREF: + if (ip_prefix_version (ippref) == IP4) + clib_memcpy (dst, &ip_prefix_v4 (ippref), 4); + else + clib_memcpy (dst, &ip_prefix_v6 (ippref), 16); + prefix_length[0] = ip_prefix_len (ippref); + break; + + case FID_ADDR_MAC: + prefix_length[0] = 0; + clib_memcpy (dst, fid_addr_mac (src), 6); + break; + + default: + clib_warning ("Unknown FID type %d!", fid_addr_type (src)); + break; + } +} + +static u8 +fid_type_to_api_type (fid_address_t * fid) +{ + ip_prefix_t *ippref; + + switch (fid_addr_type (fid)) + { + case FID_ADDR_IP_PREF: + ippref = &fid_addr_ippref (fid); + if (ip_prefix_version (ippref) == IP4) + return 0; + else if (ip_prefix_version (ippref) == IP6) + return 1; + else + return ~0; + + case FID_ADDR_MAC: + return 2; + } + + return ~0; +} + +static void send_lisp_eid_table_details (mapping_t * mapit, unix_shared_memory_queue_t * q, u32 context, u8 filter) { + fid_address_t *fid; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); locator_set_t *ls = 0; vl_api_lisp_eid_table_details_t *rmp = NULL; @@ -5856,6 +5897,15 @@ send_lisp_eid_table_details (mapping_t * mapit, switch (gid_address_type (gid)) { + case GID_ADDR_SRC_DST: + rmp->is_src_dst = 1; + fid = &gid_address_sd_src (gid); + rmp->eid_type = fid_type_to_api_type (fid); + lisp_fid_put_api (rmp->seid, &gid_address_sd_src (gid), + &rmp->seid_prefix_len); + lisp_fid_put_api (rmp->eid, &gid_address_sd_dst (gid), + &rmp->eid_prefix_len); + break; case GID_ADDR_IP_PREFIX: rmp->eid_prefix_len = ip_prefix_len (ip_prefix); if (ip_prefix_version (ip_prefix) == IP4) diff --git a/vpp/vpp-api/custom_dump.c b/vpp/vpp-api/custom_dump.c index e8ee5516..a92e6803 100644 --- a/vpp/vpp-api/custom_dump.c +++ b/vpp/vpp-api/custom_dump.c @@ -2337,24 +2337,6 @@ format_lisp_flat_eid (u8 * s, va_list * args) return 0; } -static u8 * -format_lisp_eid_vat (u8 * s, va_list * args) -{ - u32 type = va_arg (*args, u32); - u8 *eid = va_arg (*args, u8 *); - u32 eid_len = va_arg (*args, u32); - u8 *seid = va_arg (*args, u8 *); - u32 seid_len = va_arg (*args, u32); - u32 is_src_dst = va_arg (*args, u32); - - if (is_src_dst) - s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len); - - s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len); - - return s; -} - /** Used for transferring locators via VPP API */ typedef CLIB_PACKED (struct { @@ -2397,9 +2379,14 @@ static void *vl_api_lisp_add_del_remote_mapping_t_print s = format (s, "%s ", mp->is_add ? "add" : "del"); s = format (s, "vni %d ", clib_net_to_host_u32 (mp->vni)); - s = format (s, "deid %U ", format_lisp_eid_vat, - mp->eid_type, mp->eid, mp->eid_len, mp->seid, mp->seid_len, - mp->is_src_dst); + s = format (s, "eid %U ", format_lisp_flat_eid, + mp->eid_type, mp->eid, mp->eid_len); + + if (mp->is_src_dst) + { + s = format (s, "seid %U ", format_lisp_flat_eid, + mp->eid_type, mp->seid, mp->seid_len); + } rloc_num = clib_net_to_host_u32 (mp->rloc_num); @@ -2585,8 +2572,24 @@ static void *vl_api_lisp_locator_set_dump_t_print u8 *s; s = format (0, "SCRIPT: lisp_locator_set_dump "); + if (mp->filter == 1) + s = format (s, "local"); + else if (mp->filter == 2) + s = format (s, "remote"); - /* not possible to reconstruct original VAT command */ + FINISH; +} + +static void *vl_api_lisp_locator_dump_t_print + (vl_api_lisp_locator_dump_t * mp, void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: lisp_locator_dump "); + if (mp->is_index_set) + s = format (s, "ls_index %d", clib_net_to_host_u32 (mp->ls_index)); + else + s = format (s, "ls_name %s", mp->ls_name); FINISH; } @@ -2819,7 +2822,7 @@ _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump) \ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump) \ _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump) \ _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ -_(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump) \ +_(LISP_LOCATOR_DUMP, lisp_locator_dump) \ _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \ _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump) \ _(DELETE_SUBIF, delete_subif) diff --git a/vpp/vpp-api/vpe.api b/vpp/vpp-api/vpe.api index 11bb30c1..ae4c12d4 100644 --- a/vpp/vpp-api/vpe.api +++ b/vpp/vpp-api/vpe.api @@ -1148,30 +1148,6 @@ define control_ping_reply u32 vpe_pid; }; -/** \brief Control ping from client to api server request, no print json output - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request -*/ -define noprint_control_ping -{ - u32 client_index; - u32 context; -}; - -/** \brief Control ping from the client to the server response - @param client_index - opaque cookie to identify the sender - @param context - sender context, to match reply w/ request - @param retval - return code for the request - @param vpe_pid - the pid of the vpe, returned by the server -*/ -define noprint_control_ping_reply -{ - u32 context; - i32 retval; - u32 client_index; - u32 vpe_pid; -}; - /** \brief Process a vpe parser cli string request @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request @@ -2753,18 +2729,16 @@ define lisp_eid_table_add_del_map_reply @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request @param locator_set_index - index of locator_set - @param filter - filter type; - Support value: - 0: all locator - 1: local locator - 2: remote locator + @param ls_name - locator set name + @param is_index_set - flag indicating whether ls_name or ls_index is set */ define lisp_locator_dump { u32 client_index; u32 context; - u32 locator_set_index; - u8 filter; + u32 ls_index; + u8 ls_name[64]; + u8 is_index_set; }; /** \brief LISP locator_set status @@ -2786,27 +2760,25 @@ define lisp_locator_details }; /** \brief LISP locator_set status - @param locator_set_name - name of the locator_set - @param local - if is set, then locator_set is local - @param locator_count - number of locator this stats block includes - @param locator - locator data + @param context - sender context, to match reply w/ request + @param ls_index - locator set index + @param ls_name - name of the locator set */ define lisp_locator_set_details { u32 context; - u8 local; - u32 locator_set_index; - u8 locator_set_name[64]; + u32 ls_index; + u8 ls_name[64]; }; /** \brief Request for locator_set summary status @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request - @param filter - filter type; - Support value: - 0: all locator_set - 1: local locator_set - 2: remote locator_set + @param filter - filter type + Supported values: + 0: all locator sets + 1: local locator sets + 2: remote locator sets */ define lisp_locator_set_dump { @@ -2826,8 +2798,11 @@ define lisp_locator_set_dump 0 : ipv4 1 : ipv6 2 : mac + @param is_src_dst - EID is type of source/destination @param eid - EID can be ip4, ip6 or mac - @param prefix_len - prefix len + @param eid_prefix_len - prefix length + @param seid - source EID can be ip4, ip6 or mac + @param seid_prefix_len - source prefix length @param vni - virtual network instance @param ttl - time to live @param authoritative - authoritative @@ -2840,9 +2815,12 @@ define lisp_eid_table_details u8 action; u8 is_local; u8 eid_type; + u8 is_src_dst; u32 vni; u8 eid[16]; u8 eid_prefix_len; + u8 seid[16]; + u8 seid_prefix_len; u32 ttl; u8 authoritative; }; |