Skip to content

Commit

Permalink
Remove 'unnumbered' flag from output, templates can base their logic …
Browse files Browse the repository at this point in the history
…on ipv4/ipv6 being a Boolean (#435)

Co-authored-by: Jeroen van Bemmel <[email protected]>
  • Loading branch information
jbemmel and jbemmel authored Sep 11, 2022
1 parent 4ec90a4 commit c6ef55a
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 58 deletions.
2 changes: 1 addition & 1 deletion netsim/addressing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def normalize_prefix(pfx: typing.Union[str,Box]) -> Box:
return Box({ 'ipv4': str(pfx)},default_box=True,box_dots=True)
for af in 'ipv4','ipv6':
if af in pfx:
if not pfx[af] or 'unnumbered' in pfx:
if not pfx[af] or 'unnumbered' in pfx: # If 'unnumbered' is set, ipv4/ipv6 will be based on loopback afs (per node)
del pfx[af]

return pfx
Expand Down
6 changes: 2 additions & 4 deletions netsim/augment/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ def augment_link_prefix(link: Box,pools: typing.List[str],addr_pools: Box) -> di
if 'prefix' in link:
pfx_list = addressing.parse_prefix(link.prefix)
if isinstance(link.prefix,str):
link.prefix = addressing.rebuild_prefix(pfx_list)
elif 'unnumbered' in link:
link.prefix = addressing.rebuild_prefix(pfx_list) # convert str to { ipv4: , ipv6: }
elif 'unnumbered' in link: # User provided flag in topology
pfx_list = Box({ 'unnumbered': True })
else:
pfx_list = addressing.get(addr_pools,pools)
Expand All @@ -281,8 +281,6 @@ def augment_link_prefix(link: Box,pools: typing.List[str],addr_pools: Box) -> di
}
if not link.prefix:
link.pop('prefix',None)
if pfx_list.get('unnumbered',None):
link.unnumbered = True

return pfx_list

