Skip to content

Commit

Permalink
Copy only mandatory attributes from PHY to VLAN interface (fixes #866)
Browse files Browse the repository at this point in the history
  • Loading branch information
ipspace committed Sep 9, 2023
1 parent eff1e39 commit 8678560
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
4 changes: 3 additions & 1 deletion docs/module/vlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@ links:
Finally, you can set the parameters of an individual routed VLAN subinterface within the **vlan.trunk** link- or interface- dictionary.

```{warning}
Don't try to set VLAN interface parameters on access or trunk links; you might get unexpected results.
You cannot set VLAN interface parameters for bridged or IRB VLANs on access or trunk links. Most physical interface parameters[^PIFX] are ignored when creating the VLAN interface, and removed from the physical interface.
```

[^PIFX]: ... apart from IPv4/IPv6 addresses and **gateway** link parameters set during the data transformation.

(module-vlan-trunk-attributes)=
### Modifying Attributes of VLANs in a VLAN Trunk

Expand Down
11 changes: 5 additions & 6 deletions netsim/modules/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,12 @@ def create_svi_interfaces(node: Box, topology: Box) -> dict:
return vlan_ifmap

if not access_vlan in vlan_ifmap: # Do we need to create a SVI interface?
skip_attr = list(skip_ifattr) # Create a local copy of the attribute skip list
copy_attr = [ 'vlan_name','gateway' ]
vlan_mode = ifdata.vlan.get('mode','') or vlan_data.get('mode','') # Get VLAN forwarding mode
if vlan_mode == 'bridge': # ... and skip IP addresses for bridging-only VLANs
skip_attr.extend(['ipv4','ipv6'])
# continue # JvB: in fact, skip creating SVI for L2-only VLANs
vlan_ifdata = data.get_box( # Copy non-physical interface attributes into SVI interface
{ k:v for k,v in ifdata.items() if k not in skip_attr }) # ... that will also give us IP addresses
if vlan_mode != 'bridge': # ... and skip IP addresses for bridging-only VLANs
copy_attr.extend(['ipv4','ipv6'])
vlan_ifdata = data.get_box( # Copy the interface attributes generated during link transformation
{ k:v for k,v in ifdata.items() if k in copy_attr }) # ... that will also give us IP/gateway addresses
if vlan_mode: # Set VLAN forwarding mode for completness' sake
vlan_ifdata.vlan.mode = vlan_mode
vlan_ifdata.ifindex = node.interfaces[-1].ifindex + 1 # Fill in the rest of interface data:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/vxlan/vxlan-irb-ospf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ vrfs:
vlans:
red:
vrf: tenant
ospf.cost: 5
blue:
vrf: tenant
ospf.cost: 10

nodes:
h1:
Expand Down
38 changes: 25 additions & 13 deletions tests/topology/expected/vlan-routed-access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ links:
mode: route
- ifindex: 1
ifname: Ethernet1
ipv4: 172.16.0.2/24
node: s1
vlan:
access: red
Expand All @@ -31,7 +30,6 @@ links:
interfaces:
- ifindex: 2
ifname: Ethernet2
ipv4: 172.16.0.2/24
node: s1
vlan:
access: red
Expand All @@ -51,6 +49,17 @@ links:
type: lan
vlan:
access: red
- bridge: input_3
interfaces:
- ifindex: 3
ifname: Ethernet3
ipv4: 172.16.1.2/24
node: s1
linkindex: 3
node_count: 1
prefix:
ipv4: 172.16.1.0/24
type: stub
module:
- vlan
- ospf
Expand All @@ -73,7 +82,6 @@ nodes:
name: r1 -> [s1,r2]
neighbors:
- ifname: Vlan1000
ipv4: 172.16.0.2/24
node: s1
- ifname: Ethernet1
ipv4: 172.16.0.3/24
Expand Down Expand Up @@ -132,7 +140,6 @@ nodes:
ipv4: 172.16.0.1/24
node: r1
- ifname: Vlan1000
ipv4: 172.16.0.2/24
node: s1
ospf:
area: 0.0.0.0
Expand Down Expand Up @@ -189,10 +196,20 @@ nodes:
vlan:
access: red
access_id: 1000
- bridge_group: 1
- bridge: input_3
ifindex: 3
ifname: Ethernet3
ipv4: 172.16.1.2/24
linkindex: 3
name: s1 -> stub
neighbors: []
ospf:
area: 0.0.0.0
passive: true
type: stub
- bridge_group: 1
ifindex: 4
ifname: Vlan1000
ipv4: 172.16.0.2/24
name: VLAN red (1000) -> [r1,r2]
neighbors:
- ifname: GigabitEthernet0/1
Expand All @@ -201,14 +218,10 @@ nodes:
- ifname: Ethernet1
ipv4: 172.16.0.3/24
node: r2
ospf:
area: 0.0.0.0
cost: 10
passive: false
type: svi
virtual_interface: true
vlan:
mode: irb
mode: bridge
loopback:
ipv4: 10.0.0.2/32
mgmt:
Expand All @@ -230,7 +243,7 @@ nodes:
red:
bridge_group: 1
id: 1000
mode: irb
mode: bridge
ospf:
cost: 10
prefix:
Expand All @@ -248,7 +261,6 @@ vlans:
ipv4: 172.16.0.1/24
node: r1
- ifname: Vlan1000
ipv4: 172.16.0.2/24
node: s1
- ifname: Ethernet1
ipv4: 172.16.0.3/24
Expand Down
16 changes: 16 additions & 0 deletions tests/topology/expected/vlan-router-stick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ links:
access: red
linkindex: 3
node_count: 2
ospf:
cost: 10
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
Expand All @@ -92,6 +94,8 @@ links:
access: blue
linkindex: 4
node_count: 2
ospf:
cost: 20
prefix:
allocation: id_based
ipv4: 172.16.1.0/24
Expand Down Expand Up @@ -125,6 +129,7 @@ nodes:
node: ros
ospf:
area: 0.0.0.0
cost: 10
passive: false
type: lan
loopback:
Expand Down Expand Up @@ -165,6 +170,7 @@ nodes:
node: ros
ospf:
area: 0.0.0.0
cost: 20
passive: false
type: lan
loopback:
Expand Down Expand Up @@ -213,6 +219,7 @@ nodes:
node: s2
ospf:
area: 0.0.0.0
cost: 20
passive: false
parent_ifindex: 1
parent_ifname: Ethernet1
Expand All @@ -237,6 +244,7 @@ nodes:
node: s2
ospf:
area: 0.0.0.0
cost: 10
passive: false
parent_ifindex: 1
parent_ifname: Ethernet1
Expand Down Expand Up @@ -280,6 +288,8 @@ nodes:
- ifname: Ethernet1.1
ipv4: 172.16.1.5/24
node: ros
ospf:
cost: 20
prefix:
allocation: id_based
ipv4: 172.16.1.0/24
Expand All @@ -299,6 +309,8 @@ nodes:
- ifname: Ethernet1.2
ipv4: 172.16.0.5/24
node: ros
ospf:
cost: 10
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
Expand Down Expand Up @@ -545,6 +557,8 @@ vlans:
- ifname: Ethernet1.1
ipv4: 172.16.1.5/24
node: ros
ospf:
cost: 20
prefix:
allocation: id_based
ipv4: 172.16.1.0/24
Expand All @@ -563,6 +577,8 @@ vlans:
- ifname: Ethernet1.2
ipv4: 172.16.0.5/24
node: ros
ospf:
cost: 10
prefix:
allocation: id_based
ipv4: 172.16.0.0/24
4 changes: 4 additions & 0 deletions tests/topology/input/vlan-routed-access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ nodes:
device: iosv
s1:
device: eos
vlans:
red:
mode: bridge
r2:
device: eos
vlans:
Expand All @@ -23,3 +26,4 @@ links:
- s1:
r2:
vlan.access: red
- s1: # To enforce OSPF module on S1
2 changes: 2 additions & 0 deletions tests/topology/input/vlan-router-stick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ groups:

vlans:
red:
ospf.cost: 10
blue:
ospf.cost: 20

nodes:
s1:
Expand Down

0 comments on commit 8678560

Please sign in to comment.