diff --git a/netsim/modules/vlan.py b/netsim/modules/vlan.py index 126cd9dc0..7196bf0c1 100644 --- a/netsim/modules/vlan.py +++ b/netsim/modules/vlan.py @@ -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' @@ -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 @@ -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' ]) diff --git a/tests/topology/expected/vlan-access-neighbors.yml b/tests/topology/expected/vlan-access-neighbors.yml index 3c93d2614..6b55abeb2 100644 --- a/tests/topology/expected/vlan-access-neighbors.yml +++ b/tests/topology/expected/vlan-access-neighbors.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/topology/expected/vlan-access-node.yml b/tests/topology/expected/vlan-access-node.yml index 7852b467e..92f2e47bc 100644 --- a/tests/topology/expected/vlan-access-node.yml +++ b/tests/topology/expected/vlan-access-node.yml @@ -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 @@ -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 @@ -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 diff --git a/tests/topology/expected/vlan-coverage.yml b/tests/topology/expected/vlan-coverage.yml index ab7a5377b..9704d7929 100644 --- a/tests/topology/expected/vlan-coverage.yml +++ b/tests/topology/expected/vlan-coverage.yml @@ -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