]> git.puffer.fish Git - matthieu/frr.git/blob
4180bfcdf6a233c7c98e3a61015a15f7bcc4bfe9
[matthieu/frr.git] /
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 static route with BGP conditional advertisement works correctly
10 if we modify the prefix-lists.
11 """
12
13 import os
14 import re
15 import sys
16 import json
17 import pytest
18 import functools
19
20 pytestmark = pytest.mark.bgpd
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 setup_module(mod):
34 topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
35 tgen = Topogen(topodef, mod.__name__)
36 tgen.start_topology()
37
38 router_list = tgen.routers()
39
40 for _, (rname, router) in enumerate(router_list.items(), 1):
41 router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
42
43 tgen.start_router()
44
45
46 def teardown_module(mod):
47 tgen = get_topogen()
48 tgen.stop_topology()
49
50
51 def test_bgp_conditional_advertisements_static_route():
52 tgen = get_topogen()
53
54 if tgen.routers_have_failure():
55 pytest.skip(tgen.errors)
56
57 r1 = tgen.gears["r1"]
58 r2 = tgen.gears["r2"]
59
60 def _bgp_converge():
61 output = json.loads(
62 r2.vtysh_cmd(
63 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
64 )
65 )
66 expected = {
67 "advertisedRoutes": {
68 "10.10.10.1/32": {
69 "valid": True,
70 }
71 },
72 "totalPrefixCounter": 1,
73 }
74 return topotest.json_cmp(output, expected)
75
76 test_func = functools.partial(
77 _bgp_converge,
78 )
79 _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
80 assert result is None, "Can't converge"
81
82 step("Append prefix-list to advertise 10.10.10.2/32")
83
84 r2.vtysh_cmd(
85 """
86 configure terminal
87 ip prefix-list advertise seq 10 permit 10.10.10.2/32
88 """
89 )
90
91 def _bgp_check_advertised_after_update():
92 output = json.loads(
93 r2.vtysh_cmd(
94 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
95 )
96 )
97 expected = {
98 "advertisedRoutes": {
99 "10.10.10.1/32": {
100 "valid": True,
101 },
102 "10.10.10.2/32": {
103 "valid": True,
104 },
105 },
106 "totalPrefixCounter": 2,
107 }
108 return topotest.json_cmp(output, expected)
109
110 test_func = functools.partial(
111 _bgp_check_advertised_after_update,
112 )
113 _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
114 assert result is None, "10.10.10.2/32 is not advertised after prefix-list update"
115
116 def _bgp_check_received_routes():
117 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
118 expected = {
119 "paths": [
120 {
121 "community": {
122 "string": "65000:1",
123 }
124 }
125 ]
126 }
127 return topotest.json_cmp(output, expected)
128
129 test_func = functools.partial(
130 _bgp_check_received_routes,
131 )
132 _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
133 assert result is None, "10.10.10.1/32 does not have 65000:1 community attached"
134
135
136 if __name__ == "__main__":
137 args = ["-s"] + sys.argv[1:]
138 sys.exit(pytest.main(args))