]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_peer_graceful_shutdown/test_bgp_peer_graceful_shutdown.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_peer_graceful_shutdown / test_bgp_peer_graceful_shutdown.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2022 by
4 # Donatas Abraitis <donatas@opensourcerouting.org>
5 #
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
9 # in all copies.
10 #
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
18 # OF THIS SOFTWARE.
19 #
20
21 """
22 Check if routes from R1 has local-preference set to 0 and graceful-shutdown
23 community.
24 """
25
26 import os
27 import sys
28 import json
29 import pytest
30 import functools
31
32 pytestmark = pytest.mark.bgpd
33
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
37 # pylint: disable=C0413
38 from lib import topotest
39 from lib.topogen import Topogen, TopoRouter, get_topogen
40 from lib.common_config import step
41
42 pytestmark = [pytest.mark.bgpd]
43
44
45 def setup_module(mod):
46 topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
47 tgen = Topogen(topodef, mod.__name__)
48 tgen.start_topology()
49
50 router_list = tgen.routers()
51
52 for i, (rname, router) in enumerate(router_list.items(), 1):
53 router.load_config(
54 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
55 )
56 router.load_config(
57 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
58 )
59
60 tgen.start_router()
61
62
63 def teardown_module(mod):
64 tgen = get_topogen()
65 tgen.stop_topology()
66
67
68 def test_bgp_orf():
69 tgen = get_topogen()
70
71 if tgen.routers_have_failure():
72 pytest.skip(tgen.errors)
73
74 r2 = tgen.gears["r2"]
75 r3 = tgen.gears["r3"]
76
77 def _bgp_converge():
78 output = json.loads(
79 r2.vtysh_cmd(
80 "show bgp ipv4 unicast neighbor 192.168.2.2 advertised-routes json"
81 )
82 )
83 expected = {"advertisedRoutes": {"10.10.10.1/32": {"locPrf": 100}}}
84 return topotest.json_cmp(output, expected)
85
86 test_func = functools.partial(_bgp_converge)
87 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
88 assert result is None, "Can't converge at R2"
89
90 step("Mark routes from R1 as graceful-shutdown")
91 r2.vtysh_cmd(
92 """
93 configure terminal
94 router bgp
95 neighbor 192.168.1.1 graceful-shutdown
96 """
97 )
98
99 def _bgp_check_peer_graceful_shutdown():
100 output = json.loads(r3.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
101 expected = {
102 "paths": [
103 {
104 "locPrf": 0,
105 "community": {"string": "graceful-shutdown"},
106 }
107 ]
108 }
109 return topotest.json_cmp(output, expected)
110
111 test_func = functools.partial(_bgp_check_peer_graceful_shutdown)
112 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
113 assert (
114 result is None
115 ), "local-preference is not 0 and/or graceful-shutdown community missing"
116
117
118 if __name__ == "__main__":
119 args = ["-s"] + sys.argv[1:]
120 sys.exit(pytest.main(args))