VAT-to-PAPI: LISPSetup
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 0b1f06f..279f9a0 100644 (file)
@@ -24,7 +24,7 @@ from resources.libraries.python.Constants import Constants
 from resources.libraries.python.CpuUtils import CpuUtils
 from resources.libraries.python.DUTSetup import DUTSetup
 from resources.libraries.python.L2Util import L2Util
-from resources.libraries.python.PapiExecutor import PapiExecutor
+from resources.libraries.python.PapiExecutor import PapiSocketExecutor
 from resources.libraries.python.parsers.JsonParser import JsonParser
 from resources.libraries.python.ssh import SSH, exec_cmd_no_error
 from resources.libraries.python.topology import NodeType, Topology
@@ -138,7 +138,7 @@ class InterfaceUtil(object):
                 host=node['host'])
             args = dict(sw_if_index=sw_if_index,
                         admin_up_down=admin_up_down)
-            with PapiExecutor(node) as papi_exec:
+            with PapiSocketExecutor(node) as papi_exec:
                 papi_exec.add(cmd, **args).get_reply(err_msg)
         elif node['type'] == NodeType.TG or node['type'] == NodeType.VM:
             cmd = 'ip link set {ifc} {state}'.format(
@@ -210,7 +210,7 @@ class InterfaceUtil(object):
         args = dict(sw_if_index=sw_if_index,
                     mtu=int(mtu))
         try:
-            with PapiExecutor(node) as papi_exec:
+            with PapiSocketExecutor(node) as papi_exec:
                 papi_exec.add(cmd, **args).get_reply(err_msg)
         except AssertionError as err:
             # TODO: Make failure tolerance optional.
@@ -321,7 +321,7 @@ class InterfaceUtil(object):
                     name_filter='')
         err_msg = 'Failed to get interface dump on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd, **args).get_details(err_msg)
 
         def process_if_dump(if_dump):
@@ -711,25 +711,25 @@ 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,
                     vlan_id=int(vlan))
         err_msg = 'Failed to create VLAN sub-interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         if_key = Topology.add_new_port(node, 'vlan_subif')
@@ -771,7 +771,7 @@ class InterfaceUtil(object):
                     vni=int(vni))
         err_msg = 'Failed to create VXLAN tunnel interface on host {host}'.\
             format(host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         if_key = Topology.add_new_port(node, 'vxlan_tunnel')
@@ -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.
@@ -805,7 +832,7 @@ class InterfaceUtil(object):
         args = dict(sw_if_index=sw_if_index)
         err_msg = 'Failed to get VXLAN dump on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd, **args).get_details(err_msg)
 
         def process_vxlan_dump(vxlan_dump):
@@ -853,7 +880,7 @@ class InterfaceUtil(object):
         cmd = 'sw_interface_vhost_user_dump'
         err_msg = 'Failed to get vhost-user dump on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd).get_details(err_msg)
 
         def process_vhost_dump(vhost_dump):
@@ -896,7 +923,7 @@ class InterfaceUtil(object):
         cmd = 'sw_interface_tap_v2_dump'
         err_msg = 'Failed to get TAP dump on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd).get_details(err_msg)
 
         def process_tap_dump(tap_dump):
@@ -972,7 +999,7 @@ class InterfaceUtil(object):
             inner_vlan_id=int(inner_vlan_id) if inner_vlan_id else 0)
         err_msg = 'Failed to create sub-interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         if_key = Topology.add_new_port(node, 'subinterface')
@@ -1007,7 +1034,7 @@ class InterfaceUtil(object):
                     tunnel=tunnel)
         err_msg = 'Failed to create GRE tunnel interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         if_key = Topology.add_new_port(node, 'gre_tunnel')
@@ -1032,7 +1059,7 @@ class InterfaceUtil(object):
         args = dict(mac_address=0)
         err_msg = 'Failed to create loopback interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         if_key = Topology.add_new_port(node, 'loopback')
@@ -1071,7 +1098,7 @@ class InterfaceUtil(object):
                             lb=load_balance.upper())).value)
         err_msg = 'Failed to create bond interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         InterfaceUtil.add_eth_interface(node, sw_if_index=sw_if_index,
@@ -1128,7 +1155,7 @@ class InterfaceUtil(object):
                     txq_size=0)
         err_msg = 'Failed to create AVF interface on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
 
         InterfaceUtil.add_eth_interface(node, sw_if_index=sw_if_index,
@@ -1160,7 +1187,7 @@ class InterfaceUtil(object):
                   'interface {bond} on host {host}'.format(ifc=interface,
                                                            bond=bond_if,
                                                            host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             papi_exec.add(cmd, **args).get_reply(err_msg)
 
     @staticmethod
@@ -1177,7 +1204,7 @@ class InterfaceUtil(object):
             host=node['host'])
 
         data = ('Bond data on node {host}:\n'.format(host=node['host']))
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd).get_details(err_msg)
 
         for bond in details:
@@ -1220,7 +1247,7 @@ class InterfaceUtil(object):
         err_msg = 'Failed to get slave dump on host {host}'.format(
             host=node['host'])
 
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd, **args).get_details(err_msg)
 
         def process_slave_dump(slave_dump):
@@ -1281,7 +1308,7 @@ class InterfaceUtil(object):
             is_add=1)
         err_msg = 'Failed to enable input acl on interface {ifc}'.format(
             ifc=interface)
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             papi_exec.add(cmd, **args).get_reply(err_msg)
 
     @staticmethod
@@ -1306,7 +1333,7 @@ class InterfaceUtil(object):
         args = dict(sw_if_index=sw_if_index)
         err_msg = 'Failed to get classify table name by interface {ifc}'.format(
             ifc=interface)
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             reply = papi_exec.add(cmd, **args).get_reply(err_msg)
 
         return reply
@@ -1350,7 +1377,7 @@ class InterfaceUtil(object):
         args = dict(sw_if_index=sw_if_index)
         err_msg = 'Failed to get VXLAN-GPE dump on host {host}'.format(
             host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             details = papi_exec.add(cmd, **args).get_details(err_msg)
 
         def process_vxlan_gpe_dump(vxlan_dump):
@@ -1405,7 +1432,7 @@ class InterfaceUtil(object):
             vrf_id=int(table_id))
         err_msg = 'Failed to assign interface {ifc} to FIB table'.format(
             ifc=interface)
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             papi_exec.add(cmd, **args).get_reply(err_msg)
 
     @staticmethod
@@ -1563,7 +1590,7 @@ class InterfaceUtil(object):
         cmd = 'sw_interface_rx_placement_dump'
         err_msg = "Failed to run '{cmd}' PAPI command on host {host}!".format(
             cmd=cmd, host=node['host'])
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             for ifc in node['interfaces'].values():
                 if ifc['vpp_sw_index'] is not None:
                     papi_exec.add(cmd, sw_if_index=ifc['vpp_sw_index'])
@@ -1591,7 +1618,7 @@ class InterfaceUtil(object):
                   "{host}!".format(host=node['host'])
         args = dict(sw_if_index=sw_if_index, queue_id=queue_id,
                     worker_id=worker_id)
-        with PapiExecutor(node) as papi_exec:
+        with PapiSocketExecutor(node) as papi_exec:
             papi_exec.add(cmd, **args).get_reply(err_msg)
 
     @staticmethod