]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_extended_optional_parameters_length/test_bgp_extended_optional_parameters_length.py
Merge pull request #9750 from mjstapp/zebra_installed_nhg_id
[mirror_frr.git] / tests / topotests / bgp_extended_optional_parameters_length / test_bgp_extended_optional_parameters_length.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 Extended Optional Parameters Length encoding format works
23 if forced with a knob.
24 https://datatracker.ietf.org/doc/html/rfc9072
25 """
26
27 import os
28 import sys
29 import json
30 import pytest
31 import functools
32
33 pytestmark = pytest.mark.bgpd
34
35 CWD = os.path.dirname(os.path.realpath(__file__))
36 sys.path.append(os.path.join(CWD, "../"))
37
38 # pylint: disable=C0413
39 from lib import topotest
40 from lib.topogen import Topogen, TopoRouter, get_topogen
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 test_bgp_extended_optional_parameters_length():
69 tgen = get_topogen()
70
71 if tgen.routers_have_failure():
72 pytest.skip(tgen.errors)
73
74 router = tgen.gears["r1"]
75
76 def _bgp_converge(router):
77 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast summary json"))
78 expected = {
79 "peers": {
80 "192.168.1.2": {
81 "pfxRcd": 2,
82 "pfxSnt": 2,
83 "state": "Established",
84 "peerState": "OK",
85 }
86 }
87 }
88 return topotest.json_cmp(output, expected)
89
90 test_func = functools.partial(_bgp_converge, router)
91 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
92 assert result is None, "Can't converge with extended-optional-parameters"
93
94 def _bgp_extended_optional_parameters_length(router):
95 output = json.loads(router.vtysh_cmd("show bgp neighbor 192.168.1.2 json"))
96 expected = {"192.168.1.2": {"extendedOptionalParametersLength": True}}
97 return topotest.json_cmp(output, expected)
98
99 test_func = functools.partial(_bgp_extended_optional_parameters_length, router)
100 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
101 assert result is None, "Can't see Extended Optional Parameters Length to be used"
102
103
104 if __name__ == "__main__":
105 args = ["-s"] + sys.argv[1:]
106 sys.exit(pytest.main(args))