]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py
4 # test_bgp_multiview_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2016 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_bgp_multiview_topo1.py: Simple FRR Route-Server Test
28 +----------+ +----------+ +----------+ +----------+ +----------+
29 | peer1 | | peer2 | | peer3 | | peer4 | | peer5 |
30 | AS 65001 | | AS 65002 | | AS 65003 | | AS 65004 | | AS 65005 |
31 +-----+----+ +-----+----+ +-----+----+ +-----+----+ +-----+----+
32 | .1 | .2 | .3 | .4 | .5
33 | ______/ / / _________/
34 \ / ________________/ / /
35 | | / _________________________/ / +----------+
36 | | | / __________________________/ ___| peer6 |
37 | | | | / ____________________________/.6 | AS 65006 |
38 | | | | | / _________________________ +----------+
39 | | | | | | / __________________ \ +----------+
40 | | | | | | | / \ \___| peer7 |
41 | | | | | | | | \ .7 | AS 65007 |
42 ~~~~~~~~~~~~~~~~~~~~~ \ +----------+
43 ~~ SW1 ~~ \ +----------+
44 ~~ Switch ~~ \_____| peer8 |
45 ~~ 172.16.1.0/24 ~~ .8 | AS 65008 |
46 ~~~~~~~~~~~~~~~~~~~~~ +----------+
58 ~~~~~~~~~~~~~ Stub Network is redistributed
59 ~~ SW0 ~~ into each BGP view with different
60 ~~ 172.20.0.1/28 ~~ attributes (using route-map)
70 from time
import sleep
72 from functools
import partial
74 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
75 from lib
import topotest
76 from lib
.topogen
import get_topogen
, Topogen
77 from lib
.common_config
import step
80 pytestmark
= [pytest
.mark
.bgpd
]
86 #####################################################
88 ## Network Topology Definition
90 #####################################################
95 router
= tgen
.add_router("r1")
97 # Setup Provider BGP peers
100 peer
[i
] = tgen
.add_exabgp_peer(
101 "peer%s" % i
, ip
="172.16.1.%s/24" % i
, defaultRoute
="via 172.16.1.254"
104 # First switch is for a dummy interface (for local network)
105 switch
= tgen
.add_switch("sw0")
106 switch
.add_link(router
, nodeif
="r1-stub")
108 # Second switch is for connection to all peering routers
109 switch
= tgen
.add_switch("sw1")
110 switch
.add_link(router
, nodeif
="r1-eth0")
111 for j
in range(1, 9):
112 switch
.add_link(peer
[j
], nodeif
="peer%s-eth0" % j
)
115 #####################################################
119 #####################################################
122 def setup_module(module
):
123 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
124 tgen
= Topogen(build_topo
, module
.__name
__)
125 tgen
.start_topology()
128 router
= tgen
.net
["r1"]
129 router
.loadConf("zebra", "%s/r1/zebra.conf" % thisDir
)
130 router
.loadConf("bgpd", "%s/r1/bgpd.conf" % thisDir
)
131 tgen
.gears
["r1"].start()
133 # Starting PE Hosts and init ExaBGP on each of them
134 peer_list
= tgen
.exabgp_peers()
135 for pname
, peer
in peer_list
.items():
136 peer_dir
= os
.path
.join(thisDir
, pname
)
137 env_file
= os
.path
.join(thisDir
, "exabgp.env")
138 peer
.start(peer_dir
, env_file
)
141 def teardown_module(module
):
146 def test_router_running():
149 if tgen
.routers_have_failure():
150 pytest
.skip(tgen
.errors
)
153 def test_bgp_converge():
154 "Check for BGP converged on all peers and BGP views"
158 if tgen
.routers_have_failure():
159 pytest
.skip(tgen
.errors
)
161 # Wait for BGP to converge (All Neighbors in either Full or TwoWay State)
162 step("Verify for BGP to converge")
166 print("Timeout in %s: " % timeout
),
168 # Look for any node not yet converged
169 for i
in range(1, 2):
170 for view
in range(1, 4):
171 notConverged
= tgen
.net
["r%s" % i
].cmd(
172 'vtysh -c "show ip bgp view %s summary" 2> /dev/null | grep ^[0-9] | grep -vP " 11\s+(\d+)"'
176 print("Waiting for r%s, view %s" % (i
, view
))
188 # Bail out with error if a router fails to converge
189 bgpStatus
= tgen
.net
["r%s" % i
].cmd(
190 'vtysh -c "show ip bgp view %s summary"' % view
192 assert False, "BGP did not converge:\n%s" % bgpStatus
194 tgen
.routers_have_failure()
197 def test_bgp_routingTable():
200 if tgen
.routers_have_failure():
201 pytest
.skip(tgen
.errors
)
203 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
205 step("Verifying BGP Routing Tables")
207 router
= tgen
.gears
["r1"]
208 for view
in range(1, 4):
209 json_file
= "{}/{}/view_{}.json".format(thisDir
, router
.name
, view
)
210 expected
= json
.loads(open(json_file
).read())
212 topotest
.router_json_cmp
,
214 "show ip bgp view {} json".format(view
),
217 _
, result
= topotest
.run_and_expect(test_func
, None, count
=5, wait
=1)
218 assertmsg
= "Routing Table verification failed for router {}, view {}".format(
221 assert result
is None, assertmsg
223 tgen
.routers_have_failure()
226 def test_shutdown_check_memleak():
228 if not tgen
.is_memleak_enabled():
229 pytest
.skip("Memory leak test/report is disabled")
231 tgen
.report_memory_leaks()
234 if __name__
== "__main__":
235 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
236 # retval = pytest.main(["-s", "--tb=no"])
237 retval
= pytest
.main(["-s"])