Commit 037b100f81 for frr
commit 037b100f813e8be44603507c24164f5459fd0778
Author: Nageswara Soma <nsoma@cisco.com>
Date: Tue Nov 24 21:01:00 2026 -0800
tests: cover PIM OIF ownership on owner removal
Exercise mixed IGMP/PIM membership, join expiry,
Assert loss, and inherited outputs with and without
a direct child ifchannel. Check STAR retention after
local receiver removal while the parent PIM join
remains active, and independent release of each owner.
Limit Assert-loss checks to PIM ownership.
Use JOIN/RPT cases as control coverage for inherited
forwarding with and without local receiver interest.
An RPT prune must suppress parent PIM-join inheritance
while preserving the local-receiver exception.
Use one-shot PIM peers with shared neighbor setup and
bounded polling. Keep a second output active and use
a remote RP to avoid repair paths hiding lost STAR.
Wait for initial RPF rescans before ownership changes.
Confirm a channel-UP log transition before checking
join expiry. Use short keepalive and hold timers with
explicit checks that the RPT prune is present while
the parent remains joined.
Use shared configuration helpers. Track successful
group additions for cleanup, and restore KAT even if
group removal fails.
Signed-off-by: Nageswara Soma <nsoma@cisco.com>
diff --git a/tests/topotests/pim_oif_ownership/r1/frr.conf b/tests/topotests/pim_oif_ownership/r1/frr.conf
new file mode 100644
index 0000000000..b01bd2b6b7
--- /dev/null
+++ b/tests/topotests/pim_oif_ownership/r1/frr.conf
@@ -0,0 +1,23 @@
+hostname r1
+debug pim events
+!
+interface r1-eth0
+ ip address 10.1.0.1/24
+ ip pim
+ ip pim drpriority 100
+ ip igmp
+!
+interface r1-eth1
+ ip address 10.2.0.1/24
+ ip pim
+ ip pim drpriority 100
+!
+interface r1-eth2
+ ip address 10.3.0.1/24
+ ip pim
+!
+ip route 10.0.0.0/24 10.3.0.2
+!
+router pim
+ rp 10.0.0.1
+!
diff --git a/tests/topotests/pim_oif_ownership/test_pim_oif_ownership.py b/tests/topotests/pim_oif_ownership/test_pim_oif_ownership.py
new file mode 100644
index 0000000000..609f5e5db1
--- /dev/null
+++ b/tests/topotests/pim_oif_ownership/test_pim_oif_ownership.py
@@ -0,0 +1,526 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+# Copyright (c) 2026 Cisco Systems, Inc.
+
+"""Keep local, downstream PIM, and inherited OIF ownership independent.
+
+Three packet peers surround r1: h1 shares the local IGMP receiver LAN,
+h2 keeps another downstream output alive, and h3 is the RPF neighbor
+toward the remote RP and source. One-shot PIM packets control downstream
+join expiry without racing periodic joins from another FRR router.
+"""
+
+import functools
+import json
+import os
+import socket
+import struct
+import sys
+
+import pytest
+from scapy.contrib.pim import (
+ PIMv2GroupAddrs,
+ PIMv2Hdr,
+ PIMv2Hello,
+ PIMv2HelloDRPriority,
+ PIMv2HelloGenerationID,
+ PIMv2HelloHoldtime,
+ PIMv2JoinAddrs,
+ PIMv2JoinPrune,
+ PIMv2PruneAddrs,
+)
+from scapy.layers.inet import IP
+from scapy.layers.l2 import Ether
+from scapy.packet import Raw
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, ".."))
+
+from lib import topotest
+from lib.common_config import apply_raw_config
+from lib.pim import scapy_send_autorp_raw_packet
+from lib.topogen import Topogen, get_topogen
+
+pytestmark = [pytest.mark.pimd, pytest.mark.staticd]
+RP = "10.0.0.1"
+SOURCE = "10.0.0.2"
+RECV_IF = "r1-eth0"
+
+
+def build_topo(tgen):
+ router = tgen.add_router("r1")
+ for n in range(1, 4):
+ host = tgen.add_host(f"h{n}", f"10.{n}.0.2/24", f"via 10.{n}.0.1")
+ switch = tgen.add_switch(f"s{n}")
+ switch.add_link(router)
+ switch.add_link(host)
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+ tgen.gears["r1"].load_frr_config("frr.conf")
+ tgen.start_router()
+
+
+def teardown_module():
+ get_topogen().stop_topology()
+
+
+def _send(peer, payload, message_type=None):
+ packet = (
+ Ether(dst="01:00:5e:00:00:0d")
+ / IP(src=f"10.{peer}.0.2", dst="224.0.0.13", ttl=1)
+ / (PIMv2Hdr() if message_type is None else PIMv2Hdr(type=message_type))
+ / payload
+ )
+ scapy_send_autorp_raw_packet(
+ get_topogen(), f"h{peer}", f"h{peer}-eth0", bytes(packet).hex()
+ )
+
+
+def _expect(command, expected, count=30):
+ check = functools.partial(
+ topotest.router_json_cmp, get_topogen().gears["r1"], command, expected
+ )
+ _, result = topotest.run_and_expect(check, None, count=count, wait=1)
+ assert result is None, result
+
+
+@pytest.fixture(scope="module", autouse=True)
+def neighbors():
+ # The raw peers never refresh themselves. Keep their adjacencies for the
+ # module without resending three Hellos before every independent group.
+ for n in range(1, 4):
+ _send(
+ n,
+ PIMv2Hello(
+ option=[
+ PIMv2HelloHoldtime(holdtime=0xFFFF),
+ PIMv2HelloDRPriority(dr_priority=1),
+ PIMv2HelloGenerationID(generation_id=n),
+ ]
+ ),
+ )
+ _expect(
+ "show ip pim neighbor json",
+ {f"r1-eth{n - 1}": {f"10.{n}.0.2": {}}},
+ )
+
+
+@pytest.fixture(autouse=True)
+def router_running(neighbors):
+ # Independent groups let scenarios run after an earlier assertion fails,
+ # but an unavailable daemon must still fail each affected test.
+ assert get_topogen().gears["r1"].check_router_running() == ""
+
+
+@pytest.fixture(scope="module", autouse=True)
+def inherited_sources(neighbors):
+ # Prime the additional scenarios while the earlier cases run. Their
+ # initial RPF rescans can finish without adding a timer-wheel wait per
+ # case, and cannot repair a wrongly removed STAR during the assertions.
+ for suffix in (8, 9, 10, 11):
+ group = f"239.10.0.{suffix}"
+ _jp(2, group, SOURCE, holdtime=0xFFFF)
+ _channel(group, SOURCE, "JOIN", peer=2)
+
+
+def _jp(peer, group, source="*", prune=False, holdtime=600, rpt=False, rpt_prune=None):
+ address = PIMv2PruneAddrs if prune else PIMv2JoinAddrs
+ entry = address(
+ src_ip=RP if source == "*" else source,
+ sparse=1,
+ wildcard=int(source == "*"),
+ rpt=int(source == "*" or rpt),
+ )
+ prunes = [entry] if prune else []
+ if rpt_prune is not None:
+ prunes.append(PIMv2PruneAddrs(src_ip=rpt_prune, sparse=1, wildcard=0, rpt=1))
+ _send(
+ peer,
+ PIMv2JoinPrune(
+ up_neighbor_ip=f"10.{peer}.0.1",
+ holdtime=holdtime,
+ jp_ips=[
+ PIMv2GroupAddrs(
+ gaddr=group,
+ join_ips=[] if prune else [entry],
+ prune_ips=prunes,
+ )
+ ],
+ ),
+ )
+
+
+def _static_group(group, add=True):
+ result = apply_raw_config(
+ get_topogen(),
+ {
+ "r1": {
+ "raw_config": [
+ f"interface {RECV_IF}",
+ f"{'' if add else 'no '}ip igmp static-group {group}",
+ ]
+ }
+ },
+ )
+ assert result is True, result
+
+
+def _channel(group, source, state, peer=1, count=30):
+ _expect(
+ "show ip pim join json",
+ {f"r1-eth{peer - 1}": {group: {source: {"channelJoinName": state}}}},
+ count=count,
+ )
+
+
+def _oif(group, source, origin, peer=1, igmp=False):
+ _expect(
+ "show ip mroute detail json",
+ {
+ group: {
+ source: {
+ "installed": 1,
+ "iif": "r1-eth2",
+ "oil": {
+ f"r1-eth{peer - 1}": {
+ "origin": origin,
+ "protocolPim": True if "P" in origin else None,
+ "protocolIgmp": True if igmp else None,
+ "protocolInherited": True if "*" in origin else None,
+ }
+ },
+ }
+ }
+ },
+ )
+
+
+def test_mixed_igmp_pim_membership():
+ """Either owner may leave without removing the other owner's output."""
+ group = "239.10.0.1"
+ _jp(1, group)
+ _channel(group, "*", "JOIN")
+ _oif(group, "*", "P")
+ _static_group(group)
+ group_added = True
+ try:
+ _oif(group, "*", "SP", igmp=True)
+ _static_group(group, add=False)
+ group_added = False
+ _oif(group, "*", "P")
+ _static_group(group)
+ group_added = True
+ _oif(group, "*", "SP", igmp=True)
+ _jp(1, group, prune=True)
+ _channel(group, "*", "NOINFO")
+ _oif(group, "*", "S", igmp=True)
+ finally:
+ if group_added:
+ _static_group(group, add=False)
+
+
+def test_join_expiry():
+ """Actual holdtime expiry releases PIM while preserving local membership."""
+ group = "239.10.0.3"
+ group_added = False
+ try:
+ _static_group(group)
+ group_added = True
+ _oif(group, "*", "S", igmp=True)
+ router = get_topogen().gears["r1"]
+ log_start = len(router.net.getLog("log", "pimd"))
+ # Start the short expiry only after all preconditions are established.
+ # Confirm an actual transition rather than racing a JOIN/SP poll
+ # against expiry: the channel may already be NOINFO by the first poll.
+ _jp(1, group, holdtime=5)
+
+ def _joined():
+ log = router.net.getLog("log", "pimd")[log_start:]
+ for line in log.splitlines():
+ if (
+ "PIM_IFCHANNEL_UP:" in line
+ and f"(*,{group}) on interface {RECV_IF}" in line
+ ):
+ return None
+ return f"No PIM channel-UP transition for (*,{group}) on {RECV_IF}"
+
+ _, result = topotest.run_and_expect(_joined, None, count=30, wait=1)
+ assert result is None, result
+ _channel(group, "*", "NOINFO")
+ _oif(group, "*", "S", igmp=True)
+ finally:
+ if group_added:
+ _static_group(group, add=False)
+
+
+@pytest.mark.parametrize("direct_child", [False, True])
+def test_inherited_output_after_parent_and_child_prune(direct_child):
+ """Parent local membership keeps STAR across parent and child PIM prunes."""
+ group = "239.10.0.4" if direct_child else "239.10.0.5"
+ group_added = False
+ try:
+ _jp(1, group)
+ _channel(group, "*", "JOIN")
+ _static_group(group)
+ group_added = True
+ _oif(group, "*", "SP", igmp=True)
+ if direct_child:
+ _jp(1, group, SOURCE)
+ _channel(group, SOURCE, "JOIN")
+ _jp(2, group, SOURCE)
+ _channel(group, SOURCE, "JOIN", peer=2)
+ # Static (*,G) configuration also contributes the display letter S
+ # to covered (S,G)s; only the parent owns GM, the child owns STAR.
+ origin = "*SP" if direct_child else "*S"
+ _oif(group, SOURCE, origin)
+
+ # Only the parent's PIM join ends. Its local receiver still keeps
+ # this interface in inherited_olist(S,G), including inherited-only OIFs.
+ _jp(1, group, prune=True)
+ _channel(group, "*", "NOINFO")
+ _oif(group, SOURCE, origin)
+
+ # A second output keeps the OIL nonempty; the router is not the RP.
+ # Missing inheritance must not be hidden by the empty-OIL repair path.
+ upstream = (
+ get_topogen()
+ .gears["r1"]
+ .vtysh_cmd("show ip pim upstream json", isjson=True)[group][SOURCE]
+ )
+ assert upstream["keepaliveTimer"] != "--:--:--", upstream
+ if direct_child:
+ _jp(1, group, SOURCE, prune=True)
+ _channel(group, SOURCE, "NOINFO")
+ _oif(group, SOURCE, "*S")
+
+ # The original join ET and keepalive defer channel deletion.
+ channel = (
+ get_topogen()
+ .gears["r1"]
+ .vtysh_cmd("show ip pim join json", isjson=True)[RECV_IF][group][SOURCE]
+ )
+ assert channel["expire"] != "--:--", channel
+ _oif(group, SOURCE, "P", peer=2)
+ _expect(
+ "show ip pim upstream json",
+ {group: {SOURCE: {"joinState": "Joined", "inboundInterface": "r1-eth2"}}},
+ )
+ finally:
+ if group_added:
+ _static_group(group, add=False)
+
+ # Once local membership also leaves, STAR must go; the other PIM output stays.
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oil": {RECV_IF: None}}}},
+ )
+ _oif(group, SOURCE, "P", peer=2)
+
+
+def test_assert_loser_does_not_regain_pim_ownership():
+ """A parent's local receiver must not hide the direct child's Assert loss."""
+ group = "239.10.0.6"
+ tgen = get_topogen()
+ router = tgen.gears["r1"]
+ result = apply_raw_config(
+ tgen, {"r1": {"raw_config": ["router pim", "keep-alive-timer 5"]}}
+ )
+ assert result is True, result
+ group_added = False
+ try:
+ _jp(1, group)
+ _static_group(group)
+ group_added = True
+ _jp(1, group, SOURCE)
+ _channel(group, SOURCE, "JOIN")
+ _oif(group, SOURCE, "*SP")
+ _expect("show ip pim upstream json", {group: {SOURCE: {"joinState": "Joined"}}})
+
+ # Scapy's PIM contrib has no Assert layer: encode the group, unicast
+ # source, and a winning SPT preference/metric in the existing raw sender.
+ body = struct.pack(
+ "!BBBB4sBB4sII",
+ 1,
+ 0,
+ 0,
+ 32,
+ socket.inet_aton(group),
+ 1,
+ 0,
+ socket.inet_aton(SOURCE),
+ 0,
+ 0,
+ )
+ _send(1, Raw(body), message_type=5)
+ lost_assert = {
+ group: {SOURCE: {"interface": RECV_IF, "joins": True, "lostAssert": True}}
+ }
+ _expect("show ip pim channel json", lost_assert)
+
+ # Once KAT has expired, Assert loss allows forward_off even though the
+ # downstream join is still active. Parent INCLUDE must not cause
+ # forward_stop to retain the child's PIM ownership through its fallback.
+ _expect(
+ "show ip pim upstream json",
+ {group: {SOURCE: {"joinState": "NotJoined"}}},
+ )
+ _expect("show ip pim channel json", lost_assert)
+ _channel(group, SOURCE, "JOIN")
+
+ def _no_pim_owner():
+ data = json.loads(router.vtysh_cmd("show ip mroute detail json"))
+ oif = data.get(group, {}).get(SOURCE, {}).get("oil", {}).get(RECV_IF, {})
+ return topotest.json_cmp(oif, {"protocolPim": None})
+
+ # Check only PIM ownership: correcting inherited forwarding under
+ # Assert loss later may legitimately remove STAR or the entire OIF.
+ _, result = topotest.run_and_expect(_no_pim_owner, None, count=30, wait=1)
+ assert result is None, result
+ finally:
+ try:
+ if group_added:
+ _static_group(group, add=False)
+ finally:
+ result = apply_raw_config(
+ tgen, {"r1": {"raw_config": ["router pim", "no keep-alive-timer"]}}
+ )
+ assert result is True, result
+
+
+def test_local_receiver_inheritance_survives_rpt_prune():
+ """An (S,G,rpt) prune must not withdraw the parent's local IGMP receiver."""
+ group = "239.10.0.7"
+ _static_group(group)
+ try:
+ _jp(2, group, SOURCE)
+ _channel(group, SOURCE, "JOIN", peer=2)
+ _oif(group, SOURCE, "*S")
+
+ # Finish receiver/source setup before starting the parent expiry.
+ # Only one raw-packet send remains before checking the ordering.
+ _jp(1, group, holdtime=15)
+ _channel(group, "*", "JOIN")
+ _jp(1, group, SOURCE, prune=True, rpt=True)
+ _channel(group, SOURCE + ",S,Grpt", "SGRpt(P)")
+ _channel(group, "*", "JOIN")
+ _expect("show ip pim join json", {RECV_IF: {group: {SOURCE: None}}})
+ _oif(group, SOURCE, "*S")
+
+ # Expiry preserves the RPT prune; receiving a (*,G) prune deletes it.
+ # Parent NOINFO still has local INCLUDE interest that the neighbour's
+ # RPT prune cannot withdraw.
+ _channel(group, "*", "NOINFO", count=45)
+ _channel(group, SOURCE + ",S,Grpt", "SGRpt(P)")
+ _oif(group, SOURCE, "*S")
+ _oif(group, SOURCE, "P", peer=2)
+ finally:
+ _static_group(group, add=False)
+
+ _expect("show ip mroute detail json", {group: {SOURCE: {"oil": {RECV_IF: None}}}})
+ _oif(group, SOURCE, "P", peer=2)
+
+
+@pytest.mark.parametrize("direct_child", [False, True])
+def test_parent_join_keeps_inheritance_after_local_receiver_leaves(direct_child):
+ """Removing IGMP must retain STAR owned by the parent's active PIM join."""
+ group = "239.10.0.8" if direct_child else "239.10.0.9"
+ _jp(1, group)
+ _static_group(group)
+ group_added = True
+ try:
+ if direct_child:
+ _jp(1, group, SOURCE)
+ _channel(group, SOURCE, "JOIN")
+ _channel(group, SOURCE, "JOIN", peer=2)
+ _oif(group, SOURCE, "*SP" if direct_child else "*S")
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oilInheritedRescan": 0}}},
+ count=60,
+ )
+ if not direct_child:
+ _expect("show ip pim join json", {RECV_IF: {group: {SOURCE: None}}})
+ _static_group(group, add=False)
+ group_added = False
+ _channel(group, "*", "JOIN")
+ _oif(group, SOURCE, "*P" if direct_child else "*")
+
+ # Direct child ownership must not retain STAR after the parent ends.
+ _jp(1, group, prune=True)
+ if direct_child:
+ _channel(group, SOURCE, "JOIN")
+ _oif(group, SOURCE, "P")
+ # With no parent join left, adding/removing a local receiver
+ # must release STAR even though the direct child's PIM survives.
+ _static_group(group)
+ group_added = True
+ _oif(group, SOURCE, "*SP")
+ _static_group(group, add=False)
+ group_added = False
+ _oif(group, SOURCE, "P")
+ else:
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oil": {RECV_IF: None}}}},
+ )
+ _oif(group, SOURCE, "P", peer=2)
+ finally:
+ if group_added:
+ _static_group(group, add=False)
+
+
+@pytest.mark.parametrize("local_receiver", [False, True])
+def test_parent_join_with_rpt_prune(local_receiver):
+ """Control coverage for RPT suppression and its local-receiver exception.
+
+ These cases also pass with the old JOIN predicate: local membership
+ already owns STAR and refreshing the RPT prune can add it independently.
+ """
+ group = "239.10.0.10" if local_receiver else "239.10.0.11"
+ _static_group(group)
+ group_added = True
+ try:
+ _channel(group, SOURCE, "JOIN", peer=2)
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oilInheritedRescan": 0}}},
+ count=60,
+ )
+ _jp(1, group, SOURCE, prune=True, rpt=True)
+ _channel(group, SOURCE + ",S,Grpt", "SGRpt(P)")
+ _channel(group, "*", "NOINFO")
+ _oif(group, SOURCE, "*S")
+ if not local_receiver:
+ _static_group(group, add=False)
+ group_added = False
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oil": {RECV_IF: None}}}},
+ )
+
+ # Repeat the RPT prune so the parent Join does not clear it at EOM.
+ _jp(1, group, rpt_prune=SOURCE)
+ _channel(group, "*", "JOIN")
+ _channel(group, SOURCE + ",S,Grpt", "SGRpt(P)")
+ _expect("show ip pim join json", {RECV_IF: {group: {SOURCE: None}}})
+ if local_receiver:
+ _oif(group, SOURCE, "*S")
+ else:
+ _expect(
+ "show ip mroute detail json",
+ {group: {SOURCE: {"oil": {RECV_IF: None}}}},
+ )
+ _oif(group, SOURCE, "P", peer=2)
+ finally:
+ if group_added:
+ _static_group(group, add=False)
+
+ # A surviving parent PIM join is suppressed by the RPT prune once
+ # local membership ends; it must no longer own inherited output.
+ _channel(group, "*", "JOIN")
+ _channel(group, SOURCE + ",S,Grpt", "SGRpt(P)")
+ _expect("show ip mroute detail json", {group: {SOURCE: {"oil": {RECV_IF: None}}}})
+ _oif(group, SOURCE, "P", peer=2)