]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_as_wide_bgp_identifier/test_bgp_as_wide_bgp_identifier.py
Merge pull request #6506 from volta-networks/ldp_pwstatus_cleanup
[mirror_frr.git] / tests / topotests / bgp_as_wide_bgp_identifier / test_bgp_as_wide_bgp_identifier.py
CommitLineData
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"""
26rfc6286: Autonomous-System-Wide Unique BGP Identifier for BGP-4
27Test if 'Bad BGP Identifier' notification is sent only to
28internal peers (autonomous-system-wide). eBGP peers are not
29affected and should work.
30"""
31
32import os
33import sys
34import json
35import time
36import pytest
37import functools
38
39CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 40sys.path.append(os.path.join(CWD, "../"))
03eb10e6
DA
41
42# pylint: disable=C0413
43from lib import topotest
44from lib.topogen import Topogen, TopoRouter, get_topogen
45from lib.topolog import logger
46from mininet.topo import Topo
47
787e7624 48
03eb10e6
DA
49class TemplateTopo(Topo):
50 def build(self, *_args, **_opts):
51 tgen = get_topogen(self)
52
53 for routern in range(1, 4):
787e7624 54 tgen.add_router("r{}".format(routern))
55
56 switch = tgen.add_switch("s1")
57 switch.add_link(tgen.gears["r1"])
58 switch.add_link(tgen.gears["r2"])
59 switch.add_link(tgen.gears["r3"])
03eb10e6 60
03eb10e6
DA
61
62def setup_module(mod):
63 tgen = Topogen(TemplateTopo, mod.__name__)
64 tgen.start_topology()
65
66 router_list = tgen.routers()
67
68 for i, (rname, router) in enumerate(router_list.iteritems(), 1):
69 router.load_config(
787e7624 70 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
03eb10e6
DA
71 )
72 router.load_config(
787e7624 73 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
03eb10e6
DA
74 )
75
76 tgen.start_router()
77
787e7624 78
03eb10e6
DA
79def teardown_module(mod):
80 tgen = get_topogen()
81 tgen.stop_topology()
82
787e7624 83
03eb10e6
DA
84def test_bgp_as_wide_bgp_identifier():
85 tgen = get_topogen()
86
87 if tgen.routers_have_failure():
88 pytest.skip(tgen.errors)
89
90 def _bgp_converge(router):
91 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
787e7624 92 expected = {"192.168.255.1": {"bgpState": "Established"}}
03eb10e6
DA
93 return topotest.json_cmp(output, expected)
94
95 def _bgp_failed(router):
96 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
97 expected = {
787e7624 98 "192.168.255.1": {
99 "lastNotificationReason": "OPEN Message Error/Bad BGP Identifier"
03eb10e6
DA
100 }
101 }
102 return topotest.json_cmp(output, expected)
103
787e7624 104 test_func = functools.partial(_bgp_converge, tgen.gears["r1"])
03eb10e6
DA
105 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
106
787e7624 107 assert result is None, 'Failed to converge: "{}"'.format(tgen.gears["r1"])
03eb10e6 108
787e7624 109 test_func = functools.partial(_bgp_failed, tgen.gears["r3"])
03eb10e6
DA
110 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
111
787e7624 112 assert result is None, 'Bad BGP Identifier notification not sent: "{}"'.format(
113 tgen.gears["r3"]
114 )
115
03eb10e6 116
787e7624 117if __name__ == "__main__":
03eb10e6
DA
118 args = ["-s"] + sys.argv[1:]
119 sys.exit(pytest.main(args))