4 # bgp_aggregate-address_route-map.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2019 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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
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
26 bgp_aggregate-address_route-map.py:
28 Test if works the following commands:
30 address-family ipv4 unicast
31 aggregate-address 192.168.255.0/24 route-map aggr-rmap
33 route-map aggr-rmap permit 10
43 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
44 sys
.path
.append(os
.path
.join(CWD
, "../"))
46 # pylint: disable=C0413
47 from lib
import topotest
48 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
50 pytestmark
= [pytest
.mark
.bgpd
]
54 for routern
in range(1, 3):
55 tgen
.add_router("r{}".format(routern
))
57 switch
= tgen
.add_switch("s1")
58 switch
.add_link(tgen
.gears
["r1"])
59 switch
.add_link(tgen
.gears
["r2"])
62 def setup_module(mod
):
63 tgen
= Topogen(build_topo
, mod
.__name
__)
66 router_list
= tgen
.routers()
68 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
70 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
73 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
79 def teardown_module(mod
):
84 def test_bgp_maximum_prefix_invalid():
87 if tgen
.routers_have_failure():
88 pytest
.skip(tgen
.errors
)
90 router
= tgen
.gears
["r2"]
92 def _bgp_converge(router
):
93 output
= json
.loads(router
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
96 "bgpState": "Established",
97 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}},
100 return topotest
.json_cmp(output
, expected
)
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
)
107 test_func
= functools
.partial(_bgp_converge
, router
)
108 success
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
110 assert result
is None, 'Failed to see bgp convergence in "{}"'.format(router
)
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)
117 ), 'Failed to see applied metric for aggregated prefix in "{}"'.format(router
)
120 if __name__
== "__main__":
121 args
= ["-s"] + sys
.argv
[1:]
122 sys
.exit(pytest
.main(args
))