Skip to content

Commit

Permalink
Fix VLAN lookup for node-local VLANs defined on a neighbor node (#645)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen van Bemmel <[email protected]>
  • Loading branch information
2 people authored and ipspace committed Nov 11, 2022
1 parent 3360015 commit a55a60d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
22 changes: 14 additions & 8 deletions netsim/modules/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,16 @@ def create_loopback_vlan_links(topology: Box) -> None:
topology.links.append(link_data)

"""
get_vlan_data: Get VLAN data structure (node or topology)
get_vlan_data: Get VLAN data structure (node or topology or interface neighbors)
"""
def get_vlan_data(vlan: str, node: Box, topology: Box) -> typing.Optional[Box]:
return get_from_box(topology,f'vlans.{vlan}') or get_from_box(node,f'vlans.{vlan}')
def get_vlan_data(vlan: str, node: Box, topology: Box, intf: Box) -> typing.Optional[Box]:
vlan_data = get_from_box(topology,f'vlans.{vlan}') or get_from_box(node,f'vlans.{vlan}')
if not vlan_data:
for n in intf.neighbors: # Look for local vlan in neighbor
vlan_data = get_from_box(topology.nodes[n.node],f'vlans.{vlan}')
if vlan_data:
break
return vlan_data

"""
get_vlan_mode: Get VLAN mode attribute (node or topology), default 'irb'
Expand All @@ -581,7 +587,7 @@ def get_vlan_mode(node: Box, topology: Box) -> str:
update_vlan_neighbor_list: Build a VLAN-wide list of neighbors
"""
def update_vlan_neighbor_list(vlan: str, phy_if: Box, svi_if: Box, node: Box,topology: Box) -> None:
vlan_data = get_vlan_data(vlan,node,topology) # Try to get global or node-level VLAN data
vlan_data = get_vlan_data(vlan,node,topology,phy_if) # Try to get global or node-level VLAN data
if vlan_data is None: # ... and get out if there's none
return

Expand Down Expand Up @@ -740,13 +746,13 @@ def create_svi_interfaces(node: Box, topology: Box) -> dict:
def set_svi_neighbor_list(node: Box, topology: Box) -> None:
for ifdata in node.interfaces:
if 'vlan_name' in ifdata:
vlan_data = get_vlan_data(ifdata.vlan_name,node,topology) # Try to get global or local VLAN data
if vlan_data is None: # Not found?
continue # ... too bad

if get_from_box(ifdata,'vlan.routed_link'): # Don't update neighbors on a routed VLAN link
continue

vlan_data = get_vlan_data(ifdata.vlan_name,node,topology,ifdata) # Try to get global or local VLAN data
if vlan_data is None: # Not found?
continue # ... too bad

if not 'host_count' in vlan_data: # Calculate the number of hosts attached to the VLAN
vlan_data.host_count = len([ n for n in vlan_data.neighbors if topology.nodes[n.node].get('role','') == 'host' ])

Expand Down
34 changes: 28 additions & 6 deletions tests/topology/expected/vlan-access-neighbors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ nodes:
ibgp:
- standard
- extended
neighbors: []
ipv4: true
neighbors:
- activate:
ipv4: true
as: 65001
ifindex: 1
ipv4: 172.16.0.3
name: r2
type: ebgp
next_hop_self: true
router_id: 10.0.0.1
box: ceos:4.26.4M
Expand All @@ -90,11 +98,14 @@ nodes:
ifname: Ethernet1
ipv4: 172.16.0.1/24
linkindex: 1
name: r1 -> s1
name: r1 -> [s1,r2]
neighbors:
- ifname: Ethernet1
- ifname: Vlan1000
ipv4: 172.16.0.2/24
node: s1
- ifname: Ethernet1
ipv4: 172.16.0.3/24
node: r2
type: lan
loopback:
ipv4: 10.0.0.1/32
Expand All @@ -117,7 +128,15 @@ nodes:
ibgp:
- standard
- extended
neighbors: []
ipv4: true
neighbors:
- activate:
ipv4: true
as: 65000
ifindex: 1
ipv4: 172.16.0.1
name: r1
type: ebgp
next_hop_self: true
router_id: 10.0.0.3
box: ceos:4.26.4M
Expand All @@ -136,9 +155,12 @@ nodes:
ifname: Ethernet1
ipv4: 172.16.0.3/24
linkindex: 2
name: r2 -> s1
name: r2 -> [r1,s1]
neighbors:
- ifname: Ethernet2
- ifname: Ethernet1
ipv4: 172.16.0.1/24
node: r1
- ifname: Vlan1000
ipv4: 172.16.0.2/24
node: s1
type: lan
Expand Down
17 changes: 12 additions & 5 deletions tests/topology/expected/vlan-access-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ nodes:
ifname: eth1
ipv4: 172.16.0.1/24
linkindex: 1
name: h1 -> s1
name: h1 -> [s1]
neighbors:
- ifname: GigabitEthernet0/1
- ifname: BVI1
ipv4: 172.16.0.2/24
node: s1
role: stub
type: lan
mgmt:
ifname: eth0
Expand All @@ -104,9 +105,12 @@ nodes:
ifname: eth1
ipv4: 172.16.1.4/24
linkindex: 3
name: h2 -> s2
name: h2 -> [s1,s2]
neighbors:
- ifname: GigabitEthernet0/2
ipv4: 172.16.1.2/24
node: s1
- ifname: BVI1
ipv4: 172.16.1.3/24
node: s2
type: lan
Expand Down Expand Up @@ -136,11 +140,14 @@ nodes:
ifname: GigabitEthernet0/2
ipv4: 172.16.1.2/24
linkindex: 2
name: s1 -> s2
name: s1 -> [s2,h2]
neighbors:
- ifname: GigabitEthernet0/1
- ifname: BVI1
ipv4: 172.16.1.3/24
node: s2
- ifname: eth1
ipv4: 172.16.1.4/24
node: h2
type: lan
- bridge_group: 1
ifindex: 3
Expand Down
5 changes: 3 additions & 2 deletions tests/topology/expected/vlan-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ nodes:
ifname: eth2
ipv4: 172.16.1.4/24
linkindex: 4
name: h2 -> s2
name: h2 -> [s2]
neighbors:
- ifname: GigabitEthernet0/3
- ifname: BVI2
node: s2
role: stub
type: lan
mgmt:
ifname: eth0
Expand Down

0 comments on commit a55a60d

Please sign in to comment.