]>
Commit | Line | Data |
---|---|---|
b0ade0a1 | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
b0ade0a1 DA |
3 | |
4 | # | |
5 | # Copyright (c) 2022 by | |
6 | # Donatas Abraitis <donatas@opensourcerouting.org> | |
7 | # | |
b0ade0a1 DA |
8 | |
9 | """ | |
10 | Check if labeled-unicast works correctly with addpath capability. | |
387a5ffe DA |
11 | Initially R3 MUST announce 10.0.0.1/32 multipath(2) from R1 + R2. |
12 | Later, we enable R5 and 10.0.0.1/32 multipath(3) MUST be announced, | |
13 | R1 + R2 + R5. | |
b0ade0a1 DA |
14 | """ |
15 | ||
16 | import os | |
17 | import sys | |
18 | import json | |
19 | import pytest | |
20 | import functools | |
21 | ||
22 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
23 | sys.path.append(os.path.join(CWD, "../")) | |
24 | ||
25 | # pylint: disable=C0413 | |
26 | from lib import topotest | |
27 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
28 | from lib.common_config import step | |
29 | ||
30 | pytestmark = [pytest.mark.bgpd] | |
31 | ||
32 | ||
33 | def build_topo(tgen): | |
387a5ffe | 34 | for routern in range(1, 6): |
b0ade0a1 DA |
35 | tgen.add_router("r{}".format(routern)) |
36 | ||
37 | switch = tgen.add_switch("s1") | |
38 | switch.add_link(tgen.gears["r1"]) | |
39 | switch.add_link(tgen.gears["r3"]) | |
40 | ||
41 | switch = tgen.add_switch("s2") | |
42 | switch.add_link(tgen.gears["r2"]) | |
43 | switch.add_link(tgen.gears["r3"]) | |
44 | ||
45 | switch = tgen.add_switch("s3") | |
46 | switch.add_link(tgen.gears["r3"]) | |
47 | switch.add_link(tgen.gears["r4"]) | |
48 | ||
387a5ffe DA |
49 | switch = tgen.add_switch("s4") |
50 | switch.add_link(tgen.gears["r3"]) | |
51 | switch.add_link(tgen.gears["r5"]) | |
52 | ||
b0ade0a1 DA |
53 | |
54 | def setup_module(mod): | |
55 | tgen = Topogen(build_topo, mod.__name__) | |
56 | tgen.start_topology() | |
57 | ||
58 | router_list = tgen.routers() | |
59 | ||
60 | for i, (rname, router) in enumerate(router_list.items(), 1): | |
61 | router.load_config( | |
62 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | |
63 | ) | |
64 | router.load_config( | |
65 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | |
66 | ) | |
67 | ||
68 | tgen.start_router() | |
69 | ||
70 | ||
71 | def teardown_module(mod): | |
72 | tgen = get_topogen() | |
73 | tgen.stop_topology() | |
74 | ||
75 | ||
76 | def test_bgp_addpath_labeled_unicast(): | |
77 | tgen = get_topogen() | |
78 | ||
79 | if tgen.routers_have_failure(): | |
80 | pytest.skip(tgen.errors) | |
81 | ||
82 | r3 = tgen.gears["r3"] | |
83 | r4 = tgen.gears["r4"] | |
84 | ||
9db7ed2f DA |
85 | def _bgp_check_received_routes(pfxcount): |
86 | output = json.loads(r4.vtysh_cmd("show bgp ipv4 labeled-unicast summary json")) | |
b0ade0a1 | 87 | expected = { |
9db7ed2f DA |
88 | "peers": { |
89 | "192.168.34.3": { | |
90 | "pfxRcd": pfxcount, | |
91 | "state": "Established", | |
b0ade0a1 | 92 | } |
9db7ed2f | 93 | } |
b0ade0a1 DA |
94 | } |
95 | return topotest.json_cmp(output, expected) | |
96 | ||
9db7ed2f | 97 | test_func = functools.partial(_bgp_check_received_routes, 2) |
b0ade0a1 DA |
98 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) |
99 | assert ( | |
100 | result is None | |
9db7ed2f | 101 | ), "Failed to receive labeled-unicast with addpath (multipath=2)" |
b0ade0a1 | 102 | |
387a5ffe DA |
103 | step("Enable BGP session for R5") |
104 | r3.vtysh_cmd( | |
105 | """ | |
106 | configure terminal | |
107 | router bgp 65003 | |
108 | no neighbor 192.168.35.5 shutdown | |
109 | """ | |
110 | ) | |
111 | ||
9db7ed2f | 112 | test_func = functools.partial(_bgp_check_received_routes, 3) |
387a5ffe DA |
113 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) |
114 | assert ( | |
115 | result is None | |
9db7ed2f | 116 | ), "Failed to receive labeled-unicast with addpath (multipath=3)" |
387a5ffe DA |
117 | |
118 | step("Disable BGP session for R5") | |
119 | r3.vtysh_cmd( | |
120 | """ | |
121 | configure terminal | |
122 | router bgp 65003 | |
123 | neighbor 192.168.35.5 shutdown | |
124 | """ | |
125 | ) | |
126 | ||
9db7ed2f | 127 | test_func = functools.partial(_bgp_check_received_routes, 2) |
387a5ffe DA |
128 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) |
129 | assert ( | |
130 | result is None | |
9db7ed2f | 131 | ), "Failed to receive labeled-unicast with addpath (multipath=2)" |
387a5ffe | 132 | |
b0ade0a1 DA |
133 | |
134 | if __name__ == "__main__": | |
135 | args = ["-s"] + sys.argv[1:] | |
136 | sys.exit(pytest.main(args)) |