FIX: IPSec tunnel interface
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 750029e..a68b921 100644 (file)
@@ -220,6 +220,29 @@ class InterfaceUtil(object):
             return dict()
         return data
 
+    @staticmethod
+    def vpp_get_interface_name(node, sw_if_index):
+        """Get interface name for the given SW interface index from actual
+        interface dump.
+
+        :param node: VPP node to get interface data from.
+        :param sw_if_index: SW interface index of the specific interface.
+        :type node: dict
+        :type sw_if_index: int
+        :returns: Name of the given interface.
+        :rtype: str
+        """
+
+        if_data = InterfaceUtil.vpp_get_interface_data(node, sw_if_index)
+        if if_data['sup_sw_if_index'] != if_data['sw_if_index']:
+            if_data = InterfaceUtil.vpp_get_interface_data(
+                node, if_data['sup_sw_if_index'])
+        try:
+            if_name = if_data["interface_name"]
+        except KeyError:
+            if_name = None
+        return if_name
+
     @staticmethod
     def vpp_get_interface_mac(node, interface=None):
         """Get MAC address for the given interface from actual interface dump.
@@ -375,7 +398,7 @@ class InterfaceUtil(object):
                 if name == 'Driver:':
                     return value if value else None
         else:
-            raise RuntimeError('Get interface driver for: {0}'\
+            raise RuntimeError('Get interface driver for: {0}'
                                .format(pci_addr))
 
     @staticmethod
@@ -449,6 +472,47 @@ class InterfaceUtil(object):
         VatJsonUtil.update_vpp_interface_data_from_json(node,
                                                         interface_dump_json)
 
+    @staticmethod
+    def update_nic_interface_names(node):
+        """Update interface names based on nic type and PCI address.
+
+        This method updates interface names in the same format as VPP does.
+
+        :param node: Node dictionary.
+        :type node: dict
+        """
+        for ifc in node['interfaces'].values():
+            if_pci = ifc['pci_address'].replace('.', ':').split(':')
+            bus = '{:x}'.format(int(if_pci[1], 16))
+            dev = '{:x}'.format(int(if_pci[2], 16))
+            fun = '{:x}'.format(int(if_pci[3], 16))
+            loc = '{bus}/{dev}/{fun}'.format(bus=bus, dev=dev, fun=fun)
+            if ifc['model'] == 'Intel-XL710':
+                ifc['name'] = 'FortyGigabitEthernet{loc}'.format(loc=loc)
+            elif ifc['model'] == 'Intel-X710':
+                ifc['name'] = 'TenGigabitEthernet{loc}'.format(loc=loc)
+            elif ifc['model'] == 'Intel-X520-DA2':
+                ifc['name'] = 'TenGigabitEthernet{loc}'.format(loc=loc)
+            elif ifc['model'] == 'Cisco-VIC-1385':
+                ifc['name'] = 'FortyGigabitEthernet{loc}'.format(loc=loc)
+            elif ifc['model'] == 'Cisco-VIC-1227':
+                ifc['name'] = 'TenGigabitEthernet{loc}'.format(loc=loc)
+            else:
+                ifc['name'] = 'UnknownEthernet{loc}'.format(loc=loc)
+
+    @staticmethod
+    def update_nic_interface_names_on_all_duts(nodes):
+        """Update interface names based on nic type and PCI address on all DUTs.
+
+        This method updates interface names in the same format as VPP does.
+
+        :param nodes: Topology nodes.
+        :type nodes: dict
+        """
+        for node in nodes.values():
+            if node['type'] == NodeType.DUT:
+                InterfaceUtil.update_nic_interface_names(node)
+
     @staticmethod
     def update_tg_interface_data_on_node(node):
         """Update interface name for TG/linux node in DICT__nodes.