fib: fib api updates
[vpp.git] / test / test_lb.py
index fa17950..4603bd1 100644 (file)
@@ -9,6 +9,8 @@ from scapy.data import IP_PROTOS
 
 from framework import VppTestCase
 from util import ppp
+from vpp_ip_route import VppIpRoute, VppRoutePath
+from vpp_ip import INVALID_INDEX
 
 """ TestLB is a subclass of  VPPTestCase classes.
 
@@ -50,20 +52,32 @@ class TestLB(VppTestCase):
                 i.disable_ipv6_ra()
                 i.resolve_arp()
                 i.resolve_ndp()
-            dst4 = socket.inet_pton(socket.AF_INET, "10.0.0.0")
-            dst6 = socket.inet_pton(socket.AF_INET6, "2002::")
-            cls.vapi.ip_add_del_route(dst4, 24, cls.pg1.remote_ip4n)
-            cls.vapi.ip_add_del_route(dst6, 16, cls.pg1.remote_ip6n, is_ipv6=1)
-            cls.vapi.cli("lb conf ip4-src-address 39.40.41.42")
-            cls.vapi.cli("lb conf ip6-src-address 2004::1")
+
+            dst4 = VppIpRoute(cls, "10.0.0.0", 24,
+                              [VppRoutePath(cls.pg1.remote_ip4,
+                                            INVALID_INDEX)],
+                              register=False)
+            dst4.add_vpp_config()
+            dst6 = VppIpRoute(cls, "2002::", 16,
+                              [VppRoutePath(cls.pg1.remote_ip6,
+                                            INVALID_INDEX)],
+                              register=False)
+            dst6.add_vpp_config()
+            cls.vapi.lb_conf(ip4_src_address="39.40.41.42",
+                             ip6_src_address="2004::1")
         except Exception:
             super(TestLB, cls).tearDownClass()
             raise
 
+    @classmethod
+    def tearDownClass(cls):
+        super(TestLB, cls).tearDownClass()
+
     def tearDown(self):
         super(TestLB, self).tearDown()
-        if not self.vpp_dead:
-            self.logger.info(self.vapi.cli("show lb vip verbose"))
+
+    def show_commands_at_teardown(self):
+        self.logger.info(self.vapi.cli("show lb vip verbose"))
 
     def getIPv4Flow(self, id):
         return (IP(dst="90.0.%u.%u" % (id / 255, id % 255),
@@ -183,8 +197,8 @@ class TestLB(VppTestCase):
                 self.logger.error(ppp("Unexpected or invalid packet:", p))
                 raise
 
-        # This is just to 1roughly check that the balancing algorithm
-        # is not completly biased.
+        # This is just to roughly check that the balancing algorithm
+        # is not completely biased.
         for asid in self.ass:
             if load[asid] < len(self.packets) / (len(self.ass) * 2):
                 self.logger.error(