test: satellite TG filter (RED — reproduces bug)
Add test_16b_satellite_tg_filter exercising MsgTrunkFilter (type 122): satellite sends a filter matching only CLUSTER_TGS[0], then a trunk peer originates talker+audio on both CLUSTER_TGs. The satellite must receive the matching TG and NOT receive the non-matching one. Fails on current master: the parent has no handler for MsgTrunkFilter, so the filter is silently ignored and every cluster TG is forwarded to the satellite. This commit documents the bug; the next commit applies the sysop patch that makes the assertion pass. Adds MSG_TRUNK_FILTER = 122 wire constant, a build_trunk_filter() packer, and SatellitePeer.send_filter() helper.
This commit is contained in:
1 parent
bd31369e5e
commit
ba5d03e491
1 file changed
+85
@@ -69,6 +69,7 @@ MSG_TRUNK_AUDIO = 118
|
|||||||
MSG_TRUNK_FLUSH = 119
|
MSG_TRUNK_FLUSH = 119
|
||||||
MSG_TRUNK_HEARTBEAT = 120
|
MSG_TRUNK_HEARTBEAT = 120
|
||||||
MSG_TRUNK_NODE_LIST = 121
|
MSG_TRUNK_NODE_LIST = 121
|
||||||
|
MSG_TRUNK_FILTER = 122
|
||||||
|
|
||||||
# Filter test peer constants
|
# Filter test peer constants
|
||||||
FILTER_SECRET = T.TEST_PEER_FILTER["secret"]
|
FILTER_SECRET = T.TEST_PEER_FILTER["secret"]
|
||||||
@@ -166,6 +167,12 @@ def build_heartbeat() -> bytes:
|
|||||||
return struct.pack("!H", MSG_TRUNK_HEARTBEAT)
|
return struct.pack("!H", MSG_TRUNK_HEARTBEAT)
|
||||||
|
|
||||||
|
|
||||||
|
def build_trunk_filter(filter_str: str) -> bytes:
|
||||||
|
payload = struct.pack("!H", MSG_TRUNK_FILTER)
|
||||||
|
payload += pack_string(filter_str)
|
||||||
|
return payload
|
||||||
|
|
||||||
|
|
||||||
def build_node_list(nodes) -> bytes:
|
def build_node_list(nodes) -> bytes:
|
||||||
"""Build a MsgTrunkNodeList frame.
|
"""Build a MsgTrunkNodeList frame.
|
||||||
|
|
||||||
@@ -369,6 +376,9 @@ class SatellitePeer(TrunkPeer):
|
|||||||
assert msg_type == MSG_TRUNK_HELLO, \
|
assert msg_type == MSG_TRUNK_HELLO, \
|
||||||
f"Expected hello reply, got type={msg_type}"
|
f"Expected hello reply, got type={msg_type}"
|
||||||
|
|
||||||
|
def send_filter(self, filter_str: str):
|
||||||
|
send_frame(self.sock, build_trunk_filter(filter_str))
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# ClientPeer — fake V2 SvxLink client (no SSL)
|
# ClientPeer — fake V2 SvxLink client (no SSL)
|
||||||
@@ -1242,6 +1252,81 @@ class TestTrunkIntegration(unittest.TestCase):
|
|||||||
wait_until(sat_gone, timeout=20.0,
|
wait_until(sat_gone, timeout=20.0,
|
||||||
msg="satellite not cleared from /status after disconnect")
|
msg="satellite not cleared from /status after disconnect")
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Test 16b: Satellite advertises a TG filter; parent honors it
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
def test_16b_satellite_tg_filter(self):
|
||||||
|
"""Satellite sends MsgTrunkFilter after Hello; parent must drop
|
||||||
|
forwarded events for TGs outside the filter.
|
||||||
|
|
||||||
|
Setup:
|
||||||
|
- CLUSTER_TGS are [222, 999] — both normally reach a satellite
|
||||||
|
via the parent (see test_14).
|
||||||
|
- This satellite subscribes to only "222" via the filter.
|
||||||
|
- A trunk peer originates talker+audio on TG 999 (should NOT
|
||||||
|
reach the satellite) and on TG 222 (should reach it).
|
||||||
|
"""
|
||||||
|
sat = SatellitePeer()
|
||||||
|
sat.connect_satellite()
|
||||||
|
sat.handshake()
|
||||||
|
|
||||||
|
# Advertise filter; give the parent a moment to install it
|
||||||
|
assert T.CLUSTER_TGS == [222, 999], \
|
||||||
|
"test assumes CLUSTER_TGS = [222, 999]"
|
||||||
|
tg_allowed = T.CLUSTER_TGS[0] # 222 — matches
|
||||||
|
tg_blocked = T.CLUSTER_TGS[1] # 999 — does not match
|
||||||
|
sat.send_filter(str(tg_allowed))
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
sender, _ = self._connect_peer()
|
||||||
|
try:
|
||||||
|
# Originate on the BLOCKED TG first, then on the ALLOWED TG
|
||||||
|
for tg, who in ((tg_blocked, "BLOCKED_SRC"),
|
||||||
|
(tg_allowed, "ALLOWED_SRC")):
|
||||||
|
sender.send_talker_start(tg, who)
|
||||||
|
for _ in range(3):
|
||||||
|
sender.send_audio(tg, b"\xAA\x55" * 80)
|
||||||
|
sender.send_flush(tg)
|
||||||
|
sender.send_talker_stop(tg)
|
||||||
|
|
||||||
|
# Drain everything the satellite receives in 3s
|
||||||
|
sat.sock.settimeout(3.0)
|
||||||
|
allowed_talker = False
|
||||||
|
allowed_audio = False
|
||||||
|
blocked_talker = False
|
||||||
|
blocked_audio = False
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
data = recv_frame(sat.sock)
|
||||||
|
msg_type, fields = parse_msg(data)
|
||||||
|
if msg_type == MSG_TRUNK_HEARTBEAT:
|
||||||
|
continue
|
||||||
|
tg = fields.get("tg")
|
||||||
|
if msg_type == MSG_TRUNK_TALKER_START:
|
||||||
|
if tg == tg_allowed: allowed_talker = True
|
||||||
|
if tg == tg_blocked: blocked_talker = True
|
||||||
|
elif msg_type == MSG_TRUNK_AUDIO:
|
||||||
|
if tg == tg_allowed: allowed_audio = True
|
||||||
|
if tg == tg_blocked: blocked_audio = True
|
||||||
|
except (socket.timeout, ConnectionError, OSError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertTrue(allowed_talker,
|
||||||
|
f"satellite did not receive TalkerStart for TG {tg_allowed} "
|
||||||
|
f"(should match filter)")
|
||||||
|
self.assertTrue(allowed_audio,
|
||||||
|
f"satellite did not receive audio for TG {tg_allowed} "
|
||||||
|
f"(should match filter)")
|
||||||
|
self.assertFalse(blocked_talker,
|
||||||
|
f"satellite received TalkerStart for TG {tg_blocked} "
|
||||||
|
f"(should have been filtered by parent)")
|
||||||
|
self.assertFalse(blocked_audio,
|
||||||
|
f"satellite received audio for TG {tg_blocked} "
|
||||||
|
f"(should have been filtered by parent)")
|
||||||
|
finally:
|
||||||
|
sender.close()
|
||||||
|
sat.close()
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Test 17: Trunk talker notification reaches monitoring clients
|
# Test 17: Trunk talker notification reaches monitoring clients
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user