]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vpnv4_gre/test_bgp_vpnv4_gre.py
4 # test_bgp_vpnv4_gre.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2021 by 6WIND
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_bgp_vpnv4_gre.py: Test the FRR BGP daemon with BGP IPv6 interface
26 with route advertisements on a separate netns.
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.
48 pytestmark
= [pytest
.mark
.bgpd
]
58 switch
= tgen
.add_switch("s1")
59 switch
.add_link(tgen
.gears
["r1"])
60 switch
.add_link(tgen
.gears
["r2"])
62 switch
= tgen
.add_switch("s2")
63 switch
.add_link(tgen
.gears
["r1"])
65 switch
= tgen
.add_switch("s3")
66 switch
.add_link(tgen
.gears
["r2"])
68 def _populate_iface():
71 'ip link add vrf1 type vrf table 10',
72 'echo 10 > /proc/sys/net/mpls/platform_labels',
73 'ip link set dev vrf1 up',
74 'ip link set dev {0}-eth1 master vrf1',
75 'echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input',
76 'ip tunnel add {0}-gre0 mode gre ttl 64 dev {0}-eth0 local 10.125.0.{1} remote 10.125.0.{2}',
77 'ip link set dev {0}-gre0 up',
78 'echo 1 > /proc/sys/net/mpls/conf/{0}-gre0/input',
82 input = cmd
.format('r1', '1', '2')
83 logger
.info('input: ' + cmd
)
84 output
= tgen
.net
['r1'].cmd(cmd
.format('r1', '1', '2'))
85 logger
.info('output: ' + output
)
88 input = cmd
.format('r2', '2', '1')
89 logger
.info('input: ' + cmd
)
90 output
= tgen
.net
['r2'].cmd(cmd
.format('r2', '2', '1'))
91 logger
.info('output: ' + output
)
93 def setup_module(mod
):
94 "Sets up the pytest environment"
95 tgen
= Topogen(build_topo
, mod
.__name
__)
98 router_list
= tgen
.routers()
101 for rname
, router
in router_list
.items():
103 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
106 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
109 # Initialize all routers.
113 def teardown_module(_mod
):
114 "Teardown the pytest environment"
120 def test_protocols_convergence():
122 Assert that all protocols have converged
123 statuses as they depend on it.
126 if tgen
.routers_have_failure():
127 pytest
.skip(tgen
.errors
)
129 router
= tgen
.gears
['r1']
130 logger
.info("Dump some context for r1")
131 router
.vtysh_cmd("show bgp ipv4 vpn")
132 router
.vtysh_cmd("show bgp summary")
133 router
.vtysh_cmd("show bgp vrf vrf1 ipv4")
134 router
.vtysh_cmd("show running-config")
135 router
= tgen
.gears
['r2']
136 logger
.info("Dump some context for r2")
137 router
.vtysh_cmd("show bgp ipv4 vpn")
138 router
.vtysh_cmd("show bgp summary")
139 router
.vtysh_cmd("show bgp vrf vrf1 ipv4")
140 router
.vtysh_cmd("show running-config")
142 # Check IPv4 routing tables on r1
143 logger
.info("Checking IPv4 routes for convergence on r1")
144 router
= tgen
.gears
['r1']
145 json_file
= "{}/{}/ipv4_routes.json".format(CWD
, router
.name
)
146 if not os
.path
.isfile(json_file
):
147 logger
.info("skipping file {}".format(json_file
))
148 assert 0, 'ipv4_routes.json file not found'
151 expected
= json
.loads(open(json_file
).read())
153 topotest
.router_json_cmp
,
155 "show ip route vrf vrf1 json",
158 _
, result
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=2)
159 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
160 assert result
is None, assertmsg
162 # Check BGP IPv4 routing tables on r2 not installed
163 logger
.info("Checking BGP IPv4 routes for convergence on r2")
164 router
= tgen
.gears
['r2']
165 json_file
= "{}/{}/bgp_ipv4_routes.json".format(CWD
, router
.name
)
166 if not os
.path
.isfile(json_file
):
167 assert 0, 'bgp_ipv4_routes.json file not found'
169 expected
= json
.loads(open(json_file
).read())
171 topotest
.router_json_cmp
,
173 "show bgp vrf vrf1 ipv4 json",
176 _
, result
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=2)
177 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
178 assert result
is None, assertmsg
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
))