3 # Copyright (c) 2021 by
4 # Takemasa Imada <takemasa.imada@gmail.com>
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Test if minimum-holdtime works.
31 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
32 sys
.path
.append(os
.path
.join(CWD
, "../"))
34 # pylint: disable=C0413
35 from lib
import topotest
36 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
38 pytestmark
= [pytest
.mark
.bgpd
]
42 for routern
in range(1, 3):
43 tgen
.add_router("r{}".format(routern
))
45 switch
= tgen
.add_switch("s1")
46 switch
.add_link(tgen
.gears
["r1"])
47 switch
.add_link(tgen
.gears
["r2"])
50 def setup_module(mod
):
51 tgen
= Topogen(build_topo
, mod
.__name
__)
54 router_list
= tgen
.routers()
56 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
58 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
61 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
67 def teardown_module(mod
):
72 def test_bgp_minimum_holdtime():
75 if tgen
.routers_have_failure():
76 pytest
.skip(tgen
.errors
)
78 def _bgp_neighbor_check_if_notification_sent():
80 tgen
.gears
["r1"].vtysh_cmd("show ip bgp neighbor 192.168.255.2 json")
84 "connectionsEstablished": 0,
85 "lastNotificationReason": "OPEN Message Error/Unacceptable Hold Time",
86 "lastResetDueTo": "BGP Notification send",
89 return topotest
.json_cmp(output
, expected
)
91 test_func
= functools
.partial(_bgp_neighbor_check_if_notification_sent
)
92 success
, result
= topotest
.run_and_expect(test_func
, None, count
=40, wait
=0.5)
93 assert result
is None, "Failed to send notification message\n"
96 if __name__
== "__main__":
97 args
= ["-s"] + sys
.argv
[1:]
98 sys
.exit(pytest
.main(args
))