1 # Copyright (c) 2022 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Defines nodes and topology structure."""
18 from collections import Counter
20 from yaml import safe_load
22 from robot.api import logger
23 from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
25 from resources.libraries.python.Constants import Constants
28 u"DICT__nodes", u"Topology", u"NodeType", u"SocketType", u"NodeSubTypeTG"
32 def load_topo_from_yaml():
33 """Load topology from file defined in "${TOPOLOGY_PATH}" variable.
35 :returns: Nodes from loaded topology.
38 topo_path = BuiltIn().get_variable_value(u"${TOPOLOGY_PATH}")
39 except RobotNotRunningError:
42 with open(topo_path) as work_file:
43 return safe_load(work_file.read())[u"nodes"]
47 """Defines node types used in topology dictionaries."""
48 # Device Under Test (this node has VPP running on it)
50 # Traffic Generator (this node has traffic generator on it)
51 # pylint: disable=invalid-name
53 # Virtual Machine (this node running on DUT node)
54 # pylint: disable=invalid-name
59 """Defines node sub-type TG - traffic generator."""
60 # T-Rex traffic generator
69 """Defines socket types used in topology dictionaries."""
72 # VPP PAPI Stats (legacy option until stats are migrated to Socket PAPI)
78 DICT__nodes = load_topo_from_yaml()
82 """Topology data manipulation and extraction methods.
84 Defines methods used for manipulation and extraction of data from
87 "Active topology" contains initially data from the topology file and can be
88 extended with additional data from the DUTs like internal interface indexes
89 or names. Additional data which can be filled to the active topology are
91 - additional internal representation (index, name, ...)
92 - operational data (dynamic ports)
94 To access the port data it is recommended to use a port key because the key
95 does not rely on the data retrieved from nodes, this allows to call most of
96 the methods without having filled active topology with internal nodes data.
99 def add_node_item(node, value, path):
100 """Add item to topology node.
102 :param node: Topology node.
103 :param value: Value to insert.
104 :param path: Path where to insert item.
110 node[path[0]] = value
112 if path[0] not in node:
113 node[path[0]] = dict()
114 elif isinstance(node[path[0]], str):
115 node[path[0]] = dict() if node[path[0]] == u"" \
116 else {node[path[0]]: u""}
117 Topology.add_node_item(node[path[0]], value, path[1:])
120 def add_new_port(node, ptype):
121 """Add new port to the node to active topology.
123 :param node: Node to add new port on.
124 :param ptype: Port type, used as key prefix.
127 :returns: Port key or None
128 :rtype: string or None
132 for i in range(1, max_ports):
133 if node[u"interfaces"].get(str(ptype) + str(i)) is None:
134 iface = str(ptype) + str(i)
135 node[u"interfaces"][iface] = dict()
140 def remove_port(node, iface_key):
141 """Remove required port from active topology.
143 :param node: Node to remove port on.
144 :param: iface_key: Topology key of the interface.
150 node[u"interfaces"].pop(iface_key)
155 def remove_all_ports(node, ptype):
156 """Remove all ports with ptype as prefix.
158 :param node: Node to remove ports on.
159 :param: ptype: Port type, used as key prefix.
164 for if_key in list(node[u"interfaces"]):
165 if if_key.startswith(str(ptype)):
166 node[u"interfaces"].pop(if_key)
169 def remove_all_added_ports_on_all_duts_from_topology(nodes):
170 """Remove all added ports on all DUT nodes in the topology.
172 :param nodes: Nodes in the topology.
177 u"subinterface", u"vlan_subif", u"memif", u"tap", u"vhost",
178 u"loopback", u"gre_tunnel", u"vxlan_tunnel", u"eth_bond",
179 u"eth_avf", u"eth_rdma", u"geneve_tunnel", u"eth_af_xdp",
183 for node_data in nodes.values():
184 if node_data[u"type"] == NodeType.DUT:
185 for ptype in port_types:
186 Topology.remove_all_ports(node_data, ptype)
189 def remove_all_vif_ports(node):
190 """Remove all Virtual Interfaces on DUT node.
192 :param node: Node to remove VIF ports on.
196 reg_ex = re.compile(r"port\d+_vif\d+")
197 for if_key in list(node[u"interfaces"]):
198 if re.match(reg_ex, if_key):
199 node[u"interfaces"].pop(if_key)
202 def remove_all_added_vif_ports_on_all_duts_from_topology(nodes):
203 """Remove all added Virtual Interfaces on all DUT nodes in
206 :param nodes: Nodes in the topology.
210 for node_data in nodes.values():
211 if node_data[u"type"] == NodeType.DUT:
212 Topology.remove_all_vif_ports(node_data)
215 def update_interface_sw_if_index(node, iface_key, sw_if_index):
216 """Update sw_if_index on the interface from the node.
218 :param node: Node to update sw_if_index on.
219 :param iface_key: Topology key of the interface.
220 :param sw_if_index: Internal index to store.
223 :type sw_if_index: int
225 node[u"interfaces"][iface_key][u"vpp_sw_index"] = int(sw_if_index)
228 def update_interface_name(node, iface_key, name):
229 """Update name on the interface from the node.
231 :param node: Node to update name on.
232 :param iface_key: Topology key of the interface.
233 :param name: Interface name to store.
238 node[u"interfaces"][iface_key][u"name"] = str(name)
241 def update_interface_mac_address(node, iface_key, mac_address):
242 """Update mac_address on the interface from the node.
244 :param node: Node to update MAC on.
245 :param iface_key: Topology key of the interface.
246 :param mac_address: MAC address.
249 :type mac_address: str
251 node[u"interfaces"][iface_key][u"mac_address"] = str(mac_address)
254 def update_interface_pci_address(node, iface_key, pci_address):
255 """Update pci_address on the interface from the node.
257 :param node: Node to update PCI on.
258 :param iface_key: Topology key of the interface.
259 :param pci_address: PCI address.
262 :type pci_address: str
264 node[u"interfaces"][iface_key][u"pci_address"] = str(pci_address)
267 def update_interface_vlan(node, iface_key, vlan):
268 """Update VLAN on the interface from the node.
270 :param node: Node to update VLAN on.
271 :param iface_key: Topology key of the interface.
272 :param vlan: VLAN ID.
277 node[u"interfaces"][iface_key][u"vlan"] = int(vlan)
280 def update_interface_vhost_socket(node, iface_key, vhost_socket):
281 """Update vhost socket name on the interface from the node.
283 :param node: Node to update socket name on.
284 :param iface_key: Topology key of the interface.
285 :param vhost_socket: Path to named socket on node.
288 :type vhost_socket: str
290 node[u"interfaces"][iface_key][u"vhost_socket"] = str(vhost_socket)
293 def update_interface_memif_socket(node, iface_key, memif_socket):
294 """Update memif socket name on the interface from the node.
296 :param node: Node to update socket name on.
297 :param iface_key: Topology key of the interface.
298 :param memif_socket: Path to named socket on node.
301 :type memif_socket: str
303 node[u"interfaces"][iface_key][u"memif_socket"] = str(memif_socket)
306 def update_interface_memif_id(node, iface_key, memif_id):
307 """Update memif ID on the interface from the node.
309 :param node: Node to update memif ID on.
310 :param iface_key: Topology key of the interface.
311 :param memif_id: Memif interface ID.
316 node[u"interfaces"][iface_key][u"memif_id"] = str(memif_id)
319 def update_interface_memif_role(node, iface_key, memif_role):
320 """Update memif role on the interface from the node.
322 :param node: Node to update memif role on.
323 :param iface_key: Topology key of the interface.
324 :param memif_role: Memif role.
327 :type memif_role: str
329 node[u"interfaces"][iface_key][u"memif_role"] = str(memif_role)
332 def update_interface_tap_dev_name(node, iface_key, dev_name):
333 """Update device name on the tap interface from the node.
335 :param node: Node to update tap device name on.
336 :param iface_key: Topology key of the interface.
337 :param dev_name: Device name of the tap interface.
343 node[u"interfaces"][iface_key][u"dev_name"] = str(dev_name)
346 def get_node_by_hostname(nodes, hostname):
347 """Get node from nodes of the topology by hostname.
349 :param nodes: Nodes of the test topology.
350 :param hostname: Host name.
353 :returns: Node dictionary or None if not found.
355 for node in nodes.values():
356 if node[u"host"] == hostname:
362 def get_links(nodes):
363 """Get list of links(networks) in the topology.
365 :param nodes: Nodes of the test topology.
367 :returns: Links in the topology.
372 for node in nodes.values():
373 for interface in node[u"interfaces"].values():
374 link = interface.get(u"link")
376 if link not in links:
382 def _get_interface_by_key_value(node, key, value, subsequent=False):
383 """Return node interface key from topology file
384 according to key and value.
386 :param node: The node dictionary.
387 :param key: Key by which to select the interface.
388 :param value: Value that should be found using the key.
389 :param subsequent: Use second interface of the link. Useful for
390 back-to-back links. Default: False
394 :type subsequent: bool
395 :returns: Interface key from topology file
398 interfaces = node[u"interfaces"]
400 for if_key, if_val in interfaces.items():
401 k_val = if_val.get(key)
402 if k_val is not None:
412 def get_interface_by_name(node, iface_name):
413 """Return interface key based on name from DUT/TG.
415 This method returns interface key based on interface name
416 retrieved from the DUT, or TG.
418 :param node: The node topology dictionary.
419 :param iface_name: Interface name (string form).
421 :type iface_name: string
422 :returns: Interface key.
425 return Topology._get_interface_by_key_value(node, u"name", iface_name)
428 def get_interface_by_link_name(node, link_name, subsequent=False):
429 """Return interface key of link on node.
431 This method returns the interface name associated with a given link
434 :param node: The node topology dictionary.
435 :param link_name: Name of the link that a interface is connected to.
436 :param subsequent: Use second interface of the link. Useful for
437 back-to-back links. Default: False
439 :type link_name: string
440 :type subsequent: bool
441 :returns: Interface key of the interface connected to the given link.
444 return Topology._get_interface_by_key_value(
445 node, u"link", link_name, subsequent=subsequent
448 def get_interfaces_by_link_names(self, node, link_names):
449 """Return dictionary of dictionaries {"interfaceN", interface name}.
451 This method returns the interface names associated with given links
454 :param node: The node topology directory.
455 :param link_names: List of names of the link that a interface is
458 :type link_names: list
459 :returns: Dictionary of interface names that are connected to the given
465 for link_name in link_names:
466 interface = self.get_interface_by_link_name(node, link_name)
467 retval[f"interface{str(interface_number)}"] = \
468 self.get_interface_name(node, interface)
469 interface_number += 1
473 def get_interface_by_sw_index(node, sw_if_index):
474 """Return interface name of link on node.
476 This method returns the interface name associated with a software
477 interface index assigned to the interface by vpp for a given node.
479 :param node: The node topology dictionary.
480 :param sw_if_index: sw_if_index of the link that a interface is
483 :type sw_if_index: int
484 :returns: Interface name of the interface connected to the given link.
487 return Topology._get_interface_by_key_value(
488 node, u"vpp_sw_index", sw_if_index
492 def get_interface_sw_index(node, iface_key):
493 """Get VPP sw_if_index for the interface using interface key.
495 :param node: Node to get interface sw_if_index on.
496 :param iface_key: Interface key from topology file, or sw_if_index.
498 :type iface_key: str/int
499 :returns: Return sw_if_index or None if not found.
503 if isinstance(iface_key, str):
504 return node[u"interfaces"][iface_key].get(u"vpp_sw_index")
505 # TODO: use only iface_key, do not use integer
506 return int(iface_key)
507 except (KeyError, ValueError):
511 def get_interface_sw_index_by_name(node, iface_name):
512 """Get VPP sw_if_index for the interface using interface name.
514 :param node: Node to get interface sw_if_index on.
515 :param iface_name: Interface name.
517 :type iface_name: str
518 :returns: Return sw_if_index or None if not found.
519 :raises TypeError: If provided interface name is not a string.
522 if not isinstance(iface_name, str):
523 raise TypeError(u"Interface name must be a string.")
524 iface_key = Topology.get_interface_by_name(node, iface_name)
525 return node[u"interfaces"][iface_key].get(u"vpp_sw_index")
526 except (KeyError, ValueError):
530 def get_interface_mtu(node, iface_key):
531 """Get interface MTU.
533 Returns physical layer MTU (max. size of Ethernet frame).
534 :param node: Node to get interface MTU on.
535 :param iface_key: Interface key from topology file.
538 :returns: MTU or None if not found.
542 return node[u"interfaces"][iface_key].get(u"mtu")
547 def get_interface_name(node, iface_key):
548 """Get interface name (retrieved from DUT/TG).
550 Returns name in string format, retrieved from the node.
551 :param node: Node to get interface name on.
552 :param iface_key: Interface key from topology file.
555 :returns: Interface name or None if not found.
559 return node[u"interfaces"][iface_key].get(u"name")
564 def convert_interface_reference_to_key(node, interface):
565 """Takes interface reference in any format
566 (name, link name, interface key or sw_if_index)
567 and converts to interface key using Topology methods.
569 :param node: Node in topology.
570 :param interface: Name, sw_if_index, link name or key of an interface
573 :type interface: str or int
575 :returns: Interface key.
578 :raises TypeError: If provided with invalid interface argument.
579 :raises RuntimeError: If the interface does not exist in topology.
582 if isinstance(interface, int):
583 key = Topology.get_interface_by_sw_index(node, interface)
586 f"Interface with sw_if_index={interface} does not exist "
589 elif interface in Topology.get_node_interfaces(node):
591 elif interface in Topology.get_links({u"dut": node}):
592 key = Topology.get_interface_by_link_name(node, interface)
593 elif isinstance(interface, str):
594 key = Topology.get_interface_by_name(node, interface)
597 f"Interface with key, name or link name \"{interface}\" "
598 f"does not exist in topology."
602 u"Type of interface argument must be integer or string."
607 def convert_interface_reference(node, interface, wanted_format):
608 """Takes interface reference in any format
609 (name, link name, topology key or sw_if_index) and returns
610 its equivalent in the desired format.
612 :param node: Node in topology.
613 :param interface: Name, sw_if_index, link name or key of an interface
615 :param wanted_format: Format of return value wanted.
616 Valid options are: sw_if_index, key, name.
618 :type interface: str or int
619 :type wanted_format: str
620 :returns: Interface name, interface key or sw_if_index.
622 :raises TypeError, ValueError: If provided with invalid arguments.
623 :raises RuntimeError: If the interface does not exist in topology.
626 key = Topology.convert_interface_reference_to_key(node, interface)
629 u"key": lambda x, y: y,
630 u"name": Topology.get_interface_name,
631 u"sw_if_index": Topology.get_interface_sw_index
635 return conversions[wanted_format](node, key)
638 f"Unrecognized return value wanted: {wanted_format}."
639 f"Valid options are key, name, sw_if_index"
643 def get_interface_numa_node(node, iface_key):
644 """Get interface numa node.
646 Returns physical relation to numa node, numa_id.
648 :param node: Node to get numa id on.
649 :param iface_key: Interface key from topology file.
652 :returns: numa node id, None if not available.
656 return node[u"interfaces"][iface_key].get(u"numa_node")
661 def get_interfaces_numa_node(node, *iface_keys):
662 """Get numa node on which are located most of the interfaces.
664 Return numa node with highest count of interfaces provided as arguments.
665 Return 0 if the interface does not have numa_node information available.
666 If all interfaces have unknown location (-1), then return 0.
667 If most of interfaces have unknown location (-1), but there are
668 some interfaces with known location, then return the second most
669 location of the provided interfaces.
671 :param node: Node from DICT__nodes.
672 :param iface_keys: Interface keys for lookup.
674 :type iface_keys: strings
675 :returns: Numa node of most given interfaces or 0.
679 for if_key in iface_keys:
681 numa_list.append(node[u"interfaces"][if_key].get(u"numa_node"))
685 numa_cnt_mc = Counter(numa_list).most_common()
687 if numa_cnt_mc and numa_cnt_mc[0][0] != -1:
688 return numa_cnt_mc[0][0]
689 if len(numa_cnt_mc) > 1 and numa_cnt_mc[0][0] == -1:
690 return numa_cnt_mc[1][0]
694 def get_interface_mac(node, iface_key):
695 """Get MAC address for the interface.
697 :param node: Node to get interface mac on.
698 :param iface_key: Interface key from topology file.
701 :returns: Return MAC or None if not found.
704 return node[u"interfaces"][iface_key].get(u"mac_address")
709 def get_interface_ip4(node, iface_key):
710 """Get IP4 address for the interface.
712 :param node: Node to get interface mac on.
713 :param iface_key: Interface key from topology file.
716 :returns: Return IP4 or None if not found.
719 return node[u"interfaces"][iface_key].get(u"ip4_address")
724 def get_interface_ip4_prefix_length(node, iface_key):
725 """Get IP4 address prefix length for the interface.
727 :param node: Node to get prefix length on.
728 :param iface_key: Interface key from topology file.
731 :returns: Prefix length from topology file or the default
732 IP4 prefix length if not found.
734 :raises: KeyError if iface_key is not found.
736 return node[u"interfaces"][iface_key].get(u"ip4_prefix_length", \
737 Constants.DEFAULT_IP4_PREFIX_LENGTH)
740 def get_adjacent_node_and_interface(nodes_info, node, iface_key):
741 """Get node and interface adjacent to specified interface
744 :param nodes_info: Dictionary containing information on all nodes
746 :param node: Node that contains specified interface.
747 :param iface_key: Interface key from topology file.
748 :type nodes_info: dict
751 :returns: Return (node, interface_key) tuple or None if not found.
755 # get link name where the interface belongs to
756 for if_key, if_val in node[u"interfaces"].items():
757 if if_key == u"mgmt":
759 if if_key == iface_key:
760 link_name = if_val[u"link"]
763 if link_name is None:
767 for node_data in nodes_info.values():
769 l_hash = node_data[u"host"]+str(node_data[u"port"])
770 r_hash = node[u"host"]+str(node[u"port"])
774 in node_data[u"interfaces"].items():
775 if u"link" not in if_val:
777 if if_val[u"link"] == link_name:
778 return node_data, if_key
782 def get_interface_pci_addr(node, iface_key):
783 """Get interface PCI address.
785 :param node: Node to get interface PCI address on.
786 :param iface_key: Interface key from topology file.
789 :returns: Return PCI address or None if not found.
792 return node[u"interfaces"][iface_key].get(u"pci_address")
797 def get_interface_driver(node, iface_key):
798 """Get interface driver.
800 :param node: Node to get interface driver on.
801 :param iface_key: Interface key from topology file.
804 :returns: Return interface driver or None if not found.
807 return node[u"interfaces"][iface_key].get(u"driver")
812 def get_interface_vlan(node, iface_key):
813 """Get interface vlan.
815 :param node: Node to get interface driver on.
816 :param iface_key: Interface key from topology file.
819 :returns: Return interface vlan or None if not found.
822 return node[u"interfaces"][iface_key].get(u"vlan")
827 def get_node_interfaces(node):
828 """Get all node interfaces.
830 :param node: Node to get list of interfaces from.
832 :returns: Return list of keys of all interfaces.
835 return node[u"interfaces"].keys()
838 def get_node_link_mac(node, link_name):
839 """Return interface mac address by link name.
841 :param node: Node to get interface sw_if_index on.
842 :param link_name: Link name.
845 :returns: MAC address string.
848 for port in node[u"interfaces"].values():
849 if port.get(u"link") == link_name:
850 return port.get(u"mac_address")
854 def _get_node_active_link_names(node, filter_list=None, topo_has_dut=True):
855 """Return list of link names that are other than mgmt links.
857 :param node: Node topology dictionary.
858 :param filter_list: Link filter criteria.
859 :param topo_has_dut: Whether we require back-to-back links.
861 :type filter_list: list of strings
862 :type topo_has_dut: bool
863 :returns: List of link names occupied by the node.
864 :rtype: None or list of string
866 interfaces = node[u"interfaces"]
868 for interface in interfaces.values():
869 if u"link" in interface:
870 if (filter_list is not None) and (u"model" in interface):
871 for filt in filter_list:
872 if filt == interface[u"model"]:
873 link_names.append(interface[u"link"])
874 elif (filter_list is not None) and (u"model" not in interface):
876 f"Cannot apply filter on interface: {str(interface)}"
879 link_names.append(interface[u"link"])
883 new_link_names = list()
884 for link_name in link_names:
886 for interface in interfaces.values():
887 link = interface.get(u"link", None)
888 if link == link_name:
891 new_link_names.append(link_name)
892 link_names = new_link_names
895 def get_active_connecting_links(
896 self, node1, node2, filter_list_node1=None, filter_list_node2=None):
897 """Return list of link names that connect together node1 and node2.
899 :param node1: Node topology dictionary.
900 :param node2: Node topology dictionary.
901 :param filter_list_node1: Link filter criteria for node1.
902 :param filter_list_node2: Link filter criteria for node2.
905 :type filter_list_node1: list of strings
906 :type filter_list_node2: list of strings
907 :returns: List of strings that represent connecting link names.
912 node1_links = self._get_node_active_link_names(
913 node1, filter_list=filter_list_node1
915 node2_links = self._get_node_active_link_names(
916 node2, filter_list=filter_list_node2
919 # Looking for back-to-back links.
920 node1_links = self._get_node_active_link_names(
921 node1, filter_list=filter_list_node1, topo_has_dut=False
923 node2_links = node1_links
925 connecting_links = None
926 if node1_links is None:
927 logger.error(u"Unable to find active links for node1")
928 elif node2_links is None:
929 logger.error(u"Unable to find active links for node2")
931 # Not using set operations, as we need deterministic order.
933 link for link in node1_links if link in node2_links
936 return connecting_links
938 def get_first_active_connecting_link(self, node1, node2):
939 """Get first link connecting the two nodes together.
941 :param node1: Connected node.
942 :param node2: Connected node.
945 :returns: Name of a link connecting the two nodes together.
947 :raises RuntimeError: If no links are found.
949 connecting_links = self.get_active_connecting_links(node1, node2)
950 if not connecting_links:
951 raise RuntimeError(u"No links connecting the nodes were found")
952 return connecting_links[0]
954 def get_egress_interfaces_name_for_nodes(self, node1, node2):
955 """Get egress interfaces on node1 for link with node2.
957 :param node1: First node, node to get egress interface on.
958 :param node2: Second node.
961 :returns: Egress interfaces.
965 links = self.get_active_connecting_links(node1, node2)
967 raise RuntimeError(u"No link between nodes")
968 for interface in node1[u"interfaces"].values():
969 link = interface.get(u"link")
974 name = interface.get(u"name")
977 interfaces.append(name)
980 def get_first_egress_interface_for_nodes(self, node1, node2):
981 """Get first egress interface on node1 for link with node2.
983 :param node1: First node, node to get egress interface name on.
984 :param node2: Second node.
987 :returns: Egress interface name.
990 interfaces = self.get_egress_interfaces_name_for_nodes(node1, node2)
992 raise RuntimeError(u"No egress interface for nodes")
995 def get_links_dict_from_nodes(self, tgen, dut1, dut2):
996 """Return link combinations used in tests in circular topology.
998 For the time being it returns links from the Node path:
1000 The naming convention until changed to something more general is
1001 implemented is this:
1002 DUT1_DUT2_LINK: link name between DUT! and DUT2
1003 DUT1_TG_LINK: link name between DUT1 and TG
1004 DUT2_TG_LINK: link name between DUT2 and TG
1005 TG_TRAFFIC_LINKS: list of link names that generated traffic is sent
1007 DUT1_BD_LINKS: list of link names that will be connected by the bridge
1009 DUT2_BD_LINKS: list of link names that will be connected by the bridge
1012 :param tgen: Traffic generator node data.
1013 :param dut1: DUT1 node data.
1014 :param dut2: DUT2 node data.
1018 :returns: Dictionary of possible link combinations.
1021 # TODO: replace with generic function.
1022 dut1_dut2_link = self.get_first_active_connecting_link(dut1, dut2)
1023 dut1_tg_link = self.get_first_active_connecting_link(dut1, tgen)
1024 dut2_tg_link = self.get_first_active_connecting_link(dut2, tgen)
1025 tg_traffic_links = [dut1_tg_link, dut2_tg_link]
1026 dut1_bd_links = [dut1_dut2_link, dut1_tg_link]
1027 dut2_bd_links = [dut1_dut2_link, dut2_tg_link]
1029 u"DUT1_DUT2_LINK": dut1_dut2_link,
1030 u"DUT1_TG_LINK": dut1_tg_link,
1031 u"DUT2_TG_LINK": dut2_tg_link,
1032 u"TG_TRAFFIC_LINKS": tg_traffic_links,
1033 u"DUT1_BD_LINKS": dut1_bd_links,
1034 u"DUT2_BD_LINKS": dut2_bd_links
1036 return topology_links
1039 def is_tg_node(node):
1040 """Find out whether the node is TG.
1042 :param node: Node to examine.
1044 :returns: True if node is type of TG, otherwise False.
1047 return node[u"type"] == NodeType.TG
1050 def get_node_hostname(node):
1051 """Return host (hostname/ip address) of the node.
1053 :param node: Node created from topology.
1055 :returns: Hostname or IP address.
1058 return node[u"host"]
1061 def get_node_arch(node):
1062 """Return arch of the node.
1063 Default to x86_64 if no arch present
1065 :param node: Node created from topology.
1067 :returns: Node architecture
1071 return node[u"arch"]
1073 node[u"arch"] = u"x86_64"
1077 def get_cryptodev(node):
1078 """Return Crytodev configuration of the node.
1080 :param node: Node created from topology.
1082 :returns: Cryptodev configuration string.
1086 return node[u"cryptodev"]
1091 def get_uio_driver(node):
1092 """Return uio-driver configuration of the node.
1094 :param node: Node created from topology.
1096 :returns: uio-driver configuration string.
1100 return node[u"uio_driver"]
1105 def set_interface_numa_node(node, iface_key, numa_node_id):
1106 """Set interface numa_node location.
1108 :param node: Node to set numa_node on.
1109 :param iface_key: Interface key from topology file.
1110 :param numa_node_id: Num_node ID.
1112 :type iface_key: str
1113 :type numa_node_id: int
1114 :returns: Return iface_key or None if not found.
1117 node[u"interfaces"][iface_key][u"numa_node"] = numa_node_id
1123 def add_new_socket(node, socket_type, socket_id, socket_path):
1124 """Add socket file of specific SocketType and ID to node.
1126 :param node: Node to add socket on.
1127 :param socket_type: Socket type.
1128 :param socket_id: Socket id, currently equals to unique node key.
1129 :param socket_path: Socket absolute path.
1131 :type socket_type: SocketType
1132 :type socket_id: str
1133 :type socket_path: str
1135 path = [u"sockets", socket_type, socket_id]
1136 Topology.add_node_item(node, socket_path, path)
1139 def del_node_socket_id(node, socket_type, socket_id):
1140 """Delete socket of specific SocketType and ID from node.
1142 :param node: Node to delete socket from.
1143 :param socket_type: Socket type.
1144 :param socket_id: Socket id, currently equals to unique node key.
1146 :type socket_type: SocketType
1147 :type socket_id: str
1149 node[u"sockets"][socket_type].pop(socket_id)
1152 def get_node_sockets(node, socket_type=None):
1153 """Get node socket files.
1155 :param node: Node to get sockets from.
1156 :param socket_type: Socket type or None for all sockets.
1158 :type socket_type: SocketType
1159 :returns: Node sockets or None if not found.
1164 return node[u"sockets"][socket_type]
1165 return node[u"sockets"]
1170 def clean_sockets_on_all_nodes(nodes):
1171 """Remove temporary socket files from topology file.
1173 :param nodes: SUT nodes.
1176 for node in nodes.values():
1177 if u"sockets" in list(node.keys()):
1178 # Containers are disconnected and destroyed already.
1179 node.pop(u"sockets")