diff options
author | Jakub Grajciar <jgrajcia@cisco.com> | 2019-03-18 13:17:53 +0100 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-08-20 09:57:10 +0000 |
commit | 053204ab039d34a990ff0e14c32ce3b294fcce0e (patch) | |
tree | 7261eaf0b905ea456ac536d8f728e89319b16a69 /test/vpp_interface.py | |
parent | df36f4963f1a590ce9a02f048507c3d4590580ae (diff) |
api: Cleanup APIs interface.api
Use of consistent API types for interface.api
Type: fix
Change-Id: I88206d7d0907cffd564031f73c9a996df2e5e21a
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'test/vpp_interface.py')
-rw-r--r-- | test/vpp_interface.py | 128 |
1 files changed, 72 insertions, 56 deletions
diff --git a/test/vpp_interface.py b/test/vpp_interface.py index e8100d362ec..1e047f5f700 100644 --- a/test/vpp_interface.py +++ b/test/vpp_interface.py @@ -6,7 +6,8 @@ import six from six import moves from util import Host, mk_ll_addr -from vpp_papi import mac_ntop +from vpp_papi import mac_ntop, VppEnum +from vpp_ip import VppIpAddress, VppIpPrefix from ipaddress import IPv4Network try: @@ -43,22 +44,33 @@ class VppInterface(object): return self._remote_addr @property - def local_addr_n(self): - return self._local_addr_n + def local_ip4(self): + """Local IPv4 address on VPP interface (string).""" + return self._local_ip4.address + + @local_ip4.setter + def local_ip4(self, value): + self._local_ip4.address = value @property - def remote_addr_n(self): - return self._remote_addr_n + def local_ip4_prefix_len(self): + """Local IPv4 prefix length """ + return self._local_ip4.len + + @local_ip4_prefix_len.setter + def local_ip4_prefix_len(self, value): + self._local_ip4.len = value @property - def local_ip4(self): - """Local IPv4 address on VPP interface (string).""" + def local_ip4_prefix(self): + """Local IPv4 prefix """ 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) + return socket.inet_pton(socket.AF_INET, self._local_ip4.address) @property def remote_ip4(self): @@ -67,18 +79,38 @@ class VppInterface(object): @property def remote_ip4n(self): - """IPv4 address of remote peer - raw, suitable as API parameter.""" - return socket.inet_pton(socket.AF_INET, self.remote_ip4) + """DEPRECATED """ + """Local IPv6 address - raw, suitable as API parameter.""" + return socket.inet_pton(socket.AF_INET, self._remote_hosts[0].ip4) @property def local_ip6(self): """Local IPv6 address on VPP interface (string).""" + return self._local_ip6.address + + @local_ip6.setter + def local_ip6(self, value): + self._local_ip6.address = value + + @property + def local_ip6_prefix_len(self): + """Local IPv6 prefix length """ + return self._local_ip6.len + + @local_ip6_prefix_len.setter + def local_ip6_prefix_len(self, value): + self._local_ip6.len = value + + @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) + return socket.inet_pton(socket.AF_INET6, self._local_ip6.address) @property def remote_ip6(self): @@ -87,18 +119,20 @@ class VppInterface(object): @property def remote_ip6n(self): - """IPv6 address of remote peer - raw, suitable as API parameter""" - return socket.inet_pton(socket.AF_INET6, self.remote_ip6) + """DEPRECATED """ + """Local IPv6 address - raw, suitable as API parameter.""" + return socket.inet_pton(socket.AF_INET6, self._remote_hosts[0].ip6) @property def local_ip6_ll(self): """Local IPv6 link-local address on VPP interface (string).""" - return self._local_ip6_ll + return self._local_ip6_ll.address @property def local_ip6n_ll(self): - """Local IPv6 link-local address - raw, suitable as API parameter.""" - return self._local_ip6n_ll + """DEPRECATED """ + """Local IPv6 link-local address on VPP interface (string).""" + return socket.inet_pton(socket.AF_INET6, self._local_ip6_ll.address) @property def remote_ip6_ll(self): @@ -108,9 +142,9 @@ class VppInterface(object): @property def remote_ip6n_ll(self): - """Link-local IPv6 address of remote peer - - raw, suitable as API parameter""" - return self._remote_ip6n_ll + """DEPRECATED """ + """Local IPv6 link-local address on VPP interface (string).""" + return socket.inet_pton(socket.AF_INET6, self._remote_ip6_ll) @property def name(self): @@ -199,7 +233,7 @@ class VppInterface(object): def set_mac(self, mac): self._local_mac = str(mac) - self._local_ip6_ll = mk_ll_addr(self._local_mac) + self._local_ip6_ll = VppIpAddress(mk_ll_addr(self._local_mac)) self.test.vapi.sw_interface_set_mac_address( self.sw_if_index, mac.packed) @@ -208,39 +242,27 @@ class VppInterface(object): self.generate_remote_hosts() - 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 = VppIpPrefix("172.16.%u.1" % self.sw_if_index, 24) 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 = "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._local_ip6 = VppIpPrefix("fd01:%x::1" % self.sw_if_index, 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(sw_if_index=self.sw_if_index) 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 = mac_ntop(intf.l2_address) + self._local_mac = bytes(intf.l2_address) self._dump = intf break else: @@ -248,18 +270,13 @@ 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 = mk_ll_addr(self.local_mac) - self._local_ip6n_ll = socket.inet_pton(socket.AF_INET6, - self.local_ip6_ll) + self._local_ip6_ll = VppIpAddress(mk_ll_addr(self.local_mac)) 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, address=self.local_ip4n, - address_length=self.local_ip4_prefix_len) + sw_if_index=self.sw_if_index, prefix=self._local_ip4.encode()) self.has_ip4_config = True def unconfig_ip4(self): @@ -267,8 +284,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, address=self.local_ip4n, - address_length=self.local_ip4_prefix_len, is_add=0) + sw_if_index=self.sw_if_index, + prefix=self._local_ip4.encode(), is_add=0) except AttributeError: self.has_ip4_config = False self.has_ip4_config = False @@ -286,8 +303,7 @@ 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, address=self._local_ip6n, - address_length=self.local_ip6_prefix_len, is_ipv6=1) + sw_if_index=self.sw_if_index, prefix=self._local_ip6.encode()) self.has_ip6_config = True def unconfig_ip6(self): @@ -295,9 +311,8 @@ class VppInterface(object): try: if self.has_ip6_config: self.test.vapi.sw_interface_add_del_address( - sw_if_index=self.sw_if_index, address=self.local_ip6n, - address_length=self.local_ip6_prefix_len, is_ipv6=1, - is_add=0) + sw_if_index=self.sw_if_index, + prefix=self._local_ip6.encode(), is_add=0) except AttributeError: self.has_ip6_config = False self.has_ip6_config = False @@ -365,13 +380,14 @@ class VppInterface(object): def admin_up(self): """Put interface ADMIN-UP.""" - self.test.vapi.sw_interface_set_flags(self.sw_if_index, - admin_up_down=1) + 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) def admin_down(self): """Put interface ADMIN-down.""" self.test.vapi.sw_interface_set_flags(self.sw_if_index, - admin_up_down=0) + flags=0) def link_up(self): """Put interface link-state-UP.""" @@ -459,15 +475,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.admin_up_down, admin_up_down, + self.test.assert_equal((event.flags & 1), admin_up_down, "admin state") - self.test.assert_equal(event.link_up_down, link_up_down, + self.test.assert_equal((event.flags & 2), 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.admin_up_down, admin_up_down, + self.test.assert_equal((if_state.flags & 1), admin_up_down, "admin state") - self.test.assert_equal(if_state.link_up_down, link_up_down, + self.test.assert_equal((if_state.flags & 2), link_up_down, "link state") def __str__(self): |