Skip to content

Commit

Permalink
Adding ability to have multiple interfaces on a facility, while prese…
Browse files Browse the repository at this point in the history
…rving the original API with a single interface. This is meant to be used with ASM, primarily, while ARMs can continue using the old way
  • Loading branch information
Ilya Baldin committed Nov 12, 2023
1 parent 8d4b095 commit de698b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
26 changes: 21 additions & 5 deletions fim/user/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from ..graph.resources.neo4j_arm import Neo4jARMGraph
from ..slivers.delegations import Delegation, Delegations, Pools, DelegationType, DelegationFormat
from fim.graph.resources.networkx_abqm import NetworkXAggregateBQM, NetworkXABQMFactory
from fim.slivers.capacities_labels import FreeCapacity, Labels
from fim.slivers.capacities_labels import FreeCapacity, Labels, Capacities
from fim.slivers.interface_info import InterfaceType
from fim.slivers.topology_diff import TopologyDiff, TopologyDiffTuple, TopologyDiffModifiedTuple, WhatsModifiedFlag

Expand Down Expand Up @@ -225,8 +225,11 @@ def remove_node(self, name: str):
self.graph_model.remove_network_node_with_components_nss_cps_and_links(
node_id=self._get_node_by_name(name=name).node_id)

def add_facility(self, *, name: str, node_id: str = None, site: str, nstype: ServiceType = ServiceType.VLAN,
nslabels: Labels or None = None, **kwargs) -> Node:
def add_facility(self, *, name: str, node_id: str = None, site: str,
nstype: ServiceType = ServiceType.VLAN,
nslabels: Labels or None = None,
interfaces: List[Tuple[Any]] or None = None,
**kwargs) -> Node:
"""
Add a facility node with VLAN service and FacilityPort interface as a single construct.
Works for aggregate topologies and experiment topologies the same way.
Expand All @@ -236,14 +239,27 @@ def add_facility(self, *, name: str, node_id: str = None, site: str, nstype: Ser
:param site: site of the facility (must match the advertisement)
:param nstype: alternative type of network service in Facility (defaults to VLAN)
:param nslabels: additional labels for facility network service (defaults to None)
:param interfaces: definitions of interfaces - list of tuples each including (name, labels, capacities) for
each interface a facility will have. If a facility only has one interface it is OK to use **kwargs.
:kwargs: parameters for the interface of the facility (bandwidth, mtu, LAN tags etc)
"""
# should work with deep sliver reconstruction
facn = self.add_node(name=name, node_id=node_id, site=site, ntype=NodeType.Facility)
facs = facn.add_network_service(name=name + '-ns', node_id=node_id + '-ns' if node_id else None,
nstype=nstype, labels=nslabels)
faci = facs.add_interface(name=name + '-int', node_id=node_id + '-int' if node_id else None,
itype=InterfaceType.FacilityPort, **kwargs)
if not interfaces:
# if no interfaces are defined, use implicit definition and kwargs
# this is how the code was defined originally
faci = facs.add_interface(name=name + '-int', node_id=node_id + '-int' if node_id else None,
itype=InterfaceType.FacilityPort, **kwargs)
else:
# if interfaces are defined, assume a list of tuples (name, labels, capacities) are present
# this was added to support multiple interfaces per facility
for iname, ilabels, icapacities in interfaces:
iindex = 0
faci = facs.add_interface(name=iname, node_id=node_id + f'-int{iindex}' if node_id else None,
itype=InterfaceType.FacilityPort, labels=ilabels, capacities=icapacities)
iindex += 1

return facn

Expand Down
27 changes: 27 additions & 0 deletions test/slice_topology_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,33 @@ def testFPGAComponent(self):
asm_graph.validate_graph()
self.n4j_imp.delete_all_graphs()

def testMultiConnectedFacility(self):
t = self.topo

n1 = t.add_node(name='n1', site='MASS')
n1.add_component(name='nic1', model_type=ComponentModelType.SmartNIC_ConnectX_6)
n2 = t.add_node(name='n2', site='RENC')
n2.add_component(name='nic1', model_type=ComponentModelType.SmartNIC_ConnectX_6)

# add facility
fac1 = self.topo.add_facility(name='RENCI-DTN', site='RENC',
interfaces=[('to_mass', f.Labels(vlan='100'), f.Capacities(bw=10)),
('to_renc', f.Labels(vlan='101'), f.Capacities(bw=1))])

t.add_network_service(name='ns1', nstype=ServiceType.L2PTP,
interfaces=[n1.interface_list[0], fac1.interface_list[0]])
t.add_network_service(name='ns2', nstype=ServiceType.L2PTP,
interfaces=[n2.interface_list[0], fac1.interface_list[1]])

print(f'{fac1.interface_list[0].name=}')
print(f'{fac1.interface_list[1].name=}')
self.assertEqual(fac1.interface_list[0].name, 'to_mass')
self.assertEqual(fac1.interface_list[1].name, 'to_renc')

t.validate()

self.n4j_imp.delete_all_graphs()

def testL3VPNWithCloudService(self):
t = self.topo

Expand Down

0 comments on commit de698b7

Please sign in to comment.