From e566590ed0b45b1b230239a6a066f40bc4da3fb8 Mon Sep 17 00:00:00 2001 From: Hongjun Ni Date: Tue, 2 Aug 2016 00:55:03 +0800 Subject: Add nsh_map_dump API Change-Id: If901cf638c9142c362afeb9634a7cbcd458c0125 Signed-off-by: Hongjun Ni --- nsh-plugin/nsh/nsh.api | 15 ++++++++++++++- nsh-plugin/nsh/nsh.c | 39 ++++++++++++++++++++++++++++++++++++++- nsh-plugin/nsh/nsh_test.c | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 4 deletions(-) (limited to 'nsh-plugin/nsh') diff --git a/nsh-plugin/nsh/nsh.api b/nsh-plugin/nsh/nsh.api index ed9f2fd..0f9e13d 100644 --- a/nsh-plugin/nsh/nsh.api +++ b/nsh-plugin/nsh/nsh.api @@ -92,4 +92,17 @@ define nsh_add_del_map { define nsh_add_del_map_reply { u32 context; i32 retval; -}; \ No newline at end of file +}; + +define nsh_map_dump { + u32 client_index; + u32 context; +}; + +define nsh_map_details { + u32 context; + u32 nsp_nsi; + u32 mapped_nsp_nsi; + u32 sw_if_index; + u32 next_node; +}; diff --git a/nsh-plugin/nsh/nsh.c b/nsh-plugin/nsh/nsh.c index 3e0da8a..21a972e 100644 --- a/nsh-plugin/nsh/nsh.c +++ b/nsh-plugin/nsh/nsh.c @@ -75,7 +75,8 @@ #define foreach_nsh_plugin_api_msg \ _(NSH_ADD_DEL_ENTRY, nsh_add_del_entry) \ _(NSH_ENTRY_DUMP, nsh_entry_dump) \ - _(NSH_ADD_DEL_MAP, nsh_add_del_map) + _(NSH_ADD_DEL_MAP, nsh_add_del_map) \ + _(NSH_MAP_DUMP, nsh_map_dump) clib_error_t * vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h, @@ -628,6 +629,42 @@ static void vl_api_nsh_entry_dump_t_handler })); } +static void send_nsh_map_details +(nsh_map_t * t, unix_shared_memory_queue_t * q, u32 context) +{ + vl_api_nsh_map_details_t * rmp; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + + rmp->_vl_msg_id = ntohs(VL_API_NSH_MAP_DETAILS); + rmp->nsp_nsi = t->nsp_nsi; + rmp->mapped_nsp_nsi = t->mapped_nsp_nsi; + rmp->sw_if_index = t->sw_if_index; + rmp->next_node = t->next_node; + + rmp->context = context; + + vl_msg_api_send_shmem (q, (u8 *)&rmp); +} + +static void vl_api_nsh_map_dump_t_handler +(vl_api_nsh_map_dump_t * mp) +{ + unix_shared_memory_queue_t * q; + nsh_main_t * nm = &nsh_main; + nsh_map_t * t; + + q = vl_api_client_index_to_input_queue (mp->client_index); + if (q == 0) { + return; + } + + pool_foreach (t, nm->nsh_mappings, + ({ + send_nsh_map_details(t, q, mp->context); + })); +} static clib_error_t * show_nsh_entry_command_fn (vlib_main_t * vm, diff --git a/nsh-plugin/nsh/nsh_test.c b/nsh-plugin/nsh/nsh_test.c index aaea522..dc3c4d0 100644 --- a/nsh-plugin/nsh/nsh_test.c +++ b/nsh-plugin/nsh/nsh_test.c @@ -84,7 +84,8 @@ foreach_standard_reply_retval_handler; #define foreach_vpe_api_reply_msg \ _(NSH_ADD_DEL_ENTRY_REPLY, nsh_add_del_entry_reply) \ _(NSH_ENTRY_DETAILS, nsh_entry_details) \ -_(NSH_ADD_DEL_MAP_REPLY, nsh_add_del_map_reply) +_(NSH_ADD_DEL_MAP_REPLY, nsh_add_del_map_reply) \ +_(NSH_MAP_DETAILS, nsh_map_details) /* M: construct, but don't yet send a message */ @@ -316,6 +317,40 @@ static int api_nsh_add_del_map (vat_main_t * vam) } + +static void vl_api_nsh_map_details_t_handler +(vl_api_nsh_map_details_t * mp) +{ + vat_main_t * vam = &vat_main; + + fformat(vam->ofp, "%14d%14d%14d%14d\n", + ntohl(mp->nsp_nsi), + ntohl(mp->mapped_nsp_nsi), + ntohl(mp->sw_if_index), + ntohl(mp->next_node)); +} + +static int api_nsh_map_dump (vat_main_t * vam) +{ + nsh_test_main_t * sm = &nsh_test_main; + vl_api_nsh_map_dump_t *mp; + f64 timeout; + + if (!vam->json_output) { + fformat(vam->ofp, "%16s%16s%13s%13s\n", + "nsp_nsi", "mapped_nsp_nsi", "sw_if_index", "next_node"); + } + + /* Get list of nsh entries */ + M(NSH_MAP_DUMP, nsh_map_dump); + + /* send it... */ + S; + + /* Wait for a reply... */ + W; +} + /* * List of messages that the api test plugin sends, * and that the data plane plugin processes @@ -323,7 +358,8 @@ static int api_nsh_add_del_map (vat_main_t * vam) #define foreach_vpe_api_msg \ _(nsh_add_del_entry, "{nsp nsi } c1 c2 c3 c4 [md-type ] [tlv ] [del]") \ _(nsh_entry_dump, "") \ -_(nsh_add_del_map, "nsp nsi [del] map-nsp map-nsi [encap-gre-intf | encap-vxlan-gpe-intf | encap-none]") +_(nsh_add_del_map, "nsp nsi [del] mapped-nsp mapped-nsi [encap-gre-intf | encap-vxlan-gpe-intf | encap-none]") \ +_(nsh_map_dump, "") void vat_api_hookup (vat_main_t *vam) { -- cgit 1.2.3-korg