Skip to content

Commit 1433df3

Browse files
authored
Merge pull request #22117 from Jafaral/pim-bsr-fixes
pimd: BSR/C-RP fixes with expanded topotest coverage
2 parents 616d807 + 4444008 commit 1433df3

7 files changed

Lines changed: 89 additions & 21 deletions

File tree

pimd/pim_bsm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ void pim_bsm_proc_init(struct pim_instance *pim)
300300
cand_rp_groups_init(scope->cand_rp_groups);
301301

302302
scope->unicast_sock = pim_socket_raw(IPPROTO_PIM);
303+
if (scope->unicast_sock < 0) {
304+
zlog_warn("%s: Could not create BSR unicast socket: %s",
305+
__func__, safe_strerror(errno));
306+
return;
307+
}
308+
303309
set_nonblocking(scope->unicast_sock);
304310
sockopt_reuseaddr(scope->unicast_sock);
305311

@@ -320,8 +326,12 @@ void pim_bsm_proc_free(struct pim_instance *pim)
320326
struct bsgrp_node *bsgrp;
321327
struct cand_rp_group *crpgrp;
322328

329+
pim_crp_db_clear(scope);
330+
323331
event_cancel(&scope->unicast_read);
324-
close(scope->unicast_sock);
332+
if (scope->unicast_sock >= 0)
333+
close(scope->unicast_sock);
334+
scope->unicast_sock = -1;
325335

326336
pim_bs_timer_stop(scope);
327337
pim_bsm_frags_free(scope);

pimd/pim_bsm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,4 @@ int pim_cand_config_write(struct pim_instance *pim, struct vty *vty);
395395

396396
DECLARE_MTYPE(PIM_BSM_FRAG);
397397

398-
DECLARE_MTYPE(PIM_BSM_FRAG);
399-
400-
DECLARE_MTYPE(PIM_BSM_FRAG);
401-
402398
#endif

pimd/pim_bsr_rpdb.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,15 @@ int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,
466466
return -1;
467467
}
468468

469-
//pim_ifp->pim_ifstat_bsm_rx++;
469+
pim_ifp->pim_ifstat_bsm_rx++;
470470
pim = pim_ifp->pim;
471-
//pim->bsm_rcvd++;
471+
pim->bsm_rcvd++;
472472

473473
if (!pim_ifp->bsm_enable) {
474474
zlog_warn("%s: BSM not enabled on interface %s", __func__,
475475
ifp->name);
476-
//pim_ifp->pim_ifstat_bsm_cfg_miss++;
477-
//pim->bsm_dropped++;
476+
pim_ifp->pim_ifstat_bsm_cfg_miss++;
477+
pim->bsm_dropped++;
478478
return -1;
479479
}
480480

