Use IP and MAC API types for neighbors
[vpp.git] / test / vpp_interface.py
index 0f798cb..58384d2 100644 (file)
@@ -1,9 +1,11 @@
+import binascii
 import socket
 from abc import abstractmethod, ABCMeta
 
-import six
+from six import moves
 
-from util import Host, mk_ll_addr, mactobinary
+from util import Host, mk_ll_addr
+from vpp_papi import mac_ntop
 
 
 class VppInterface(object):
@@ -189,11 +191,10 @@ class VppInterface(object):
         self._hosts_by_ip6 = {}
 
     def set_mac(self, mac):
-        self._local_mac = mac
-        self._local_ip6_ll = mk_ll_addr(mac)
+        self._local_mac = str(mac)
+        self._local_ip6_ll = mk_ll_addr(self._local_mac)
         self.test.vapi.sw_interface_set_mac_address(
-            self.sw_if_index,
-            mactobinary(self._local_mac))
+            self.sw_if_index, mac.packed)
 
     def set_sw_if_index(self, sw_if_index):
         self._sw_if_index = sw_if_index
@@ -230,17 +231,16 @@ class VppInterface(object):
         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]
-                self._local_mac = \
-                    ':'.join(intf.l2_address.encode('hex')[i:i + 2]
-                             for i in range(0, 12, 2))
+                self._name = intf.interface_name.split(b'\0',
+                                                       1)[0].decode('utf8')
+                self._local_mac = mac_ntop(intf.l2_address)
                 self._dump = intf
                 break
         else:
             raise Exception(
                 "Could not find interface with sw_if_index %d "
                 "in interface dump %s" %
-                (self.sw_if_index, six.reprlib(r)))
+                (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)
@@ -273,10 +273,9 @@ class VppInterface(object):
         :param vrf_id: The FIB table / VRF ID. (Default value = 0)
         """
         for host in self._remote_hosts:
-            macn = host.mac.replace(":", "").decode('hex')
-            ipn = host.ip4n
-            self.test.vapi.ip_neighbor_add_del(
-                self.sw_if_index, macn, ipn)
+            self.test.vapi.ip_neighbor_add_del(self.sw_if_index,
+                                               host.mac,
+                                               host.ip4)
 
     def config_ip6(self):
         """Configure IPv6 address on the VPP interface."""
@@ -304,10 +303,9 @@ class VppInterface(object):
         :param vrf_id: The FIB table / VRF ID. (Default value = 0)
         """
         for host in self._remote_hosts:
-            macn = host.mac.replace(":", "").decode('hex')
-            ipn = host.ip6n
-            self.test.vapi.ip_neighbor_add_del(
-                self.sw_if_index, macn, ipn, is_ipv6=1)
+            self.test.vapi.ip_neighbor_add_del(self.sw_if_index,
+                                               host.mac,
+                                               host.ip6)
 
     def unconfig(self):
         """Unconfigure IPv6 and IPv4 address on the VPP interface."""