Skip to content

Commit

Permalink
Merge pull request #87 from fabric-testbed/issue-86
Browse files Browse the repository at this point in the history
Issue 86
  • Loading branch information
ibaldin authored Sep 27, 2021
2 parents 9768727 + 14bfa21 commit 6f01e20
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 22 deletions.
2 changes: 1 addition & 1 deletion fim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#
__VERSION__ = "1.0.5"
__VERSION__ = "1.0.7"
2 changes: 1 addition & 1 deletion fim/user/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, *, name: str, node_id: str = None, topo: Any,
raise RuntimeError(f"Component with this id and name {name} doesn't exist")

@property
def ctype(self):
def type(self):
return self.get_property('type') if self.__dict__.get('topo', None) is not None else None

@property
Expand Down
55 changes: 35 additions & 20 deletions fim/user/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def get_parent_element(self, e: ModelElement) -> ModelElement or None:
parent=ABCPropertyGraph.CLASS_NetworkNode)
if node_id is not None:
return Node(name=node_name, node_id=node_id, topo=self)
else:
return None

node_name, node_id = self.graph_model.get_parent(node_id=e.node_id,
rel=ABCPropertyGraph.REL_HAS,
parent=ABCPropertyGraph.CLASS_CompositeNode)
if node_id is not None:
return CompositeNode(name=node_name, node_id=node_id, topo=self)
# interfaces have NSs as parents
if isinstance(e, Interface):
node_name, node_id = self.graph_model.get_parent(node_id=e.node_id,
Expand Down Expand Up @@ -516,23 +520,23 @@ def __str__(self):
"""
lines = list()
for n in self.nodes.values():
lines.append(n.name + "[" + str(n.get_property("type")) + ", " +
str(n.get_property("site")) + "]: " +
self.__print_caplabs__(n.get_property("capacities")))
lines.append(n.name + "[" + str(n.type) + ", " +
str(n.site) + "]: " +
self.__print_caplabs__(n.capacities))
for i in n.direct_interfaces.values():
lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " +
self.__print_caplabs__(i.get_property("capacities")) + " " +
self.__print_caplabs__(i.get_property("labels")))
lines.append("\t\t" + i.name + ": " + str(i.type) + " " +
self.__print_caplabs__(i.capacities) + " " +
self.__print_caplabs__(i.labels))
for c in n.components.values():
lines.append("\t" + c.name + ": " + " " + str(c.get_property("type")) + " " +
c.get_property("model"))
lines.append("\t" + c.name + ": " + " " + str(c.type) + " " +
c.model)
for i in c.interfaces.values():
lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " +
self.__print_caplabs__(i.get_property("capacities")))
lines.append("\t\t" + i.name + ": " + str(i.type) + " " +
self.__print_caplabs__(i.capacities))
lines.append("Links:")
for l in self.links.values():
interface_names = [iff.name for iff in l.interface_list]
lines.append("\t" + l.name + "[" + str(l.get_property("type")) + "]: " +
lines.append("\t" + l.name + "[" + str(l.type) + "]: " +
str(interface_names))

return "\n".join(lines)
Expand Down Expand Up @@ -750,6 +754,14 @@ def __list_links(self) -> ViewOnlyDict:
def sites(self):
return self.__list_sites()

@property
def nodes(self):
"""
Same as sites property
:return:
"""
return self.__list_sites()

@property
def links(self):
return self.__list_links()
Expand Down Expand Up @@ -841,28 +853,31 @@ def __str__(self):
"""
lines = list()
for n in self.sites.values():
tot_cap = n.get_property("capacities")
alloc_cap = n.get_property("capacity_allocations")
if tot_cap is not None and alloc_cap is not None:
tot_cap = n.capacities
alloc_cap = n.get_property('capacity_allocations')
if alloc_cap is None:
# if nothing is allocated, just zero out
alloc_cap = Capacities()
if tot_cap is not None:
ncp = CapacityTuple(total=tot_cap, allocated=alloc_cap)
lines.append(n.name + ": " + str(ncp))
else:
lines.append(n.name)
lines.append("\tComponents:")
for c in n.components.values():
ccp = CapacityTuple(total=c.get_property("capacities"),
ccp = CapacityTuple(total=c.capacities,
allocated=c.get_property("capacity_allocations"))
lines.append("\t\t" + c.name + ": " + " " + str(c.get_property("type")) + " " +
c.get_property("model") + " " + str(ccp))
c.model + " " + str(ccp))
lines.append("\tSite Interfaces:")
for i in n.interfaces.values():
icp = CapacityTuple(total=i.get_property("capacities"),
icp = CapacityTuple(total=i.capacities,
allocated=i.get_property("capacity_allocations"))
lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " +
str(icp))
lines.append("Links:")
for l in self.links.values():
interface_names = [iff.name for iff in l.interface_list]
lines.append("\t" + l.name + "[" + str(l.get_property("type")) + "]: " +
lines.append("\t" + l.name + "[" + str(l.type) + "]: " +
str(interface_names))
return "\n".join(lines)
17 changes: 17 additions & 0 deletions test/ad_topology_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest

import fim.user as f


class SliceTest(unittest.TestCase):

def setUp(self):
pass

def tearDown(self) -> None:
pass

def testAd(self) -> None:
self.topo = f.AdvertisedTopology(graph_file='test/models/advertised_topo.graphml')
self.assertEqual(self.topo.get_owner_node(self.topo.links['port+lbnl-data-sw:HundredGigE0/0/0/0.2401-link'].interface_list[0]).name, 'UKY')

Loading

0 comments on commit 6f01e20

Please sign in to comment.