]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vpnv4_ebgp/test_bgp_vpnv4_ebgp.py
4 # test_bgp_vpnv4_ebgp.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2022 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_ebgp.py: Test the FRR BGP daemon with EBGP direct connection
31 from functools
import partial
34 # Save the Current Working Directory to find configuration files.
35 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 sys
.path
.append(os
.path
.join(CWD
, "../"))
38 # pylint: disable=C0413
39 # Import topogen and topotest helpers
40 from lib
import topotest
41 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
42 from lib
.topolog
import logger
44 # Required to instantiate the topology builder class.
47 pytestmark
= [pytest
.mark
.bgpd
]
57 switch
= tgen
.add_switch("s1")
58 switch
.add_link(tgen
.gears
["r1"])
59 switch
.add_link(tgen
.gears
["r2"])
61 switch
= tgen
.add_switch("s2")
62 switch
.add_link(tgen
.gears
["r1"])
64 switch
= tgen
.add_switch("s3")
65 switch
.add_link(tgen
.gears
["r2"])
67 def _populate_iface():
70 'ip link add vrf1 type vrf table 10',
71 'echo 100000 > /proc/sys/net/mpls/platform_labels',
72 'ip link set dev vrf1 up',
73 'ip link set dev {0}-eth1 master vrf1',
74 'echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input',
78 input = cmd
.format('r1', '1', '2')
79 logger
.info('input: ' + cmd
)
80 output
= tgen
.net
['r1'].cmd(cmd
.format('r1', '1', '2'))
81 logger
.info('output: ' + output
)
84 input = cmd
.format('r2', '2', '1')
85 logger
.info('input: ' + cmd
)
86 output
= tgen
.net
['r2'].cmd(cmd
.format('r2', '2', '1'))
87 logger
.info('output: ' + output
)
89 def setup_module(mod
):
90 "Sets up the pytest environment"
91 tgen
= Topogen(build_topo
, mod
.__name
__)
94 router_list
= tgen
.routers()
97 for rname
, router
in router_list
.items():
99 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
102 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
105 # Initialize all routers.
109 def teardown_module(_mod
):
110 "Teardown the pytest environment"
116 def test_protocols_convergence():
118 Assert that all protocols have converged
119 statuses as they depend on it.
122 if tgen
.routers_have_failure():
123 pytest
.skip(tgen
.errors
)
125 router
= tgen
.gears
['r1']
126 logger
.info("Dump some context for r1")
127 router
.vtysh_cmd("show bgp ipv4 vpn")
128 router
.vtysh_cmd("show bgp summary")
129 router
.vtysh_cmd("show bgp vrf vrf1 ipv4")
130 router
.vtysh_cmd("show running-config")
131 router
= tgen
.gears
['r2']
132 logger
.info("Dump some context for r2")
133 router
.vtysh_cmd("show bgp ipv4 vpn")
134 router
.vtysh_cmd("show bgp summary")
135 router
.vtysh_cmd("show bgp vrf vrf1 ipv4")
136 router
.vtysh_cmd("show running-config")
138 # Check IPv4 routing tables on r1
139 logger
.info("Checking IPv4 routes for convergence on r1")
140 router
= tgen
.gears
['r1']
141 json_file
= "{}/{}/ipv4_routes.json".format(CWD
, router
.name
)
142 if not os
.path
.isfile(json_file
):
143 logger
.info("skipping file {}".format(json_file
))
144 assert 0, 'ipv4_routes.json file not found'
147 expected
= json
.loads(open(json_file
).read())
149 topotest
.router_json_cmp
,
151 "show ip route vrf vrf1 json",
154 _
, result
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=2)
155 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
156 assert result
is None, assertmsg
158 # Check BGP IPv4 routing tables on r2 not installed
159 logger
.info("Checking BGP IPv4 routes for convergence on r2")
160 router
= tgen
.gears
['r2']
161 json_file
= "{}/{}/bgp_ipv4_routes.json".format(CWD
, router
.name
)
162 if not os
.path
.isfile(json_file
):
163 assert 0, 'bgp_ipv4_routes.json file not found'
165 expected
= json
.loads(open(json_file
).read())
167 topotest
.router_json_cmp
,
169 "show bgp vrf vrf1 ipv4 json",
172 _
, result
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=2)
173 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
174 assert result
is None, assertmsg
176 def test_memory_leak():
177 "Run the memory leak test and report results."
179 if not tgen
.is_memleak_enabled():
180 pytest
.skip("Memory leak test/report is disabled")
182 tgen
.report_memory_leaks()
185 if __name__
== "__main__":
186 args
= ["-s"] + sys
.argv
[1:]
187 sys
.exit(pytest
.main(args
))