]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_distance_change/test_bgp_distance_change.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_distance_change / test_bgp_distance_change.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_distance_change.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2019 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 bgp_distance_change.py:
27
28 Test if works the following commands:
29 router bgp 65031
30 address-family ipv4 unicast
31 distance bgp 123 123 123
32
33 Changed distance should reflect to RIB after changes.
34 """
35
36 import os
37 import sys
38 import json
39 import pytest
40 import functools
41
42 CWD = os.path.dirname(os.path.realpath(__file__))
43 sys.path.append(os.path.join(CWD, "../"))
44
45 # pylint: disable=C0413
46 from lib import topotest
47 from lib.topogen import Topogen, TopoRouter, get_topogen
48
49 pytestmark = [pytest.mark.bgpd]
50
51
52 def build_topo(tgen):
53 for routern in range(1, 3):
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
60
61 def setup_module(mod):
62 tgen = Topogen(build_topo, mod.__name__)
63 tgen.start_topology()
64
65 router_list = tgen.routers()
66
67 for i, (rname, router) in enumerate(router_list.items(), 1):
68 router.load_config(
69 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
70 )
71 router.load_config(
72 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
73 )
74
75 tgen.start_router()
76
77
78 def teardown_module(mod):
79 tgen = get_topogen()
80 tgen.stop_topology()
81
82
83 def test_bgp_maximum_prefix_invalid():
84 tgen = get_topogen()
85
86 if tgen.routers_have_failure():
87 pytest.skip(tgen.errors)
88
89 router = tgen.gears["r1"]
90
91 def _bgp_converge(router):
92 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.2 json"))
93 expected = {
94 "192.168.255.2": {
95 "bgpState": "Established",
96 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}},
97 }
98 }
99 return topotest.json_cmp(output, expected)
100
101 def _bgp_distance_change(router):
102 router.vtysh_cmd(
103 """
104 configure terminal
105 router bgp 65000
106 address-family ipv4 unicast
107 distance bgp 123 123 123
108 """
109 )
110
111 def _bgp_check_distance_change(router):
112 output = json.loads(router.vtysh_cmd("show ip route 172.16.255.254/32 json"))
113 expected = {"172.16.255.254/32": [{"protocol": "bgp", "distance": 123}]}
114 return topotest.json_cmp(output, expected)
115
116 test_func = functools.partial(_bgp_converge, router)
117 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
118
119 assert result is None, 'Failed to see BGP convergence in "{}"'.format(router)
120
121 _bgp_distance_change(router)
122
123 test_func = functools.partial(_bgp_check_distance_change, router)
124 success, result = topotest.run_and_expect(test_func, None, count=15, wait=0.5)
125
126 assert result is None, 'Failed to see applied BGP distance in RIB "{}"'.format(
127 router
128 )
129
130
131 if __name__ == "__main__":
132 args = ["-s"] + sys.argv[1:]
133 sys.exit(pytest.main(args))