From c6ef55aa7e946f38591c3ee2f908abe0059cd756 Mon Sep 17 00:00:00 2001 From: J vanBemmel Date: Sun, 11 Sep 2022 13:52:41 -0500 Subject: [PATCH] Remove 'unnumbered' flag from output, templates can base their logic on ipv4/ipv6 being a Boolean (#435) Co-authored-by: Jeroen van Bemmel --- netsim/addressing.py | 2 +- netsim/augment/links.py | 6 ++---- netsim/augment/nodes.py | 5 ++++- tests/topology/expected/addressing-lan.yml | 4 ---- tests/topology/expected/addressing-p2p.yml | 3 --- tests/topology/expected/bgp-ibgp.yml | 12 ------------ tests/topology/expected/bgp-unnumbered.yml | 3 --- tests/topology/expected/igp-af.yml | 12 ------------ tests/topology/expected/isis-feature-test.yml | 9 --------- tests/topology/expected/unnumbered.yml | 9 --------- 10 files changed, 7 insertions(+), 58 deletions(-) diff --git a/netsim/addressing.py b/netsim/addressing.py index 1dd687c85..6c13c62b8 100644 --- a/netsim/addressing.py +++ b/netsim/addressing.py @@ -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 diff --git a/netsim/augment/links.py b/netsim/augment/links.py index 03d7aec71..5a65a80ce 100644 --- a/netsim/augment/links.py +++ b/netsim/augment/links.py @@ -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) @@ -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 diff --git a/netsim/augment/nodes.py b/netsim/augment/nodes.py index f5f404b66..658836cf9 100644 --- a/netsim/augment/nodes.py +++ b/netsim/augment/nodes.py @@ -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: diff --git a/tests/topology/expected/addressing-lan.yml b/tests/topology/expected/addressing-lan.yml index 8b329fa80..6982f5327 100644 --- a/tests/topology/expected/addressing-lan.yml +++ b/tests/topology/expected/addressing-lan.yml @@ -54,7 +54,6 @@ links: node_count: 3 role: unnumbered type: lan - unnumbered: true - bridge: input_4 interfaces: - ifindex: 5 @@ -317,7 +316,6 @@ nodes: node: r3 role: unnumbered type: lan - unnumbered: true - bridge: input_4 ifindex: 5 ifname: GigabitEthernet5 @@ -543,7 +541,6 @@ nodes: node: r3 role: unnumbered type: lan - unnumbered: true - bridge: input_4 ifindex: 5 ifname: GigabitEthernet5 @@ -769,7 +766,6 @@ nodes: node: r2 role: unnumbered type: lan - unnumbered: true - bridge: input_4 ifindex: 5 ifname: GigabitEthernet5 diff --git a/tests/topology/expected/addressing-p2p.yml b/tests/topology/expected/addressing-p2p.yml index b28681cf4..17d764fe9 100644 --- a/tests/topology/expected/addressing-p2p.yml +++ b/tests/topology/expected/addressing-p2p.yml @@ -66,7 +66,6 @@ links: node: r2 role: unnumbered type: p2p - unnumbered: true - interfaces: - ifindex: 5 ipv6: 2001:db8:2::1/64 @@ -381,7 +380,6 @@ nodes: node: r2 role: unnumbered type: p2p - unnumbered: true - ifindex: 5 ifname: GigabitEthernet5 ipv6: 2001:db8:2::1/64 @@ -563,7 +561,6 @@ nodes: node: r1 role: unnumbered type: p2p - unnumbered: true - ifindex: 5 ifname: GigabitEthernet5 ipv6: 2001:db8:2::2/64 diff --git a/tests/topology/expected/bgp-ibgp.yml b/tests/topology/expected/bgp-ibgp.yml index 848217bb1..d5fe87598 100644 --- a/tests/topology/expected/bgp-ibgp.yml +++ b/tests/topology/expected/bgp-ibgp.yml @@ -42,7 +42,6 @@ links: ipv4: true node: s1 type: p2p - unnumbered: true - interfaces: - ifindex: 1 ipv4: true @@ -62,7 +61,6 @@ links: ipv4: true node: s1 type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: true @@ -82,7 +80,6 @@ links: ipv4: true node: s2 type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: true @@ -102,7 +99,6 @@ links: ipv4: true node: s2 type: p2p - unnumbered: true module: - bgp - ospf @@ -156,7 +152,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet1/2 ipv4: true @@ -171,7 +166,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true loopback: ipv4: 10.0.0.1/32 mgmt: @@ -236,7 +230,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet2 ipv4: true @@ -251,7 +244,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true loopback: ipv4: 10.0.0.2/32 mgmt: @@ -323,7 +315,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet1/2 ipv4: true @@ -338,7 +329,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true loopback: ipv4: 10.0.0.3/32 mgmt: @@ -410,7 +400,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet1/2 ipv4: true @@ -425,7 +414,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true loopback: ipv4: 10.0.0.4/32 mgmt: diff --git a/tests/topology/expected/bgp-unnumbered.yml b/tests/topology/expected/bgp-unnumbered.yml index e6cd24738..3215d9e5a 100644 --- a/tests/topology/expected/bgp-unnumbered.yml +++ b/tests/topology/expected/bgp-unnumbered.yml @@ -55,7 +55,6 @@ links: node: r2 role: external type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: 10.10.10.1/24 @@ -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 @@ -192,7 +190,6 @@ nodes: node: r1 role: external type: p2p - unnumbered: true - ifindex: 2 ifname: swp2 ipv4: 10.10.10.1/24 diff --git a/tests/topology/expected/igp-af.yml b/tests/topology/expected/igp-af.yml index 6ff249db1..1a6dc3f20 100644 --- a/tests/topology/expected/igp-af.yml +++ b/tests/topology/expected/igp-af.yml @@ -30,7 +30,6 @@ links: ipv6: true node: r2 type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: true @@ -54,7 +53,6 @@ links: ipv6: true node: r3 type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: true @@ -78,7 +76,6 @@ links: ipv6: true node: r4 type: p2p - unnumbered: true - interfaces: - ifindex: 2 ipv4: true @@ -102,7 +99,6 @@ links: ipv6: true node: r5 type: p2p - unnumbered: true - bridge: input_5 interfaces: - ifindex: 2 @@ -146,7 +142,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet2 ipv4: true @@ -166,7 +161,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true isis: af: ipv4: true @@ -218,7 +212,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true isis: af: ipv4: true @@ -270,7 +263,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet2 ipv4: true @@ -290,7 +282,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true isis: af: ipv4: true @@ -341,7 +332,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - ifindex: 2 ifname: Ethernet2 ipv4: true @@ -361,7 +351,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true isis: af: ipv4: true @@ -413,7 +402,6 @@ nodes: network_type: point-to-point passive: false type: p2p - unnumbered: true - bridge: input_5 ifindex: 2 ifname: Ethernet2 diff --git a/tests/topology/expected/isis-feature-test.yml b/tests/topology/expected/isis-feature-test.yml index dffa7f815..5bdf6cae9 100644 --- a/tests/topology/expected/isis-feature-test.yml +++ b/tests/topology/expected/isis-feature-test.yml @@ -138,7 +138,6 @@ links: ipv4: true node: c_nxos type: p2p - unnumbered: true - interfaces: - ifindex: 6 ipv4: true @@ -158,7 +157,6 @@ links: ipv4: true node: c_nxos type: p2p - unnumbered: true - interfaces: - ifindex: 7 ipv6: true @@ -220,7 +218,6 @@ links: ipv4: true node: c_csr type: p2p - unnumbered: true - interfaces: - ifindex: 8 ipv6: true @@ -356,7 +353,6 @@ nodes: ipv4: true node: c_nxos type: p2p - unnumbered: true - ifindex: 6 ifname: Ethernet6 ipv6: true @@ -383,7 +379,6 @@ nodes: ipv4: true node: c_csr type: p2p - unnumbered: true - ifindex: 8 ifname: Ethernet8 linkindex: 14 @@ -500,7 +495,6 @@ nodes: ipv4: true node: c_nxos type: p2p - unnumbered: true - ifindex: 7 ifname: GigabitEthernet7 ipv4: true @@ -514,7 +508,6 @@ nodes: ipv4: true node: a_eos type: p2p - unnumbered: true - ifindex: 8 ifname: GigabitEthernet8 ipv6: true @@ -637,7 +630,6 @@ nodes: ipv4: true node: a_eos type: p2p - unnumbered: true - ifindex: 6 ifname: Ethernet1/6 ipv4: true @@ -651,7 +643,6 @@ nodes: ipv4: true node: c_csr type: p2p - unnumbered: true - ifindex: 7 ifname: Ethernet1/7 ipv6: true diff --git a/tests/topology/expected/unnumbered.yml b/tests/topology/expected/unnumbered.yml index fbe8e086d..47c61fe7d 100644 --- a/tests/topology/expected/unnumbered.yml +++ b/tests/topology/expected/unnumbered.yml @@ -50,7 +50,6 @@ links: node: c_nxos role: core type: p2p - unnumbered: true - interfaces: - ifindex: 3 ipv4: true @@ -75,7 +74,6 @@ links: node: n_cumulus role: core type: p2p - unnumbered: true - interfaces: - ifindex: 3 ipv4: true @@ -100,7 +98,6 @@ links: node: j_vsrx role: core type: p2p - unnumbered: true name: input nodes: a_eos: @@ -145,7 +142,6 @@ nodes: node: c_nxos role: core type: p2p - unnumbered: true - ifindex: 3 ifname: Ethernet3 ipv4: true @@ -159,7 +155,6 @@ nodes: node: n_cumulus role: core type: p2p - unnumbered: true loopback: ipv4: 172.18.1.2/32 ipv6: 2001:db8:0:2::1/64 @@ -210,7 +205,6 @@ nodes: node: a_eos role: core type: p2p - unnumbered: true - ifindex: 3 ifname: Ethernet1/3 ipv4: true @@ -224,7 +218,6 @@ nodes: node: j_vsrx role: core type: p2p - unnumbered: true loopback: ipv4: 172.18.1.1/32 ipv6: 2001:db8:0:1::1/64 @@ -275,7 +268,6 @@ nodes: node: c_nxos role: core type: p2p - unnumbered: true loopback: ipv4: 172.18.1.3/32 ipv6: 2001:db8:0:3::1/64 @@ -326,7 +318,6 @@ nodes: node: a_eos role: core type: p2p - unnumbered: true loopback: ipv4: 172.18.1.4/32 ipv6: 2001:db8:0:4::1/64