Add logging to vfio code
[vpp.git] / test / vpp_ip_route.py
index 9e5c531..d24e4b1 100644 (file)
@@ -6,6 +6,7 @@
 
 from vpp_object import *
 from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
+from vpp_ip import *
 
 # from vnet/vnet/mpls/mpls_types.h
 MPLS_IETF_MAX_LABEL = 0xfffff
@@ -29,15 +30,6 @@ class MRouteEntryFlags:
     MFIB_ENTRY_FLAG_INHERIT_ACCEPT = 8
 
 
-class DpoProto:
-    DPO_PROTO_IP4 = 0
-    DPO_PROTO_IP6 = 1
-    DPO_PROTO_MPLS = 2
-    DPO_PROTO_ETHERNET = 3
-    DPO_PROTO_BIER = 4
-    DPO_PROTO_NSH = 5
-
-
 class MplsLspMode:
     PIPE = 0
     UNIFORM = 1
@@ -200,6 +192,9 @@ class VppRoutePath(object):
                 'n_labels': len(self.nh_labels),
                 'label_stack': self.encode_labels()}
 
+    def __eq__(self, other):
+        return self.nh_addr == other.nh_addr
+
 
 class VppMRoutePath(VppRoutePath):
 
@@ -223,7 +218,7 @@ class VppIpRoute(VppObject):
 
     def __init__(self, test, dest_addr,
                  dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0,
-                 is_unreach=0, is_prohibit=0):
+                 is_unreach=0, is_prohibit=0, is_drop=0):
         self._test = test
         self.paths = paths
         self.dest_addr_len = dest_addr_len
@@ -232,6 +227,7 @@ class VppIpRoute(VppObject):
         self.is_local = is_local
         self.is_unreach = is_unreach
         self.is_prohibit = is_prohibit
+        self.is_drop = is_drop
         self.dest_addr_p = dest_addr
         if is_ip6:
             self.dest_addr = inet_pton(AF_INET6, dest_addr)
@@ -246,8 +242,9 @@ class VppIpRoute(VppObject):
         self.is_prohibit = is_prohibit
 
     def add_vpp_config(self):
-        if self.is_local or self.is_unreach or self.is_prohibit:
-            self._test.vapi.ip_add_del_route(
+        if self.is_local or self.is_unreach or \
+           self.is_prohibit or self.is_drop:
+            r = self._test.vapi.ip_add_del_route(
                 self.dest_addr,
                 self.dest_addr_len,
                 inet_pton(AF_INET6, "::"),
@@ -255,13 +252,14 @@ class VppIpRoute(VppObject):
                 is_local=self.is_local,
                 is_unreach=self.is_unreach,
                 is_prohibit=self.is_prohibit,
+                is_drop=self.is_drop,
                 table_id=self.table_id,
                 is_ipv6=self.is_ip6)
         else:
             for path in self.paths:
                 lstack = path.encode_labels()
 
-                self._test.vapi.ip_add_del_route(
+                r = self._test.vapi.ip_add_del_route(
                     self.dest_addr,
                     self.dest_addr_len,
                     path.nh_addr,
@@ -279,10 +277,12 @@ class VppIpRoute(VppObject):
                     is_source_lookup=path.is_source_lookup,
                     is_udp_encap=path.is_udp_encap,
                     is_multipath=1 if len(self.paths) > 1 else 0)
+        self.stats_index = r.stats_index
         self._test.registry.register(self, self._test.logger)
 
     def remove_vpp_config(self):
-        if self.is_local or self.is_unreach or self.is_prohibit:
+        if self.is_local or self.is_unreach or \
+           self.is_prohibit or self.is_drop:
             self._test.vapi.ip_add_del_route(
                 self.dest_addr,
                 self.dest_addr_len,
@@ -326,6 +326,14 @@ class VppIpRoute(VppObject):
                    self.dest_addr_p,
                    self.dest_addr_len))
 
+    def get_stats_to(self):
+        c = self._test.statistics.get_counter("/net/route/to")
+        return c[0][self.stats_index]
+
+    def get_stats_via(self):
+        c = self._test.statistics.get_counter("/net/route/via")
+        return c[0][self.stats_index]
+
 
 class VppIpMRoute(VppObject):
     """
@@ -582,7 +590,7 @@ class VppMplsRoute(VppObject):
         for path in self.paths:
             lstack = path.encode_labels()
 
-            self._test.vapi.mpls_route_add_del(
+            r = self._test.vapi.mpls_route_add_del(
                 self.local_label,
                 self.eos_bit,
                 path.proto,
@@ -597,6 +605,7 @@ class VppMplsRoute(VppObject):
                 next_hop_n_out_labels=len(lstack),
                 next_hop_via_label=path.nh_via_label,
                 next_hop_table_id=path.nh_table_id)
+        self.stats_index = r.stats_index
         self._test.registry.register(self, self._test.logger)
 
     def remove_vpp_config(self):
@@ -627,3 +636,11 @@ class VppMplsRoute(VppObject):
                 % (self.table_id,
                    self.local_label,
                    20+self.eos_bit))
+
+    def get_stats_to(self):
+        c = self._test.statistics.get_counter("/net/route/to")
+        return c[0][self.stats_index]
+
+    def get_stats_via(self):
+        c = self._test.statistics.get_counter("/net/route/via")
+        return c[0][self.stats_index]