Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass vlan for mirror port #344

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased

### Fixed
- Port Mirroring with Basic NICs (Issue [#343](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/343))
- P4 support (Issue [#340](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/340))
- ERO Support (Issue [#338](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/338))
- List hosts (Issue [#331](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/331))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ help FABlib, please review the [guidelines] first.
[configuration]: https://fabric-fablib.readthedocs.io/en/latest/#configuring-fablib

[guidelines]: ./CONTRIBUTING.md

81 changes: 63 additions & 18 deletions fabrictestbed_extensions/fablib/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ def get_peer_port_name(self) -> str or None:
else:
return None

def get_peer_port_vlan(self) -> str:
"""
Returns the VLAN associated with the interface.
For shared NICs extracts it from label_allocations.

:return: VLAN to be used for Port Mirroring
:rtype: String
"""
vlan = self.get_vlan()
if not vlan:
label_allocations = self.get_fim_interface().get_property(
pname="label_allocations"
)
if label_allocations:
return label_allocations.vlan

def get_device_name(self) -> str:
"""
Gets a name of the device name on the node
Expand Down Expand Up @@ -557,8 +573,8 @@ def set_vlan(self, vlan: Any = None):
"""
Set the VLAN on the FABRIC request.

:param addr: vlan
:type addr: String or int
:param vlan: vlan
:type vlan: String or int
"""
if vlan:
vlan = str(vlan)
Expand Down Expand Up @@ -623,19 +639,6 @@ def get_vlan(self) -> str:
vlan = None
return vlan

def get_bandwidth(self) -> int:
"""
Gets the FABRIC bandwidth of an interface.

:return: VLAN
:rtype: String
"""
try:
bw = self.get_fim_interface().get_property(pname="capacities").bw
except:
bw = None
return bw

sajith marked this conversation as resolved.
Show resolved Hide resolved
def get_reservation_id(self) -> str or None:
try:
# TODO THIS DOESNT WORK.
Expand Down Expand Up @@ -994,10 +997,22 @@ def config(self):
# manual mode... do nothing
pass

def add_mirror(self, port_name: str, name: str = "mirror"):
def add_mirror(self, port_name: str, name: str = "mirror", vlan: str = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to have a docstring. :-)

"""
Add Port Mirror Service

:param port_name: Mirror Port Name
:type port_name: String
:param vlan: Mirror Port vlan
:type vlan: String
:param name: Name of the Port Mirror service
:type name: String

"""
self.get_slice().get_fim_topology().add_port_mirror_service(
name=name,
from_interface_name=port_name,
from_interface_vlan=vlan,
to_interface=self.get_fim_interface(),
)

Expand Down Expand Up @@ -1033,33 +1048,63 @@ def set_subnet(self, ipv4_subnet: str = None, ipv6_subnet: str = None):
ipaddress.ip_network(ipv6_subnet, strict=False)
labels = Labels.update(labels, ipv6_subnet=ipv6_subnet)

self.get_fim().set_property('labels', labels)
self.get_fim().set_property("labels", labels)
except Exception as e:
logging.error(f"Failed to set the ip subnet e: {e}")
raise e

def get_subnet(self):
"""
Get Subnet associated with the interface

:return: ipv4/ipv6 subnet associated with the interface
:rtype: String
"""
if self.get_fim() and self.get_fim().labels:
if self.get_fim().labels.ipv4_subnet:
return self.get_fim().labels.ipv4_subnet
if self.get_fim().labels.ipv6_subnet:
return self.get_fim().labels.ipv6_subnet

def get_peer_subnet(self):
"""
Get Peer Subnet associated with the interface

:return: peer ipv4/ipv6 subnet associated with the interface
:rtype: String
"""
if self.get_fim() and self.get_fim().peer_labels:
if self.get_fim().peer_labels.ipv4_subnet:
return self.get_fim().peer_labels.ipv4_subnet
if self.get_fim().peer_labels.ipv6_subnet:
return self.get_fim().peer_labels.ipv6_subnet

def get_peer_asn(self):
"""
Get Peer ASN; Set only for Peered Interface using L3Peering via AL2S

:return: peer asn
:rtype: String
"""
if self.get_fim() and self.get_fim().peer_labels:
return self.get_fim().peer_labels.asn

def get_peer_bgp_key(self):
"""
Get Peer BGP Key; Set only for Peered Interface using L3Peering via AL2S

:return: peer BGP Key
:rtype: String
"""
if self.get_fim() and self.get_fim().peer_labels:
return self.get_fim().peer_labels.bgp_key

def get_peer_account_id(self):
"""
Get Peer Account Id associated with the interface

:return: peer account id associated with the interface (Used when interface is peered to AWS via AL2S)
:rtype: String
"""
if self.get_fim() and self.get_fim().peer_labels:
return self.get_fim().peer_labels.account_id
return self.get_fim().peer_labels.account_id
7 changes: 6 additions & 1 deletion fabrictestbed_extensions/fablib/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def new_portmirror_service(
slice: Slice = None,
name: str = None,
mirror_interface_name: str = None,
mirror_interface_vlan: str = None,
receive_interface: Interface or None = None,
mirror_direction: str = "both",
) -> NetworkService:
Expand Down Expand Up @@ -344,6 +345,7 @@ def new_portmirror_service(
fim_network_service = slice.topology.add_port_mirror_service(
name=name,
from_interface_name=mirror_interface_name,
from_interface_vlan=mirror_interface_vlan,
to_interface=receive_interface.fim_interface,
direction=direction,
)
Expand Down Expand Up @@ -1064,7 +1066,10 @@ def get_interfaces(self) -> List[Interface]:
except:
logging.warning(f"interface not found: {interface.name}")
from fabrictestbed_extensions.fablib.interface import Interface
self.interfaces.append(Interface(fim_interface=interface, node=self))

self.interfaces.append(
Interface(fim_interface=interface, node=self)
)

return self.interfaces

Expand Down
3 changes: 3 additions & 0 deletions fabrictestbed_extensions/fablib/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ def add_port_mirror_service(
name: str,
mirror_interface_name: str,
receive_interface: Interface or None = None,
mirror_interface_vlan: str = None,
mirror_direction: str = "both",
) -> NetworkService:
"""
Expand All @@ -921,6 +922,7 @@ def add_port_mirror_service(
:param name: Name of the service
:param mirror_interface_name: Name of the interface on the
dataplane switch to mirror
:param mirror_interface_vlan: Vlan of the interface
:param receive_interface: Interface in the topology belonging
to a SmartNIC component
:param mirror_direction: String 'rx', 'tx' or 'both'
Expand All @@ -932,6 +934,7 @@ def add_port_mirror_service(
slice=self,
name=name,
mirror_interface_name=mirror_interface_name,
mirror_interface_vlan=mirror_interface_vlan,
receive_interface=receive_interface,
mirror_direction=mirror_direction,
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
"ipyleaflet",
"ipycytoscape",
"tabulate",
"fabrictestbed==1.7.0b9",
"fabrictestbed==1.7.0b11",
"paramiko",
"jinja2>=3.0.0",
"pandas",
Expand Down