]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_route_map/test_bgp_aggregate-address_route-map.py
Merge pull request #8535 from opensourcerouting/zlog-rnode
[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 time
41 import pytest
42 import functools
43
44 CWD = os.path.dirname(os.path.realpath(__file__))
45 sys.path.append(os.path.join(CWD, "../"))
46
47 # pylint: disable=C0413
48 from lib import topotest
49 from lib.topogen import Topogen, TopoRouter, get_topogen
50 from lib.topolog import logger
51 from mininet.topo import Topo
52
53 pytestmark = [pytest.mark.bgpd]
54
55
56 class TemplateTopo(Topo):
57 def build(self, *_args, **_opts):
58 tgen = get_topogen(self)
59
60 for routern in range(1, 3):
61 tgen.add_router("r{}".format(routern))
62
63 switch = tgen.add_switch("s1")
64 switch.add_link(tgen.gears["r1"])
65 switch.add_link(tgen.gears["r2"])
66
67
68 def setup_module(mod):
69 tgen = Topogen(TemplateTopo, mod.__name__)
70 tgen.start_topology()
71
72 router_list = tgen.routers()
73
74 for i, (rname, router) in enumerate(router_list.items(), 1):
75 router.load_config(
76 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
77 )
78 router.load_config(
79 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
80 )
81
82 tgen.start_router()
83
84
85 def teardown_module(mod):
86 tgen = get_topogen()
87 tgen.stop_topology()
88
89
90 def test_bgp_maximum_prefix_invalid():
91 tgen = get_topogen()
92
93 if tgen.routers_have_failure():
94 pytest.skip(tgen.errors)
95
96 router = tgen.gears["r2"]
97
98 def _bgp_converge(router):
99 output = json.loads(router.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
100 expected = {
101 "192.168.255.1": {
102 "bgpState": "Established",
103 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
104 }
105 }
106 return topotest.json_cmp(output, expected)
107
108 def _bgp_aggregate_address_has_metric(router):
109 output = json.loads(router.vtysh_cmd("show ip bgp 172.16.255.0/24 json"))
110 expected = {"paths": [{"metric": 123}]}
111 return topotest.json_cmp(output, expected)
112
113 test_func = functools.partial(_bgp_converge, router)
114 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
115
116 assert result is None, 'Failed to see bgp convergence in "{}"'.format(router)
117
118 test_func = functools.partial(_bgp_aggregate_address_has_metric, router)
119 success, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
120
121 assert (
122 result is None
123 ), 'Failed to see applied metric for aggregated prefix in "{}"'.format(router)
124
125
126 if __name__ == "__main__":
127 args = ["-s"] + sys.argv[1:]
128 sys.exit(pytest.main(args))