summaryrefslogtreecommitdiff
path: root/tests/topotests/bgp_features/test_bgp_features.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/topotests/bgp_features/test_bgp_features.py')
-rw-r--r--tests/topotests/bgp_features/test_bgp_features.py276
1 files changed, 276 insertions, 0 deletions
diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py
index 91613a0193..7c45ca8a29 100644
--- a/tests/topotests/bgp_features/test_bgp_features.py
+++ b/tests/topotests/bgp_features/test_bgp_features.py
@@ -261,6 +261,282 @@ def test_bgp_no_shutdown():
assert res is None, assertmsg
+def test_bgp_metric_config():
+ "Test BGP Changing metric values in route-maps"
+
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Configuring bgp route-maps on router r1 and r2 to update metric")
+
+ # # Adding the following configuration to r1:
+ # router bgp 65000
+ # address-family ipv4 unicast
+ # neighbor 192.168.0.2 route-map addmetric-in in
+ # neighbor 192.168.0.2 route-map addmetric-out out
+ # neighbor 192.168.101.2 route-map setmetric-in in
+ # neighbor 192.168.101.2 route-map setmetric-out out
+ # exit-address-family
+ # !
+ # ip prefix-list net1 seq 10 permit 192.168.101.0/24
+ # ip prefix-list net2 seq 20 permit 192.168.1.0/24
+ # !
+ # route-map setmetric-in permit 10
+ # match ip address prefix-list net1
+ # set metric 111
+ # !
+ # route-map setmetric-in permit 20
+ # !
+ # route-map setmetric-out permit 10
+ # match ip address prefix-list net2
+ # set metric 1011
+ # !
+ # route-map setmetric-out permit 20
+ # !
+ # route-map addmetric-in permit 10
+ # set metric +11
+ # !
+ # route-map addmetric-out permit 10
+ # set metric +12
+ # !
+
+ tgen.net['r1'].cmd('vtysh -c "conf t" -c "router bgp 65000" '+
+ '-c "address-family ipv4 unicast" '+
+ '-c "neighbor 192.168.0.2 route-map addmetric-in in" '+
+ '-c "neighbor 192.168.0.2 route-map addmetric-out out" '+
+ '-c "neighbor 192.168.101.2 route-map setmetric-in in" '+
+ '-c "neighbor 192.168.101.2 route-map setmetric-out out" ')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "ip prefix-list net1 seq 10 permit 192.168.101.0/24" '+
+ '-c "ip prefix-list net2 seq 20 permit 192.168.1.0/24"')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "route-map setmetric-in permit 10" '+
+ '-c "match ip address prefix-list net1" '+
+ '-c "set metric 111" '+
+ '-c "route-map setmetric-in permit 20"')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "route-map setmetric-out permit 10" '+
+ '-c "match ip address prefix-list net2" '+
+ '-c "set metric 1011" '+
+ '-c "route-map setmetric-out permit 20"')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "route-map addmetric-in permit 10" '+
+ '-c "set metric +11"')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "route-map addmetric-out permit 10" '+
+ '-c "set metric +12"')
+
+ # # Adding the following configuration to r2:
+ # router bgp 65000
+ # address-family ipv4 unicast
+ # neighbor 192.168.0.1 route-map subtractmetric-in in
+ # neighbor 192.168.0.1 route-map subtractmetric-out out
+ # neighbor 192.168.201.2 route-map setmetric-in in
+ # neighbor 192.168.201.2 route-map setmetric-out out
+ # exit-address-family
+ # !
+ # ip prefix-list net1 seq 10 permit 192.168.201.0/24
+ # ip prefix-list net2 seq 20 permit 192.168.2.0/24
+ # !
+ # route-map setmetric-in permit 10
+ # match ip address prefix-list net1
+ # set metric 222
+ # !
+ # route-map setmetric-in permit 20
+ # !
+ # route-map setmetric-out permit 10
+ # match ip address prefix-list net2
+ # set metric 2022
+ # !
+ # route-map setmetric-out permit 20
+ # !
+ # route-map subtractmetric-in permit 10
+ # set metric -22
+ # !
+ # route-map subtractmetric-out permit 10
+ # set metric -23
+ # !
+
+ tgen.net['r2'].cmd('vtysh -c "conf t" -c "router bgp 65000" '+
+ '-c "address-family ipv4 unicast" '+
+ '-c "neighbor 192.168.0.1 route-map subtractmetric-in in" '+
+ '-c "neighbor 192.168.0.1 route-map subtractmetric-out out" '+
+ '-c "neighbor 192.168.201.2 route-map setmetric-in in" ' +
+ '-c "neighbor 192.168.201.2 route-map setmetric-out out" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "ip prefix-list net1 seq 10 permit 192.168.201.0/24" '+
+ '-c "ip prefix-list net2 seq 20 permit 192.168.2.0/24" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "route-map setmetric-in permit 10" '+
+ '-c "match ip address prefix-list net1" '+
+ '-c "set metric 222" '+
+ '-c "route-map setmetric-in permit 20"')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "route-map setmetric-out permit 10" '+
+ '-c "match ip address prefix-list net2" '+
+ '-c "set metric 2022" '+
+ '-c "route-map setmetric-out permit 20"')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "route-map subtractmetric-in permit 10" '+
+ '-c "set metric -22"')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "route-map subtractmetric-out permit 10" '+
+ '-c "set metric -23"')
+
+ # Clear IN the bgp neighbors to make sure the route-maps are applied
+ tgen.net['r1'].cmd('vtysh -c "clear ip bgp 192.168.0.2 in" '+
+ '-c "clear ip bgp 192.168.101.2 in"')
+ tgen.net['r2'].cmd('vtysh -c "clear ip bgp 192.168.0.1 in" '+
+ '-c "clear ip bgp 192.168.201.2 in"')
+
+ # tgen.mininet_cli()
+
+ # Checking BGP config - should show the bgp metric settings in the route-maps
+ logger.info("Checking BGP configuration for correct 'set metric' values")
+
+ setmetric111 = tgen.net['r1'].cmd('vtysh -c "show running" | grep "^ set metric 111"').rstrip()
+ assertmsg = "'set metric 111' configuration applied to R1, but not visible in configuration"
+ assert setmetric111 == ' set metric 111', assertmsg
+
+ setmetric222 = tgen.net['r2'].cmd('vtysh -c "show running" | grep "^ set metric 222"').rstrip()
+ assertmsg = "'set metric 222' configuration applied to R2, but not visible in configuration"
+ assert setmetric222 == ' set metric 222', assertmsg
+
+
+def test_bgp_metric_add_config():
+ "Test BGP Changing metric values in route-maps"
+
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Checking BGP configuration for correct 'set metric' ADD value")
+
+ setmetricP11 = tgen.net['r1'].cmd('vtysh -c "show running" | grep "^ set metric +11"').rstrip()
+ assertmsg = "'set metric +11' configuration applied to R1, but not visible in configuration"
+ assert setmetricP11 == ' set metric +11', assertmsg
+
+
+def test_bgp_metric_subtract_config():
+ "Test BGP Changing metric values in route-maps"
+
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Checking BGP configuration for correct 'set metric' SUBTRACT value")
+
+ setmetricM22 = tgen.net['r2'].cmd('vtysh -c "show running" | grep "^ set metric -22"').rstrip()
+ assertmsg = "'set metric -22' configuration applied to R2, but not visible in configuration"
+ assert setmetricM22 == ' set metric -22', assertmsg
+
+
+def test_bgp_set_metric():
+ "Test setting metrics"
+
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Test absolute metric")
+
+ # Check BGP Summary on local and remote routers
+ for rtrNum in [1, 2, 4, 5]:
+ logger.info("Checking metrics of BGP router on r{}".format(rtrNum))
+
+ router = tgen.gears["r{}".format(rtrNum)]
+ reffile = os.path.join(CWD, "r{}/show_bgp_metric_test.json".format(rtrNum))
+ expected = json.loads(open(reffile).read())
+
+ test_func = functools.partial(
+ topotest.router_json_cmp, router, "show ip bgp json", expected
+ )
+ _, res = topotest.run_and_expect(test_func, None, count=60, wait=2)
+ assertmsg = "BGP metrics on router r{} wrong".format(rtrNum)
+ assert res is None, assertmsg
+
+
+def test_bgp_remove_metric_rmaps():
+ "Test removing route-maps with metric changes again"
+
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Test absolute metric")
+
+ # Remove metric route-maps and relevant comfiguration
+
+ tgen.net['r1'].cmd('vtysh -c "conf t" -c "router bgp 65000" '+
+ '-c "address-family ipv4 unicast" '+
+ '-c "no neighbor 192.168.0.2 route-map addmetric-in in" '+
+ '-c "no neighbor 192.168.0.2 route-map addmetric-out out" '+
+ '-c "no neighbor 192.168.101.2 route-map setmetric-in in" '+
+ '-c "no neighbor 192.168.101.2 route-map setmetric-out out" ')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "no ip prefix-list net1" '+
+ '-c "no ip prefix-list net2"')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map setmetric-in" ')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map setmetric-out" ')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map addmetric-in" ')
+ tgen.net['r1'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map addmetric-out" ')
+
+ tgen.net['r2'].cmd('vtysh -c "conf t" -c "router bgp 65000" '+
+ '-c "address-family ipv4 unicast" '+
+ '-c "no neighbor 192.168.0.1 route-map subtractmetric-in in" '+
+ '-c "no neighbor 192.168.0.1 route-map subtractmetric-out out" '+
+ '-c "no neighbor 192.168.201.2 route-map setmetric-in in" ' +
+ '-c "no neighbor 192.168.201.2 route-map setmetric-out out" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "no ip prefix-list net1" '+
+ '-c "no ip prefix-list net2" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map setmetric-in" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map setmetric-out" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map addmetric-in" ')
+ tgen.net['r2'].cmd('vtysh -c "conf t" '+
+ '-c "no route-map addmetric-out" ')
+
+ # Clear IN the bgp neighbors to make sure the route-maps are applied
+ tgen.net['r1'].cmd('vtysh -c "clear ip bgp 192.168.0.2 in" '+
+ '-c "clear ip bgp 192.168.101.2 in"')
+ tgen.net['r2'].cmd('vtysh -c "clear ip bgp 192.168.0.1 in" '+
+ '-c "clear ip bgp 192.168.201.2 in"')
+
+ # tgen.mininet_cli()
+
+ # Check BGP Summary on local and remote routers
+ for rtrNum in [1, 2]:
+ logger.info("Checking metrics of BGP router on r{}".format(rtrNum))
+
+ router = tgen.gears["r{}".format(rtrNum)]
+ reffile = os.path.join(CWD, "r{}/show_bgp.json".format(rtrNum))
+ expected = json.loads(open(reffile).read())
+
+ test_func = functools.partial(
+ topotest.router_json_cmp, router, "show ip bgp json", expected
+ )
+ _, res = topotest.run_and_expect(test_func, None, count=60, wait=2)
+ assertmsg = "BGP routes on router r{} are wrong after removing metric route-maps".format(rtrNum)
+ assert res is None, assertmsg
+
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]