SNAT: user_session_dump is_ip4 and vat unformating added 69/5669/2
authorMartin <magalik@cisco.com>
Wed, 8 Mar 2017 11:31:02 +0000 (03:31 -0800)
committerMartin <magalik@cisco.com>
Wed, 8 Mar 2017 12:38:37 +0000 (04:38 -0800)
Change-Id: I0ffab147c3218a75b7c3bb829983f538c7b637ee
Signed-off-by: Martin <magalik@cisco.com>
src/plugins/snat/snat.api
src/plugins/snat/snat.c
src/plugins/snat/snat_test.c
test/vpp_papi_provider.py

index 8ff69b2..612830f 100644 (file)
@@ -387,12 +387,14 @@ define snat_user_details {
 /** \brief S-NAT user's sessions
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
+    @param is_ip4 - 1 if address type is IPv4
     @param user_ip - IP address of the user to dump
     @param vrf_id - VRF_ID
 */
 define snat_user_session_dump {
   u32 client_index;
   u32 context;
+  u8 is_ip4;
   u8 ip_address[16];
   u32 vrf_id;
 };
index 1cf2b0c..fc9f586 100644 (file)
@@ -1539,6 +1539,8 @@ vl_api_snat_user_session_dump_t_handler
   q = vl_api_client_index_to_input_queue (mp->client_index);
   if (q == 0)
     return;
+  if (!mp->is_ip4)
+    return;
 
   clib_memcpy (&ukey.addr, mp->ip_address, 4);
   ukey.fib_index = ip4_fib_index_from_table_id (ntohl(mp->vrf_id));
index c60554b..39db45c 100644 (file)
@@ -667,8 +667,11 @@ static void vl_api_snat_user_session_details_t_handler
 
 static int api_snat_user_session_dump(vat_main_t * vam)
 {
+  unformat_input_t* i = vam->input;
   vl_api_snat_user_session_dump_t * mp;
   vl_api_snat_control_ping_t *mp_ping;
+  ip4_address_t addr;
+  u32 vrf_id = ~0;
   int ret;
 
   if (vam->json_output)
@@ -677,11 +680,24 @@ static int api_snat_user_session_dump(vat_main_t * vam)
       return -99;
     }
 
+  if (unformat (i, "ip_address %U vrf_id %d",
+                unformat_ip4_address, &addr, &vrf_id))
+    ;
+  else
+    {
+      clib_warning("unknown input '%U'", format_unformat_error, i);
+      return -99;
+    }
+
   M(SNAT_USER_SESSION_DUMP, mp);
   S(mp);
 
   /* Use a control ping for synchronization */
   M(SNAT_CONTROL_PING, mp_ping);
+  memset(mp->ip_address, 0, 16);
+  clib_memcpy(mp->ip_address, &addr, 4);
+  mp->vrf_id = htonl(vrf_id);
+  mp->is_ip4 = 1;
   S(mp_ping);
 
   W (ret);
index f04537b..3d6af8a 100644 (file)
@@ -1109,7 +1109,8 @@ class VppPapiProvider(object):
     def snat_user_session_dump(
             self,
             ip_address,
-            vrf_id):
+            vrf_id,
+            is_ip4=1):
         """Dump S-NAT user's sessions
 
         :param ip_address: ip adress of the user to be dumped
@@ -1120,7 +1121,8 @@ class VppPapiProvider(object):
         return self.api(
             self.papi.snat_user_session_dump,
             {'ip_address': ip_address,
-             'vrf_id': vrf_id})
+             'vrf_id': vrf_id,
+             'is_ip4': is_ip4})
 
     def snat_user_dump(self):
         """Dump S-NAT users