aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/NodePath.py
diff options
context:
space:
mode:
authorPeter Mikus <pmikus@cisco.com>2020-02-21 22:09:02 +0000
committerPeter Mikus <pmikus@cisco.com>2020-04-06 08:27:39 +0000
commit14a71b74b414df7616ccb5ada3d50ecb90d96bae (patch)
treebfee617c9a4b20ce4c6467ffbbe6c0a15199ba52 /resources/libraries/python/NodePath.py
parent8e601d0f37f715ca4ce55dded8bc27cadfe175c2 (diff)
Improve pf layer
+ Merge single/double link + Introduce _pf{n}[0] variables so we can access physical function same way as virtual function + Cleanup code by moving complex logic to python + Prepare code for multiple vf functions Signed-off-by: Peter Mikus <pmikus@cisco.com> Change-Id: Ic2e74a38bfa146441357de8f0916aeb638941c49
Diffstat (limited to 'resources/libraries/python/NodePath.py')
-rw-r--r--resources/libraries/python/NodePath.py83
1 files changed, 80 insertions, 3 deletions
diff --git a/resources/libraries/python/NodePath.py b/resources/libraries/python/NodePath.py
index 6f08be491b..04e8e5ef3c 100644
--- a/resources/libraries/python/NodePath.py
+++ b/resources/libraries/python/NodePath.py
@@ -13,7 +13,7 @@
"""Path utilities library for nodes in the topology."""
-from resources.libraries.python.topology import Topology
+from resources.libraries.python.topology import Topology, NodeType
class NodePath:
@@ -71,16 +71,18 @@ class NodePath:
self._nodes_filter.append(filter_list)
self._nodes.append(node)
- def append_nodes(self, *nodes):
+ def append_nodes(self, *nodes, filter_list=None):
"""Append nodes to the path.
:param nodes: Nodes to append to the path.
+ :param filter_list: Filter criteria list.
:type nodes: dict
+ :type filter_list: list of strings
.. note:: Node order does matter.
"""
for node in nodes:
- self.append_node(node)
+ self.append_node(node, filter_list=filter_list)
def clear_path(self):
"""Clear path."""
@@ -204,3 +206,78 @@ class NodePath:
if not self._path:
raise RuntimeError(u"No path for topology")
return self._path[-2]
+
+ def compute_circular_topology(self, nodes, filter_list=None, nic_pfs=1):
+ """Return computed circular path.
+
+ :param nodes: Nodes to append to the path.
+ :param filter_list: Filter criteria list.
+ :param nic_pfs: Number of PF of NIC.
+ :type nodes: dict
+ :type filter_list: list of strings
+ :type path_count: int
+ :returns: Topology information dictionary.
+ :rtype: dict
+ """
+ t_dict = dict()
+ duts = [key for key in nodes if u"DUT" in key]
+ t_dict[u"duts"] = duts
+ t_dict[u"duts_count"] = len(duts)
+ t_dict[u"int"] = u"pf"
+
+ for idx in range(0, nic_pfs // 2):
+ self.append_node(nodes[u"TG"])
+ for dut in duts:
+ self.append_node(nodes[dut], filter_list=filter_list)
+ self.append_node(nodes[u"TG"])
+ self.compute_path(always_same_link=False)
+
+ n_idx = 0
+ t_idx = 1
+ d_idx = 0
+ while True:
+ interface, node = self.next_interface()
+ if not interface:
+ break
+ if node[u"type"] == u"TG":
+ n_pfx = f"TG"
+ p_pfx = f"pf{t_idx}"
+ i_pfx = f"if{t_idx}"
+ n_idx = 0
+ t_idx = t_idx + 1
+ else:
+ n_pfx = f"DUT{n_idx // 2 + 1}"
+ p_pfx = f"pf{d_idx % 2 + t_idx - 1}"
+ i_pfx = f"if{d_idx % 2 + t_idx - 1}"
+ n_idx = n_idx + 1
+ d_idx = d_idx + 1
+
+ t_dict[f"{n_pfx}"] = node
+ t_dict[f"{n_pfx}_{p_pfx}"] = [interface]
+ t_dict[f"{n_pfx}_{p_pfx}_mac"] = \
+ [Topology.get_interface_mac(node, interface)]
+ t_dict[f"{n_pfx}_{p_pfx}_vlan"] = \
+ [Topology.get_interface_vlan(node, interface)]
+ t_dict[f"{n_pfx}_{p_pfx}_pci"] = \
+ [Topology.get_interface_pci_addr(node, interface)]
+ t_dict[f"{n_pfx}_{p_pfx}_ip4_addr"] = \
+ [Topology.get_interface_ip4(node, interface)]
+ t_dict[f"{n_pfx}_{p_pfx}_ip4_prefix"] = \
+ [Topology.get_interface_ip4_prefix_length(node, interface)]
+ if f"{n_pfx}_pf_pci" not in t_dict:
+ t_dict[f"{n_pfx}_pf_pci"] = []
+ t_dict[f"{n_pfx}_pf_pci"].append(
+ Topology.get_interface_pci_addr(node, interface))
+ # Backward compatibility below
+ t_dict[f"{n_pfx.lower()}_{i_pfx}"] = interface
+ t_dict[f"{n_pfx.lower()}_{i_pfx}_mac"] = \
+ Topology.get_interface_mac(node, interface)
+ t_dict[f"{n_pfx.lower()}_{i_pfx}_pci"] = \
+ Topology.get_interface_pci_addr(node, interface)
+ t_dict[f"{n_pfx.lower()}_{i_pfx}_ip4_addr"] = \
+ Topology.get_interface_ip4(node, interface)
+ t_dict[f"{n_pfx.lower()}_{i_pfx}_ip4_prefix"] = \
+ Topology.get_interface_ip4_prefix_length(node, interface)
+
+ self.clear_path()
+ return t_dict