]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_lu_topo2/test_bgp_lu2.py
5 # Part of FRR/NetDEF Topology Tests
7 # Copyright (c) 2020 by Volta Networks
8 # Copyright (c) 2021 by Nvidia, Inc.
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_bgp_lu2.py: Test BGP LU label allocation
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.
47 pytestmark
= [pytest
.mark
.bgpd
]
50 # Basic scenario for BGP-LU. Nodes are directly connected.
51 # Node 3 is advertising routes to 2, which advertises them
52 # as BGP-LU to 1; this way we get routes with actual labels, as
53 # opposed to implicit-null routes in the 2-node case.
55 # R2 is an LER, with MPLS towards R1, and IP towards R3. R1 is an LSR, with
59 # AS4 BGP-LU AS1 BGP-LU AS2 iBGP AS2
60 # +-----+ +-----+ +-----+ +-----+
61 # | |.4 .1| |.1 .2| |.2 .3| |
62 # | 4 +-------------+ 1 +----------------+ 2 +-----------------+ 3 |
63 # | | 10.0.4.0/24 | | 10.0.0.0/24 | | 10.0.1.0/24 | |
64 # +-----+ +-----+ +-----+ +-----+
72 # This function's only purpose is to define allocation and relationship
73 # between routers, switches and hosts.
83 switch
= tgen
.add_switch("s1")
84 switch
.add_link(tgen
.gears
["R1"])
85 switch
.add_link(tgen
.gears
["R2"])
88 switch
= tgen
.add_switch("s2")
89 switch
.add_link(tgen
.gears
["R2"])
90 switch
.add_link(tgen
.gears
["R3"])
93 switch
= tgen
.add_switch("s3")
94 switch
.add_link(tgen
.gears
["R1"])
95 switch
.add_link(tgen
.gears
["R4"])
98 def setup_module(mod
):
99 "Sets up the pytest environment"
100 # This function initiates the topology build with Topogen...
101 tgen
= Topogen(build_topo
, mod
.__name
__)
103 # Skip if no mpls support
105 logger
.info("MPLS is not available, skipping test")
106 pytest
.skip("MPLS is not available, skipping")
109 # ... and here it calls Mininet initialization functions.
110 tgen
.start_topology()
112 # This is a sample of configuration loading.
113 router_list
= tgen
.routers()
115 # Enable mpls input for routers, so we can ping
116 sval
= "net.mpls.conf.{}.input"
117 topotest
.sysctl_assure(router_list
["R2"], sval
.format("R2-eth0"), 1)
118 topotest
.sysctl_assure(router_list
["R1"], sval
.format("R1-eth0"), 1)
119 topotest
.sysctl_assure(router_list
["R1"], sval
.format("R1-eth1"), 1)
120 topotest
.sysctl_assure(router_list
["R4"], sval
.format("R4-eth0"), 1)
122 # For all registered routers, load the zebra configuration file
123 for rname
, router
in router_list
.items():
125 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
128 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
131 # Have static config for R3 too
132 if router
== router_list
["R3"]:
134 TopoRouter
.RD_STATIC
, os
.path
.join(CWD
, "{}/staticd.conf".format(rname
))
137 # After loading the configurations, this function loads configured daemons.
141 def teardown_module(mod
):
142 "Teardown the pytest environment"
145 # This function tears down the whole topology.
149 def check_labelpool(router
):
150 json_file
= "{}/{}/labelpool.summ.json".format(CWD
, router
.name
)
151 expected
= json
.loads(open(json_file
).read())
154 topotest
.router_json_cmp
, router
, "show bgp labelpool summary json", expected
156 _
, result
= topotest
.run_and_expect(test_func
, None, count
=20, wait
=1)
157 assertmsg
= '"{}" JSON output mismatches - Did not converge'.format(router
.name
)
158 assert result
is None, assertmsg
161 def test_converge_bgplu():
162 "Wait for protocol convergence"
165 # Don't run this test if we have any failure.
166 if tgen
.routers_have_failure():
167 pytest
.skip(tgen
.errors
)
169 # TODO -- enable for debugging
172 r1
= tgen
.gears
["R1"]
173 r2
= tgen
.gears
["R2"]
184 # Don't run this test if we have any failure.
185 if tgen
.routers_have_failure():
186 pytest
.skip(tgen
.errors
)
189 logger
.info("Ping from R2 to R3")
190 router
= tgen
.gears
["R2"]
191 output
= router
.run("ping -c 4 -w 4 {}".format("10.0.1.3"))
192 assert " 0% packet loss" in output
, "Ping R2->R3 FAILED"
193 logger
.info("Ping from R2 to R3 ... success")
196 logger
.info("Ping from R4 to R2")
197 router
= tgen
.gears
["R4"]
198 output
= router
.run("ping -c 4 -w 4 {}".format("10.0.0.2"))
199 assert " 0% packet loss" in output
, "Ping R4->R2 FAILED"
200 logger
.info("Ping from R4 to R2 ... success")
203 logger
.info("Ping from R4 to R3")
204 router
= tgen
.gears
["R4"]
205 output
= router
.run("ping -c 4 -w 4 {}".format("10.0.1.3"))
206 assert " 0% packet loss" in output
, "Ping R4->R3 FAILED"
207 logger
.info("Ping from R4 to R3 ... success")
210 def test_memory_leak():
211 "Run the memory leak test and report results."
213 if not tgen
.is_memleak_enabled():
214 pytest
.skip("Memory leak test/report is disabled")
216 tgen
.report_memory_leaks()
219 if __name__
== "__main__":
220 args
= ["-s"] + sys
.argv
[1:]
221 sys
.exit(pytest
.main(args
))