]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd-topo3/test_bfd_topo3.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 test_bfd_topo3.py: Test the FRR BFD daemon multi hop.
32 from functools
import partial
35 # Save the Current Working Directory to find configuration files.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
import topotest
42 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
43 from lib
.topolog
import logger
45 # Required to instantiate the topology builder class.
46 from mininet
.topo
import Topo
50 "Test topology builder"
52 def build(self
, *_args
, **_opts
):
54 tgen
= get_topogen(self
)
57 for routern
in range(1, 5):
58 tgen
.add_router("r{}".format(routern
))
60 switch
= tgen
.add_switch("s1")
61 switch
.add_link(tgen
.gears
["r1"])
62 switch
.add_link(tgen
.gears
["r2"])
64 switch
= tgen
.add_switch("s2")
65 switch
.add_link(tgen
.gears
["r2"])
66 switch
.add_link(tgen
.gears
["r3"])
68 switch
= tgen
.add_switch("s3")
69 switch
.add_link(tgen
.gears
["r3"])
70 switch
.add_link(tgen
.gears
["r4"])
73 def setup_module(mod
):
74 "Sets up the pytest environment"
75 tgen
= Topogen(BFDTopo
, mod
.__name
__)
78 router_list
= tgen
.routers()
79 for rname
, router
in router_list
.items():
80 daemon_file
= "{}/{}/bfdd.conf".format(CWD
, rname
)
81 if os
.path
.isfile(daemon_file
):
82 router
.load_config(TopoRouter
.RD_BFD
, daemon_file
)
84 daemon_file
= "{}/{}/zebra.conf".format(CWD
, rname
)
85 if os
.path
.isfile(daemon_file
):
86 router
.load_config(TopoRouter
.RD_ZEBRA
, daemon_file
)
88 daemon_file
= "{}/{}/bgpd.conf".format(CWD
, rname
)
89 if os
.path
.isfile(daemon_file
):
90 router
.load_config(TopoRouter
.RD_BGP
, daemon_file
)
92 # Initialize all routers.
96 def test_wait_bgp_convergence():
97 "Wait for BGP to converge"
99 if tgen
.routers_have_failure():
100 pytest
.skip(tgen
.errors
)
102 logger
.info("waiting for protocols to converge")
104 def expect_loopback_route(router
, iptype
, route
, proto
):
105 "Wait until route is present on RIB for protocol."
106 logger
.info('waiting route {} in {}'.format(route
, router
))
108 topotest
.router_json_cmp
,
110 'show {} route json'.format(iptype
),
111 { route
: [{ 'protocol': proto
}] }
113 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
114 assertmsg
= '"{}" OSPF convergence failure'.format(router
)
115 assert result
is None, assertmsg
117 # Wait for R1 <-> R2 convergence.
118 expect_loopback_route('r1', 'ip', '10.254.254.2/32', 'bgp')
119 # Wait for R1 <-> R3 convergence.
120 expect_loopback_route('r1', 'ip', '10.254.254.3/32', 'bgp')
121 # Wait for R1 <-> R4 convergence.
122 expect_loopback_route('r1', 'ip', '10.254.254.4/32', 'bgp')
124 # Wait for R2 <-> R1 convergence.
125 expect_loopback_route('r2', 'ip', '10.254.254.1/32', 'bgp')
126 # Wait for R2 <-> R3 convergence.
127 expect_loopback_route('r2', 'ip', '10.254.254.3/32', 'bgp')
128 # Wait for R2 <-> R4 convergence.
129 expect_loopback_route('r2', 'ip', '10.254.254.4/32', 'bgp')
131 # Wait for R3 <-> R1 convergence.
132 expect_loopback_route('r3', 'ip', '10.254.254.1/32', 'bgp')
133 # Wait for R3 <-> R2 convergence.
134 expect_loopback_route('r3', 'ip', '10.254.254.2/32', 'bgp')
135 # Wait for R3 <-> R4 convergence.
136 expect_loopback_route('r3', 'ip', '10.254.254.4/32', 'bgp')
138 # Wait for R4 <-> R1 convergence.
139 expect_loopback_route('r4', 'ip', '10.254.254.1/32', 'bgp')
140 # Wait for R4 <-> R2 convergence.
141 expect_loopback_route('r4', 'ip', '10.254.254.2/32', 'bgp')
142 # Wait for R4 <-> R3 convergence.
143 expect_loopback_route('r4', 'ip', '10.254.254.3/32', 'bgp')
146 def test_wait_bfd_convergence():
147 "Wait for BFD to converge"
149 if tgen
.routers_have_failure():
150 pytest
.skip(tgen
.errors
)
152 logger
.info("test BFD configurations")
154 def expect_bfd_configuration(router
):
155 "Load JSON file and compare with 'show bfd peer json'"
156 logger
.info('waiting BFD configuration on router {}'.format(router
))
157 bfd_config
= json
.loads(open('{}/{}/bfd-peers.json'.format(CWD
, router
)).read())
159 topotest
.router_json_cmp
,
161 'show bfd peers json',
164 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
165 assertmsg
= '"{}" BFD configuration failure'.format(router
)
166 assert result
is None, assertmsg
168 expect_bfd_configuration('r1')
169 expect_bfd_configuration('r2')
170 expect_bfd_configuration('r3')
171 expect_bfd_configuration('r4')
174 def teardown_module(_mod
):
175 "Teardown the pytest environment"
180 def test_memory_leak():
181 "Run the memory leak test and report results."
183 if not tgen
.is_memleak_enabled():
184 pytest
.skip("Memory leak test/report is disabled")
186 tgen
.report_memory_leaks()
189 if __name__
== "__main__":
190 args
= ["-s"] + sys
.argv
[1:]
191 sys
.exit(pytest
.main(args
))