Skip to content

Commit

Permalink
Merge pull request #145 from fabric-testbed/feature-portmirror-lzhang9
Browse files Browse the repository at this point in the history
Updated port mirror service.
  • Loading branch information
kthare10 authored Jul 18, 2024
2 parents 7c1f9bd + 1ad0c3b commit ffff56e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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,17 @@ 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 sliver.mirror_vlan:
if 'from-interface-vlan' not in data:
data['from-interface-vlan'] = []
interface['outervlan'] = sliver.mirror_vlan
data['from-interface-vlan'].append(interface)
else:
if 'from-interface' not in data:
data['from-interface'] = []
data['from-interface'].append(interface)
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 @@ -918,7 +927,10 @@ def __portmirror_create_data(self, sliver: NetworkServiceSliver, service_name: s
data['device'] = labs.device_name
if labs.local_name is None:
raise NetHandlerException(f'port_mirror - interface "{interface_name}" has no "local_name" label')
data['to-interface'] = self.parse_interface_name(labs.local_name)
interface = self.parse_interface_name(labs.local_name)
if labs.vlan:
interface['outervlan'] = labs.vlan
data['to-interface'] = interface
return data

def parse_interface_name(self, interface_name: str) -> dict:
Expand Down
12 changes: 9 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,16 @@ 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"
# Optional: set the vlan tag
sliver.mirror_vlan = "100"
# direction also comes from ASM network service sliver
sliver.mirror_direction = MirrorDirection.Both

Expand All @@ -1078,7 +1080,11 @@ 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',
# Optional: set VLAN tag
vlan="100"
)
sliver_capacities = Capacities(bw=2000)
stp_to.set_labels(sliver_labels)
stp_to.set_capacities(sliver_capacities)
Expand Down

0 comments on commit ffff56e

Please sign in to comment.