lb plugin tests - wipe flowtable after each unit test 67/9067/5
authorGabriel Ganne <gabriel.ganne@enea.com>
Mon, 30 Oct 2017 14:44:31 +0000 (15:44 +0100)
committerDamjan Marion <dmarion.lists@gmail.com>
Tue, 31 Oct 2017 08:00:36 +0000 (08:00 +0000)
Add new cli api: "test lb flowtable flush" which flushes everything.
Call this new cli function after the end of each lb unit test.

Change-Id: I71d04a7bfba398f7d4dd9cc3ed24bba786943663
Signed-off-by: Gabriel Ganne <gabriel.ganne@enea.com>
src/plugins/lb/cli.c
test/test_lb.py

index f6d6520..a5a87fc 100644 (file)
@@ -273,3 +273,41 @@ VLIB_CLI_COMMAND (lb_show_vips_command, static) =
   .short_help = "show lb vips [verbose]",
   .function = lb_show_vips_command_fn,
 };
+
+static clib_error_t *
+lb_flowtable_flush_command_fn (vlib_main_t * vm,
+              unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+  u32 thread_index;
+  vlib_thread_main_t *tm = vlib_get_thread_main();
+  lb_main_t *lbm = &lb_main;
+
+  for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
+    lb_hash_t *h = lbm->per_cpu[thread_index].sticky_ht;
+    if (h != NULL) {
+        u32 i;
+        lb_hash_bucket_t *b;
+
+        lb_hash_foreach_entry(h, b, i) {
+            vlib_refcount_add(&lbm->as_refcount, thread_index, b->value[i], -1);
+            vlib_refcount_add(&lbm->as_refcount, thread_index, 0, 1);
+        }
+
+        lb_hash_free(h);
+        lbm->per_cpu[thread_index].sticky_ht = 0;
+    }
+  }
+
+  return NULL;
+}
+
+/*
+ * flush all lb flowtables
+ * This is indented for debug and unit-tests purposes only
+ */
+VLIB_CLI_COMMAND (lb_flowtable_flush_command, static) =
+{
+  .path = "test lb flowtable flush",
+  .short_help = "test lb flowtable flush",
+  .function = lb_flowtable_flush_command_fn,
+};
index db4d46b..ab9a209 100644 (file)
@@ -162,6 +162,7 @@ class TestLB(VppTestCase):
             for asid in self.ass:
                 self.vapi.cli("lb as 90.0.0.0/8 10.0.0.%u del" % (asid))
             self.vapi.cli("lb vip 90.0.0.0/8 encap gre4 del")
+            self.vapi.cli("test lb flowtable flush")
 
     def test_lb_ip6_gre4(self):
         """ Load Balancer IP6 GRE4 """
@@ -180,6 +181,7 @@ class TestLB(VppTestCase):
             for asid in self.ass:
                 self.vapi.cli("lb as 2001::/16 10.0.0.%u del" % (asid))
             self.vapi.cli("lb vip 2001::/16 encap gre4 del")
+            self.vapi.cli("test lb flowtable flush")
 
     def test_lb_ip4_gre6(self):
         """ Load Balancer IP4 GRE6 """
@@ -197,6 +199,7 @@ class TestLB(VppTestCase):
             for asid in self.ass:
                 self.vapi.cli("lb as 90.0.0.0/8 2002::%u del" % (asid))
             self.vapi.cli("lb vip 90.0.0.0/8 encap gre6 del")
+            self.vapi.cli("test lb flowtable flush")
 
     def test_lb_ip6_gre6(self):
         """ Load Balancer IP6 GRE6 """
@@ -214,3 +217,4 @@ class TestLB(VppTestCase):
             for asid in self.ass:
                 self.vapi.cli("lb as 2001::/16 2002::%u del" % (asid))
             self.vapi.cli("lb vip 2001::/16 encap gre6 del")
+            self.vapi.cli("test lb flowtable flush")