]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py
Merge pull request #6807 from opensourcerouting/xref-extract
[mirror_frr.git] / tests / topotests / bgp_as_wide_bgp_identifier / test_bgp_as_wide_bgp_identifier.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_as_wide_bgp_identifier.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2020 by
8 # Donatas Abraitis <donatas.abraitis@gmail.com>
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 rfc6286: Autonomous-System-Wide Unique BGP Identifier for BGP-4
27 Test if 'Bad BGP Identifier' notification is sent only to
28 internal peers (autonomous-system-wide). eBGP peers are not
29 affected and should work.
30 """
31
32 import os
33 import sys
34 import json
35 import time
36 import pytest
37 import functools
38
39 CWD = os.path.dirname(os.path.realpath(__file__))
40 sys.path.append(os.path.join(CWD, "../"))
41
42 # pylint: disable=C0413
43 from lib import topotest
44 from lib.topogen import Topogen, TopoRouter, get_topogen
45 from lib.topolog import logger
46 from mininet.topo import Topo
47
48 pytestmark = [pytest.mark.bgpd]
49
50
51 class TemplateTopo(Topo):
52 def build(self, *_args, **_opts):
53 tgen = get_topogen(self)
54
55 for routern in range(1, 4):
56 tgen.add_router("r{}".format(routern))
57
58 switch = tgen.add_switch("s1")
59 switch.add_link(tgen.gears["r1"])
60 switch.add_link(tgen.gears["r2"])
61 switch.add_link(tgen.gears["r3"])
62
63
64 def setup_module(mod):
65 tgen = Topogen(TemplateTopo, mod.__name__)
66 tgen.start_topology()
67
68 router_list = tgen.routers()
69
70 for i, (rname, router) in enumerate(router_list.items(), 1):
71 router.load_config(
72 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
73 )
74 router.load_config(
75 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
76 )
77
78 tgen.start_router()
79
80
81 def teardown_module(mod):
82 tgen = get_topogen()
83 tgen.stop_topology()
84
85
86 def test_bgp_as_wide_bgp_identifier():
87 tgen = get_topogen()
88
89 if tgen.routers_have_failure():
90 pytest.skip(tgen.errors)
91
92 def _bgp_converge(router):
93 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
94 expected = {"192.168.255.1": {"bgpState": "Established"}}
95 return topotest.json_cmp(output, expected)
96
97 def _bgp_failed(router):
98 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
99 expected = {
100 "192.168.255.1": {
101 "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier"
102 }
103 }
104 return topotest.json_cmp(output, expected)
105
106 test_func = functools.partial(_bgp_converge, tgen.gears["r1"])
107 success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5)
108
109 assert result is None, 'Failed to converge: "{}"'.format(tgen.gears["r1"])
110
111 test_func = functools.partial(_bgp_failed, tgen.gears["r3"])
112 success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5)
113
114 assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format(
115 tgen.gears["r3"]
116 )
117
118
119 if __name__ == "__main__":
120 args = ["-s"] + sys.argv[1:]
121 sys.exit(pytest.main(args))