1 # Copyright (c) 2020 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)
76 DICT__nodes = load_topo_from_yaml()
80 """Topology data manipulation and extraction methods.
82 Defines methods used for manipulation and extraction of data from
85 "Active topology" contains initially data from the topology file and can be
86 extended with additional data from the DUTs like internal interface indexes
87 or names. Additional data which can be filled to the active topology are
89 - additional internal representation (index, name, ...)
90 - operational data (dynamic ports)
92 To access the port data it is recommended to use a port key because the key
93 does not rely on the data retrieved from nodes, this allows to call most of
94 the methods without having filled active topology with internal nodes data.
97 def add_node_item(node, value, path):
98 """Add item to topology node.
100 :param node: Topology node.
101 :param value: Value to insert.
102 :param path: Path where to insert item.
108 node[path[0]] = value
110 if path[0] not in node:
111 node[path[0]] = dict()
112 elif isinstance(node[path[0]], str):
113 node[path[0]] = dict() if node[path[0]] == u"" \
114 else {node[path[0]]: u""}
115 Topology.add_node_item(node[path[0]], value, path[1:])
118 def add_new_port(node, ptype):
119 """Add new port to the node to active topology.
121 :param node: Node to add new port on.
122 :param ptype: Port type, used as key prefix.
125 :returns: Port key or None
126 :rtype: string or None
130 for i in range(1, max_ports):
131 if node[u"interfaces"].get(str(ptype) + str(i)) is None:
132 iface = str(ptype) + str(i)
133 node[u"interfaces"][iface] = dict()
138 def remove_port(node, iface_key):
139 """Remove required port from active topology.
141 :param node: Node to remove port on.
142 :param: iface_key: Topology key of the interface.
148 node[u"interfaces"].pop(iface_key)
153 def remove_all_ports(node, ptype):
154 """Remove all ports with ptype as prefix.
156 :param node: Node to remove ports on.
157 :param: ptype: Port type, used as key prefix.
162 for if_key in list(node[u"interfaces"]):
163 if if_key.startswith(str(ptype)):
164 node[u"interfaces"].pop(if_key)
167 def remove_all_added_ports_on_all_duts_from_topology(nodes):
168 """Remove all added ports on all DUT nodes in the topology.
170 :param nodes: Nodes in the topology.
175 u"subinterface", u"vlan_subif", u"memif", u"tap", u"vhost",
176 u"loopback", u"gre_tunnel", u"vxlan_tunnel", u"eth_bond",
177 u"eth_avf", u"eth_rdma", u"geneve_tunnel"
180 for node_data in nodes.values():
181 if node_data[u"type"] == NodeType.DUT:
182 for ptype in port_types:
183 Topology.remove_all_ports(node_data, ptype)
186 def remove_all_vif_ports(node):
187 """Remove all Virtual Interfaces on DUT node.
189 :param node: Node to remove VIF ports on.
193 reg_ex = re.compile(r"port\d+_vif\d+")
194 for if_key in list(node[u"interfaces"]):
195 if re.match(reg_ex, if_key):
196 node[u"interfaces"].pop(if_key)
199 def remove_all_added_vif_ports_on_all_duts_from_topology(nodes):
200 """Remove all added Virtual Interfaces on all DUT nodes in
203 :param nodes: Nodes in the topology.
207 for node_data in nodes.values():
208 if node_data[u"type"] == NodeType.DUT:
209 Topology.remove_all_vif_ports(node_data)
212 def update_interface_sw_if_index(node, iface_key, sw_if_index):
213 """Update sw_if_index on the interface from the node.
215 :param node: Node to update sw_if_index on.
216 :param iface_key: Topology key of the interface.
217 :param sw_if_index: Internal index to store.
220 :type sw_if_index: int
222 node[u"interfaces"][iface_key][u"vpp_sw_index"] = int(sw_if_index)
225 def update_interface_name(node, iface_key, name):
226 """Update name on the interface from the node.
228 :param node: Node to update name on.
229 :param iface_key: Topology key of the interface.
230 :param name: Interface name to store.
235 node[u"interfaces"][iface_key][u"name"] = str(name)
238 def update_interface_mac_address(node, iface_key, mac_address):
239 """Update mac_address on the interface from the node.
241 :param node: Node to update MAC on.
242 :param iface_key: Topology key of the interface.
243 :param mac_address: MAC address.
246 :type mac_address: str
248 node[u"interfaces"][iface_key][u"mac_address"] = str(mac_address)
251 def update_interface_pci_address(node, iface_key, pci_address):
252 """Update pci_address on the interface from the node.
254 :param node: Node to update PCI on.
255 :param iface_key: Topology key of the interface.
256 :param pci_address: PCI address.
259 :type pci_address: str
261 node[u"interfaces"][iface_key][u"pci_address"] = str(pci_address)
264 def update_interface_vlan(node, iface_key, vlan):
265 """Update VLAN on the interface from the node.
267 :param node: Node to update VLAN on.
268 :param iface_key: Topology key of the interface.
269 :param vlan: VLAN ID.
274 node[u"interfaces"][iface_key][u"vlan"] = int(vlan)
277 def update_interface_vhost_socket(node, iface_key, vhost_socket):
278 """Update vhost socket name on the interface from the node.
280 :param node: Node to update socket name on.
281 :param iface_key: Topology key of the interface.
282 :param vhost_socket: Path to named socket on node.
285 :type vhost_socket: str
287 node[u"interfaces"][iface_key][u"vhost_socket"] = str(vhost_socket)
290 def update_interface_memif_socket(node, iface_key, memif_socket):
291 """Update memif socket name on the interface from the node.
293 :param node: Node to update socket name on.
294 :param iface_key: Topology key of the interface.
295 :param memif_socket: Path to named socket on node.
298 :type memif_socket: str
300 node[u"interfaces"][iface_key][u"memif_socket"] = str(memif_socket)
303 def update_interface_memif_id(node, iface_key, memif_id):
304 """Update memif ID on the interface from the node.
306 :param node: Node to update memif ID on.
307 :param iface_key: Topology key of the interface.
308 :param memif_id: Memif interface ID.
313 node[u"interfaces"][iface_key][u"memif_id"] = str(memif_id)
316 def update_interface_memif_role(node, iface_key, memif_role):
317 """Update memif role on the interface from the node.
319 :param node: Node to update memif role on.
320 :param iface_key: Topology key of the interface.
321 :param memif_role: Memif role.
324 :type memif_role: str
326 node[u"interfaces"][iface_key][u"memif_role"] = str(memif_role)
329 def update_interface_tap_dev_name(node, iface_key, dev_name):
330 """Update device name on the tap interface from the node.
332 :param node: Node to update tap device name on.
333 :param iface_key: Topology key of the interface.
334 :param dev_name: Device name of the tap interface.
340 node[u"interfaces"][iface_key][u"dev_name"] = str(dev_name)
343 def get_node_by_hostname(nodes, hostname):
344 """Get node from nodes of the topology by hostname.
346 :param nodes: Nodes of the test topology.
347 :param hostname: Host name.
350 :returns: Node dictionary or None if not found.
352 for node in nodes.values():
353 if node[u"host"] == hostname:
359 def get_links(nodes):
360 """Get list of links(networks) in the topology.
362 :param nodes: Nodes of the test topology.
364 :returns: Links in the topology.
369 for node in nodes.values():
370 for interface in node[u"interfaces"].values():
371 link = interface.get(u"link")
373 if link not in links:
379 def _get_interface_by_key_value(node, key, value):
380 """Return node interface key from topology file
381 according to key and value.
383 :param node: The node dictionary.
384 :param key: Key by which to select the interface.
385 :param value: Value that should be found using the key.
389 :returns: Interface key from topology file
392 interfaces = node[u"interfaces"]
394 for if_key, if_val in interfaces.items():
395 k_val = if_val.get(key)
396 if k_val is not None:
403 def get_interface_by_name(node, iface_name):
404 """Return interface key based on name from DUT/TG.
406 This method returns interface key based on interface name
407 retrieved from the DUT, or TG.
409 :param node: The node topology dictionary.
410 :param iface_name: Interface name (string form).
412 :type iface_name: string
413 :returns: Interface key.
416 return Topology._get_interface_by_key_value(node, u"name", iface_name)
419 def get_interface_by_link_name(node, link_name):
420 """Return interface key of link on node.
422 This method returns the interface name associated with a given link
425 :param node: The node topology dictionary.
426 :param link_name: Name of the link that a interface is connected to.
428 :type link_name: string
429 :returns: Interface key of the interface connected to the given link.
432 return Topology._get_interface_by_key_value(node, u"link", link_name)
434 def get_interfaces_by_link_names(self, node, link_names):
435 """Return dictionary of dictionaries {"interfaceN", interface name}.
437 This method returns the interface names associated with given links
440 :param node: The node topology directory.
441 :param link_names: List of names of the link that a interface is
444 :type link_names: list
445 :returns: Dictionary of interface names that are connected to the given
451 for link_name in link_names:
452 interface = self.get_interface_by_link_name(node, link_name)
453 retval[f"interface{str(interface_number)}"] = \
454 self.get_interface_name(node, interface)
455 interface_number += 1
459 def get_interface_by_sw_index(node, sw_if_index):
460 """Return interface name of link on node.
462 This method returns the interface name associated with a software
463 interface index assigned to the interface by vpp for a given node.
465 :param node: The node topology dictionary.
466 :param sw_if_index: sw_if_index of the link that a interface is
469 :type sw_if_index: int
470 :returns: Interface name of the interface connected to the given link.
473 return Topology._get_interface_by_key_value(
474 node, u"vpp_sw_index", sw_if_index
478 def get_interface_sw_index(node, iface_key):
479 """Get VPP sw_if_index for the interface using interface key.
481 :param node: Node to get interface sw_if_index on.
482 :param iface_key: Interface key from topology file, or sw_if_index.
484 :type iface_key: str/int
485 :returns: Return sw_if_index or None if not found.
489 if isinstance(iface_key, str):
490 return node[u"interfaces"][iface_key].get(u"vpp_sw_index")
491 # TODO: use only iface_key, do not use integer
492 return int(iface_key)
493 except (KeyError, ValueError):
497 def get_interface_sw_index_by_name(node, iface_name):
498 """Get VPP sw_if_index for the interface using interface name.
500 :param node: Node to get interface sw_if_index on.
501 :param iface_name: Interface name.
503 :type iface_name: str
504 :returns: Return sw_if_index or None if not found.
505 :raises TypeError: If provided interface name is not a string.
508 if not isinstance(iface_name, str):
509 raise TypeError(u"Interface name must be a string.")
510 iface_key = Topology.get_interface_by_name(node, iface_name)
511 return node[u"interfaces"][iface_key].get(u"vpp_sw_index")
512 except (KeyError, ValueError):
516 def get_interface_mtu(node, iface_key):
517 """Get interface MTU.
519 Returns physical layer MTU (max. size of Ethernet frame).
520 :param node: Node to get interface MTU on.
521 :param iface_key: Interface key from topology file.
524 :returns: MTU or None if not found.
528 return node[u"interfaces"][iface_key].get(u"mtu")
533 def get_interface_name(node, iface_key):
534 """Get interface name (retrieved from DUT/TG).
536 Returns name in string format, retrieved from the node.
537 :param node: Node to get interface name on.
538 :param iface_key: Interface key from topology file.
541 :returns: Interface name or None if not found.
545 return node[u"interfaces"][iface_key].get(u"name")
550 def convert_interface_reference_to_key(node, interface):
551 """Takes interface reference in any format
552 (name, link name, interface key or sw_if_index)
553 and converts to interface key using Topology methods.
555 :param node: Node in topology.
556 :param interface: Name, sw_if_index, link name or key of an interface
559 :type interface: str or int
561 :returns: Interface key.
564 :raises TypeError: If provided with invalid interface argument.
565 :raises RuntimeError: If the interface does not exist in topology.
568 if isinstance(interface, int):
569 key = Topology.get_interface_by_sw_index(node, interface)
572 f"Interface with sw_if_index={interface} does not exist "
575 elif interface in Topology.get_node_interfaces(node):
577 elif interface in Topology.get_links({u"dut": node}):
578 key = Topology.get_interface_by_link_name(node, interface)
579 elif isinstance(interface, str):
580 key = Topology.get_interface_by_name(node, interface)
583 f"Interface with key, name or link name \"{interface}\" "
584 f"does not exist in topology."
588 u"Type of interface argument must be integer or string."
593 def convert_interface_reference(node, interface, wanted_format):
594 """Takes interface reference in any format
595 (name, link name, topology key or sw_if_index) and returns
596 its equivalent in the desired format.
598 :param node: Node in topology.
599 :param interface: Name, sw_if_index, link name or key of an interface
601 :param wanted_format: Format of return value wanted.
602 Valid options are: sw_if_index, key, name.
604 :type interface: str or int
605 :type wanted_format: str
606 :returns: Interface name, interface key or sw_if_index.
608 :raises TypeError, ValueError: If provided with invalid arguments.
609 :raises RuntimeError: If the interface does not exist in topology.
612 key = Topology.convert_interface_reference_to_key(node, interface)
615 u"key": lambda x, y: y,
616 u"name": Topology.get_interface_name,
617 u"sw_if_index": Topology.get_interface_sw_index
621 return conversions[wanted_format](node, key)
624 f"Unrecognized return value wanted: {wanted_format}."
625 f"Valid options are key, name, sw_if_index"
629 def get_interface_numa_node(node, iface_key):
630 """Get interface numa node.
632 Returns physical relation to numa node, numa_id.
634 :param node: Node to get numa id on.
635 :param iface_key: Interface key from topology file.
638 :returns: numa node id, None if not available.
642 return node[u"interfaces"][iface_key].get(u"numa_node")
647 def get_interfaces_numa_node(node, *iface_keys):
648 """Get numa node on which are located most of the interfaces.
650 Return numa node with highest count of interfaces provided as arguments.
651 Return 0 if the interface does not have numa_node information available.
652 If all interfaces have unknown location (-1), then return 0.
653 If most of interfaces have unknown location (-1), but there are
654 some interfaces with known location, then return the second most
655 location of the provided interfaces.
657 :param node: Node from DICT__nodes.
658 :param iface_keys: Interface keys for lookup.
660 :type iface_keys: strings
661 :returns: Numa node of most given interfaces or 0.
665 for if_key in iface_keys:
667 numa_list.append(node[u"interfaces"][if_key].get(u"numa_node"))
671 numa_cnt_mc = Counter(numa_list).most_common()
673 if numa_cnt_mc and numa_cnt_mc[0][0] != -1:
674 return numa_cnt_mc[0][0]
675 if len(numa_cnt_mc) > 1 and numa_cnt_mc[0][0] == -1:
676 return numa_cnt_mc[1][0]
680 def get_interface_mac(node, iface_key):
681 """Get MAC address for the interface.
683 :param node: Node to get interface mac on.
684 :param iface_key: Interface key from topology file.
687 :returns: Return MAC or None if not found.
690 return node[u"interfaces"][iface_key].get(u"mac_address")
695 def get_interface_ip4(node, iface_key):
696 """Get IP4 address for the interface.
698 :param node: Node to get interface mac on.
699 :param iface_key: Interface key from topology file.
702 :returns: Return IP4 or None if not found.
705 return node[u"interfaces"][iface_key].get(u"ip4_address")
710 def get_interface_ip4_prefix_length(node, iface_key):
711 """Get IP4 address prefix length for the interface.
713 :param node: Node to get prefix length on.
714 :param iface_key: Interface key from topology file.
717 :returns: Prefix length from topology file or the default
718 IP4 prefix length if not found.
720 :raises: KeyError if iface_key is not found.
722 return node[u"interfaces"][iface_key].get(u"ip4_prefix_length", \
723 Constants.DEFAULT_IP4_PREFIX_LENGTH)
726 def get_adjacent_node_and_interface(nodes_info, node, iface_key):
727 """Get node and interface adjacent to specified interface
730 :param nodes_info: Dictionary containing information on all nodes
732 :param node: Node that contains specified interface.
733 :param iface_key: Interface key from topology file.
734 :type nodes_info: dict
737 :returns: Return (node, interface_key) tuple or None if not found.
741 # get link name where the interface belongs to
742 for if_key, if_val in node[u"interfaces"].items():
743 if if_key == u"mgmt":
745 if if_key == iface_key:
746 link_name = if_val[u"link"]
749 if link_name is None:
753 for node_data in nodes_info.values():
755 if node_data[u"host"] == node[u"host"]:
758 in node_data[u"interfaces"].items():
759 if u"link" not in if_val:
761 if if_val[u"link"] == link_name:
762 return node_data, if_key
766 def get_interface_pci_addr(node, iface_key):
767 """Get interface PCI address.
769 :param node: Node to get interface PCI address on.
770 :param iface_key: Interface key from topology file.
773 :returns: Return PCI address or None if not found.
776 return node[u"interfaces"][iface_key].get(u"pci_address")
781 def get_interface_driver(node, iface_key):
782 """Get interface driver.
784 :param node: Node to get interface driver on.
785 :param iface_key: Interface key from topology file.
788 :returns: Return interface driver or None if not found.
791 return node[u"interfaces"][iface_key].get(u"driver")
796 def get_interface_vlan(node, iface_key):
797 """Get interface vlan.
799 :param node: Node to get interface driver on.
800 :param iface_key: Interface key from topology file.
803 :returns: Return interface vlan or None if not found.
806 return node[u"interfaces"][iface_key].get(u"vlan")
811 def get_node_interfaces(node):
812 """Get all node interfaces.
814 :param node: Node to get list of interfaces from.
816 :returns: Return list of keys of all interfaces.
819 return node[u"interfaces"].keys()
822 def get_node_link_mac(node, link_name):
823 """Return interface mac address by link name.
825 :param node: Node to get interface sw_if_index on.
826 :param link_name: Link name.
829 :returns: MAC address string.
832 for port in node[u"interfaces"].values():
833 if port.get(u"link") == link_name:
834 return port.get(u"mac_address")
838 def _get_node_active_link_names(node, filter_list=None):
839 """Return list of link names that are other than mgmt links.
841 :param node: Node topology dictionary.
842 :param filter_list: Link filter criteria.
844 :type filter_list: list of strings
845 :returns: List of link names occupied by the node.
846 :rtype: None or list of string
848 interfaces = node[u"interfaces"]
850 for interface in interfaces.values():
851 if u"link" in interface:
852 if (filter_list is not None) and (u"model" in interface):
853 for filt in filter_list:
854 if filt == interface[u"model"]:
855 link_names.append(interface[u"link"])
856 elif (filter_list is not None) and (u"model" not in interface):
858 f"Cannot apply filter on interface: {str(interface)}"
861 link_names.append(interface[u"link"])
866 def get_active_connecting_links(
867 self, node1, node2, filter_list_node1=None, filter_list_node2=None):
868 """Return list of link names that connect together node1 and node2.
870 :param node1: Node topology dictionary.
871 :param node2: Node topology dictionary.
872 :param filter_list_node1: Link filter criteria for node1.
873 :param filter_list_node2: Link filter criteria for node2.
876 :type filter_list_node1: list of strings
877 :type filter_list_node2: list of strings
878 :returns: List of strings that represent connecting link names.
882 node1_links = self._get_node_active_link_names(
883 node1, filter_list=filter_list_node1
885 node2_links = self._get_node_active_link_names(
886 node2, filter_list=filter_list_node2
889 connecting_links = None
890 if node1_links is None:
891 logger.error(u"Unable to find active links for node1")
892 elif node2_links is None:
893 logger.error(u"Unable to find active links for node2")
895 # Not using set operations, as we need deterministic order.
897 link for link in node1_links if link in node2_links
900 return connecting_links
902 def get_first_active_connecting_link(self, node1, node2):
903 """Get first link connecting the two nodes together.
905 :param node1: Connected node.
906 :param node2: Connected node.
909 :returns: Name of a link connecting the two nodes together.
911 :raises RuntimeError: If no links are found.
913 connecting_links = self.get_active_connecting_links(node1, node2)
914 if not connecting_links:
915 raise RuntimeError(u"No links connecting the nodes were found")
916 return connecting_links[0]
918 def get_egress_interfaces_name_for_nodes(self, node1, node2):
919 """Get egress interfaces on node1 for link with node2.
921 :param node1: First node, node to get egress interface on.
922 :param node2: Second node.
925 :returns: Egress interfaces.
929 links = self.get_active_connecting_links(node1, node2)
931 raise RuntimeError(u"No link between nodes")
932 for interface in node1[u"interfaces"].values():
933 link = interface.get(u"link")
938 name = interface.get(u"name")
941 interfaces.append(name)
944 def get_first_egress_interface_for_nodes(self, node1, node2):
945 """Get first egress interface on node1 for link with node2.
947 :param node1: First node, node to get egress interface name on.
948 :param node2: Second node.
951 :returns: Egress interface name.
954 interfaces = self.get_egress_interfaces_name_for_nodes(node1, node2)
956 raise RuntimeError(u"No egress interface for nodes")
959 def get_links_dict_from_nodes(self, tgen, dut1, dut2):
960 """Return link combinations used in tests in circular topology.
962 For the time being it returns links from the Node path:
964 The naming convention until changed to something more general is
966 DUT1_DUT2_LINK: link name between DUT! and DUT2
967 DUT1_TG_LINK: link name between DUT1 and TG
968 DUT2_TG_LINK: link name between DUT2 and TG
969 TG_TRAFFIC_LINKS: list of link names that generated traffic is sent
971 DUT1_BD_LINKS: list of link names that will be connected by the bridge
973 DUT2_BD_LINKS: list of link names that will be connected by the bridge
976 :param tgen: Traffic generator node data.
977 :param dut1: DUT1 node data.
978 :param dut2: DUT2 node data.
982 :returns: Dictionary of possible link combinations.
985 # TODO: replace with generic function.
986 dut1_dut2_link = self.get_first_active_connecting_link(dut1, dut2)
987 dut1_tg_link = self.get_first_active_connecting_link(dut1, tgen)
988 dut2_tg_link = self.get_first_active_connecting_link(dut2, tgen)
989 tg_traffic_links = [dut1_tg_link, dut2_tg_link]
990 dut1_bd_links = [dut1_dut2_link, dut1_tg_link]
991 dut2_bd_links = [dut1_dut2_link, dut2_tg_link]
993 u"DUT1_DUT2_LINK": dut1_dut2_link,
994 u"DUT1_TG_LINK": dut1_tg_link,
995 u"DUT2_TG_LINK": dut2_tg_link,
996 u"TG_TRAFFIC_LINKS": tg_traffic_links,
997 u"DUT1_BD_LINKS": dut1_bd_links,
998 u"DUT2_BD_LINKS": dut2_bd_links
1000 return topology_links
1003 def is_tg_node(node):
1004 """Find out whether the node is TG.
1006 :param node: Node to examine.
1008 :returns: True if node is type of TG, otherwise False.
1011 return node[u"type"] == NodeType.TG
1014 def get_node_hostname(node):
1015 """Return host (hostname/ip address) of the node.
1017 :param node: Node created from topology.
1019 :returns: Hostname or IP address.
1022 return node[u"host"]
1025 def get_node_arch(node):
1026 """Return arch of the node.
1027 Default to x86_64 if no arch present
1029 :param node: Node created from topology.
1031 :returns: Node architecture
1035 return node[u"arch"]
1037 node[u"arch"] = u"x86_64"
1041 def get_cryptodev(node):
1042 """Return Crytodev configuration of the node.
1044 :param node: Node created from topology.
1046 :returns: Cryptodev configuration string.
1050 return node[u"cryptodev"]
1055 def get_uio_driver(node):
1056 """Return uio-driver configuration of the node.
1058 :param node: Node created from topology.
1060 :returns: uio-driver configuration string.
1064 return node[u"uio_driver"]
1069 def set_interface_numa_node(node, iface_key, numa_node_id):
1070 """Set interface numa_node location.
1072 :param node: Node to set numa_node on.
1073 :param iface_key: Interface key from topology file.
1074 :param numa_node_id: Num_node ID.
1076 :type iface_key: str
1077 :type numa_node_id: int
1078 :returns: Return iface_key or None if not found.
1081 node[u"interfaces"][iface_key][u"numa_node"] = numa_node_id
1087 def add_new_socket(node, socket_type, socket_id, socket_path):
1088 """Add socket file of specific SocketType and ID to node.
1090 :param node: Node to add socket on.
1091 :param socket_type: Socket type.
1092 :param socket_id: Socket id, currently equals to unique node key.
1093 :param socket_path: Socket absolute path.
1095 :type socket_type: SocketType
1096 :type socket_id: str
1097 :type socket_path: str
1099 path = [u"sockets", socket_type, socket_id]
1100 Topology.add_node_item(node, socket_path, path)
1103 def del_node_socket_id(node, socket_type, socket_id):
1104 """Delete socket of specific SocketType and ID from node.
1106 :param node: Node to delete socket from.
1107 :param socket_type: Socket type.
1108 :param socket_id: Socket id, currently equals to unique node key.
1110 :type socket_type: SocketType
1111 :type socket_id: str
1113 node[u"sockets"][socket_type].pop(socket_id)
1116 def get_node_sockets(node, socket_type=None):
1117 """Get node socket files.
1119 :param node: Node to get sockets from.
1120 :param socket_type: Socket type or None for all sockets.
1122 :type socket_type: SocketType
1123 :returns: Node sockets or None if not found.
1128 return node[u"sockets"][socket_type]
1129 return node[u"sockets"]
1134 def clean_sockets_on_all_nodes(nodes):
1135 """Remove temporary socket files from topology file.
1137 :param nodes: SUT nodes.
1140 for node in nodes.values():
1141 if u"sockets" in list(node.keys()):
1142 # Containers are disconnected and destroyed already.
1143 node.pop(u"sockets")