tests: Enhance bgp_features topotest suite with tests for "bgp no-rib"

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
Signed-off-by: David Schweizer <dschweizer@opensourcerouting.org>
This commit is contained in:
David Schweizer 2020-09-02 18:20:09 +02:00
parent c163f2971b
commit 251931afbd
No known key found for this signature in database
GPG Key ID: A07D97BEEE79EF7F
3 changed files with 806 additions and 1 deletions

View File

@ -0,0 +1,382 @@
{
"0.0.0.0\/0":[
{
"prefix":"0.0.0.0\/0",
"protocol":"bgp",
"selected":true,
"destSelected":true,
"distance":20,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.101.2",
"afi":"ipv4",
"interfaceIndex":4,
"interfaceName":"r1-eth3",
"active":true,
"weight":1
}
]
}
],
"192.168.0.1\/32":[
{
"prefix":"192.168.0.1\/32",
"protocol":"ospf",
"distance":110,
"metric":0,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":1,
"interfaceName":"lo",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.0.1\/32",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":1,
"interfaceName":"lo",
"active":true
}
]
}
],
"192.168.0.2\/32":[
{
"prefix":"192.168.0.2\/32",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":10,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
}
],
"192.168.0.3\/32":[
{
"prefix":"192.168.0.3\/32",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":10,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.1.0\/24":[
{
"prefix":"192.168.1.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"table":254,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.1.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true
}
]
}
],
"192.168.2.0\/24":[
{
"prefix":"192.168.2.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
},
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.3.0\/24":[
{
"prefix":"192.168.3.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.3.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true
}
]
}
],
"192.168.6.0\/24":[
{
"prefix":"192.168.6.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":5,
"interfaceName":"r1-eth0",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.6.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":5,
"interfaceName":"r1-eth0",
"active":true
}
]
}
],
"192.168.7.0\/24":[
{
"prefix":"192.168.7.0\/24",
"protocol":"bgp",
"distance":200,
"metric":0,
"nexthops":[
{
"flags":5,
"ip":"192.168.0.2",
"afi":"ipv4",
"active":true,
"recursive":true,
"weight":1
},
{
"flags":1,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.7.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
}
],
"192.168.8.0\/24":[
{
"prefix":"192.168.8.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.101.0\/24":[
{
"prefix":"192.168.101.0\/24",
"protocol":"bgp",
"distance":20,
"metric":0,
"nexthops":[
{
"flags":0,
"ip":"192.168.101.2",
"afi":"ipv4",
"weight":1
}
]
},
{
"prefix":"192.168.101.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":4,
"interfaceName":"r1-eth3",
"active":true
}
]
}
],
"192.168.102.0\/24":[
{
"prefix":"192.168.102.0\/24",
"protocol":"bgp",
"selected":true,
"destSelected":true,
"distance":20,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.101.2",
"afi":"ipv4",
"interfaceIndex":4,
"interfaceName":"r1-eth3",
"active":true,
"weight":1
}
]
}
]
}

View File

@ -0,0 +1,296 @@
{
"192.168.0.1\/32":[
{
"prefix":"192.168.0.1\/32",
"protocol":"ospf",
"distance":110,
"metric":0,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":1,
"interfaceName":"lo",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.0.1\/32",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":1,
"interfaceName":"lo",
"active":true
}
]
}
],
"192.168.0.2\/32":[
{
"prefix":"192.168.0.2\/32",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":10,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
}
],
"192.168.0.3\/32":[
{
"prefix":"192.168.0.3\/32",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":10,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.1.0\/24":[
{
"prefix":"192.168.1.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.1.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true
}
]
}
],
"192.168.2.0\/24":[
{
"prefix":"192.168.2.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
},
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.3.0\/24":[
{
"prefix":"192.168.3.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.3.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true
}
]
}
],
"192.168.6.0\/24":[
{
"prefix":"192.168.6.0\/24",
"protocol":"ospf",
"distance":110,
"metric":10,
"nexthops":[
{
"flags":1,
"directlyConnected":true,
"interfaceIndex":5,
"interfaceName":"r1-eth0",
"active":true,
"weight":1
}
]
},
{
"prefix":"192.168.6.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":5,
"interfaceName":"r1-eth0",
"active":true
}
]
}
],
"192.168.7.0\/24":[
{
"prefix":"192.168.7.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.1.2",
"afi":"ipv4",
"interfaceIndex":2,
"interfaceName":"r1-eth1",
"active":true,
"weight":1
}
]
}
],
"192.168.8.0\/24":[
{
"prefix":"192.168.8.0\/24",
"protocol":"ospf",
"selected":true,
"destSelected":true,
"distance":110,
"metric":20,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"ip":"192.168.3.2",
"afi":"ipv4",
"interfaceIndex":3,
"interfaceName":"r1-eth2",
"active":true,
"weight":1
}
]
}
],
"192.168.101.0\/24":[
{
"prefix":"192.168.101.0\/24",
"protocol":"connected",
"selected":true,
"destSelected":true,
"distance":0,
"metric":0,
"installed":true,
"nexthops":[
{
"flags":3,
"fib":true,
"directlyConnected":true,
"interfaceIndex":4,
"interfaceName":"r1-eth3",
"active":true
}
]
}
]
}

