]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_aggregate_address_route_map / test_bgp_aggregate-address_route-map.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_aggregate-address_route-map.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2019 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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_aggregate-address_route-map.py:
27
28 Test if works the following commands:
29 router bgp 65031
30 address-family ipv4 unicast
31 aggregate-address 192.168.255.0/24 route-map aggr-rmap
32
33 route-map aggr-rmap permit 10
34 set metric 123
35 """
36
37 import os
38 import sys
39 import json
40 import pytest
41 import functools
42
43 CWD = os.path.dirname(os.path.realpath(__file__))
44 sys.path.append(os.path.join(CWD, "../"))
45
46 # pylint: disable=C0413
47 from lib import topotest
48 from lib.topogen import Topogen, TopoRouter, get_topogen
49
50 pytestmark = [pytest.mark.bgpd]
51
52
53 def build_topo(tgen):
54 for routern in range(1, 3):
55 tgen.add_router("r{}".format(routern))
56
57 switch = tgen.add_switch("s1")
58 switch.add_link(tgen.gears["r1"])
59 switch.add_link(tgen.gears["r2"])
60
61
62 def setup_module(mod):
63 tgen = Topogen(build_topo, mod.__name__)
64 tgen.start_topology()
65
66 router_list = tgen.routers()
67
68 for i, (rname, router) in enumerate(router_list.items(), 1):
69 router.load_config(
70 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
71 )
72 router.load_config(
73 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
74 )
75
76 tgen.start_router()
77
78
79 def teardown_module(mod):
80 tgen = get_topogen()
81 tgen.stop_topology()
82
83
84 def test_bgp_maximum_prefix_invalid():
85 tgen = get_topogen()
86
87 if tgen.routers_have_failure():
88 pytest.skip(tgen.errors)
89
90 router = tgen.gears["r2"]
91
92 def _bgp_converge(router):
93 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
94 expected = {
95 "192.168.255.1": {
96 "bgpState": "Established",
97 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
98 }
99 }
100 return topotest.json_cmp(output, expected)
101
102 def _bgp_aggregate_address_has_metric(router):
103 output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json"))
104 expected = {"paths": [{"metric": 123}]}
105 return topotest.json_cmp(output, expected)
106
107 test_func = functools.partial(_bgp_converge, router)
108 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
109
110 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
111
112 test_func = functools.partial(_bgp_aggregate_address_has_metric, router)
113 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
114
115 assert (
116 result is None
117 ), 'Failed to see applied metric for aggregated prefix in "{}"'.format(router)
118
119
120 if __name__ == "__main__":
121 args = ["-s"] + sys.argv[1:]
122 sys.exit(pytest.main(args))