Skip to content

Commit 5e5cf4d

Browse files
authored
Merge pull request #18828 from krishna-samy/krishna-samy/exist-map
bgpd: fix to show exist/non-exist-map in 'show run' properly
2 parents cc1063e + f15cb73 commit 5e5cf4d

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

bgpd/bgp_vty.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18545,12 +18545,23 @@ static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi,
1854518545
uint8_t type, int direct)
1854618546
{
1854718547
struct bgp_filter *filter;
18548+
filter = &peer->filter[afi][safi];
1854818549

18549-
if (peer_group_active(peer))
18550+
if (peer_group_active(peer)) {
18551+
/* This is required because the filter_override stores only the filter type.
18552+
* To determine whether exist-map or non-exist-map is configured along with adv-map filter,
18553+
* 'advmap.condition == direct' is evaluated where 'direct' should be passed appropriately by the caller */
18554+
if (type == PEER_FT_ADVERTISE_MAP) {
18555+
if (CHECK_FLAG(peer->filter_override[afi][safi][RMAP_OUT], type)) {
18556+
/* Only return true if the condition matches what we're checking for */
18557+
return (filter->advmap.condition == direct);
18558+
}
18559+
return false;
18560+
}
1855018561
return !!CHECK_FLAG(peer->filter_override[afi][safi][direct],
1855118562
type);
18563+
}
1855218564

18553-
filter = &peer->filter[afi][safi];
1855418565
switch (type) {
1855518566
case PEER_FT_DISTRIBUTE_LIST:
1855618567
return !!(filter->dlist[direct].name);

tests/topotests/bgp_peer_group/test_bgp_peer-group.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,89 @@ def _check_route_advertisement():
286286
)
287287

288288

289+
def test_bgp_advertise_map_peer_group_config():
290+
"""
291+
Test that advertise-map configurations show correctly in running config
292+
when a peer is part of a peer group. Tests both exist-map and non-exist-map.
293+
"""
294+
tgen = get_topogen()
295+
296+
if tgen.routers_have_failure():
297+
pytest.skip(tgen.errors)
298+
299+
r1 = tgen.gears["r1"]
300+
301+
# Create route-maps
302+
r1.vtysh_cmd(
303+
"""
304+
configure terminal
305+
route-map EXIST-MAP permit 10
306+
route-map ADV-MAP permit 10
307+
"""
308+
)
309+
310+
# First verify the peer is part of a peer group
311+
output = r1.vtysh_cmd("show bgp neighbor 192.168.252.2 json")
312+
json_output = json.loads(output)
313+
assert (
314+
"peerGroup" in json_output["192.168.252.2"]
315+
), "Peer is not part of a peer group"
316+
317+
# Test 1: Configure advertise-map with exist-map
318+
r1.vtysh_cmd(
319+
"""
320+
configure terminal
321+
router bgp 65001
322+
address-family ipv4 unicast
323+
neighbor 192.168.252.2 advertise-map ADV-MAP exist-map EXIST-MAP
324+
"""
325+
)
326+
327+
output = r1.vtysh_cmd("show running-config")
328+
exist_map_config = (
329+
"neighbor 192.168.252.2 advertise-map ADV-MAP exist-map EXIST-MAP"
330+
)
331+
332+
assert exist_map_config in output, (
333+
f"Exist-map configuration not found or incorrect in running config. "
334+
f"Expected: '{exist_map_config}'"
335+
)
336+
337+
# Test 2: Configure advertise-map with non-exist-map
338+
r1.vtysh_cmd(
339+
"""
340+
configure terminal
341+
router bgp 65001
342+
address-family ipv4 unicast
343+
neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP
344+
"""
345+
)
346+
347+
output = r1.vtysh_cmd("show running-config")
348+
non_exist_map_config = (
349+
"neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP"
350+
)
351+
352+
assert non_exist_map_config in output, (
353+
f"Non-exist-map configuration not found or incorrect in running config. "
354+
f"Expected: '{non_exist_map_config}'"
355+
)
356+
357+
logger.info("exist/non-exist-map configuration correctly shown in running config")
358+
359+
# cleanup
360+
r1.vtysh_cmd(
361+
"""
362+
configure terminal
363+
router bgp 65001
364+
address-family ipv4 unicast
365+
no neighbor 192.168.252.2 advertise-map ADV-MAP non-exist-map EXIST-MAP
366+
no route-map EXIST-MAP permit 10
367+
no route-map ADV-MAP permit 10
368+
"""
369+
)
370+
371+
289372
if __name__ == "__main__":
290373
args = ["-s"] + sys.argv[1:]
291374
sys.exit(pytest.main(args))

0 commit comments

Comments
 (0)