]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_max_med_on_startup/test_bgp_max_med_on_startup.py
a83d43310bf9737b5808aa0301488e3f2cf2d1c8
4 # test_bgp_max_med_on_startup.py
6 # Copyright (c) 2022 Rubicon Communications, LLC.
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
13 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 Test whether `bgp max-med on-startup (5-86400) [(0-4294967295)]` is working
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
41 pytestmark
= [pytest
.mark
.bgpd
]
45 for routern
in range(1, 3):
46 tgen
.add_router("r{}".format(routern
))
48 switch
= tgen
.add_switch("s1")
49 switch
.add_link(tgen
.gears
["r1"])
50 switch
.add_link(tgen
.gears
["r2"])
53 def setup_module(mod
):
54 tgen
= Topogen(build_topo
, mod
.__name
__)
57 router_list
= tgen
.routers()
59 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
61 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
64 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
70 def teardown_module(mod
):
75 def test_bgp_max_med_on_startup():
78 if tgen
.routers_have_failure():
79 pytest
.skip(tgen
.errors
)
81 router1
= tgen
.gears
["r1"]
82 router2
= tgen
.gears
["r2"]
84 def _bgp_converge(router
):
85 output
= json
.loads(router
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
86 expected
= {"192.168.255.1": {"bgpState": "Established"}}
87 return topotest
.json_cmp(output
, expected
)
89 def _bgp_has_routes(router
, metric
):
91 router
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 routes json")
93 expected
= {"routes": {"172.16.255.254/32": [{"metric": metric
}]}}
94 return topotest
.json_cmp(output
, expected
)
96 # Check session is established
97 test_func
= functools
.partial(_bgp_converge
, router2
)
98 success
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
99 assert result
is None, "Failed bgp convergence on r2"
101 # Check metric has value of max-med
102 test_func
= functools
.partial(_bgp_has_routes
, router2
, 777)
103 success
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
104 assert result
is None, "r2 does not receive routes with metric 777"
106 # Check that when the max-med timer expires, metric is updated
107 test_func
= functools
.partial(_bgp_has_routes
, router2
, 0)
108 success
, result
= topotest
.run_and_expect(test_func
, None, count
=16, wait
=0.5)
109 assert result
is None, "r2 does not receive routes with metric 0"
112 if __name__
== "__main__":
113 args
= ["-s"] + sys
.argv
[1:]
114 sys
.exit(pytest
.main(args
))