tests: Use errno value rather than a specific int
[vpp.git] / test / vpp_sub_interface.py
index a374cba..b896a6e 100644 (file)
@@ -1,14 +1,23 @@
 from scapy.layers.l2 import Dot1Q
 import abc
-import six
 from vpp_pg_interface import VppPGInterface
-from vpp_papi_provider import L2_VTR_OP
 from vpp_interface import VppInterface
+from vpp_papi import VppEnum
 
 
-@six.add_metaclass(abc.ABCMeta)
-class VppSubInterface(VppPGInterface):
+class L2_VTR_OP:
+    L2_DISABLED = 0
+    L2_PUSH_1 = 1
+    L2_PUSH_2 = 2
+    L2_POP_1 = 3
+    L2_POP_2 = 4
+    L2_TRANSLATE_1_1 = 5
+    L2_TRANSLATE_1_2 = 6
+    L2_TRANSLATE_2_1 = 7
+    L2_TRANSLATE_2_2 = 8
 
+
+class VppSubInterface(VppPGInterface, metaclass=abc.ABCMeta):
     @property
     def parent(self):
         """Parent interface for this sub-interface"""
@@ -48,7 +57,7 @@ class VppSubInterface(VppPGInterface):
         pass
 
     @abc.abstractmethod
-    def create_ndp_req(self):
+    def create_ndp_req(self, addr=None):
         pass
 
     def resolve_arp(self):
@@ -107,26 +116,33 @@ class VppSubInterface(VppPGInterface):
         self._tag2 = 0
         self._push1q = 0
 
-        if (vtr == L2_VTR_OP.L2_PUSH_1 or
-            vtr == L2_VTR_OP.L2_TRANSLATE_1_1 or
-                vtr == L2_VTR_OP.L2_TRANSLATE_2_1):
+        if (
+            vtr == L2_VTR_OP.L2_PUSH_1
+            or vtr == L2_VTR_OP.L2_TRANSLATE_1_1
+            or vtr == L2_VTR_OP.L2_TRANSLATE_2_1
+        ):
             self._tag1 = tag
             self._push1q = push1q
-        if (vtr == L2_VTR_OP.L2_PUSH_2 or
-            vtr == L2_VTR_OP.L2_TRANSLATE_1_2 or
-                vtr == L2_VTR_OP.L2_TRANSLATE_2_2):
+        if (
+            vtr == L2_VTR_OP.L2_PUSH_2
+            or vtr == L2_VTR_OP.L2_TRANSLATE_1_2
+            or vtr == L2_VTR_OP.L2_TRANSLATE_2_2
+        ):
             self._tag1 = outer
             self._tag2 = inner
             self._push1q = push1q
 
         self.test.vapi.l2_interface_vlan_tag_rewrite(
-            self.sw_if_index, vtr, push=self._push1q,
-            tag1=self._tag1, tag2=self._tag2)
+            sw_if_index=self.sw_if_index,
+            vtr_op=vtr,
+            push_dot1q=self._push1q,
+            tag1=self._tag1,
+            tag2=self._tag2,
+        )
         self._vtr = vtr
 
 
 class VppDot1QSubint(VppSubInterface):
-
     @property
     def vlan(self):
         """VLAN tag"""
@@ -144,8 +160,8 @@ class VppDot1QSubint(VppSubInterface):
         packet = VppPGInterface.create_arp_req(self)
         return self.add_dot1_layer(packet)
 
-    def create_ndp_req(self):
-        packet = VppPGInterface.create_ndp_req(self)
+    def create_ndp_req(self, addr=None):
+        packet = VppPGInterface.create_ndp_req(self, addr)
         return self.add_dot1_layer(packet)
 
     # called before sending packet
@@ -158,7 +174,6 @@ class VppDot1QSubint(VppSubInterface):
 
 
 class VppDot1ADSubint(VppSubInterface):
-
     @property
     def outer_vlan(self):
         """Outer VLAN tag"""
@@ -171,9 +186,18 @@ class VppDot1ADSubint(VppSubInterface):
 
     def __init__(self, test, parent, sub_id, outer_vlan, inner_vlan):
         super(VppDot1ADSubint, self).__init__(test, parent, sub_id)
-        r = test.vapi.create_subif(parent.sw_if_index, sub_id, outer_vlan,
-                                   inner_vlan, dot1ad=1, two_tags=1,
-                                   exact_match=1)
+        flags = (
+            VppEnum.vl_api_sub_if_flags_t.SUB_IF_API_FLAG_DOT1AD
+            | VppEnum.vl_api_sub_if_flags_t.SUB_IF_API_FLAG_TWO_TAGS
+            | VppEnum.vl_api_sub_if_flags_t.SUB_IF_API_FLAG_EXACT_MATCH
+        )
+        r = test.vapi.create_subif(
+            sw_if_index=parent.sw_if_index,
+            sub_id=sub_id,
+            outer_vlan_id=outer_vlan,
+            inner_vlan_id=inner_vlan,
+            sub_if_flags=flags,
+        )
         self.set_sw_if_index(r.sw_if_index)
         self._outer_vlan = outer_vlan
         self._inner_vlan = inner_vlan
@@ -182,24 +206,21 @@ class VppDot1ADSubint(VppSubInterface):
         packet = VppPGInterface.create_arp_req(self)
         return self.add_dot1_layer(packet)
 
-    def create_ndp_req(self):
-        packet = VppPGInterface.create_ndp_req(self)
+    def create_ndp_req(self, addr=None):
+        packet = VppPGInterface.create_ndp_req(self, addr)
         return self.add_dot1_layer(packet)
 
     def add_dot1_layer(self, packet):
         return self.add_dot1ad_layer(packet, self.outer_vlan, self.inner_vlan)
 
     def remove_dot1_layer(self, packet):
-        return self.remove_dot1ad_layer(packet, self.outer_vlan,
-                                        self.inner_vlan)
+        return self.remove_dot1ad_layer(packet, self.outer_vlan, self.inner_vlan)
 
 
 class VppP2PSubint(VppSubInterface):
-
     def __init__(self, test, parent, sub_id, remote_mac):
         super(VppP2PSubint, self).__init__(test, parent, sub_id)
-        r = test.vapi.p2p_ethernet_add(parent.sw_if_index,
-                                       remote_mac, sub_id)
+        r = test.vapi.p2p_ethernet_add(parent.sw_if_index, remote_mac, sub_id)
         self.set_sw_if_index(r.sw_if_index)
         self.parent_sw_if_index = parent.sw_if_index
         self.p2p_remote_mac = remote_mac
@@ -214,6 +235,6 @@ class VppP2PSubint(VppSubInterface):
         packet = VppPGInterface.create_arp_req(self)
         return packet
 
-    def create_ndp_req(self):
-        packet = VppPGInterface.create_ndp_req(self)
+    def create_ndp_req(self, addr=None):
+        packet = VppPGInterface.create_ndp_req(self, addr)
         return packet