diff options
Diffstat (limited to 'test/vpp_interface.py')
-rw-r--r-- | test/vpp_interface.py | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/test/vpp_interface.py b/test/vpp_interface.py index 4c4e4138479..d586c849b02 100644 --- a/test/vpp_interface.py +++ b/test/vpp_interface.py @@ -6,8 +6,7 @@ import six from six import moves from util import Host, mk_ll_addr -from vpp_papi import mac_ntop, VppEnum -from vpp_ip import VppIpAddress, VppIpPrefix +from vpp_papi import mac_ntop @six.add_metaclass(abc.ABCMeta) @@ -38,25 +37,22 @@ class VppInterface(object): return self._remote_addr @property - def local_ip4(self): - """Local IPv4 address on VPP interface (string).""" - return self._local_ip4.address + def local_addr_n(self): + return self._local_addr_n @property - def local_ip4_prefix_len(self): - """Local IPv4 prefix length """ - return self._local_ip4.len + def remote_addr_n(self): + return self._remote_addr_n @property - def local_ip4_prefix(self): - """Local IPv4 prefix """ + def local_ip4(self): + """Local IPv4 address on VPP interface (string).""" return self._local_ip4 @property def local_ip4n(self): - """DEPRECATED """ """Local IPv4 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET, self._local_ip4.address) + return socket.inet_pton(socket.AF_INET, self._local_ip4) @property def remote_ip4(self): @@ -65,30 +61,18 @@ class VppInterface(object): @property def remote_ip4n(self): - """DEPRECATED """ - """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET, self._remote_hosts[0].ip4) + """IPv4 address of remote peer - raw, suitable as API parameter.""" + return socket.inet_pton(socket.AF_INET, self.remote_ip4) @property def local_ip6(self): """Local IPv6 address on VPP interface (string).""" - return self._local_ip6.address - - @property - def local_ip6_prefix_len(self): - """Local IPv6 prefix length """ - return self._local_ip6.len - - @property - def local_ip6_prefix(self): - """Local IPv6 prefix """ return self._local_ip6 @property def local_ip6n(self): - """DEPRECATED """ """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET6, self._local_ip6.address) + return socket.inet_pton(socket.AF_INET6, self.local_ip6) @property def remote_ip6(self): @@ -97,20 +81,18 @@ class VppInterface(object): @property def remote_ip6n(self): - """DEPRECATED """ - """Local IPv6 address - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET6, self._remote_hosts[0].ip6) + """IPv6 address of remote peer - raw, suitable as API parameter""" + return socket.inet_pton(socket.AF_INET6, self.remote_ip6) @property def local_ip6_ll(self): """Local IPv6 link-local address on VPP interface (string).""" - return self._local_ip6_ll.address + return self._local_ip6_ll @property def local_ip6n_ll(self): - """DEPRECATED """ - """Local IPv6 link-local address on VPP interface (string).""" - return socket.inet_pton(socket.AF_INET6, self._local_ip6_ll.address) + """Local IPv6 link-local address - raw, suitable as API parameter.""" + return self._local_ip6n_ll @property def remote_ip6_ll(self): @@ -120,9 +102,9 @@ class VppInterface(object): @property def remote_ip6n_ll(self): - """DEPRECATED """ - """Local IPv6 link-local address on VPP interface (string).""" - return socket.inet_pton(socket.AF_INET6, self._remote_ip6_ll) + """Link-local IPv6 address of remote peer + - raw, suitable as API parameter""" + return self._remote_ip6n_ll @property def name(self): @@ -211,7 +193,7 @@ class VppInterface(object): def set_mac(self, mac): self._local_mac = str(mac) - self._local_ip6_ll = VppIpAddress(mk_ll_addr(self._local_mac)) + self._local_ip6_ll = mk_ll_addr(self._local_mac) self.test.vapi.sw_interface_set_mac_address( self.sw_if_index, mac.packed) @@ -220,27 +202,39 @@ class VppInterface(object): self.generate_remote_hosts() - self._local_ip4 = VppIpPrefix("172.16.%u.1" % self.sw_if_index, 24) + self._local_ip4 = "172.16.%u.1" % self.sw_if_index + self._local_ip4n = socket.inet_pton(socket.AF_INET, self.local_ip4) self._local_ip4_subnet = "172.16.%u.0" % self.sw_if_index + self._local_ip4n_subnet = socket.inet_pton(socket.AF_INET, + self._local_ip4_subnet) self._local_ip4_bcast = "172.16.%u.255" % self.sw_if_index + self._local_ip4n_bcast = socket.inet_pton(socket.AF_INET, + self._local_ip4_bcast) + self.local_ip4_prefix_len = 24 self.has_ip4_config = False self.ip4_table_id = 0 - self._local_ip6 = VppIpPrefix("fd01:%x::1" % self.sw_if_index, 64) + self._local_ip6 = "fd01:%x::1" % self.sw_if_index + self._local_ip6n = socket.inet_pton(socket.AF_INET6, self.local_ip6) + self.local_ip6_prefix_len = 64 self.has_ip6_config = False self.ip6_table_id = 0 self._local_addr = {socket.AF_INET: self.local_ip4, socket.AF_INET6: self.local_ip6} + self._local_addr_n = {socket.AF_INET: self.local_ip4n, + socket.AF_INET6: self.local_ip6n} self._remote_addr = {socket.AF_INET: self.remote_ip4, socket.AF_INET6: self.remote_ip6} + self._remote_addr_n = {socket.AF_INET: self.remote_ip4n, + socket.AF_INET6: self.remote_ip6n} r = self.test.vapi.sw_interface_dump() for intf in r: if intf.sw_if_index == self.sw_if_index: self._name = intf.interface_name.split(b'\0', 1)[0].decode('utf8') - self._local_mac = bytes(intf.l2_address) + self._local_mac = mac_ntop(intf.l2_address) self._dump = intf break else: @@ -248,13 +242,18 @@ class VppInterface(object): "Could not find interface with sw_if_index %d " "in interface dump %s" % (self.sw_if_index, moves.reprlib.repr(r))) - self._local_ip6_ll = VppIpAddress(mk_ll_addr(self.local_mac)) + self._local_ip6_ll = mk_ll_addr(self.local_mac) + self._local_ip6n_ll = socket.inet_pton(socket.AF_INET6, + self.local_ip6_ll) self._remote_ip6_ll = mk_ll_addr(self.remote_mac) + self._remote_ip6n_ll = socket.inet_pton(socket.AF_INET6, + self.remote_ip6_ll) def config_ip4(self): """Configure IPv4 address on the VPP interface.""" self.test.vapi.sw_interface_add_del_address( - sw_if_index=self.sw_if_index, prefix=self._local_ip4.encode()) + sw_if_index=self.sw_if_index, address=self.local_ip4n, + address_length=self.local_ip4_prefix_len) self.has_ip4_config = True def unconfig_ip4(self): @@ -262,8 +261,8 @@ class VppInterface(object): try: if self.has_ip4_config: self.test.vapi.sw_interface_add_del_address( - sw_if_index=self.sw_if_index, - prefix=self._local_ip4.encode(), is_add=0) + sw_if_index=self.sw_if_index, address=self.local_ip4n, + address_length=self.local_ip4_prefix_len, is_add=0) except AttributeError: self.has_ip4_config = False self.has_ip4_config = False @@ -281,7 +280,8 @@ class VppInterface(object): def config_ip6(self): """Configure IPv6 address on the VPP interface.""" self.test.vapi.sw_interface_add_del_address( - sw_if_index=self.sw_if_index, prefix=self._local_ip6.encode()) + sw_if_index=self.sw_if_index, address=self._local_ip6n, + address_length=self.local_ip6_prefix_len, is_ipv6=1) self.has_ip6_config = True def unconfig_ip6(self): @@ -289,8 +289,9 @@ class VppInterface(object): try: if self.has_ip6_config: self.test.vapi.sw_interface_add_del_address( - sw_if_index=self.sw_if_index, - prefix=self._local_ip6.encode(), is_add=0) + sw_if_index=self.sw_if_index, address=self.local_ip6n, + address_length=self.local_ip6_prefix_len, is_ipv6=1, + is_add=0) except AttributeError: self.has_ip6_config = False self.has_ip6_config = False @@ -356,14 +357,13 @@ class VppInterface(object): def admin_up(self): """Put interface ADMIN-UP.""" - self.test.vapi.sw_interface_set_flags( - self.sw_if_index, - flags=VppEnum.vl_api_if_status_flags_t.IF_STATUS_API_FLAG_ADMIN_UP) + self.test.vapi.sw_interface_set_flags(self.sw_if_index, + admin_up_down=1) def admin_down(self): """Put interface ADMIN-down.""" self.test.vapi.sw_interface_set_flags(self.sw_if_index, - flags=0) + admin_up_down=0) def link_up(self): """Put interface link-state-UP.""" @@ -450,15 +450,15 @@ class VppInterface(object): name='sw_interface_event') self.test.assert_equal(event.sw_if_index, self.sw_if_index, "sw_if_index") - self.test.assert_equal((event.flags & 1), admin_up_down, + self.test.assert_equal(event.admin_up_down, admin_up_down, "admin state") - self.test.assert_equal((event.flags & 2), link_up_down, + self.test.assert_equal(event.link_up_down, link_up_down, "link state") dump = self.test.vapi.sw_interface_dump() if_state = self.get_interface_config_from_dump(dump) - self.test.assert_equal((if_state.flags & 1), admin_up_down, + self.test.assert_equal(if_state.admin_up_down, admin_up_down, "admin state") - self.test.assert_equal((if_state.flags & 2), link_up_down, + self.test.assert_equal(if_state.link_up_down, link_up_down, "link state") def __str__(self): |