2 # SPDX-License-Identifier: ISC
5 # bgp_bfd_down_cease_notification.py
7 # Copyright (c) 2022 by
8 # Donatas Abraitis <donatas@opensourcerouting.org>
12 Check if Cease/BFD Down notification message is sent/received
22 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
23 sys
.path
.append(os
.path
.join(CWD
, "../"))
25 # pylint: disable=C0413
26 from lib
import topotest
27 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
28 from lib
.common_config
import kill_router_daemons
, step
30 pytestmark
= [pytest
.mark
.bfdd
, pytest
.mark
.bgpd
]
34 for routern
in range(1, 3):
35 tgen
.add_router("r{}".format(routern
))
37 switch
= tgen
.add_switch("s1")
38 switch
.add_link(tgen
.gears
["r1"])
39 switch
.add_link(tgen
.gears
["r2"])
42 def setup_module(mod
):
43 tgen
= Topogen(build_topo
, mod
.__name
__)
46 router_list
= tgen
.routers()
48 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
50 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
53 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
56 TopoRouter
.RD_BFD
, os
.path
.join(CWD
, "{}/bfdd.conf".format(rname
))
62 def teardown_module(mod
):
67 def test_bgp_bfd_down_notification():
70 if tgen
.routers_have_failure():
71 pytest
.skip(tgen
.errors
)
76 output
= json
.loads(r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
79 "bgpState": "Established",
80 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}},
81 "peerBfdInfo": {"status": "Up"},
84 return topotest
.json_cmp(output
, expected
)
86 def _bgp_bfd_down_notification():
87 output
= json
.loads(r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
90 "lastNotificationReason": "Cease/BFD Down",
93 return topotest
.json_cmp(output
, expected
)
95 step("Initial BGP converge")
96 test_func
= functools
.partial(_bgp_converge
)
97 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
98 assert result
is None, "Failed to see BGP convergence on R2"
100 step("Kill bfdd on R2")
101 kill_router_daemons(tgen
, "r2", ["bfdd"])
103 step("Check if we received Cease/BFD Down notification message")
104 test_func
= functools
.partial(_bgp_bfd_down_notification
)
105 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
106 assert result
is None, "Failed to see BGP Cease/BFD Down notification message on R2"
109 if __name__
== "__main__":
110 args
= ["-s"] + sys
.argv
[1:]
111 sys
.exit(pytest
.main(args
))