@@ -510,7 +510,7 @@ int pim_crp_process(struct interface *ifp, pim_sgaddr *src_dst, uint8_t *buf,
510510
ngroups = crp_hdr->prefix_cnt;
511511
rpaddr = crp_hdr->rp_addr.addr;
512512

513-
if (remain < ngroups * sizeof(struct pim_encoded_group_ipv4)) {
513+
if (remain < ngroups * sizeof(pim_encoded_group)) {
514514
if (PIM_DEBUG_BSM)
515515
zlog_debug("truncated Candidate-RP advertisement for RP %pPA from %pPA (too short for %zu groups)",
516516
&rpaddr, &src_dst->src, ngroups);

pimd/pim_cmd_common.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5791,12 +5791,9 @@ int pim_show_bsr_cand_bsr(const struct vrf *vrf, struct vty *vty, bool uj)
57915791
}
57925792

57935793
if (uj) {
5794-
char buf[INET_ADDRSTRLEN];
5795-
57965794
jsondata = json_object_new_object();
5797-
inet_ntop(AF_INET, &scope->bsr_addrsel.run_addr, buf,
5798-
sizeof(buf));
5799-
json_object_string_add(jsondata, "address", buf);
5795+
json_object_string_addf(jsondata, "address", "%pPA",
5796+
&scope->bsr_addrsel.run_addr);
58005797
json_object_int_add(jsondata, "priority", scope->cand_bsr_prio);
58015798
json_object_boolean_add(jsondata, "elected",
58025799
pim->global_scope.state == BSR_ELECTED);

pimd/pim_nb_config.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,8 +4332,7 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_rp
43324332

43334333
scope->cand_bsr_prio = yang_dnode_get_uint8(args->dnode, NULL);
43344334

4335-
/* FIXME: force prio update */
4336-
candidate_bsr_addrsel(scope, args->dnode);
4335+
pim_cand_bsr_apply(scope);
43374336
break;
43384337
}
43394338

pimd/pim_pim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ static void pim_sock_read(struct event *t)
528528

529529
pim_ifp = ifp->info;
530530

531-
if (pim_sock_read_helper(fd, pim_ifp->pim, true) == 0)
531+
if (pim_sock_read_helper(fd, pim_ifp->pim, true) != 0)
532532
++pim_ifp->pim_ifstat_hello_recvfail;
533533

534534
pim_sock_read_on(ifp);

tests/topotests/pim_cand_rp_bsr/test_pim_cand_rp_bsr.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,50 @@ def test_pim_bsr_rp_info(request):
303303
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
304304

305305

306+
def test_pim_bsr_priority_modify(request):
307+
"Test PIM BSR candidate-BSR priority-only change"
308+
tgen = get_topogen()
309+
tc_name = request.node.name
310+
write_test_header(tc_name)
311+
312+
if tgen.routers_have_failure():
313+
pytest.skip("skipped because of router(s) failure")
314+
315+
r2 = tgen.gears["r2"]
316+
317+
step("Raise r2 candidate-BSR priority above r1")
318+
r2.vtysh_cmd(
319+
"""
320+
configure
321+
router pim
322+
bsr candidate-bsr priority 250
323+
"""
324+
)
325+
326+
step("Verify r2 reports the updated candidate-BSR state")
327+
expected = {"address": "10.0.0.2", "priority": 250, "elected": True}
328+
test_func = partial(
329+
topotest.router_json_cmp, r2, "show ip pim bsr candidate-bsr json", expected
330+
)
331+
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
332+
333+
assertmsg = "r2: candidate bsr priority modify mismatch"
334+
assert result is None, assertmsg
335+
336+
step("Verify r2 is elected as the new BSR")
337+
expected = {
338+
"bsr": "10.0.0.2",
339+
"priority": 250,
340+
"state": "BSR_ELECTED",
341+
}
342+
343+
test_func = partial(topotest.router_json_cmp, r2, "show ip pim bsr json", expected)
344+
_, result = topotest.run_and_expect(test_func, None, count=180, wait=1)
345+
346+
assertmsg = "r2: failed to become BSR after priority increase"
347+
assert result is None, assertmsg
348+
349+
306350
def test_pim_bsr_election_fallback_r2(request):
307351
"Test PIM BSR Election Backup"
308352
tgen = get_topogen()
@@ -328,16 +372,16 @@ def test_pim_bsr_election_fallback_r2(request):
328372
test_func = partial(
329373
topotest.router_json_cmp, r1, "show ip pim bsr candidate-bsr json", expected
330374
)
331-
_, result = topotest.run_and_expect(test_func, None, count=10, wait=1)
375+
_, result = topotest.run_and_expect(test_func, None, count=20, wait=3)
332376

333377
assertmsg = "r1: failed to remove bsr candidate configuration"
334378
assert result is None, assertmsg
335379

336380
r2 = tgen.gears["r2"]
337-
# We should fall back to r2 as the BSR
381+
# r2 became BSR earlier after its priority was raised to 250
338382
expected = {
339383
"bsr": "10.0.0.2",
340-
"priority": 100,
384+
"priority": 250,
341385
"state": "BSR_ELECTED",
342386
}
343387

@@ -429,6 +473,28 @@ def test_pimv6_bsr_election_r1(request):
429473
assert result is None, assertmsg
430474

431475

476+
def test_pimv6_bsr_cand_bsr_r2(request):
477+
"Test PIMv6 BSR candidate BSR JSON output"
478+
tgen = get_topogen()
479+
tc_name = request.node.name
480+
write_test_header(tc_name)
481+
482+
if tgen.routers_have_failure():
483+
pytest.skip("skipped because of router(s) failure")
484+
485+
r2 = tgen.gears["r2"]
486+
487+
# r2 is a candidate bsr with low priority: elected = False
488+
expected = {"address": "fd00::2", "priority": 100, "elected": False}
489+
test_func = partial(
490+
topotest.router_json_cmp, r2, "show ipv6 pim bsr candidate-bsr json", expected
491+
)
492+
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
493+
494+
assertmsg = "r2: IPv6 candidate bsr mismatch"
495+
assert result is None, assertmsg
496+
497+
432498
def test_pimv6_bsr_cand_rp(request):
433499
"Test PIMv6 BSR candidate RP"
434500
tgen = get_topogen()

0 commit comments

Comments
 (0)