Expand Down
5 changes: 4 additions & 1 deletion netsim/augment/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ def transform(topology: Box, defaults: Box, pools: Box) -> None:
if pools.loopback and n.get('role','') != 'host':
prefix_list = addressing.get(pools,['loopback'],n.id)
for af in prefix_list:
if not n.loopback[af]:
if isinstance(prefix_list[af],bool):
if prefix_list[af]:
common.fatal( f"Loopback addresses must be valid IP prefixes, not 'True': {prefix_list}" )
elif not n.loopback[af]:
if af == 'ipv6':
n.loopback[af] = addressing.get_addr_mask(prefix_list[af],1)
else:
Expand Down
4 changes: 0 additions & 4 deletions tests/topology/expected/addressing-lan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ links:
node_count: 3
role: unnumbered
type: lan
unnumbered: true
- bridge: input_4
interfaces:
- ifindex: 5
Expand Down Expand Up @@ -317,7 +316,6 @@ nodes:
node: r3
role: unnumbered
type: lan
unnumbered: true
- bridge: input_4
ifindex: 5
ifname: GigabitEthernet5
Expand Down Expand Up @@ -543,7 +541,6 @@ nodes:
node: r3
role: unnumbered
type: lan
unnumbered: true
- bridge: input_4
ifindex: 5
ifname: GigabitEthernet5
Expand Down Expand Up @@ -769,7 +766,6 @@ nodes:
node: r2
role: unnumbered
type: lan
unnumbered: true
- bridge: input_4
ifindex: 5
ifname: GigabitEthernet5
Expand Down
3 changes: 0 additions & 3 deletions tests/topology/expected/addressing-p2p.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ links:
node: r2
role: unnumbered
type: p2p
unnumbered: true
- interfaces:
- ifindex: 5
ipv6: 2001:db8:2::1/64
Expand Down Expand Up @@ -381,7 +380,6 @@ nodes:
node: r2
role: unnumbered
type: p2p
unnumbered: true
- ifindex: 5
ifname: GigabitEthernet5
ipv6: 2001:db8:2::1/64
Expand Down Expand Up @@ -563,7 +561,6 @@ nodes:
node: r1
role: unnumbered
type: p2p
unnumbered: true
- ifindex: 5
ifname: GigabitEthernet5
ipv6: 2001:db8:2::2/64
Expand Down
12 changes: 0 additions & 12 deletions tests/topology/expected/bgp-ibgp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ links:
ipv4: true
node: s1
type: p2p
unnumbered: true
- interfaces:
- ifindex: 1
ipv4: true
Expand All @@ -62,7 +61,6 @@ links:
ipv4: true
node: s1
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: true
Expand All @@ -82,7 +80,6 @@ links:
ipv4: true
node: s2
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: true
Expand All @@ -102,7 +99,6 @@ links:
ipv4: true
node: s2
type: p2p
unnumbered: true
module:
- bgp
- ospf
Expand Down Expand Up @@ -156,7 +152,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet1/2
ipv4: true
Expand All @@ -171,7 +166,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
loopback:
ipv4: 10.0.0.1/32
mgmt:
Expand Down Expand Up @@ -236,7 +230,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet2
ipv4: true
Expand All @@ -251,7 +244,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
loopback:
ipv4: 10.0.0.2/32
mgmt:
Expand Down Expand Up @@ -323,7 +315,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet1/2
ipv4: true
Expand All @@ -338,7 +329,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
loopback:
ipv4: 10.0.0.3/32
mgmt:
Expand Down Expand Up @@ -410,7 +400,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet1/2
ipv4: true
Expand All @@ -425,7 +414,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
loopback:
ipv4: 10.0.0.4/32
mgmt:
Expand Down
3 changes: 0 additions & 3 deletions tests/topology/expected/bgp-unnumbered.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ links:
node: r2
role: external
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: 10.10.10.1/24
Expand Down Expand Up @@ -128,7 +127,6 @@ nodes:
node: r2
role: external
type: p2p
unnumbered: true
loopback:
ipv4: 10.0.0.1/32
ipv6: 2001:db8:cafe:1::1/64
Expand Down Expand Up @@ -192,7 +190,6 @@ nodes:
node: r1
role: external
type: p2p
unnumbered: true
- ifindex: 2
ifname: swp2
ipv4: 10.10.10.1/24
Expand Down
12 changes: 0 additions & 12 deletions tests/topology/expected/igp-af.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ links:
ipv6: true
node: r2
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: true
Expand All @@ -54,7 +53,6 @@ links:
ipv6: true
node: r3
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: true
Expand All @@ -78,7 +76,6 @@ links:
ipv6: true
node: r4
type: p2p
unnumbered: true
- interfaces:
- ifindex: 2
ipv4: true
Expand All @@ -102,7 +99,6 @@ links:
ipv6: true
node: r5
type: p2p
unnumbered: true
- bridge: input_5
interfaces:
- ifindex: 2
Expand Down Expand Up @@ -146,7 +142,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet2
ipv4: true
Expand All @@ -166,7 +161,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
isis:
af:
ipv4: true
Expand Down Expand Up @@ -218,7 +212,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
isis:
af:
ipv4: true
Expand Down Expand Up @@ -270,7 +263,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet2
ipv4: true
Expand All @@ -290,7 +282,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
isis:
af:
ipv4: true
Expand Down Expand Up @@ -341,7 +332,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- ifindex: 2
ifname: Ethernet2
ipv4: true
Expand All @@ -361,7 +351,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
isis:
af:
ipv4: true
Expand Down Expand Up @@ -413,7 +402,6 @@ nodes:
network_type: point-to-point
passive: false
type: p2p
unnumbered: true
- bridge: input_5
ifindex: 2
ifname: Ethernet2
Expand Down
9 changes: 0 additions & 9 deletions tests/topology/expected/isis-feature-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ links:
ipv4: true
node: c_nxos
type: p2p
unnumbered: true
- interfaces:
- ifindex: 6
ipv4: true
Expand All @@ -158,7 +157,6 @@ links:
ipv4: true
node: c_nxos
type: p2p
unnumbered: true
- interfaces:
- ifindex: 7
ipv6: true
Expand Down Expand Up @@ -220,7 +218,6 @@ links:
ipv4: true
node: c_csr
type: p2p
unnumbered: true
- interfaces:
- ifindex: 8
ipv6: true
Expand Down Expand Up @@ -356,7 +353,6 @@ nodes:
ipv4: true
node: c_nxos
type: p2p
unnumbered: true
- ifindex: 6
ifname: Ethernet6
ipv6: true
Expand All @@ -383,7 +379,6 @@ nodes:
ipv4: true
node: c_csr
type: p2p
unnumbered: true
- ifindex: 8
ifname: Ethernet8
linkindex: 14
Expand Down Expand Up @@ -500,7 +495,6 @@ nodes:
ipv4: true
node: c_nxos
type: p2p
unnumbered: true
- ifindex: 7
ifname: GigabitEthernet7
ipv4: true
Expand All @@ -514,7 +508,6 @@ nodes:
ipv4: true
node: a_eos
type: p2p
unnumbered: true
- ifindex: 8
ifname: GigabitEthernet8
ipv6: true
Expand Down Expand Up @@ -637,7 +630,6 @@ nodes:
ipv4: true
node: a_eos
type: p2p
unnumbered: true
- ifindex: 6
ifname: Ethernet1/6
ipv4: true
Expand All @@ -651,7 +643,6 @@ nodes:
ipv4: true
node: c_csr
type: p2p
unnumbered: true
- ifindex: 7
ifname: Ethernet1/7
ipv6: true
Expand Down
Loading

0 comments on commit c6ef55a

Please sign in to comment.