]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_route_leak_basic/test_bgp-vrf-route-leak-basic.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_vrf_route_leak_basic / test_bgp-vrf-route-leak-basic.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp-vrf-route-leak-basic.py
5 #
6 # Copyright (c) 2018 Cumulus Networks, Inc.
7 # Donald Sharp
8 #
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
12 # in all copies.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS" AND Cumulus Networks 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
21 # OF THIS SOFTWARE.
22 #
23
24 """
25 test_bgp-vrf-route-leak-basic.py.py: Test basic vrf route leaking
26 """
27
28 import os
29 import sys
30 from functools import partial
31 import pytest
32
33 CWD = os.path.dirname(os.path.realpath(__file__))
34 sys.path.append(os.path.join(CWD, "../"))
35
36 # pylint: disable=C0413
37 from lib import topotest
38 from lib.topogen import Topogen, TopoRouter, get_topogen
39 from lib.topolog import logger
40
41
42 pytestmark = [pytest.mark.bgpd]
43
44
45 def build_topo(tgen):
46 "Build function"
47
48 for routern in range(1, 2):
49 tgen.add_router("r{}".format(routern))
50
51
52 def setup_module(mod):
53 "Sets up the pytest environment"
54 tgen = Topogen(build_topo, mod.__name__)
55 tgen.start_topology()
56
57 # For all registered routers, load the zebra configuration file
58 for rname, router in tgen.routers().items():
59 router.run("/bin/bash {}/setup_vrfs".format(CWD))
60 router.load_config(
61 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
62 )
63 router.load_config(
64 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
65 )
66
67 # After loading the configurations, this function loads configured daemons.
68 tgen.start_router()
69 # tgen.mininet_cli()
70
71
72 def teardown_module(mod):
73 "Teardown the pytest environment"
74 tgen = get_topogen()
75
76 # This function tears down the whole topology.
77 tgen.stop_topology()
78
79
80 def test_vrf_route_leak():
81 logger.info("Ensure that routes are leaked back and forth")
82 tgen = get_topogen()
83 # Don't run this test if we have any failure.
84 if tgen.routers_have_failure():
85 pytest.skip(tgen.errors)
86
87 r1 = tgen.gears["r1"]
88
89 # Test DONNA VRF.
90 expect = {
91 "10.0.0.0/24": [
92 {
93 "protocol": "connected",
94 }
95 ],
96 "10.0.1.0/24": [
97 {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]}
98 ],
99 "10.0.2.0/24": [{"protocol": "connected"}],
100 "10.0.3.0/24": [
101 {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]}
102 ],
103 }
104
105 test_func = partial(
106 topotest.router_json_cmp, r1, "show ip route vrf DONNA json", expect
107 )
108 result, diff = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
109 assert result, "BGP VRF DONNA check failed:\n{}".format(diff)
110
111 # Test EVA VRF.
112 expect = {
113 "10.0.0.0/24": [
114 {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]}
115 ],
116 "10.0.1.0/24": [
117 {
118 "protocol": "connected",
119 }
120 ],
121 "10.0.2.0/24": [
122 {"protocol": "bgp", "selected": True, "nexthops": [{"fib": True}]}
123 ],
124 "10.0.3.0/24": [
125 {
126 "protocol": "connected",
127 }
128 ],
129 }
130
131 test_func = partial(
132 topotest.router_json_cmp, r1, "show ip route vrf EVA json", expect
133 )
134 result, diff = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
135 assert result, "BGP VRF EVA check failed:\n{}".format(diff)
136
137
138 def test_memory_leak():
139 "Run the memory leak test and report results."
140 tgen = get_topogen()
141 if not tgen.is_memleak_enabled():
142 pytest.skip("Memory leak test/report is disabled")
143
144 tgen.report_memory_leaks()
145
146
147 if __name__ == "__main__":
148 args = ["-s"] + sys.argv[1:]
149 sys.exit(pytest.main(args))