4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 Test if aggregate-address command works fine when suppressing summary-only
24 and using matching-MED-only together.
32 from lib
.common_config
import (
36 # pylint: disable=C0413
37 from lib
import topotest
38 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
40 pytestmark
= [pytest
.mark
.bgpd
]
42 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
43 sys
.path
.append(os
.path
.join(CWD
, "../"))
47 for routern
in range(1, 5):
48 tgen
.add_router("r{}".format(routern
))
50 switch
= tgen
.add_switch("s1")
51 switch
.add_link(tgen
.gears
["r1"])
52 switch
.add_link(tgen
.gears
["r2"])
54 switch
= tgen
.add_switch("s2")
55 switch
.add_link(tgen
.gears
["r2"])
56 switch
.add_link(tgen
.gears
["r3"])
59 def setup_module(mod
):
60 tgen
= Topogen(build_topo
, mod
.__name
__)
63 router_list
= tgen
.routers()
65 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
67 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
70 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
76 def teardown_module(mod
):
81 def test_aggregate_address_matching_med():
84 if tgen
.routers_have_failure():
85 pytest
.skip(tgen
.errors
)
91 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast json"))
94 "172.16.255.0/24": None,
95 "172.16.255.1/32": [{"path": "65002 65001"}],
96 "172.16.255.2/32": [{"path": "65002 65001"}],
97 "172.16.255.3/32": [{"path": "65002 65001"}],
100 return topotest
.json_cmp(output
, expected
)
102 test_func
= functools
.partial(_bgp_converge
)
103 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
104 assert result
is None, "Failed to see unsuppressed routes from R2"
106 step("Change MED for 172.16.255.3/32 from 400 to 300")
110 route-map r2 permit 20
115 step("Check if 172.16.255.0/24 aggregated route was created and others suppressed")
117 def _bgp_aggregated_summary_only_med_match():
118 output
= json
.loads(r3
.vtysh_cmd("show bgp ipv4 unicast json"))
121 "172.16.255.0/24": [{"path": "65002"}],
122 "172.16.255.1/32": None,
123 "172.16.255.2/32": None,
124 "172.16.255.3/32": None,
127 return topotest
.json_cmp(output
, expected
)
129 test_func
= functools
.partial(_bgp_aggregated_summary_only_med_match
)
130 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
131 assert result
is None, "Failed to see unsuppressed routes from R2"
133 step("Change MED for 172.16.255.3/32 back to 400 from 300")
137 route-map r2 permit 20
141 test_func
= functools
.partial(_bgp_converge
)
142 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
143 assert result
is None, "Failed to see unsuppressed routes from R2"
146 if __name__
== "__main__":
147 args
= ["-s"] + sys
.argv
[1:]
148 sys
.exit(pytest
.main(args
))