]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_minimum_holdtime/test_bgp_minimum_holdtime.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_minimum_holdtime / test_bgp_minimum_holdtime.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 # Copyright (c) 2021 by
5 # Takemasa Imada <takemasa.imada@gmail.com>
6 #
7
8 """
9 Test if minimum-holdtime works.
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.bgpd]
26
27
28 def build_topo(tgen):
29 for routern in range(1, 3):
30 tgen.add_router("r{}".format(routern))
31
32 switch = tgen.add_switch("s1")
33 switch.add_link(tgen.gears["r1"])
34 switch.add_link(tgen.gears["r2"])
35
36
37 def setup_module(mod):
38 tgen = Topogen(build_topo, mod.__name__)
39 tgen.start_topology()
40
41 router_list = tgen.routers()
42
43 for i, (rname, router) in enumerate(router_list.items(), 1):
44 router.load_config(
45 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
46 )
47 router.load_config(
48 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
49 )
50
51 tgen.start_router()
52
53
54 def teardown_module(mod):
55 tgen = get_topogen()
56 tgen.stop_topology()
57
58
59 def test_bgp_minimum_holdtime():
60 tgen = get_topogen()
61
62 if tgen.routers_have_failure():
63 pytest.skip(tgen.errors)
64
65 def _bgp_neighbor_check_if_notification_sent():
66 output = json.loads(
67 tgen.gears["r1"].vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")
68 )
69 expected = {
70 "192.168.255.2": {
71 "connectionsEstablished": 0,
72 "lastNotificationReason": "OPEN Message Error/Unacceptable Hold Time",
73 "lastResetDueTo": "BGP Notification send",
74 }
75 }
76 return topotest.json_cmp(output, expected)
77
78 test_func = functools.partial(_bgp_neighbor_check_if_notification_sent)
79 success, result = topotest.run_and_expect(test_func, None, count=40, wait=0.5)
80 assert result is None, "Failed to send notification message\n"
81
82
83 if __name__ == "__main__":
84 args = ["-s"] + sys.argv[1:]
85 sys.exit(pytest.main(args))