]>
Commit | Line | Data |
---|---|---|
83c78d54 DA |
1 | #!/usr/bin/env python |
2 | # SPDX-License-Identifier: ISC | |
3 | ||
4 | # Copyright (c) 2023 by | |
5 | # Donatas Abraitis <donatas@opensourcerouting.org> | |
6 | # | |
7 | ||
8 | """ | |
9 | Test if RIP `allow-ecmp` command works correctly. | |
10 | """ | |
11 | ||
12 | import os | |
13 | import sys | |
14 | import json | |
15 | import pytest | |
16 | import functools | |
17 | ||
18 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
19 | sys.path.append(os.path.join(CWD, "../")) | |
20 | ||
21 | # pylint: disable=C0413 | |
22 | from lib import topotest | |
23 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
24 | ||
25 | pytestmark = [pytest.mark.ripd] | |
26 | ||
27 | ||
28 | def setup_module(mod): | |
29 | topodef = {"s1": ("r1", "r2", "r3")} | |
30 | tgen = Topogen(topodef, mod.__name__) | |
31 | tgen.start_topology() | |
32 | ||
33 | router_list = tgen.routers() | |
34 | ||
35 | for _, (rname, router) in enumerate(router_list.items(), 1): | |
36 | router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) | |
37 | ||
38 | tgen.start_router() | |
39 | ||
40 | ||
41 | def teardown_module(mod): | |
42 | tgen = get_topogen() | |
43 | tgen.stop_topology() | |
44 | ||
45 | ||
46 | def test_rip_allow_ecmp(): | |
47 | tgen = get_topogen() | |
48 | ||
49 | if tgen.routers_have_failure(): | |
50 | pytest.skip(tgen.errors) | |
51 | ||
52 | r1 = tgen.gears["r1"] | |
53 | ||
54 | def _show_rip_routes(): | |
9b3fd1ef CH |
55 | xpath = ( |
56 | "/frr-ripd:ripd/instance[vrf='default']" | |
57 | "/state/routes/route[prefix='10.10.10.1/32']" | |
8d6765aa | 58 | ) |
9b3fd1ef CH |
59 | try: |
60 | output = json.loads( | |
61 | r1.vtysh_cmd(f"show yang operational-data {xpath} ripd") | |
62 | ) | |
63 | except Exception: | |
64 | return False | |
65 | ||
83c78d54 DA |
66 | try: |
67 | output = output["frr-ripd:ripd"]["instance"][0]["state"]["routes"] | |
68 | except KeyError: | |
69 | return False | |
70 | ||
71 | expected = { | |
72 | "route": [ | |
73 | { | |
74 | "prefix": "10.10.10.1/32", | |
75 | "nexthops": { | |
76 | "nexthop": [ | |
77 | { | |
78 | "nh-type": "ip4", | |
79 | "protocol": "rip", | |
80 | "rip-type": "normal", | |
81 | "gateway": "192.168.1.2", | |
82 | "from": "192.168.1.2", | |
83 | "tag": 0, | |
84 | }, | |
85 | { | |
86 | "nh-type": "ip4", | |
87 | "protocol": "rip", | |
88 | "rip-type": "normal", | |
89 | "gateway": "192.168.1.3", | |
90 | "from": "192.168.1.3", | |
91 | "tag": 0, | |
92 | }, | |
93 | ] | |
94 | }, | |
95 | "metric": 2, | |
83c78d54 DA |
96 | }, |
97 | ] | |
98 | } | |
99 | return topotest.json_cmp(output, expected) | |
100 | ||
101 | test_func = functools.partial(_show_rip_routes) | |
102 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) | |
103 | assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip rip`" | |
104 | ||
105 | def _show_routes(): | |
106 | output = json.loads(r1.vtysh_cmd("show ip route json")) | |
107 | expected = { | |
108 | "10.10.10.1/32": [ | |
109 | { | |
110 | "nexthops": [ | |
111 | { | |
112 | "ip": "192.168.1.2", | |
113 | "active": True, | |
114 | }, | |
115 | { | |
116 | "ip": "192.168.1.3", | |
117 | "active": True, | |
118 | }, | |
119 | ] | |
120 | } | |
121 | ] | |
122 | } | |
123 | return topotest.json_cmp(output, expected) | |
124 | ||
125 | test_func = functools.partial(_show_routes) | |
126 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) | |
127 | assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip route`" | |
128 | ||
129 | ||
130 | if __name__ == "__main__": | |
131 | args = ["-s"] + sys.argv[1:] | |
132 | sys.exit(pytest.main(args)) |