+ :returns: Interface name or None if not found.
+ :rtype: str
+ """
+ try:
+ return node[u"interfaces"][iface_key].get(u"name")
+ except KeyError:
+ return None
+
+ @staticmethod
+ def convert_interface_reference_to_key(node, interface):
+ """Takes interface reference in any format
+ (name, link name, interface key or sw_if_index)
+ and converts to interface key using Topology methods.
+
+ :param node: Node in topology.
+ :param interface: Name, sw_if_index, link name or key of an interface
+ on the node.
+ :type node: dict
+ :type interface: str or int
+
+ :returns: Interface key.
+ :rtype: str
+
+ :raises TypeError: If provided with invalid interface argument.
+ :raises RuntimeError: If the interface does not exist in topology.
+ """
+
+ if isinstance(interface, int):
+ key = Topology.get_interface_by_sw_index(node, interface)
+ if key is None:
+ raise RuntimeError(
+ f"Interface with sw_if_index={interface} does not exist "
+ f"in topology."
+ )
+ elif interface in Topology.get_node_interfaces(node):
+ key = interface
+ elif interface in Topology.get_links({u"dut": node}):
+ key = Topology.get_interface_by_link_name(node, interface)
+ elif isinstance(interface, str):
+ key = Topology.get_interface_by_name(node, interface)
+ if key is None:
+ raise RuntimeError(
+ f"Interface with key, name or link name \"{interface}\" "
+ f"does not exist in topology."
+ )
+ else:
+ raise TypeError(
+ u"Type of interface argument must be integer or string."
+ )
+ return key
+
+ @staticmethod
+ def convert_interface_reference(node, interface, wanted_format):
+ """Takes interface reference in any format
+ (name, link name, topology key or sw_if_index) and returns
+ its equivalent in the desired format.
+
+ :param node: Node in topology.
+ :param interface: Name, sw_if_index, link name or key of an interface
+ on the node.
+ :param wanted_format: Format of return value wanted.
+ Valid options are: sw_if_index, key, name.
+ :type node: dict
+ :type interface: str or int
+ :type wanted_format: str
+ :returns: Interface name, interface key or sw_if_index.
+ :rtype: str or int
+ :raises TypeError, ValueError: If provided with invalid arguments.
+ :raises RuntimeError: If the interface does not exist in topology.
+ """
+
+ key = Topology.convert_interface_reference_to_key(node, interface)
+
+ conversions = {
+ u"key": lambda x, y: y,
+ u"name": Topology.get_interface_name,
+ u"sw_if_index": Topology.get_interface_sw_index
+ }
+
+ try:
+ return conversions[wanted_format](node, key)
+ except KeyError:
+ raise ValueError(
+ f"Unrecognized return value wanted: {wanted_format}."
+ f"Valid options are key, name, sw_if_index"
+ )
+
+ @staticmethod
+ def get_interface_numa_node(node, iface_key):
+ """Get interface numa node.
+
+ Returns physical relation to numa node, numa_id.
+
+ :param node: Node to get numa id on.
+ :param iface_key: Interface key from topology file.
+ :type node: dict
+ :type iface_key: str
+ :returns: numa node id, None if not available.