2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2022 by
6 # Donatas Abraitis <donatas@opensourcerouting.org>
10 Test if aggregate-address command works fine when suppressing summary-only
11 and using matching-MED-only together.
19 from lib
.common_config
import (
23 # pylint: disable=C0413
24 from lib
import topotest
25 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
27 pytestmark
= [pytest
.mark
.bgpd
]
29 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
30 sys
.path
.append(os
.path
.join(CWD
, "../"))
34 for routern
in range(1, 5):
35 tgen
.add_router("r{}".format(routern
))
37 switch
= tgen
.add_switch("s1")
38 switch
.add_link(tgen
.gears
["r1"])
39 switch
.add_link(tgen
.gears
["r2"])
41 switch
= tgen
.add_switch("s2")
42 switch
.add_link(tgen
.gears
["r2"])
43 switch
.add_link(tgen
.gears
["r3"])
46 def setup_module(mod
):
47 tgen
= Topogen(build_topo
, mod
.__name
__)
50 router_list
= tgen
.routers()
52 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
54 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
57 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
63 def teardown_module(mod
):
68 def test_aggregate_address_matching_med():
71 if tgen
.routers_have_failure():
72 pytest
.skip(tgen
.errors
)
78 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast json"))
81 "172.16.255.0/24": None,
82 "172.16.255.1/32": [{"path": "65002 65001"}],
83 "172.16.255.2/32": [{"path": "65002 65001"}],
84 "172.16.255.3/32": [{"path": "65002 65001"}],
87 return topotest
.json_cmp(output
, expected
)
89 test_func
= functools
.partial(_bgp_converge
)
90 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
91 assert result
is None, "Failed to see unsuppressed routes from R2"
93 step("Change MED for 172.16.255.3/32 from 400 to 300")
97 route-map r2 permit 20
102 step("Check if 172.16.255.0/24 aggregated route was created and others suppressed")
104 def _bgp_aggregated_summary_only_med_match():
105 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast json"))
108 "172.16.255.0/24": [{"path": "65002"}],
109 "172.16.255.1/32": None,
110 "172.16.255.2/32": None,
111 "172.16.255.3/32": None,
114 return topotest
.json_cmp(output
, expected
)
116 test_func
= functools
.partial(_bgp_aggregated_summary_only_med_match
)
117 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
118 assert result
is None, "Failed to see unsuppressed routes from R2"
120 step("Change MED for 172.16.255.3/32 back to 400 from 300")
124 route-map r2 permit 20
128 test_func
= functools
.partial(_bgp_converge
)
129 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
130 assert result
is None, "Failed to see unsuppressed routes from R2"
133 if __name__
== "__main__":
134 args
= ["-s"] + sys
.argv
[1:]
135 sys
.exit(pytest
.main(args
))