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

Updated port mirror service. #145

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions fabric_am/handlers/net_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,16 @@ def __portmirror_create_data(self, sliver: NetworkServiceSliver, service_name: s
if sliver.mirror_direction:
direction = str(sliver.mirror_direction).lower()
data = {"name": service_name,
"from-interface": self.parse_interface_name(sliver.mirror_port),
"direction": direction}
interface = self.parse_interface_name(sliver.mirror_port)
if "outervlan" in interface or "innervlan" in interface:
if 'from-interface-vlan' not in data:
data['from-interface-vlan'] = []
data['from-interface-vlan'].append(self.parse_interface_name(sliver.mirror_port))
else:
if 'from-interface' not in data:
data['from-interface'] = []
data['from-interface'].append(self.parse_interface_name(sliver.mirror_port))
zlion marked this conversation as resolved.
Show resolved Hide resolved
if len(sliver.interface_info.interfaces) != 1:
raise NetHandlerException(
f'port_mirror - requires 1 destination interface but was given {len(sliver.interface_info.interfaces)}')
Expand All @@ -925,7 +933,11 @@ def parse_interface_name(self, interface_name: str) -> dict:
interface_type_id = re.findall(r'(\w+)(\d.+)', interface_name)
if not interface_type_id or len(interface_type_id[0]) != 2:
raise NetHandlerException(f'interface name "{interface_name}" is malformed')
interface = {'type': interface_type_id[0][0], 'id': interface_type_id[0][1]}
if "." in interface_type_id[0][1]:
id_tags = interface_type_id[0][1].split(".")
interface = {'type': interface_type_id[0][0], 'id': id_tags[0], 'outervlan': id_tags[1]}
else:
interface = {'type': interface_type_id[0][0], 'id': interface_type_id[0][1]}
return interface

def poa(self, unit: ConfigToken, data: dict) -> Tuple[dict, ConfigToken]:
Expand Down
8 changes: 5 additions & 3 deletions fabric_am/test/test_network_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,14 +1060,15 @@ def test_PortMirror(self):
#
sliver = NetworkServiceSliver()
# service name (set by user) - only guaranteed unique within a slice
sliver.set_name('PortMirror-UKY')
sliver.set_name('PortMirror-RENC')
sliver.set_type(ServiceType.PortMirror)
sliver.set_layer(NSLayer.L2)

# mirror_port is the name of the port being mirrored - actual name the way
# service definition needs it. It comes directly from ASM network service sliver
# whatever the right name is - user must to know it when creating a slice
sliver.mirror_port = "TwentyFiveGigE0/0/0/24"
#sliver.mirror_port = "HundredGigE0/0/0/17"
sliver.mirror_port = "HundredGigE0/0/0/17.100"
# direction also comes from ASM network service sliver
sliver.mirror_direction = MirrorDirection.Both

zlion marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -1078,7 +1079,8 @@ def test_PortMirror(self):
stp_to = InterfaceSliver()
stp_to.set_name('Interface_To_Which_We_Send_Mirrored_Traffic')
stp_to.set_type(InterfaceType.ServicePort)
sliver_labels = Labels(local_name='TwentyFiveGigE0/0/0/23/1', device_name='lbnl-data-sw')
#sliver_labels = Labels(local_name='HundredGigE0/0/0/19', device_name='renc-data-sw')
sliver_labels = Labels(local_name='HundredGigE0/0/0/19.100', device_name='renc-data-sw')
sliver_capacities = Capacities(bw=2000)
stp_to.set_labels(sliver_labels)
stp_to.set_capacities(sliver_capacities)
Expand Down