Make table chain deletion optional in classifier API (VPP-206) 32/4132/3
authorJuraj Sloboda <jsloboda@cisco.com>
Tue, 6 Dec 2016 20:25:19 +0000 (21:25 +0100)
committerDamjan Marion <dmarion.lists@gmail.com>
Wed, 7 Dec 2016 09:42:18 +0000 (09:42 +0000)
Change-Id: If30c0f6d5de34943bc399b3412c2d10847538c3c
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
plugins/acl-plugin/acl/acl.c
vnet/vnet/classify/vnet_classify.c
vnet/vnet/classify/vnet_classify.h
vpp-api-test/vat/api_format.c
vpp/vpp-api/api.c
vpp/vpp-api/custom_dump.c
vpp/vpp-api/vpe.api

index 149f006..6b7f637 100644 (file)
@@ -416,7 +416,8 @@ acl_classify_add_del_table_big (vnet_classify_main_t * cm, u8 * mask,
                                      memory_size, skip, match,
                                      next_table_index, miss_next_index,
                                      table_index, current_data_flag,
-                                     current_data_offset, is_add);
+                                     current_data_offset, is_add,
+                                     1 /* delete_chain */);
 }
 
 static int
@@ -440,7 +441,8 @@ acl_classify_add_del_table_small (vnet_classify_main_t * cm, u8 * mask,
                                      memory_size, skip, match,
                                      next_table_index, miss_next_index,
                                      table_index, current_data_flag,
-                                     current_data_offset, is_add);
+                                     current_data_offset, is_add,
+                                     1 /* delete_chain */);
 }
 
 
