]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ldp_vpls_topo1/test_ldp_vpls_topo1.py
4 # test_ldp_vpls_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2017 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_ldp_vpls_topo1.py:
28 +---------+ +---------+
32 +---------+ +---------+
33 ce1-eth0 (172.16.1.1/24)| |ce2-eth0 (172.16.1.2/24)
37 +---------+ 10.0.1.0/24 +---------+
39 | RT1 +----------------+ RT2 |
40 | 1.1.1.1 | rt2-eth1| 2.2.2.2 |
42 +---------+ +---------+
46 10.0.2.0/24| +---------+ |10.0.3.0/24
49 +--------+ 3.3.3.3 +-------+
55 ce3-eth0 (172.16.1.3/24)|
67 from functools
import partial
69 # Save the Current Working Directory to find configuration files.
70 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
71 sys
.path
.append(os
.path
.join(CWD
, "../"))
73 # pylint: disable=C0413
74 # Import topogen and topotest helpers
75 from lib
import topotest
76 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
77 from lib
.topolog
import logger
79 # Required to instantiate the topology builder class.
81 pytestmark
= [pytest
.mark
.ldpd
, pytest
.mark
.ospfd
]
90 for router
in ["ce1", "ce2", "ce3", "r1", "r2", "r3"]:
91 tgen
.add_router(router
)
96 switch
= tgen
.add_switch("s1")
97 switch
.add_link(tgen
.gears
["ce1"])
98 switch
.add_link(tgen
.gears
["r1"])
100 switch
= tgen
.add_switch("s2")
101 switch
.add_link(tgen
.gears
["ce2"])
102 switch
.add_link(tgen
.gears
["r2"])
104 switch
= tgen
.add_switch("s3")
105 switch
.add_link(tgen
.gears
["ce3"])
106 switch
.add_link(tgen
.gears
["r3"])
108 switch
= tgen
.add_switch("s4")
109 switch
.add_link(tgen
.gears
["r1"])
110 switch
.add_link(tgen
.gears
["r2"])
112 switch
= tgen
.add_switch("s5")
113 switch
.add_link(tgen
.gears
["r1"])
114 switch
.add_link(tgen
.gears
["r3"])
116 switch
= tgen
.add_switch("s6")
117 switch
.add_link(tgen
.gears
["r2"])
118 switch
.add_link(tgen
.gears
["r3"])
121 def setup_module(mod
):
122 "Sets up the pytest environment"
123 tgen
= Topogen(build_topo
, mod
.__name
__)
124 tgen
.start_topology()
126 router_list
= tgen
.routers()
128 # For all registered routers, load the zebra configuration file
129 for rname
, router
in router_list
.items():
131 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
133 # Don't start ospfd and ldpd in the CE nodes
134 if router
.name
[0] == "r":
136 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
139 TopoRouter
.RD_LDP
, os
.path
.join(CWD
, "{}/ldpd.conf".format(rname
))
145 def teardown_module(mod
):
146 "Teardown the pytest environment"
149 # This function tears down the whole topology.
153 def router_compare_json_output(rname
, command
, reference
, count
=80, wait
=1):
154 "Compare router JSON output"
156 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
159 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
160 expected
= json
.loads(open(filename
).read())
162 # Run test function until we get an result.
163 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
164 _
, diff
= topotest
.run_and_expect(test_func
, None, count
, wait
)
165 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
166 assert diff
is None, assertmsg
169 def test_ospf_convergence():
170 logger
.info("Test: check OSPF adjacencies")
173 # Skip if previous fatal error condition is raised
174 if tgen
.routers_have_failure():
175 pytest
.skip(tgen
.errors
)
177 for rname
in ["r1", "r2", "r3"]:
178 router_compare_json_output(
179 rname
, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json"
184 logger
.info("Test: verify RIB")
187 # Skip if previous fatal error condition is raised
188 if tgen
.routers_have_failure():
189 pytest
.skip(tgen
.errors
)
191 for rname
in ["r1", "r2", "r3"]:
192 router_compare_json_output(rname
, "show ip route json", "show_ip_route.ref")
195 def test_ldp_adjacencies():
196 logger
.info("Test: verify LDP adjacencies")
199 # Skip if previous fatal error condition is raised
200 if tgen
.routers_have_failure():
201 pytest
.skip(tgen
.errors
)
203 for rname
in ["r1", "r2", "r3"]:
204 router_compare_json_output(
205 rname
, "show mpls ldp discovery json", "show_ldp_discovery.ref"
209 def test_ldp_neighbors():
210 logger
.info("Test: verify LDP neighbors")
213 # Skip if previous fatal error condition is raised
214 if tgen
.routers_have_failure():
215 pytest
.skip(tgen
.errors
)
217 for rname
in ["r1", "r2", "r3"]:
218 router_compare_json_output(
219 rname
, "show mpls ldp neighbor json", "show_ldp_neighbor.ref"
223 def test_ldp_bindings():
224 logger
.info("Test: verify LDP bindings")
227 # Skip if previous fatal error condition is raised
228 if tgen
.routers_have_failure():
229 pytest
.skip(tgen
.errors
)
231 for rname
in ["r1", "r2", "r3"]:
232 router_compare_json_output(
233 rname
, "show mpls ldp binding json", "show_ldp_binding.ref"
237 def test_ldp_pwid_bindings():
238 logger
.info("Test: verify LDP PW-ID bindings")
241 # Skip if previous fatal error condition is raised
242 if tgen
.routers_have_failure():
243 pytest
.skip(tgen
.errors
)
245 for rname
in ["r1", "r2", "r3"]:
246 router_compare_json_output(
247 rname
, "show l2vpn atom binding json", "show_l2vpn_binding.ref"
251 def test_ldp_pseudowires():
252 logger
.info("Test: verify LDP pseudowires")
255 # Skip if previous fatal error condition is raised
256 if tgen
.routers_have_failure():
257 pytest
.skip(tgen
.errors
)
259 for rname
in ["r1", "r2", "r3"]:
260 router_compare_json_output(
261 rname
, "show l2vpn atom vc json", "show_l2vpn_vc.ref"
265 def test_ldp_pseudowires_after_link_down():
266 logger
.info("Test: verify LDP pseudowires after r1-r2 link goes down")
269 # Skip if previous fatal error condition is raised
270 if tgen
.routers_have_failure():
271 pytest
.skip(tgen
.errors
)
273 # Shut down r1-r2 link */
276 tgen
.gears
[rname
].peer_link_enable("r1-eth1", False)
277 router_compare_json_output(
279 "show ip route json",
280 "show_ip_route_after_link_down.ref",
284 # check if the pseudowire is still up (using an alternate path
285 # for nexthop resolution). Give some extra wait time.
286 for rname
in ["r1", "r2", "r3"]:
287 router_compare_json_output(
288 rname
, "show l2vpn atom vc json", "show_l2vpn_vc.ref", count
=160, wait
=1
292 # Memory leak test template
293 def test_memory_leak():
294 "Run the memory leak test and report results."
296 if not tgen
.is_memleak_enabled():
297 pytest
.skip("Memory leak test/report is disabled")
299 tgen
.report_memory_leaks()
302 if __name__
== "__main__":
303 args
= ["-s"] + sys
.argv
[1:]
304 sys
.exit(pytest
.main(args
))