]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_lu_topo1/test_bgp_lu.py
2 # SPDX-License-Identifier: ISC
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2020 by Volta Networks
12 test_bgp_lu.py: Test BGP LU label allocation
18 from functools
import partial
21 # Save the Current Working Directory to find configuration files.
22 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
23 sys
.path
.append(os
.path
.join(CWD
, "../"))
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib
import topotest
28 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
30 # Required to instantiate the topology builder class.
33 pytestmark
= [pytest
.mark
.bgpd
]
36 # Basic scenario for BGP-LU. Nodes are directly connected.
37 # Node 3 is advertising many routes to 2, which advertises them
38 # as BGP-LU to 1; this way we get routes with actual labels, as
39 # opposed to implicit-null routes in the 2-node case.
41 # AS1 BGP-LU AS2 iBGP AS2
42 # +-----+ +-----+ +-----+
44 # | 1 +----------------+ 2 +-----------------+ 3 |
45 # | | 10.0.0.0/24 | | 10.0.1.0/24 | |
46 # +-----+ +-----+ +-----+
52 # This function only purpose is to define allocation and relationship
53 # between routers, switches and hosts.
62 switch
= tgen
.add_switch("s1")
63 switch
.add_link(tgen
.gears
["R1"])
64 switch
.add_link(tgen
.gears
["R2"])
67 switch
= tgen
.add_switch("s2")
68 switch
.add_link(tgen
.gears
["R2"])
69 switch
.add_link(tgen
.gears
["R3"])
72 def setup_module(mod
):
73 "Sets up the pytest environment"
74 # This function initiates the topology build with Topogen...
75 tgen
= Topogen(build_topo
, mod
.__name
__)
76 # ... and here it calls Mininet initialization functions.
79 # This is a sample of configuration loading.
80 router_list
= tgen
.routers()
82 # For all registered routers, load the zebra configuration file
83 for rname
, router
in router_list
.items():
85 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
88 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
91 # After loading the configurations, this function loads configured daemons.
95 def teardown_module(mod
):
96 "Teardown the pytest environment"
99 # This function tears down the whole topology.
103 def check_labelpool(router
):
104 json_file
= "{}/{}/labelpool.summ.json".format(CWD
, router
.name
)
105 expected
= json
.loads(open(json_file
).read())
108 topotest
.router_json_cmp
, router
, "show bgp labelpool summary json", expected
110 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
111 assertmsg
= '"{}" JSON output mismatches - Did not converge'.format(router
.name
)
112 assert result
is None, assertmsg
115 def test_converge_bgplu():
116 "Wait for protocol convergence"
119 # Don't run this test if we have any failure.
120 if tgen
.routers_have_failure():
121 pytest
.skip(tgen
.errors
)
123 # tgen.mininet_cli();
124 r1
= tgen
.gears
["R1"]
125 r2
= tgen
.gears
["R2"]
131 def test_clear_bgplu():
132 "Wait for protocol convergence"
135 # Don't run this test if we have any failure.
136 if tgen
.routers_have_failure():
137 pytest
.skip(tgen
.errors
)
139 # tgen.mininet_cli();
140 r1
= tgen
.gears
["R1"]
141 r2
= tgen
.gears
["R2"]
143 r1
.vtysh_cmd("clear bgp 10.0.0.2")
147 r2
.vtysh_cmd("clear bgp 10.0.1.3")
151 r1
.vtysh_cmd("clear bgp 10.0.0.2")
152 r2
.vtysh_cmd("clear bgp 10.0.1.3")
157 def test_memory_leak():
158 "Run the memory leak test and report results."
160 if not tgen
.is_memleak_enabled():
161 pytest
.skip("Memory leak test/report is disabled")
163 tgen
.report_memory_leaks()
166 if __name__
== "__main__":
167 args
= ["-s"] + sys
.argv
[1:]
168 sys
.exit(pytest
.main(args
))