]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/zebra_multiple_connected/test_zebra_multiple_connected.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / zebra_multiple_connected / test_zebra_multiple_connected.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # test_zebra_multiple_connected.py
6 #
7 # Copyright (c) 2022 by
8 # Nvidia Corporation
9 # Donald Sharp
10 #
11
12 """
13 test_zebra_multiple_connected.py: Testing multiple connected
14
15 """
16
17 import os
18 import re
19 import sys
20 import pytest
21 import json
22 from functools import partial
23
24 # Save the Current Working Directory to find configuration files.
25 CWD = os.path.dirname(os.path.realpath(__file__))
26 sys.path.append(os.path.join(CWD, "../"))
27
28 # pylint: disable=C0413
29 # Import topogen and topotest helpers
30 from lib import topotest
31 from lib.topogen import Topogen, TopoRouter, get_topogen
32 from lib.topolog import logger
33
34 # Required to instantiate the topology builder class.
35
36 #####################################################
37 ##
38 ## Network Topology Definition
39 ##
40 #####################################################
41
42
43 def build_topo(tgen):
44 for routern in range(1, 4):
45 tgen.add_router("r{}".format(routern))
46
47 # On main router
48 # First switch is for a dummy interface (for local network)
49 switch = tgen.add_switch("sw1")
50 switch.add_link(tgen.gears["r1"])
51
52 # Switches for zebra
53 # switch 2 switch is for connection to zebra router
54 switch = tgen.add_switch("sw2")
55 switch.add_link(tgen.gears["r1"])
56 switch.add_link(tgen.gears["r2"])
57
58 # switch 4 is stub on remote zebra router
59 switch = tgen.add_switch("sw4")
60 switch.add_link(tgen.gears["r3"])
61
62 # switch 3 is between zebra routers
63 switch = tgen.add_switch("sw3")
64 switch.add_link(tgen.gears["r2"])
65 switch.add_link(tgen.gears["r3"])
66
67
68 #####################################################
69 ##
70 ## Tests starting
71 ##
72 #####################################################
73
74
75 def setup_module(module):
76 "Setup topology"
77 tgen = Topogen(build_topo, module.__name__)
78 tgen.start_topology()
79
80 # This is a sample of configuration loading.
81 router_list = tgen.routers()
82 for rname, router in router_list.items():
83 router.load_config(
84 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
85 )
86
87 tgen.start_router()
88
89
90 def teardown_module(_mod):
91 "Teardown the pytest environment"
92 tgen = get_topogen()
93
94 # This function tears down the whole topology.
95 tgen.stop_topology()
96
97
98 def test_zebra_connected_multiple():
99 "Test multiple connected routes that have a kernel route pointing at one"
100
101 tgen = get_topogen()
102 # Don't run this test if we have any failure.
103 if tgen.routers_have_failure():
104 pytest.skip(tgen.errors)
105
106 router = tgen.gears["r1"]
107 router.run("ip route add 192.168.1.1/32 via 10.0.1.99 dev r1-eth1")
108 router.run("ip link add dummy1 type dummy")
109 router.run("ip link set dummy1 up")
110 router.run("ip link set dummy1 down")
111
112 routes = "{}/{}/ip_route.json".format(CWD, router.name)
113 expected = json.loads(open(routes).read())
114
115 test_func = partial(
116 topotest.router_json_cmp, router, "show ip route json", expected
117 )
118
119 _, result = topotest.run_and_expect(test_func, None, count=20, wait=1)
120 assert result is None, "Kernel route is missing from zebra"
121
122
123 def test_zebra_system_recursion():
124 "Test a system route recursing through another system route"
125
126 tgen = get_topogen()
127 if tgen.routers_have_failure():
128 pytest.skip(tgen.errors)
129
130 router = tgen.gears["r1"]
131 router.run("ip route add 10.0.1.30/32 dev r1-eth1")
132 router.run("ip route add 10.9.9.0/24 via 10.0.1.30 dev r1-eth1")
133 router.run("ip link add dummy2 type dummy")
134 router.run("ip link set dummy2 up")
135 router.run("ip link set dummy2 down")
136
137 routes = "{}/{}/ip_route2.json".format(CWD, router.name)
138 expected = json.loads(open(routes).read())
139 test_func = partial(
140 topotest.router_json_cmp, router, "show ip route json", expected
141 )
142
143 _, result = topotest.run_and_expect(test_func, None, count=20, wait=1)
144 assert result is None, "Kernel route is missing from zebra"
145
146
147 if __name__ == "__main__":
148 args = ["-s"] + sys.argv[1:]
149 sys.exit(pytest.main(args))