]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map_delay_timer/test_bgp_route_map_delay_timer.py
Merge pull request #13060 from opensourcerouting/feature/allow_peering_with_127.0.0.1
[mirror_frr.git] / tests / topotests / bgp_route_map_delay_timer / test_bgp_route_map_delay_timer.py
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
10 """
11
12 import os
13 import sys
14 import json
15 import pytest
16 import functools
17
18 pytestmark = pytest.mark.bgpd
19
20 CWD = os.path.dirname(os.path.realpath(__file__))
21 sys.path.append(os.path.join(CWD, "../"))
22
23 # pylint: disable=C0413
24 from lib import topotest
25 from lib.topogen import Topogen, TopoRouter, get_topogen
26
27 pytestmark = [pytest.mark.bgpd]
28
29
30 def setup_module(mod):
31 topodef = {"s1": ("r1", "r2")}
32 tgen = Topogen(topodef, mod.__name__)
33 tgen.start_topology()
34
35 router_list = tgen.routers()
36
37 for i, (rname, router) in enumerate(router_list.items(), 1):
38 router.load_config(
39 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
40 )
41 router.load_config(
42 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
43 )
44
45 tgen.start_router()
46
47
48 def teardown_module(mod):
49 tgen = get_topogen()
50 tgen.stop_topology()
51
52
53 def test_bgp_route_map_delay_timer():
54 tgen = get_topogen()
55
56 if tgen.routers_have_failure():
57 pytest.skip(tgen.errors)
58
59 r1 = tgen.gears["r1"]
60 r2 = tgen.gears["r2"]
61
62 def _bgp_converge_1():
63 output = json.loads(
64 r1.vtysh_cmd(
65 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
66 )
67 )
68 expected = {
69 "advertisedRoutes": {
70 "10.10.10.0/24": {},
71 "10.10.10.1/32": {},
72 "10.10.10.2/32": {},
73 "10.10.10.3/32": None,
74 }
75 }
76 return topotest.json_cmp(output, expected)
77
78 test_func = functools.partial(_bgp_converge_1)
79 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
80 assert result is None, "10.10.10.3/32 should not be advertised to r2"
81
82 # Set route-map delay-timer to max value and remove 10.10.10.2/32.
83 # After this, r1 MUST do not announce updates immediately, and wait
84 # 600 seconds before withdrawing 10.10.10.2/32.
85 r2.vtysh_cmd(
86 """
87 configure terminal
88 bgp route-map delay-timer 600
89 no ip prefix-list r1 seq 10 permit 10.10.10.2/32
90 """
91 )
92
93 def _bgp_converge_2():
94 output = json.loads(
95 r1.vtysh_cmd(
96 "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
97 )
98 )
99 expected = {
100 "advertisedRoutes": {
101 "10.10.10.0/24": {},
102 "10.10.10.1/32": {},
103 "10.10.10.2/32": None,
104 "10.10.10.3/32": None,
105 }
106 }
107 return topotest.json_cmp(output, expected)
108
109 # We are checking `not None` here to wait count*wait time and if we have different
110 # results than expected, it means good - 10.10.10.2/32 wasn't withdrawn immediately.
111 test_func = functools.partial(_bgp_converge_2)
112 _, result = topotest.run_and_expect(test_func, not None, count=60, wait=0.5)
113 assert (
114 result is not None
115 ), "10.10.10.2/32 advertised, but should not be advertised to r2"
116
117
118 if __name__ == "__main__":
119 args = ["-s"] + sys.argv[1:]
120 sys.exit(pytest.main(args))