aboutsummaryrefslogtreecommitdiffstats
path: root/test/vpp_ip_route.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/vpp_ip_route.py')
-rw-r--r--test/vpp_ip_route.py76
1 files changed, 38 insertions, 38 deletions
diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py
index 8f9d51a7d2a..d6004756d34 100644
--- a/test/vpp_ip_route.py
+++ b/test/vpp_ip_route.py
@@ -6,7 +6,7 @@
from vpp_object import VppObject
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
-from vpp_ip import DpoProto, VppIpPrefix, INVALID_INDEX, VppIpAddressUnion, \
+from vpp_ip import DpoProto, INVALID_INDEX, VppIpAddressUnion, \
VppIpMPrefix
from ipaddress import ip_address, IPv4Network, IPv6Network
@@ -72,6 +72,13 @@ class MplsLspMode:
UNIFORM = 1
+def mk_network(addr, len):
+ if ip_address(text_type(addr)).version == 4:
+ return IPv4Network("%s/%d" % (addr, len), strict=False)
+ else:
+ return IPv6Network("%s/%d" % (addr, len), strict=False)
+
+
def ip_to_dpo_proto(addr):
if addr.version == 6:
return DpoProto.DPO_PROTO_IP6
@@ -87,18 +94,16 @@ def address_proto(ip_addr):
def find_route(test, addr, len, table_id=0):
- ip_addr = ip_address(text_type(addr))
+ prefix = mk_network(addr, len)
- if 4 is ip_addr.version:
+ if 4 is prefix.version:
routes = test.vapi.ip_route_dump(table_id, False)
- prefix = IPv4Network("%s/%d" % (text_type(addr), len), strict=False)
else:
routes = test.vapi.ip_route_dump(table_id, True)
- prefix = IPv6Network("%s/%d" % (text_type(addr), len), strict=False)
for e in routes:
if table_id == e.route.table_id \
- and prefix == e.route.prefix:
+ and str(e.route.prefix) == str(prefix):
return True
return False
@@ -138,22 +143,16 @@ def find_mpls_route(test, table_id, label, eos_bit, paths=None):
return False
-def fib_interface_ip_prefix(test, address, length, sw_if_index):
- ip_addr = ip_address(text_type(address))
-
- if 4 is ip_addr.version:
- addrs = test.vapi.ip_address_dump(sw_if_index)
- prefix = IPv4Network("%s/%d" % (text_type(address), length),
- strict=False)
- else:
- addrs = test.vapi.ip_address_dump(sw_if_index, is_ipv6=1)
- prefix = IPv6Network("%s/%d" % (text_type(address), length),
- strict=False)
+def fib_interface_ip_prefix(test, addr, len, sw_if_index):
+ # can't use python net here since we need the host bits in the prefix
+ prefix = "%s/%d" % (addr, len)
+ addrs = test.vapi.ip_address_dump(
+ sw_if_index,
+ is_ipv6=(6 == ip_address(addr).version))
- # TODO: refactor this to VppIpPrefix.__eq__
for a in addrs:
if a.sw_if_index == sw_if_index and \
- a.prefix.network == prefix:
+ str(a.prefix) == prefix:
return True
return False
@@ -198,23 +197,25 @@ class VppIpInterfaceAddress(VppObject):
def __init__(self, test, intf, addr, len):
self._test = test
self.intf = intf
- self.prefix = VppIpPrefix(addr, len)
+ self.addr = addr
+ self.len = len
+ self.prefix = "%s/%d" % (addr, len)
def add_vpp_config(self):
self._test.vapi.sw_interface_add_del_address(
- sw_if_index=self.intf.sw_if_index, prefix=self.prefix.encode(),
+ sw_if_index=self.intf.sw_if_index, prefix=self.prefix,
is_add=1)
self._test.registry.register(self, self._test.logger)
def remove_vpp_config(self):
self._test.vapi.sw_interface_add_del_address(
- sw_if_index=self.intf.sw_if_index, prefix=self.prefix.encode(),
+ sw_if_index=self.intf.sw_if_index, prefix=self.prefix,
is_add=0)
def query_vpp_config(self):
return fib_interface_ip_prefix(self._test,
- self.prefix.address,
- self.prefix.length,
+ self.addr,
+ self.len,
self.intf.sw_if_index)
def object_id(self):
@@ -424,7 +425,7 @@ class VppIpRoute(VppObject):
self._test = test
self.paths = paths
self.table_id = table_id
- self.prefix = VppIpPrefix(dest_addr, dest_addr_len)
+ self.prefix = mk_network(dest_addr, dest_addr_len)
self.register = register
self.stats_index = None
self.modified = False
@@ -447,7 +448,7 @@ class VppIpRoute(VppObject):
self.modified = True
self._test.vapi.ip_route_add_del(route={'table_id': self.table_id,
- 'prefix': self.prefix.encode(),
+ 'prefix': self.prefix,
'n_paths': len(
self.encoded_paths),
'paths': self.encoded_paths,
@@ -458,7 +459,7 @@ class VppIpRoute(VppObject):
def add_vpp_config(self):
r = self._test.vapi.ip_route_add_del(
route={'table_id': self.table_id,
- 'prefix': self.prefix.encode(),
+ 'prefix': self.prefix,
'n_paths': len(self.encoded_paths),
'paths': self.encoded_paths,
},
@@ -476,7 +477,7 @@ class VppIpRoute(VppObject):
if self.modified:
self._test.vapi.ip_route_add_del(
route={'table_id': self.table_id,
- 'prefix': self.prefix.encode(),
+ 'prefix': self.prefix,
'n_paths': len(
self.encoded_paths),
'paths': self.encoded_paths},
@@ -485,23 +486,22 @@ class VppIpRoute(VppObject):
else:
self._test.vapi.ip_route_add_del(
route={'table_id': self.table_id,
- 'prefix': self.prefix.encode(),
+ 'prefix': self.prefix,
'n_paths': 0},
is_add=0,
is_multipath=0)
def query_vpp_config(self):
return find_route(self._test,
- self.prefix.address,
- self.prefix.len,
+ self.prefix.network_address,
+ self.prefix.prefixlen,
self.table_id)
def object_id(self):
- return ("%s:table-%d-%s/%d" % (
- 'ip6-route' if self.prefix.addr.version == 6 else 'ip-route',
+ return ("%s:table-%d-%s" % (
+ 'ip6-route' if self.prefix.version == 6 else 'ip-route',
self.table_id,
- self.prefix.address,
- self.prefix.len))
+ self.prefix))
def get_stats_to(self):
c = self._test.statistics.get_counter("/net/route/to")
@@ -627,18 +627,18 @@ class VppMplsIpBind(VppObject):
self.local_label = local_label
self.table_id = table_id
self.ip_table_id = ip_table_id
- self.prefix = VppIpPrefix(dest_addr, dest_addr_len)
+ self.prefix = mk_network(dest_addr, dest_addr_len)
def add_vpp_config(self):
self._test.vapi.mpls_ip_bind_unbind(self.local_label,
- self.prefix.encode(),
+ self.prefix,
table_id=self.table_id,
ip_table_id=self.ip_table_id)
self._test.registry.register(self, self._test.logger)
def remove_vpp_config(self):
self._test.vapi.mpls_ip_bind_unbind(self.local_label,
- self.prefix.encode(),
+ self.prefix,
table_id=self.table_id,
ip_table_id=self.ip_table_id,
is_bind=0)