]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
Merge pull request #12654 from Pdoijode/evpn-evi-detail-json-changes
[mirror_frr.git] / tests / topotests / bgp_dont_capability_negotiate / test_bgp_dont_capability_negotiate.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2021 by
4 # Donatas Abraitis <donatas.abraitis@gmail.com>
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 Test if BGP connection is established if at least one peer
23 sets `dont-capability-negotiate`.
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")}
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 bgp_converge(router):
69 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
70 expected = {
71 "peers": {
72 "192.168.1.2": {
73 "pfxRcd": 2,
74 "pfxSnt": 2,
75 "state": "Established",
76 "peerState": "OK",
77 }
78 }
79 }
80 return topotest.json_cmp(output, expected)
81
82
83 def test_bgp_dont_capability_negotiate():
84 tgen = get_topogen()
85
86 if tgen.routers_have_failure():
87 pytest.skip(tgen.errors)
88
89 r1 = tgen.gears["r1"]
90
91 test_func = functools.partial(bgp_converge, r1)
92 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
93 assert result is None, "Can't converge with dont-capability-negotiate"
94
95
96 def test_bgp_check_fqdn():
97 tgen = get_topogen()
98
99 if tgen.routers_have_failure():
100 pytest.skip(tgen.errors)
101
102 r1 = tgen.gears["r1"]
103 r2 = tgen.gears["r2"]
104
105 def _bgp_check_fqdn(fqdn=None):
106 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json"))
107 expected = {
108 "paths": [
109 {
110 "nexthops": [
111 {
112 "hostname": fqdn,
113 }
114 ],
115 "peer": {
116 "hostname": fqdn,
117 },
118 }
119 ]
120 }
121 return topotest.json_cmp(output, expected)
122
123 step("Enable all capabilities")
124 r1.vtysh_cmd(
125 """
126 configure terminal
127 router bgp
128 address-family ipv4 unicast
129 no neighbor 192.168.1.2 dont-capability-negotiate
130 end
131 clear bgp 192.168.1.2
132 """
133 )
134
135 step("Wait to converge")
136 test_func = functools.partial(bgp_converge, r1)
137 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
138 assert result is None, "Can't converge with dont-capability-negotiate"
139
140 test_func = functools.partial(_bgp_check_fqdn, "r2")
141 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
142 assert result is None, "FQDN capability enabled, but r1 can't see it"
143
144 step("Disable sending any capabilities from r2")
145 r2.vtysh_cmd(
146 """
147 configure terminal
148 router bgp
149 address-family ipv4 unicast
150 neighbor 192.168.1.1 dont-capability-negotiate
151 end
152 clear bgp 192.168.1.1
153 """
154 )
155
156 step("Wait to converge")
157 test_func = functools.partial(bgp_converge, r1)
158 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
159 assert result is None, "Can't converge with dont-capability-negotiate"
160
161 step("Make sure FQDN capability is reset")
162 test_func = functools.partial(_bgp_check_fqdn)
163 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
164 assert result is None, "FQDN capability disabled, but we still have a hostname"
165
166
167 if __name__ == "__main__":
168 args = ["-s"] + sys.argv[1:]
169 sys.exit(pytest.main(args))