index d7a0d81..ce38f9f 100644 (file)
@@ -142,7 +142,7 @@ vnet_classify_new_table (vnet_classify_main_t *cm,
 }
 
 void vnet_classify_delete_table_index (vnet_classify_main_t *cm, 
-                                       u32 table_index)
+                                       u32 table_index, int del_chain)
 {
   vnet_classify_table_t * t;
 
@@ -151,8 +151,9 @@ void vnet_classify_delete_table_index (vnet_classify_main_t *cm,
     return;
 
   t = pool_elt_at_index (cm->tables, table_index);
-  if (t->next_table_index != ~0)
-    vnet_classify_delete_table_index (cm, t->next_table_index);
+  if (del_chain && t->next_table_index != ~0)
+    /* Recursively delete the entire chain */
+    vnet_classify_delete_table_index (cm, t->next_table_index, del_chain);
 
   vec_free (t->mask);
   vec_free (t->buckets);
@@ -656,7 +657,8 @@ int vnet_classify_add_del_table (vnet_classify_main_t * cm,
                                  u32 * table_index,
                                  u8 current_data_flag,
                                  i16 current_data_offset,
-                                 int is_add)
+                                 int is_add,
+                                 int del_chain)
 {
   vnet_classify_table_t * t;
 
@@ -688,7 +690,7 @@ int vnet_classify_add_del_table (vnet_classify_main_t * cm,
       return 0;
     }
   
-  vnet_classify_delete_table_index (cm, *table_index);
+  vnet_classify_delete_table_index (cm, *table_index, del_chain);
   return 0;
 }
 
@@ -1385,6 +1387,7 @@ classify_table_command_fn (vlib_main_t * vm,
   u32 skip = ~0;
   u32 match = ~0;
   int is_add = 1;
+  int del_chain = 0;
   u32 table_index = ~0;
   u32 next_table_index = ~0;
   u32 miss_next_index = ~0;
@@ -1400,6 +1403,11 @@ classify_table_command_fn (vlib_main_t * vm,
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
     if (unformat (input, "del"))
       is_add = 0;
+    else if (unformat (input, "del-chain"))
+      {
+       is_add = 0;
+        del_chain = 1;
+      }
     else if (unformat (input, "buckets %d", &nbuckets))
       ;
     else if (unformat (input, "skip %d", &skip))
@@ -1451,8 +1459,8 @@ classify_table_command_fn (vlib_main_t * vm,
     return clib_error_return (0, "table index required for delete");
 
   rv = vnet_classify_add_del_table (cm, mask, nbuckets, memory_size,
-        skip, match, next_table_index, miss_next_index,
-        &table_index, current_data_flag, current_data_offset, is_add);
+        skip, match, next_table_index, miss_next_index, &table_index,
+       current_data_flag, current_data_offset, is_add, del_chain);
   switch (rv)
     {
     case 0:
@@ -1470,7 +1478,8 @@ VLIB_CLI_COMMAND (classify_table, static) = {
   .short_help = 
   "classify table [miss-next|l2-miss_next|acl-miss-next <next_index>]"
   "\n mask <mask-value> buckets <nn> [skip <n>] [match <n>]"
-  "\n [current-data-flag <n>] [current-data-offset <n>] [table <n>] [del]",
+  "\n [current-data-flag <n>] [current-data-offset <n>] [table <n>]"
+  "\n [del] [del-chain]",
   .function = classify_table_command_fn,
 };
 
index ed8442b..d0b896e 100644 (file)
@@ -489,7 +489,8 @@ int vnet_classify_add_del_table (vnet_classify_main_t * cm,
                                  u32 * table_index,
                                  u8 current_data_flag,
                                  i16 current_data_offset,
-                                 int is_add);
+                                 int is_add,
+                                int del_chain);
 
 unformat_function_t unformat_ip4_mask;
 unformat_function_t unformat_ip6_mask;
index 344259b..c6e5ac8 100644 (file)
@@ -8891,6 +8891,7 @@ api_classify_add_del_table (vat_main_t * vam)
   u32 skip = ~0;
   u32 match = ~0;
   int is_add = 1;
+  int del_chain = 0;
   u32 table_index = ~0;
   u32 next_table_index = ~0;
   u32 miss_next_index = ~0;
@@ -8904,6 +8905,11 @@ api_classify_add_del_table (vat_main_t * vam)
     {
       if (unformat (i, "del"))
        is_add = 0;
+      else if (unformat (i, "del-chain"))
+       {
+         is_add = 0;
+         del_chain = 1;
+       }
       else if (unformat (i, "buckets %d", &nbuckets))
        ;
       else if (unformat (i, "memory_size %d", &memory_size))
@@ -8963,6 +8969,7 @@ api_classify_add_del_table (vat_main_t * vam)
   M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table, vec_len (mask));
 
   mp->is_add = is_add;
+  mp->del_chain = del_chain;
   mp->table_index = ntohl (table_index);
   mp->nbuckets = ntohl (nbuckets);
   mp->memory_size = ntohl (memory_size);
@@ -17485,7 +17492,7 @@ _(sr_multicast_map_add_del,                                             \
   "address [ip6 multicast address] sr-policy [policy name] [del]")     \
 _(classify_add_del_table,                                               \
   "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n"     \
-  " [del] mask <mask-value>\n"                                          \
+  " [del] [del-chain] mask <mask-value>\n"                              \
   " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n"            \
   " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]")   \
 _(classify_add_del_session,                                             \
index 7e90f74..967e632 100644 (file)
@@ -2499,7 +2499,7 @@ static void vl_api_classify_add_del_table_t_handler
     (cm, mp->mask, nbuckets, memory_size,
      skip_n_vectors, match_n_vectors,
      next_table_index, miss_next_index, &table_index,
-     current_data_flag, current_data_offset, mp->is_add);
+     current_data_flag, current_data_offset, mp->is_add, mp->del_chain);
 
 out:
   /* *INDENT-OFF* */
index 82195f6..bfebf49 100644 (file)
@@ -1179,7 +1179,7 @@ static void *vl_api_classify_add_del_table_t_print
   if (mp->is_add == 0)
     {
       s = format (s, "table %d ", ntohl (mp->table_index));
-      s = format (s, "del ");
+      s = format (s, "%s ", mp->del_chain ? "del-chain" : "del");
     }
   else
     {
index b1760fd..537f568 100644 (file)
@@ -1211,6 +1211,7 @@ define bd_ip_mac_add_del_reply
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
     @param is_add- if non-zero add the table, else delete it
+    @param del_chain - if non-zero delete the whole chain of tables
     @param table_index - if add, reuturns index of the created table, else specifies the table to delete  
     @param nbuckets - number of buckets when adding a table
     @param memory_size - memory size when adding a table
@@ -1235,6 +1236,7 @@ define classify_add_del_table
   u32 client_index;
   u32 context;
   u8 is_add;
+  u8 del_chain;
   u32 table_index;
   u32 nbuckets;
   u32 memory_size;