From 914f91b837564416b3a8b15566c627aae6d567d2 Mon Sep 17 00:00:00 2001 From: Andrej Kozemcak Date: Mon, 18 Jul 2016 13:55:37 +0200 Subject: [PATCH] Add new lisp API - Show pitr VAT API: - show_lisp_pitr CLI API: - show lisp pitr Change-Id: Ibd31cb09efc34a49b439338e9467faf7a151f2cd Signed-off-by: Andrej Kozemcak --- vnet/vnet/lisp-cp/control.c | 44 +++++++++++++++++++++++++++ vpp-api-test/vat/api_format.c | 69 +++++++++++++++++++++++++++++++++++++++++-- vpp/vpp-api/api.c | 38 ++++++++++++++++++++++++ vpp/vpp-api/vpe.api | 21 +++++++++++++ 4 files changed, 170 insertions(+), 2 deletions(-) diff --git a/vnet/vnet/lisp-cp/control.c b/vnet/vnet/lisp-cp/control.c index 7ab336c292a..bea37004f72 100644 --- a/vnet/vnet/lisp-cp/control.c +++ b/vnet/vnet/lisp-cp/control.c @@ -1338,6 +1338,50 @@ VLIB_CLI_COMMAND (lisp_pitr_set_locator_set_command) = { .function = lisp_pitr_set_locator_set_command_fn, }; +static clib_error_t * +lisp_show_pitr_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + lisp_cp_main_t * lcm = vnet_lisp_cp_get_main (); + mapping_t * m; + locator_set_t * ls; + u8 * tmp_str = 0; + + vlib_cli_output (vm, "%=20s%=16s", + "pitr", lcm->lisp_pitr ? "locator-set" : ""); + + if (!lcm->lisp_pitr) { + vlib_cli_output (vm, "%=20s", "disable"); + return 0; + } + + if (~0 == lcm->pitr_map_index) { + tmp_str = format(0, "N/A"); + } else { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) { + ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format(0, "%s", ls->name); + } else { + tmp_str = format(0, "N/A"); + } + } + vec_add1(tmp_str, 0); + + vlib_cli_output (vm, "%=20s%=16s", + "enable", tmp_str); + + vec_free(tmp_str); + + return 0; +} + +VLIB_CLI_COMMAND (lisp_show_pitr_command) = { + .path = "show lisp pitr", + .short_help = "Show pitr", + .function = lisp_show_pitr_command_fn, +}; static u8 * format_eid_entry (u8 * s, va_list * args) diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c index 53450769f9f..70d8e96a603 100644 --- a/vpp-api-test/vat/api_format.c +++ b/vpp-api-test/vat/api_format.c @@ -2362,6 +2362,47 @@ vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json ( vam->result_ready = 1; } +static void +vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl(mp->retval); + + if (0 <= retval) { + fformat(vam->ofp, "%-20s%-16s\n", + mp->status ? "enabled" : "disabled", + mp->status ? (char *) mp->locator_set_name : ""); + } + + vam->retval = retval; + vam->result_ready = 1; +} + +static void +vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t * mp) +{ + vat_main_t *vam = &vat_main; + vat_json_node_t node; + u8 * status = 0; + + status = format (0, "%s", mp->status ? "enabled" : "disabled"); + vec_add1 (status, 0); + + vat_json_init_object(&node); + vat_json_object_add_string_copy(&node, "status", status); + if (mp->status) { + vat_json_object_add_string_copy(&node, "locator_set", mp->locator_set_name); + } + + vec_free (status); + + vat_json_print(vam->ofp, &node); + vat_json_free(&node); + + vam->retval = ntohl(mp->retval); + vam->result_ready = 1; +} + static u8 * format_policer_type (u8 * s, va_list * va) { u32 i = va_arg (*va, u32); @@ -3030,6 +3071,7 @@ _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \ lisp_add_del_map_request_itr_rlocs_reply) \ _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \ lisp_get_map_request_itr_rlocs_reply) \ +_(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \ _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \ _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \ _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \ @@ -10873,6 +10915,28 @@ api_lisp_pitr_set_locator_set (vat_main_t * vam) return 0; } +static int +api_show_lisp_pitr (vat_main_t * vam) +{ + vl_api_show_lisp_pitr_t *mp; + f64 timeout = ~0; + + if (!vam->json_output) { + fformat(vam->ofp, "%=20s\n", + "lisp status:"); + } + + M(SHOW_LISP_PITR, show_lisp_pitr); + /* send it... */ + S; + + /* Wait for a reply... */ + W; + + /* NOTREACHED */ + return 0; +} + /** * Add/delete mapping between vni and vrf */ @@ -11470,8 +11534,8 @@ api_lisp_enable_disable_status_dump(vat_main_t *vam) f64 timeout = ~0; if (!vam->json_output) { - fformat(vam->ofp, "%=20s\n", - "lisp status:"); + fformat(vam->ofp, "%-20s%-16s\n", + "lisp status", "locator-set"); } M(LISP_ENABLE_DISABLE_STATUS_DUMP, @@ -12760,6 +12824,7 @@ _(lisp_gpe_tunnel_dump, "") \ _(lisp_map_resolver_dump, "") \ _(lisp_enable_disable_status_dump, "") \ _(lisp_get_map_request_itr_rlocs, "") \ +_(show_lisp_pitr, "") \ _(af_packet_create, "name [hw_addr ]") \ _(af_packet_delete, "name ") \ _(policer_add_del, "name [del]") \ diff --git a/vpp/vpp-api/api.c b/vpp/vpp-api/api.c index 6a5a152ea56..4fe183bc579 100644 --- a/vpp/vpp-api/api.c +++ b/vpp/vpp-api/api.c @@ -347,6 +347,7 @@ _(LISP_ENABLE_DISABLE_STATUS_DUMP, \ _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, \ lisp_add_del_map_request_itr_rlocs) \ _(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs) \ +_(SHOW_LISP_PITR, show_lisp_pitr) \ _(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del) \ _(AF_PACKET_CREATE, af_packet_create) \ _(AF_PACKET_DELETE, af_packet_delete) \ @@ -5608,6 +5609,43 @@ vl_api_lisp_get_map_request_itr_rlocs_t_handler ( vec_free(tmp_str); } +static void +vl_api_show_lisp_pitr_t_handler (vl_api_show_lisp_pitr_t * mp) +{ + unix_shared_memory_queue_t * q = NULL; + vl_api_show_lisp_pitr_reply_t * rmp = NULL; + lisp_cp_main_t * lcm = vnet_lisp_cp_get_main(); + mapping_t * m; + locator_set_t * ls = 0; + u8 * tmp_str = 0; + int rv = 0; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) { + return; + } + + if (~0 == lcm->pitr_map_index) { + tmp_str = format(0, "N/A"); + } else { + m = pool_elt_at_index (lcm->mapping_pool, lcm->pitr_map_index); + if (~0 != m->locator_set_index) { + ls = pool_elt_at_index (lcm->locator_set_pool, m->locator_set_index); + tmp_str = format(0, "%s", ls->name); + } else { + tmp_str = format(0, "N/A"); + } + } + vec_add1(tmp_str, 0); + + REPLY_MACRO2(VL_API_SHOW_LISP_PITR_REPLY, + ({ + rmp->status = lcm->lisp_pitr; + strncpy((char *) rmp->locator_set_name, (char *) tmp_str, + ARRAY_LEN(rmp->locator_set_name) - 1); + })); +} + static void vl_api_interface_name_renumber_t_handler (vl_api_interface_name_renumber_t *mp) { diff --git a/vpp/vpp-api/vpe.api b/vpp/vpp-api/vpe.api index 841f3088ba4..78a87f36113 100644 --- a/vpp/vpp-api/vpe.api +++ b/vpp/vpp-api/vpe.api @@ -2661,6 +2661,27 @@ define lisp_get_map_request_itr_rlocs_reply { u8 locator_set_name[64]; }; +/** \brief Request for lisp pitr status + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request +*/ +define show_lisp_pitr { + u32 client_index; + u32 context; +}; + +/** \brief Status of lisp pitr, enable or disable + @param context - sender context, to match reply w/ request + @param status - lisp pitr enable if non-zero, else disable + @param locator_set_name - name of the locator_set +*/ +define show_lisp_pitr_reply { + u32 context; + i32 retval; + u8 status; + u8 locator_set_name[64]; +}; + /* Gross kludge, DGMS */ define interface_name_renumber { u32 client_index; -- 2.16.6