]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_as_wide_bgp_identifier / test_bgp_as_wide_bgp_identifier.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # test_bgp_as_wide_bgp_identifier.py
6 # Part of NetDEF Topology Tests
7 #
8 # Copyright (c) 2020 by
9 # Donatas Abraitis <donatas.abraitis@gmail.com>
10 #
11
12 """
13 rfc6286: Autonomous-System-Wide Unique BGP Identifier for BGP-4
14 Test if 'Bad BGP Identifier' notification is sent only to
15 internal peers (autonomous-system-wide). eBGP peers are not
16 affected and should work.
17 """
18
19 import os
20 import sys
21 import json
22 import pytest
23 import functools
24
25 CWD = os.path.dirname(os.path.realpath(__file__))
26 sys.path.append(os.path.join(CWD, "../"))
27
28 # pylint: disable=C0413
29 from lib import topotest
30 from lib.topogen import Topogen, TopoRouter, get_topogen
31
32 pytestmark = [pytest.mark.bgpd]
33
34
35 def build_topo(tgen):
36 for routern in range(1, 4):
37 tgen.add_router("r{}".format(routern))
38
39 switch = tgen.add_switch("s1")
40 switch.add_link(tgen.gears["r1"])
41 switch.add_link(tgen.gears["r2"])
42 switch.add_link(tgen.gears["r3"])
43
44
45 def setup_module(mod):
46 tgen = Topogen(build_topo, mod.__name__)
47 tgen.start_topology()
48
49 router_list = tgen.routers()
50
51 for i, (rname, router) in enumerate(router_list.items(), 1):
52 router.load_config(
53 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
54 )
55 router.load_config(
56 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
57 )
58
59 tgen.start_router()
60
61
62 def teardown_module(mod):
63 tgen = get_topogen()
64 tgen.stop_topology()
65
66
67 def test_bgp_as_wide_bgp_identifier():
68 tgen = get_topogen()
69
70 if tgen.routers_have_failure():
71 pytest.skip(tgen.errors)
72
73 def _bgp_converge(router):
74 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
75 expected = {"192.168.255.1": {"bgpState": "Established"}}
76 return topotest.json_cmp(output, expected)
77
78 def _bgp_failed(router):
79 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
80 expected = {
81 "192.168.255.1": {
82 "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier"
83 }
84 }
85 return topotest.json_cmp(output, expected)
86
87 test_func = functools.partial(_bgp_converge, tgen.gears["r1"])
88 success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5)
89
90 assert result is None, 'Failed to converge: "{}"'.format(tgen.gears["r1"])
91
92 test_func = functools.partial(_bgp_failed, tgen.gears["r3"])
93 success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5)
94
95 assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format(
96 tgen.gears["r3"]
97 )
98
99
100 if __name__ == "__main__":
101 args = ["-s"] + sys.argv[1:]
102 sys.exit(pytest.main(args))