Skip to content

Commit a4c3b6e

Browse files
committed
tests: Verify BGP-LS routes withdrawn on peer deactivate
Add test_bgp_ls_peer_deactivate() to verify that deactivating the last BGP-LS peer on r2 withdraws all locally originated routes on r2 and clears all received routes on rr. Add test_bgp_ls_peer_reactivate() to verify that reactivating the peer triggers a fresh TED sync, re-originates all BGP-LS NLRIs on r2, and re-advertises them to rr. Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
1 parent 763126a commit a4c3b6e

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

tests/topotests/bgp_link_state/test_bgp_link_state.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,22 @@ def get_bgp_ls_count(router):
213213
return len(data)
214214

215215

216+
def check_bgp_ls_empty(router):
217+
"""
218+
Check that the BGP-LS routing table is empty.
219+
220+
Args:
221+
router: Router instance
222+
223+
Returns:
224+
None if table is empty, error message otherwise
225+
"""
226+
count = get_bgp_ls_count(router)
227+
if count > 0:
228+
return f"BGP-LS table not empty: {count} route(s) still present"
229+
return None
230+
231+
216232
def build_topo(tgen):
217233
"""Build the test topology"""
218234

@@ -853,6 +869,97 @@ def test_bgp_ls_r4_link_no_shutdown():
853869
assert result is None, '"rr" did not receive BGP-LS r4 link up update'
854870

855871

872+
def test_bgp_ls_peer_deactivate():
873+
"""
874+
Test that deactivating the last BGP-LS peer:
875+
- Withdraws all locally originated BGP-LS routes on the producer (r2)
876+
- Clears all received BGP-LS routes on the consumer (rr)
877+
"""
878+
tgen = get_topogen()
879+
880+
if tgen.routers_have_failure():
881+
pytest.skip(tgen.errors)
882+
883+
logger.info(
884+
"Deactivating BGP-LS peer on r2 and verifying route withdrawal on r2 and rr"
885+
)
886+
887+
r2 = tgen.gears["r2"]
888+
889+
# Deactivate the only BGP-LS peer on r2 (neighbor 10.0.3.4 = rr).
890+
r2.vtysh_cmd(
891+
"configure terminal\n"
892+
"router bgp 65000\n"
893+
"address-family link-state\n"
894+
"no neighbor 10.0.3.4 activate"
895+
)
896+
897+
# r2 must have withdrawn all its locally originated BGP-LS routes
898+
test_func = functools.partial(check_bgp_ls_empty, r2)
899+
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
900+
assert result is None, '"r2" BGP-LS routes not withdrawn after peer deactivation'
901+
902+
# rr (consumer) must have no BGP-LS routes once r2's session goes down
903+
consumer = tgen.gears["rr"]
904+
test_func = functools.partial(check_bgp_ls_empty, consumer)
905+
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
906+
assert result is None, '"rr" BGP-LS routes not cleared after r2 peer deactivation'
907+
908+
909+
def test_bgp_ls_peer_reactivate():
910+
"""
911+
Test that reactivating a BGP-LS peer after deactivation:
912+
- Triggers a fresh TED sync from the IGP
913+
- Re-originates all IGP topology as BGP-LS NLRIs
914+
- Re-advertises all routes to the consumer (rr)
915+
916+
The previous test (test_bgp_ls_peer_deactivate) must run first.
917+
"""
918+
tgen = get_topogen()
919+
920+
if tgen.routers_have_failure():
921+
pytest.skip(tgen.errors)
922+
923+
logger.info(
924+
"Reactivating BGP-LS peer on r2 and verifying route re-advertisement on r2 and rr"
925+
)
926+
927+
r2 = tgen.gears["r2"]
928+
929+
# Reactivate the BGP-LS peer.
930+
r2.vtysh_cmd(
931+
"configure terminal\n"
932+
"router bgp 65000\n"
933+
"address-family link-state\n"
934+
"neighbor 10.0.3.4 activate"
935+
)
936+
937+
# r2 must re-originate all BGP-LS NLRIs for the full ISIS topology
938+
reffile = os.path.join(CWD, "r2/bgp_ls_nlri.json")
939+
expected = json.loads(open(reffile).read())
940+
test_func = functools.partial(
941+
topotest.router_json_cmp,
942+
r2,
943+
"show bgp link-state link-state json",
944+
expected,
945+
)
946+
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
947+
assert result is None, '"r2" did not re-originate BGP-LS routes after peer reactivation'
948+
949+
# rr (consumer) must receive all BGP-LS routes again
950+
consumer = tgen.gears["rr"]
951+
reffile = os.path.join(CWD, "rr/bgp_ls_nlri.json")
952+
expected = json.loads(open(reffile).read())
953+
test_func = functools.partial(
954+
topotest.router_json_cmp,
955+
consumer,
956+
"show bgp link-state link-state json",
957+
expected,
958+
)
959+
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
960+
assert result is None, '"rr" did not receive BGP-LS routes after r2 peer reactivation'
961+
962+
856963
def test_memory_leak():
857964
"""Run the memory leak test and report results"""
858965
tgen = get_topogen()

0 commit comments

Comments
 (0)