Skip to content

Commit

Permalink
Fix vlan lookup for local vlan defined on neighbor node only
Browse files Browse the repository at this point in the history
  • Loading branch information
jbemmel committed Nov 10, 2022
1 parent 22e05b3 commit 98400d5
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 8 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
252 changes: 252 additions & 0 deletions tests/topology/expected/vlan-single-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
bgp:
advertise_loopback: true
community:
ebgp:
- standard
ibgp:
- standard
- extended
next_hop_self: true
groups:
as65000:
members:
- r1
as65001:
members:
- r2
input:
- topology/input/vlan-single-node.yml
- /home/jeroen/.netlab.yml
- package:topology-defaults.yml
links:
- bridge: input_1
interfaces:
- ifindex: 1
ifname: ethernet-1/1
ipv4: 172.16.0.1/24
node: r1
- ifindex: 1
ifname: ethernet-1/1
ipv4: 172.16.0.2/24
node: s1
vlan:
access: red
linkindex: 1
node_count: 2
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
type: lan
- bridge: input_2
interfaces:
- ifindex: 1
ifname: ethernet-1/1
ipv4: 172.16.0.3/24
node: r2
- ifindex: 2
ifname: ethernet-1/2
ipv4: 172.16.0.2/24
node: s1
vlan:
access: red
linkindex: 2
node_count: 2
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
type: lan
module:
- vlan
- bgp
name: input
nodes:
r1:
af:
ipv4: true
bgp:
advertise_loopback: true
as: 65000
community:
ebgp:
- standard
ibgp:
- standard
- extended
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: ghcr.io/nokia/srlinux
clab:
kind: srl
type: ixrd2
device: srlinux
hostname: clab-input-r1
id: 1
interfaces:
- bridge: input_1
clab:
name: e1-1
ifindex: 1
ifname: ethernet-1/1
ipv4: 172.16.0.1/24
linkindex: 1
name: r1 -> [s1,r2]
neighbors:
- ifname: irb0.1000
ipv4: 172.16.0.2/24
node: s1
- ifname: ethernet-1/1
ipv4: 172.16.0.3/24
node: r2
type: lan
loopback:
ipv4: 10.0.0.1/32
mgmt:
ifname: mgmt0
ipv4: 192.168.121.101
mac: 08-4F-A9-00-00-01
module:
- bgp
name: r1
r2:
af:
ipv4: true
bgp:
advertise_loopback: true
as: 65001
community:
ebgp:
- standard
ibgp:
- standard
- extended
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: ghcr.io/nokia/srlinux
clab:
kind: srl
type: ixrd2
device: srlinux
hostname: clab-input-r2
id: 3
interfaces:
- bridge: input_2
clab:
name: e1-1
ifindex: 1
ifname: ethernet-1/1
ipv4: 172.16.0.3/24
linkindex: 2
name: r2 -> [r1,s1]
neighbors:
- ifname: ethernet-1/1
ipv4: 172.16.0.1/24
node: r1
- ifname: irb0.1000
ipv4: 172.16.0.2/24
node: s1
type: lan
loopback:
ipv4: 10.0.0.3/32
mgmt:
ifname: mgmt0
ipv4: 192.168.121.103
mac: 08-4F-A9-00-00-03
module:
- bgp
name: r2
s1:
af:
ipv4: true
box: ghcr.io/nokia/srlinux
clab:
kind: srl
type: ixrd2
device: srlinux
hostname: clab-input-s1
id: 2
interfaces:
- bridge: input_1
clab:
name: e1-1
ifindex: 1
ifname: ethernet-1/1
linkindex: 1
type: lan
vlan:
access: red
access_id: 1000
- bridge: input_2
clab:
name: e1-2
ifindex: 2
ifname: ethernet-1/2
linkindex: 2
type: lan
vlan:
access: red
access_id: 1000
- bridge_group: 1
ifindex: 3
ifname: irb0.1000
ipv4: 172.16.0.2/24
name: VLAN red (1000) -> [r1,r2]
neighbors:
- ifname: ethernet-1/1
ipv4: 172.16.0.1/24
node: r1
- ifname: ethernet-1/1
ipv4: 172.16.0.3/24
node: r2
type: svi
virtual_interface: true
vlan:
mode: irb
loopback:
ipv4: 10.0.0.2/32
mgmt:
ifname: mgmt0
ipv4: 192.168.121.102
mac: 08-4F-A9-00-00-02
module:
- vlan
name: s1
vlan:
max_bridge_group: 1
vlans:
red:
bridge_group: 1
host_count: 0
id: 1000
mode: irb
neighbors:
- ifname: ethernet-1/1
ipv4: 172.16.0.1/24
node: r1
- ifname: irb0.1000
ipv4: 172.16.0.2/24
node: s1
- ifname: ethernet-1/1
ipv4: 172.16.0.3/24
node: r2
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
provider: clab
27 changes: 27 additions & 0 deletions tests/topology/input/vlan-single-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defaults.device: srlinux

provider: clab

# Works if the vlan is global
#vlans:
# red:

nodes:
r1:
module: [ bgp ]
bgp.as: 65000
s1:
module: [ vlan ]
vlans:
red:
r2:
module: [ bgp ]
bgp.as: 65001

links:
- r1:
s1:
vlan.access: red
- r2:
s1:
vlan.access: red

0 comments on commit 98400d5

Please sign in to comment.