Skip to content

Commit

Permalink
Merge pull request #360 from fabric-testbed/fabnet-subnet
Browse files Browse the repository at this point in the history
Allow users to request specific subnets for FabNetv* or FabNetv6Ext when available
  • Loading branch information
kthare10 authored Sep 3, 2024
2 parents c7e024a + 677863e commit 7fc94da
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Missing docstrings in network_service module (Issue [#313](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/314))
- Artifact Manager Support (Issue [#358](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/358))

- FabNet user specified subnets (Issue [#361](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/361))

## [1.7.3] - 08/05/2024
### Fixed
Expand Down
15 changes: 9 additions & 6 deletions fabrictestbed_extensions/fablib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,15 @@ def get_model(self) -> str:
:return: the model of this interface's component
:rtype: str
"""
if self.model:
return self.model
elif self.node:
return self.node.get_model()
else:
return self.get_component().get_model()
try:
if self.model:
return self.model
elif self.node:
return self.node.get_model()
else:
return self.get_component().get_model()
except Exception:
return ""

def get_site(self) -> str:
"""
Expand Down
32 changes: 31 additions & 1 deletion fabrictestbed_extensions/fablib/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from typing import TYPE_CHECKING, List, Union

from fim.slivers.path_info import Path
from fim.user import ERO
from fim.user import ERO, Gateway
from tabulate import tabulate

if TYPE_CHECKING:
Expand Down Expand Up @@ -368,6 +368,7 @@ def new_l3network(
type: str = None,
user_data={},
technology: str = None,
subnet: ipaddress.ip_network = None,
):
"""
Not inteded for API use. See slice.add_l3network
Expand Down Expand Up @@ -398,6 +399,7 @@ def new_l3network(
interfaces=interfaces,
user_data=user_data,
technology=technology,
subnet=subnet,
)

@staticmethod
Expand Down Expand Up @@ -478,6 +480,7 @@ def __new_network_service(
interfaces: List[Interface] = [],
user_data: dict = {},
technology: str = None,
subnet: ipaddress.ip_network = None,
):
"""
Not intended for API use. See slice.add_l2network
Expand All @@ -487,14 +490,23 @@ def __new_network_service(
:param slice: the fabric slice to build the network service with
:type slice: Slice
:param name: the name of the new network service
:type name: str
:param nstype: the type of network service to create
:type nstype: ServiceType
:param interfaces: a list of interfaces to
:type interfaces: List
:param technology: Specify the technology used should be set to AL2S when using for AL2S peering; otherwise None
:type technology: str
:param subnet: Request a specific subnet for FabNetv4, FabNetv6 or FabNetv6Ext services.
It's ignored for any other services.
:type ipaddress.ip_network
:return: the new fablib network service
:rtype: NetworkService
"""
Expand All @@ -509,6 +521,22 @@ def __new_network_service(
name=name, nstype=nstype, interfaces=fim_interfaces, technology=technology
)

if subnet:
if nstype == ServiceType.FABNetv4:
fim_network_service.gateway = Gateway(
lab=Labels(
ipv4_subnet=subnet.with_prefixlen,
ipv4=str(next(subnet.hosts())),
)
)
elif nstype in [ServiceType.FABNetv6, ServiceType.FABNetv6Ext]:
fim_network_service.gateway = Gateway(
lab=Labels(
ipv6_subnet=subnet.with_prefixlen,
ipv6=str(next(subnet.hosts())),
)
)

network_service = NetworkService(
slice=slice, fim_network_service=fim_network_service
)
Expand Down Expand Up @@ -1088,11 +1116,13 @@ def get_interfaces(self) -> List[Interface]:
)
except:
logging.warning(f"interface not found: {interface.name}")
""" Commenting this code as not sure why this was added for now.
from fabrictestbed_extensions.fablib.interface import Interface
self.interfaces.append(
Interface(fim_interface=interface, node=self)
)
"""

return self.interfaces

Expand Down
10 changes: 8 additions & 2 deletions fabrictestbed_extensions/fablib/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from typing import TYPE_CHECKING, Tuple

import pandas as pd
from fim.user import Capacities, Labels, NodeType
from fim.user import Labels
from fss_utils.sshkey import FABRICSSHKey
from IPython.core.display_functions import display

Expand Down Expand Up @@ -1022,6 +1022,7 @@ def add_l3network(
type: str = "IPv4",
user_data: dict = {},
technology: str = None,
subnet: ipaddress.ip_network = None,
) -> NetworkService:
"""
Adds a new L3 network service to this slice.
Expand Down Expand Up @@ -1069,11 +1070,15 @@ def add_l3network(
:type type: String
:param user_data
:type user_data: dict
:param technology: Specify the technology used should be set to AL2S when using for AL2S peering; otherwise None
:type technology: str
:param subnet: Request a specific subnet for FabNetv4, FabNetv6 or FabNetv6Ext services.
It's ignored for any other services.
:type ipaddress.ip_network
:return: a new L3 network service
:rtype: NetworkService
"""
Expand All @@ -1087,6 +1092,7 @@ def add_l3network(
type=type,
user_data=user_data,
technology=technology,
subnet=subnet,
)

def add_facility_port(
Expand Down

0 comments on commit 7fc94da

Please sign in to comment.