]>
Commit | Line | Data |
---|---|---|
03eb10e6 DA |
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 | |
03eb10e6 DA |
35 | import pytest |
36 | import functools | |
37 | ||
38 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
787e7624 | 39 | sys.path.append(os.path.join(CWD, "../")) |
03eb10e6 DA |
40 | |
41 | # pylint: disable=C0413 | |
42 | from lib import topotest | |
43 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
03eb10e6 | 44 | |
5ad1fd54 DS |
45 | pytestmark = [pytest.mark.bgpd] |
46 | ||
787e7624 | 47 | |
e82b531d CH |
48 | def build_topo(tgen): |
49 | for routern in range(1, 4): | |
50 | tgen.add_router("r{}".format(routern)) | |
03eb10e6 | 51 | |
e82b531d CH |
52 | switch = tgen.add_switch("s1") |
53 | switch.add_link(tgen.gears["r1"]) | |
54 | switch.add_link(tgen.gears["r2"]) | |
55 | switch.add_link(tgen.gears["r3"]) | |
03eb10e6 | 56 | |
03eb10e6 DA |
57 | |
58 | def setup_module(mod): | |
e82b531d | 59 | tgen = Topogen(build_topo, mod.__name__) |
03eb10e6 DA |
60 | tgen.start_topology() |
61 | ||
62 | router_list = tgen.routers() | |
63 | ||
e5f0ed14 | 64 | for i, (rname, router) in enumerate(router_list.items(), 1): |
03eb10e6 | 65 | router.load_config( |
787e7624 | 66 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) |
03eb10e6 DA |
67 | ) |
68 | router.load_config( | |
787e7624 | 69 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) |
03eb10e6 DA |
70 | ) |
71 | ||
72 | tgen.start_router() | |
73 | ||
787e7624 | 74 | |
03eb10e6 DA |
75 | def teardown_module(mod): |
76 | tgen = get_topogen() | |
77 | tgen.stop_topology() | |
78 | ||
787e7624 | 79 | |
03eb10e6 DA |
80 | def test_bgp_as_wide_bgp_identifier(): |
81 | tgen = get_topogen() | |
82 | ||
83 | if tgen.routers_have_failure(): | |
84 | pytest.skip(tgen.errors) | |
85 | ||
86 | def _bgp_converge(router): | |
87 | output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) | |
787e7624 | 88 | expected = {"192.168.255.1": {"bgpState": "Established"}} |
03eb10e6 DA |
89 | return topotest.json_cmp(output, expected) |
90 | ||
91 | def _bgp_failed(router): | |
92 | output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) | |
93 | expected = { | |
787e7624 | 94 | "192.168.255.1": { |
95 | "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier" | |
03eb10e6 DA |
96 | } |
97 | } | |
98 | return topotest.json_cmp(output, expected) | |
99 | ||
787e7624 | 100 | test_func = functools.partial(_bgp_converge, tgen.gears["r1"]) |
9ccb078d | 101 | success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5) |
03eb10e6 | 102 | |
787e7624 | 103 | assert result is None, 'Failed to converge: "{}"'.format(tgen.gears["r1"]) |
03eb10e6 | 104 | |
787e7624 | 105 | test_func = functools.partial(_bgp_failed, tgen.gears["r3"]) |
9ccb078d | 106 | success, result = topotest.run_and_expect(test_func, None, count=260, wait=0.5) |
03eb10e6 | 107 | |
787e7624 | 108 | assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format( |
109 | tgen.gears["r3"] | |
110 | ) | |
111 | ||
03eb10e6 | 112 | |
787e7624 | 113 | if __name__ == "__main__": |
03eb10e6 DA |
114 | args = ["-s"] + sys.argv[1:] |
115 | sys.exit(pytest.main(args)) |