CSIT-1597 API cleanup: tap 53/21953/5
authorJan Gelety <jgelety@cisco.com>
Tue, 3 Sep 2019 20:18:17 +0000 (22:18 +0200)
committerJan Gelety <jgelety@cisco.com>
Wed, 11 Sep 2019 15:22:53 +0000 (17:22 +0200)
cover API changes in VPP: https://gerrit.fd.io/r/c/vpp/+/21706

Change-Id: I16b3e3e29e7e7491cd19c067e8f3d8ced4947852
Signed-off-by: Jan Gelety <jgelety@cisco.com>
resources/api/vpp/supported_crcs.yaml
resources/libraries/python/Tap.py

index 720ce26..2fd8002 100644 (file)
     sw_interface_slave_dump: '0xd85aab0d'  # perf
     # ^^ see bond_*
     sw_interface_tap_v2_dump: '0x51077d14'  # dev
-    sw_interface_tap_v2_details: '0x5ee87a5f'  # dev
+    sw_interface_tap_v2_details: '0x547b146a'  # dev
     sw_interface_vhost_user_details: '0x91ff3307'  # dev
     sw_interface_vhost_user_dump: '0x51077d14'  # dev
-    tap_create_v2: '0x8fa99320'  # dev
-    tap_create_v2_reply: '0xfda5941f'  # dev
+    tap_create_v2: '0x958bfdfc'  # dev
+    tap_create_v2_reply: '0x903324db'  # dev
     vxlan_add_del_tunnel: '0x00f4bdd0'  # virl
     vxlan_add_del_tunnel_reply: '0xfda5941f'  # virl
     vxlan_tunnel_details: '0xce38e127'  # virl
index 103eeff..50e065f 100644 (file)
 
 """Tap utilities library."""
 
-from ipaddress import ip_address
+from enum import IntEnum
+
 from robot.api import logger
 
 from resources.libraries.python.Constants import Constants
-from resources.libraries.python.L2Util import L2Util
 from resources.libraries.python.InterfaceUtil import InterfaceUtil
+from resources.libraries.python.L2Util import L2Util
 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
 from resources.libraries.python.topology import Topology
 
 
+class TapFlags(IntEnum):
+    """TAP interface flags."""
+    TAP_FLAG_GSO = 1
+
+
 class Tap(object):
     """Tap utilities."""
 
@@ -44,17 +50,18 @@ class Tap(object):
         cmd = 'tap_create_v2'
         args = dict(
             id=Constants.BITWISE_NON_ZERO,
-            use_random_mac=0 if mac else 1,
-            mac_address=L2Util.mac_to_bin(mac) if mac else 6 * b'\x00',
-            host_namespace=64 * b'\x00',
-            host_mac_addr=6 * b'\x00',
-            host_if_name_set=1,
-            host_if_name=tap_name + (64 - len(tap_name)) * b'\x00',
-            host_bridge=64 * b'\x00',
-            host_ip4_addr=4 * b'\x00',
-            host_ip6_addr=16 * b'\x00',
-            host_ip4_gw=4 * b'\x00',
-            host_ip6_gw=16 * b'\x00'
+            use_random_mac=False if mac else True,
+            mac_address=L2Util.mac_to_bin(mac) if mac else None,
+            host_mtu_set=False,
+            host_mac_addr_set=False,
+            host_ip4_prefix_set=False,
+            host_ip6_prefix_set=False,
+            host_ip4_gw_set=False,
+            host_ip6_gw_set=False,
+            host_namespace_set=False,
+            host_if_name_set=True,
+            host_bridge_set=False,
+            host_if_name=tap_name,
         )
         err_msg = 'Failed to create tap interface {tap} on host {host}'.format(
             tap=tap_name, host=node['host'])
@@ -120,14 +127,19 @@ class Tap(object):
             :returns: Processed tap interface dump.
             :rtype: dict
             """
-            tap_dump['dev_name'] = tap_dump['dev_name'].rstrip('\x00')
-            tap_dump['host_if_name'] = tap_dump['host_if_name'].rstrip('\x00')
-            tap_dump['host_namespace'] = \
-                tap_dump['host_namespace'].rstrip('\x00')
-            tap_dump['host_mac_addr'] = \
-                L2Util.bin_to_mac(tap_dump['host_mac_addr'])
-            tap_dump['host_ip4_addr'] = ip_address(tap_dump['host_ip4_addr'])
-            tap_dump['host_ip6_addr'] = ip_address(tap_dump['host_ip6_addr'])
+            tap_dump['host_mac_addr'] = str(tap_dump['host_mac_addr'])
+            tap_dump['host_ip4_prefix'] = str(tap_dump['host_ip4_prefix'])
+            tap_dump['host_ip6_prefix'] = str(tap_dump['host_ip6_prefix'])
+            tap_dump['tap_flags'] = tap_dump['tap_flags'].value \
+                if hasattr(tap_dump['tap_flags'], 'value') \
+                else int(tap_dump['tap_flags'])
+            tap_dump['host_namespace'] = None \
+                if tap_dump['host_namespace'] == '(nil)' \
+                else tap_dump['host_namespace']
+            tap_dump['host_bridge'] = None \
+                if tap_dump['host_bridge'] == '(nil)' \
+                else tap_dump['host_bridge']
+
             return tap_dump
 
         cmd = 'sw_interface_tap_v2_dump'
@@ -140,7 +152,7 @@ class Tap(object):
         for dump in details:
             if name is None:
                 data.append(process_tap_dump(dump))
-            elif dump.get('host_if_name').rstrip('\x00') == name:
+            elif dump.get('host_if_name') == name:
                 data = process_tap_dump(dump)
                 break