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