]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_confed1/test_bgp_confed1.py
6 # Copyright 2022 6WIND S.A.
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 6WIND DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 6WIND 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_bgp_confed1.py: Test the FRR BGP confederations with AS member
25 same as confederation Id, verify BGP prefixes and path distribution
31 from functools
import partial
34 # Save the Current Working Directory to find configuration files.
35 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 sys
.path
.append(os
.path
.join(CWD
, "../"))
38 # pylint: disable=C0413
39 # Import topogen and topotest helpers
40 from lib
import topotest
41 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
42 from lib
.topolog
import logger
44 pytestmark
= [pytest
.mark
.bgpd
]
48 for routern
in range(1, 5):
49 tgen
.add_router("r{}".format(routern
))
51 switch
= tgen
.add_switch("s1")
52 switch
.add_link(tgen
.gears
["r1"])
53 switch
.add_link(tgen
.gears
["r2"])
55 switch
= tgen
.add_switch("s3")
56 switch
.add_link(tgen
.gears
["r3"])
57 switch
.add_link(tgen
.gears
["r4"])
59 switch
= tgen
.add_switch("s2")
60 switch
.add_link(tgen
.gears
["r2"])
61 switch
.add_link(tgen
.gears
["r3"])
63 def setup_module(mod
):
65 tgen
= Topogen(build_topo
, mod
.__name
__)
68 router_list
= tgen
.routers()
69 for rname
, router
in router_list
.items():
71 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
74 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
77 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
80 # Initialize all routers.
83 def teardown_module(_mod
):
84 "Teardown the pytest environment"
89 def test_bgp_convergence():
90 "Assert that BGP is converging."
92 if tgen
.routers_have_failure():
93 pytest
.skip(tgen
.errors
)
95 logger
.info("waiting for bgp peers to go up")
97 for router
in tgen
.routers().values():
98 ref_file
= "{}/{}/bgp_summary.json".format(CWD
, router
.name
)
99 expected
= json
.loads(open(ref_file
).read())
101 topotest
.router_json_cmp
, router
, "show ip bgp summary json", expected
103 _
, res
= topotest
.run_and_expect(test_func
, None, count
=125, wait
=2.0)
104 assertmsg
= "{}: bgp did not converge".format(router
.name
)
105 assert res
is None, assertmsg
108 def test_bgp_confed_ipv4_unicast():
109 "Assert that BGP is exchanging BGP route."
111 if tgen
.routers_have_failure():
112 pytest
.skip(tgen
.errors
)
114 logger
.info("waiting for bgp peers exchanging UPDATES")
116 for router
in tgen
.routers().values():
117 ref_file
= "{}/{}/bgp_ipv4_unicast.json".format(CWD
, router
.name
)
118 expected
= json
.loads(open(ref_file
).read())
120 topotest
.router_json_cmp
, router
, "show bgp ipv4 unicast json", expected
122 _
, res
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=2.5)
123 assertmsg
= "{}: BGP UPDATE exchange failure".format(router
.name
)
124 assert res
is None, assertmsg
127 if __name__
== "__main__":
128 args
= ["-s"] + sys
.argv
[1:]
129 sys
.exit(pytest
.main(args
))