Add nsh_map_dump API 50/2150/1
authorHongjun Ni <[email protected]>
Mon, 1 Aug 2016 16:55:03 +0000 (00:55 +0800)
committerHongjun Ni <[email protected]>
Mon, 1 Aug 2016 16:55:03 +0000 (00:55 +0800)
Change-Id: If901cf638c9142c362afeb9634a7cbcd458c0125
Signed-off-by: Hongjun Ni <[email protected]>
nsh-plugin/nsh/nsh.api
nsh-plugin/nsh/nsh.c
nsh-plugin/nsh/nsh_test.c

index ed9f2fd..0f9e13d 100644 (file)
@@ -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;
+};
index 3e0da8a..21a972e 100644 (file)
@@ -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,
index aaea522..dc3c4d0 100644 (file)
@@ -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 <nn> nsi <nn>} c1 <nn> c2 <nn> c3 <nn> c4 <nn> [md-type <nn>] [tlv <xx>] [del]") \
 _(nsh_entry_dump, "")   \
-_(nsh_add_del_map, "nsp <nn> nsi <nn> [del] map-nsp <nn> map-nsi <nn> [encap-gre-intf <nn> | encap-vxlan-gpe-intf <nn> | encap-none]")
+_(nsh_add_del_map, "nsp <nn> nsi <nn> [del] mapped-nsp <nn> mapped-nsi <nn> [encap-gre-intf <nn> | encap-vxlan-gpe-intf <nn> | encap-none]")  \
+_(nsh_map_dump, "")
 
 void vat_api_hookup (vat_main_t *vam)
 {