View File

@ -102,7 +102,7 @@ def setup_module(module):
# Starting Routers
router_list = tgen.routers()
for rname, router in router_list.items():
for rname, router in router_list.iteritems():
router.load_config(
TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
)
@ -538,6 +538,133 @@ def test_bgp_remove_metric_rmaps():
assert res is None, assertmsg
def test_bgp_norib():
"Test BGP disable RIB (Zebra) Route Install"
tgen = get_topogen()
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
logger.info("Configuring 'bgp no-rib' on router r1")
tgen.net['r1'].cmd('vtysh -c \"conf t\" -c \"bgp no-rib\"')
# Checking BGP config - should show the "bgp no-rib" under the router bgp section
logger.info("Checking BGP configuration for 'bgp no-rib'")
norib_cfg = tgen.net['r1'].cmd('vtysh -c "show running bgpd" | grep "^bgp no-rib"').rstrip()
assertmsg = "'bgp no-rib' configuration applied, but not visible in configuration"
assert norib_cfg == 'bgp no-rib', assertmsg
def test_bgp_norib_routes():
"Test Routes in Zebra and BGP with the 'bgp-norib' configuration"
tgen = get_topogen()
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
# Checking local BGP routes - they need to be gone from Zebra
logger.info("Checking Zebra routes after removing bgp shutdown on router r1")
router = tgen.gears["r1"]
reffile = os.path.join(CWD, "r1/ip_route_norib.json")
expected = json.loads(open(reffile).read())
test_func = functools.partial(
topotest.router_json_cmp, router, "show ip route json", expected
)
_, res = topotest.run_and_expect(test_func, None, count=30, wait=2)
assertmsg = "Zebra IPv4 Routes after configuring 'bgp no-rib' (There should be no BGP routes in Zebra anymore)"
assert res is None, assertmsg
# Check BGP Summary on local and remote routers
for rtrNum in [1, 2, 4]:
logger.info("Checking BGP Summary after 'bgp no-rib' on router r1 on router r{}".format(rtrNum))
router = tgen.gears["r{}".format(rtrNum)]
reffile = os.path.join(CWD, "r{}/bgp_summary.json".format(rtrNum))
expected = json.loads(open(reffile).read())
test_func = functools.partial(
topotest.router_json_cmp, router, "show ip bgp summary json", expected
)
_, res = topotest.run_and_expect(test_func, None, count=30, wait=2)
assertmsg = "BGP sessions on router R{} has incorrect routes after adding 'bgp no-rib on r1'".format(rtrNum)
assert res is None, assertmsg
# tgen.mininet_cli()
def test_bgp_disable_norib():
"Test BGP disabling the no-RIB (Zebra) Route Install"
tgen = get_topogen()
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
logger.info("Configuring 'no bgp no-rib' on router r1")
tgen.net['r1'].cmd('vtysh -c \"conf t\" -c \"no bgp no-rib\"')
# Checking BGP config - should show the "bgp no-rib" under the router bgp section
logger.info("Checking BGP configuration for 'bgp no-rib'")
norib_cfg = tgen.net['r1'].cmd('vtysh -c "show running bgpd" | grep "^ bgp no-rib"').rstrip()
assertmsg = "'no bgp no-rib'configuration applied, but still visible in configuration"
assert norib_cfg == '', assertmsg
def test_bgp_disable_norib_routes():
"Test Routes in Zebra and BGP with the 'bgp-norib' configuration"
tgen = get_topogen()
# Skip if previous fatal error condition is raised
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
# Checking local BGP routes - they need to be gone from Zebra
logger.info("Checking Zebra routes after removing bgp shutdown on router r1")
router = tgen.gears["r1"]
reffile = os.path.join(CWD, "r1/ip_route.json")
expected = json.loads(open(reffile).read())
test_func = functools.partial(
topotest.router_json_cmp, router, "show ip route json", expected
)
_, res = topotest.run_and_expect(test_func, None, count=30, wait=2)
assertmsg = "Zebra IPv4 Routes wrong after removing the 'bgp no-rib'"
assert res is None, assertmsg
# Check BGP Summary on local and remote routers
for rtrNum in [1, 2, 4]:
logger.info("Checking BGP Summary after removing the 'bgp no-rib' on router r1 on router r{}".format(rtrNum))
router = tgen.gears["r{}".format(rtrNum)]
reffile = os.path.join(CWD, "r{}/bgp_summary.json".format(rtrNum))
expected = json.loads(open(reffile).read())
test_func = functools.partial(
topotest.router_json_cmp, router, "show ip bgp summary json", expected
)
_, res = topotest.run_and_expect(test_func, None, count=30, wait=2)
assertmsg = "BGP sessions on router R{} has incorrect routes after removing 'bgp no-rib on r1'".format(rtrNum)
assert res is None, assertmsg
# tgen.mininet_cli()
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))