Skip to content

Commit

Permalink
Merge pull request #14637 from FRRouting/mergify/bp/dev/9.1/pr-14628
Browse files Browse the repository at this point in the history
bgpd: Do not suppress conditional advertisement updates if triggered (backport #14628)
  • Loading branch information
ton31337 authored Oct 24, 2023
2 parents a0cfc4f + 9c26d21 commit 42cae6e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions bgpd/bgp_conditional_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,

addpath_capable = bgp_addpath_encode_tx(peer, afi, safi);

SET_FLAG(subgrp->sflags, SUBGRP_STATUS_FORCE_UPDATES);
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
dest_p = bgp_dest_get_prefix(dest);
assert(dest_p);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!
int r1-eth0
ip address 192.168.1.1/24
!
router bgp 65000
no bgp ebgp-requires-policy
neighbor 192.168.1.2 remote-as internal
neighbor 192.168.1.2 timers 1 3
neighbor 192.168.1.2 timers connect 1
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
!
!debug bgp conditional-advertisement
!debug bgp updates
!
int r2-eth0
ip address 192.168.1.2/24
!
int r2-eth1
ip address 192.168.2.2/24
!
router bgp 65000
no bgp ebgp-requires-policy
bgp conditional-advertisement timer 5
neighbor 192.168.1.1 remote-as internal
neighbor 192.168.1.1 timers 1 3
neighbor 192.168.1.1 timers connect 1
neighbor 192.168.2.1 remote-as internal
neighbor 192.168.2.1 timers 1 3
neighbor 192.168.2.1 timers connect 1
address-family ipv4 unicast
redistribute static
neighbor 192.168.1.1 advertise-map advertise-map exist-map exist-map
neighbor 192.168.1.1 route-map deny-all out
exit-address-family
!
ip route 10.10.10.1/32 r2-eth0
ip route 10.10.10.2/32 r2-eth0
!
ip prefix-list default seq 5 permit 0.0.0.0/0
ip prefix-list advertise seq 5 permit 10.10.10.1/32
!
route-map deny-all deny 10
!
route-map exist-map permit 10
match ip address prefix-list default
!
route-map advertise-map permit 10
match ip address prefix-list advertise
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!
int lo
ip address 10.10.10.1/32
ip address 10.10.10.2/32
!
int r3-eth0
ip address 192.168.2.1/24
!
router bgp 65000
no bgp ebgp-requires-policy
no bgp network import-check
neighbor 192.168.2.2 remote-as internal
neighbor 192.168.2.2 timers 1 3
neighbor 192.168.2.2 timers connect 1
!
address-family ipv4 unicast
neighbor 192.168.2.2 default-originate
exit-address-family
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python
# SPDX-License-Identifier: ISC

# Copyright (c) 2023 by
# Donatas Abraitis <[email protected]>
#

"""
Test if static route with BGP conditional advertisement works correctly
if we modify the prefix-lists.
"""

import os
import re
import sys
import json
import pytest
import functools

pytestmark = pytest.mark.bgpd

CWD = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(CWD, "../"))

# pylint: disable=C0413
from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.common_config import step

pytestmark = [pytest.mark.bgpd]


def setup_module(mod):
topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
tgen = Topogen(topodef, mod.__name__)
tgen.start_topology()

router_list = tgen.routers()

for _, (rname, router) in enumerate(router_list.items(), 1):
router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))

tgen.start_router()


def teardown_module(mod):
tgen = get_topogen()
tgen.stop_topology()


def test_bgp_conditional_advertisements_static_route():
tgen = get_topogen()

if tgen.routers_have_failure():
pytest.skip(tgen.errors)

r2 = tgen.gears["r2"]

def _bgp_converge():
output = json.loads(
r2.vtysh_cmd(
"show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
)
)
expected = {
"advertisedRoutes": {
"10.10.10.1/32": {
"valid": True,
}
},
"totalPrefixCounter": 1,
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(
_bgp_converge,
)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "Can't converge"

step("Append prefix-list to advertise 10.10.10.2/32")

r2.vtysh_cmd(
"""
configure terminal
ip prefix-list advertise seq 10 permit 10.10.10.2/32
"""
)

def _bgp_check_advertised_after_update():
output = json.loads(
r2.vtysh_cmd(
"show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
)
)
expected = {
"advertisedRoutes": {
"10.10.10.1/32": {
"valid": True,
},
"10.10.10.2/32": {
"valid": True,
},
},
"totalPrefixCounter": 2,
}
return topotest.json_cmp(output, expected)

test_func = functools.partial(
_bgp_check_advertised_after_update,
)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "10.10.10.2/32 is not advertised after prefix-list update"


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

0 comments on commit 42cae6e

Please sign in to comment.