]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_instance_redistribute/test_ospf_instance_redistribute.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / ospf_instance_redistribute / test_ospf_instance_redistribute.py
1 #!/usr/bin/env python
2
3 #
4 # test_ospf_instance_redistribute.py
5 #
6 # Copyright (c) 2022 by
7 # Nvidia, Inc.
8 # Donald Sharp
9 #
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
13 # in all copies.
14 #
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
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 test_ospf_instance_redistribute
27
28 """
29
30 import os
31 import re
32 import sys
33 import pytest
34 import json
35
36 pytestmark = [pytest.mark.ospfd, pytest.mark.sharpd]
37
38 # Save the Current Working Directory to find configuration files.
39 CWD = os.path.dirname(os.path.realpath(__file__))
40 sys.path.append(os.path.join(CWD, "../"))
41
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib import topotest
45 from lib.topogen import Topogen, TopoRouter, get_topogen
46 from lib.topolog import logger
47 from functools import partial
48
49 # Required to instantiate the topology builder class.
50
51 #####################################################
52 ##
53 ## Network Topology Definition
54 ##
55 #####################################################
56
57
58 def build_topo(tgen):
59 tgen.add_router("r1")
60
61 # Connect r1 and r2 through the eth0 interface
62 switch = tgen.add_switch("sw1")
63 switch.add_link(tgen.gears["r1"])
64
65
66 #####################################################
67 ##
68 ## Tests starting
69 ##
70 #####################################################
71
72
73 def setup_module(module):
74 "Setup topology"
75 tgen = Topogen(build_topo, module.__name__)
76 tgen.start_topology()
77
78 # This is a sample of configuration loading.
79 r1 = tgen.gears["r1"]
80 r1.load_config(
81 TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf")
82 )
83 r1.load_config(
84 TopoRouter.RD_OSPF, os.path.join(CWD, "r1/ospfd-3.conf"),
85 "-n 3"
86 )
87 r1.load_config(
88 TopoRouter.RD_SHARP, os.path.join(CWD, "r1/sharpd.conf")
89 )
90
91 tgen.start_router()
92
93
94 def teardown_module(_mod):
95 "Teardown the pytest environment"
96 tgen = get_topogen()
97
98 # This function tears down the whole topology.
99 tgen.stop_topology()
100
101
102 def test_install_sharp_instance_routes():
103 tgen = get_topogen()
104
105 if tgen.routers_have_failure():
106 pytest.skip(tgen.errors)
107
108 logger.info("Installing sharp routes")
109 r1 = tgen.gears["r1"]
110 r1.vtysh_cmd("sharp install route 4.5.6.7 nexthop 192.168.100.2 1")
111 r1.vtysh_cmd("sharp install route 4.5.6.8 nexthop 192.168.100.2 1 instance 3")
112 r1.vtysh_cmd("sharp install route 4.5.6.9 nexthop 192.168.100.3 1 instance 4")
113 r1.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
114
115 json_file = "{}/r1/sharp_installed.json".format(CWD)
116 expected = json.loads(open(json_file).read())
117
118 test_func = partial(
119 topotest.router_json_cmp, r1, "show ip route summ json", expected)
120
121 logger.info("Ensuring that they exist in the rib/fib")
122 _, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
123 assertmsg = '"r1" sharp routes are not installed'
124 assert result is None, assertmsg
125
126 def test_ospf_instance_redistribute():
127 tgen = get_topogen()
128
129 if tgen.routers_have_failure():
130 pytest.skip(tgen.errors)
131
132 logger.info("Testing that ospf instance 3 has the redistributed sharp route")
133 r1 = tgen.gears["r1"]
134 r1.vtysh_cmd("conf\nrouter ospf 3\nredistribute sharp")
135
136 json_file = "{}/r1/ospf_instance_lsa.json".format(CWD)
137 expected = json.loads(open(json_file).read())
138
139 test_func = partial(
140 topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
141
142 _, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
143 assertmsg = '"r1" ospf instance 3 does not have the proper redistributed routes'
144 assert result is None, assertmsg
145
146 r1.vtysh_cmd("sharp install route 4.5.6.10 nexthop 192.168.100.2 1")
147 r1.vtysh_cmd("sharp install route 4.5.6.11 nexthop 192.168.100.2 1 instance 3")
148 r1.vtysh_cmd("sharp install route 4.5.6.12 nexthop 192.168.100.2 1 instance 4")
149
150 logger.info("Added new sharp routes let's see if we pick up only the .10")
151 json_file = "{}/r1/ospf_instance_lsa2.json".format(CWD)
152 expected = json.loads(open(json_file).read())
153
154 test_func = partial(
155 topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
156
157 _, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
158 assertmsg = '"r1" ospf instance 3 does not have the proper redistributed routes'
159 assert result is None, assertmsg
160
161
162 def test_ospf_instance_default_information():
163 tgen = get_topogen()
164
165 if tgen.routers_have_failure():
166 pytest.skip(tgen.errors)
167
168 logger.info("Testing the using default information originate")
169 r1 = tgen.gears["r1"]
170 r1.vtysh_cmd("conf\nrouter ospf 3\ndefault-information originate")
171
172 r1.vtysh_cmd("conf\nip route 0.0.0.0/0 192.168.100.2")
173 json_file = "{}/r1/ospf_default_information.json".format(CWD)
174 expected = json.loads(open(json_file).read())
175
176 test_func = partial(
177 topotest.router_json_cmp, r1, "show ip ospf 3 data json", expected)
178
179 _, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
180 assertmsg = '"r1" ospf instance 3 does not properly redistribute the default route'
181 assert result is None, assertmsg
182
183
184
185 if __name__ == "__main__":
186 args = ["-s"] + sys.argv[1:]
187 sys.exit(pytest.main(args))
188