Add: Dot1Q + L2BD + GBP
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 6de17d1..34ccd7c 100644 (file)
@@ -711,18 +711,18 @@ class InterfaceUtil(object):
         """Create VLAN sub-interface on node.
 
         :param node: Node to add VLAN subinterface on.
-        :param interface: Interface name on which create VLAN subinterface.
+        :param interface: Interface name or index on which create VLAN
+            subinterface.
         :param vlan: VLAN ID of the subinterface to be created.
         :type node: dict
-        :type interface: str
+        :type interface: str on int
         :type vlan: int
         :returns: Name and index of created subinterface.
         :rtype: tuple
         :raises RuntimeError: if it is unable to create VLAN subinterface on the
-            node.
+            node or interface cannot be converted.
         """
-        iface_key = Topology.get_interface_by_name(node, interface)
-        sw_if_index = Topology.get_interface_sw_index(node, iface_key)
+        sw_if_index = InterfaceUtil.get_interface_index(node, interface)
 
         cmd = 'create_vlan_subif'
         args = dict(sw_if_index=sw_if_index,
@@ -781,6 +781,33 @@ class InterfaceUtil(object):
 
         return sw_if_index
 
+    @staticmethod
+    def set_vxlan_bypass(node, interface=None):
+        """Add the 'ip4-vxlan-bypass' graph node for a given interface.
+
+        By adding the IPv4 vxlan-bypass graph node to an interface, the node
+        checks for and validate input vxlan packet and bypass ip4-lookup,
+        ip4-local, ip4-udp-lookup nodes to speedup vxlan packet forwarding.
+        This node will cause extra overhead to for non-vxlan packets which is
+        kept at a minimum.
+
+        :param node: Node where to set VXLAN bypass.
+        :param interface: Numeric index or name string of a specific interface.
+        :type node: dict
+        :type interface: int or str
+        :raises RuntimeError: if it failed to set VXLAN bypass on interface.
+        """
+        sw_if_index = InterfaceUtil.get_interface_index(node, interface)
+
+        cmd = 'sw_interface_set_vxlan_bypass'
+        args = dict(is_ipv6=0,
+                    sw_if_index=sw_if_index,
+                    enable=1)
+        err_msg = 'Failed to set VXLAN bypass on interface on host {host}'.\
+            format(host=node['host'])
+        with PapiSocketExecutor(node) as papi_exec:
+            papi_exec.add(cmd, **args).get_replies(err_msg)
+
     @staticmethod
     def vxlan_dump(node, interface=None):
         """Get VxLAN data for the given interface.
@@ -1018,18 +1045,20 @@ class InterfaceUtil(object):
         return ifc_name, sw_if_index
 
     @staticmethod
-    def vpp_create_loopback(node):
+    def vpp_create_loopback(node, mac=None):
         """Create loopback interface on VPP node.
 
         :param node: Node to create loopback interface on.
+        :param mac: Optional MAC address for Loopback interface.
         :type node: dict
+        :type mac: str
         :returns: SW interface index.
         :rtype: int
         :raises RuntimeError: If it is not possible to create loopback on the
             node.
         """
         cmd = 'create_loopback'
-        args = dict(mac_address=0)
+        args = dict(mac_address=L2Util.mac_to_bin(mac) if mac else 0)
         err_msg = 'Failed to create loopback interface on host {host}'.format(
             host=node['host'])
         with PapiSocketExecutor(node) as papi_exec:
@@ -1039,6 +1068,9 @@ class InterfaceUtil(object):
         Topology.update_interface_sw_if_index(node, if_key, sw_if_index)
         ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index)
         Topology.update_interface_name(node, if_key, ifc_name)
+        if mac:
+            mac = InterfaceUtil.vpp_get_interface_mac(node, ifc_name)
+            Topology.update_interface_mac_address(node, if_key, mac)
 
         return sw_if_index
 
@@ -1499,10 +1531,11 @@ class InterfaceUtil(object):
         pf_mac_addr = Topology.get_interface_mac(node, ifc_key).split(":")
         uio_driver = Topology.get_uio_driver(node)
         kernel_driver = Topology.get_interface_driver(node, ifc_key)
-        if kernel_driver != "i40e":
+        if kernel_driver not in ("i40e", "i40evf"):
             raise RuntimeError(
-                "AVF needs i40e driver, not {driver} at node {host} ifc {ifc}"\
-                .format(driver=kernel_driver, host=node["host"], ifc=ifc_key))
+                "AVF needs i40e-compatible driver, not {driver} at node {host}"
+                " ifc {ifc}".format(
+                    driver=kernel_driver, host=node["host"], ifc=ifc_key))
         current_driver = DUTSetup.get_pci_dev_driver(
             node, pf_pci_addr.replace(':', r'\:'))
 
@@ -1516,7 +1549,7 @@ class InterfaceUtil(object):
             # Bind to kernel driver.
             DUTSetup.pci_driver_bind(node, pf_pci_addr, kernel_driver)
 
-        # Initialize PCI VFs
+        # Initialize PCI VFs.
         DUTSetup.set_sriov_numvfs(node, pf_pci_addr, numvfs)
 
         vf_ifc_keys = []