VPP-1508: Use scapy.compat to manage packet level library differences.
[vpp.git] / test / test_punt.py
index b20dc76..e265dc0 100644 (file)
@@ -11,6 +11,7 @@ import struct
 from struct import unpack, unpack_from
 from util import ppp, ppc
 from re import compile
+import scapy.compat
 from scapy.packet import Raw
 from scapy.layers.l2 import Ether
 from scapy.layers.inet import IP, UDP, ICMP
@@ -20,12 +21,12 @@ from framework import VppTestCase, VppTestRunner
 
 # Format MAC Address
 def get_mac_addr(bytes_addr):
-    return ':'.join('%02x' % ord(b) for b in bytes_addr)
+    return ':'.join('%02x' % scapy.compat.orb(b) for b in bytes_addr)
 
 
 # Format IP Address
 def ipv4(bytes_addr):
-    return '.'.join('%d' % ord(b) for b in bytes_addr)
+    return '.'.join('%d' % scapy.compat.orb(b) for b in bytes_addr)
 
 
 # Unpack Ethernet Frame
@@ -119,10 +120,18 @@ class TestPuntSocket(VppTestCase):
     portsCheck = dict()
     nr_packets = 256
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestPuntSocket, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestPuntSocket, cls).tearDownClass()
+
     @classmethod
     def setUpConstants(cls):
-        tempdir = cls.tempdir
-        cls.config.add('punt', 'socket', '%s/socket_punt' % cls.tempdir)
+        cls.extra_vpp_punt_config = [
+            "punt", "{", "socket", cls.tempdir+"/socket_punt", "}"]
         super(TestPuntSocket, cls).setUpConstants()
 
     def setUp(self):
@@ -135,6 +144,7 @@ class TestPuntSocket(VppTestCase):
 
     def tearDown(self):
         del self.sock_servers[:]
+        super(TestPuntSocket, self).tearDown()
 
     def socket_client_create(self, sock_name, id=None):
         thread = serverSocketThread(id, sock_name, self.portsCheck)
@@ -149,6 +159,14 @@ class TestPuntSocket(VppTestCase):
 class TestIP4PuntSocket(TestPuntSocket):
     """ Punt Socket for IPv4 """
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIP4PuntSocket, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIP4PuntSocket, cls).tearDownClass()
+
     def setUp(self):
         super(TestIP4PuntSocket, self).setUp()
 
@@ -385,6 +403,14 @@ class TestIP4PuntSocket(TestPuntSocket):
 class TestIP6PuntSocket(TestPuntSocket):
     """ Punt Socket for IPv6"""
 
+    @classmethod
+    def setUpClass(cls):
+        super(TestIP6PuntSocket, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(TestIP6PuntSocket, cls).tearDownClass()
+
     def setUp(self):
         super(TestIP6PuntSocket, self).setUp()