]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_dont_capability_negotiate/test_bgp_dont_capability_negotiate.py
Merge pull request #12698 from Orange-OpenSource/isisd
[mirror_frr.git] / tests / topotests / bgp_dont_capability_negotiate / test_bgp_dont_capability_negotiate.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 # Copyright (c) 2021 by
5 # Donatas Abraitis <donatas.abraitis@gmail.com>
6 #
7
8 """
9 Test if BGP connection is established if at least one peer
10 sets `dont-capability-negotiate`.
11 """
12
13 import os
14 import sys
15 import json
16 import pytest
17 import functools
18
19 pytestmark = pytest.mark.bgpd
20
21 CWD = os.path.dirname(os.path.realpath(__file__))
22 sys.path.append(os.path.join(CWD, "../"))
23
24 # pylint: disable=C0413
25 from lib import topotest
26 from lib.topogen import Topogen, TopoRouter, get_topogen
27 from lib.common_config import step
28
29 pytestmark = [pytest.mark.bgpd]
30
31
32 def setup_module(mod):
33 topodef = {"s1": ("r1", "r2")}
34 tgen = Topogen(topodef, mod.__name__)
35 tgen.start_topology()
36
37 router_list = tgen.routers()
38
39 for i, (rname, router) in enumerate(router_list.items(), 1):
40 router.load_config(
41 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
42 )
43 router.load_config(
44 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
45 )
46
47 tgen.start_router()
48
49
50 def teardown_module(mod):
51 tgen = get_topogen()
52 tgen.stop_topology()
53
54
55 def bgp_converge(router):
56 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
57 expected = {
58 "peers": {
59 "192.168.1.2": {
60 "pfxRcd": 2,
61 "pfxSnt": 2,
62 "state": "Established",
63 "peerState": "OK",
64 }
65 }
66 }
67 return topotest.json_cmp(output, expected)
68
69
70 def test_bgp_dont_capability_negotiate():
71 tgen = get_topogen()
72
73 if tgen.routers_have_failure():
74 pytest.skip(tgen.errors)
75
76 r1 = tgen.gears["r1"]
77
78 test_func = functools.partial(bgp_converge, r1)
79 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
80 assert result is None, "Can't converge with dont-capability-negotiate"
81
82
83 def test_bgp_check_fqdn():
84 tgen = get_topogen()
85
86 if tgen.routers_have_failure():
87 pytest.skip(tgen.errors)
88
89 r1 = tgen.gears["r1"]
90 r2 = tgen.gears["r2"]
91
92 def _bgp_check_fqdn(fqdn=None):
93 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 172.16.16.1/32 json"))
94 expected = {
95 "paths": [
96 {
97 "nexthops": [
98 {
99 "hostname": fqdn,
100 }
101 ],
102 "peer": {
103 "hostname": fqdn,
104 },
105 }
106 ]
107 }
108 return topotest.json_cmp(output, expected)
109
110 step("Enable all capabilities")
111 r1.vtysh_cmd(
112 """
113 configure terminal
114 router bgp
115 address-family ipv4 unicast
116 no neighbor 192.168.1.2 dont-capability-negotiate
117 end
118 clear bgp 192.168.1.2
119 """
120 )
121
122 step("Wait to converge")
123 test_func = functools.partial(bgp_converge, r1)
124 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
125 assert result is None, "Can't converge with dont-capability-negotiate"
126
127 test_func = functools.partial(_bgp_check_fqdn, "r2")
128 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
129 assert result is None, "FQDN capability enabled, but r1 can't see it"
130
131 step("Disable sending any capabilities from r2")
132 r2.vtysh_cmd(
133 """
134 configure terminal
135 router bgp
136 address-family ipv4 unicast
137 neighbor 192.168.1.1 dont-capability-negotiate
138 end
139 clear bgp 192.168.1.1
140 """
141 )
142
143 step("Wait to converge")
144 test_func = functools.partial(bgp_converge, r1)
145 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
146 assert result is None, "Can't converge with dont-capability-negotiate"
147
148 step("Make sure FQDN capability is reset")
149 test_func = functools.partial(_bgp_check_fqdn)
150 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
151 assert result is None, "FQDN capability disabled, but we still have a hostname"
152
153
154 if __name__ == "__main__":
155 args = ["-s"] + sys.argv[1:]
156 sys.exit(pytest.main(args))