Add satellite integration tests

5 new tests covering satellite protocol: handshake and /status visibility,
audio delivery from satellite to parent's local clients, trunk-to-satellite
audio forwarding, satellite audio routed to trunk peers via parent, and
disconnect cleanup. Reflector-a acts as the satellite parent with a
[SATELLITE] section; a SatellitePeer class connects as a fake satellite
using MsgTrunkHello with ROLE_SATELLITE.
This commit is contained in:
Audric committed 2026-03-27 14:58:51 +01:00
1 parent 685d7253ff
commit d2f4acffcd
3 files changed
+231 -1

No files matched your search

+19 -1
View File
@@ -74,6 +74,16 @@ def generate_reflector_conf(name: str) -> str:
"", "",
] ]
# Satellite server section (only on the primary reflector)
primary = sorted(T.REFLECTORS)[0]
if name == primary:
lines += [
"[SATELLITE]",
f"LISTEN_PORT={T.SATELLITE['listen_port']}",
f"SECRET={T.SATELLITE['secret']}",
"",
]
return "\n".join(lines) return "\n".join(lines)
@@ -82,6 +92,8 @@ def generate_docker_compose() -> str:
services = [] services = []
volumes = [] volumes = []
primary = sorted(T.REFLECTORS)[0]
for name in sorted(T.REFLECTORS): for name in sorted(T.REFLECTORS):
svc = T.service_name(name) svc = T.service_name(name)
client_port = T.mapped_client_port(name) client_port = T.mapped_client_port(name)
@@ -90,6 +102,12 @@ def generate_docker_compose() -> str:
vol = f"pki-{name}" vol = f"pki-{name}"
volumes.append(vol) volumes.append(vol)
# Satellite port only on the primary reflector
sat_port_line = ""
if name == primary:
sat_port = T.mapped_satellite_port(name)
sat_port_line = f'\n - "{sat_port}:{T.SATELLITE["listen_port"]}/tcp"'
services.append(f""" {svc}: services.append(f""" {svc}:
build: build:
context: .. context: ..
@@ -101,7 +119,7 @@ def generate_docker_compose() -> str:
- "{client_port}:{T.INTERNAL_CLIENT_PORT}/tcp" - "{client_port}:{T.INTERNAL_CLIENT_PORT}/tcp"
- "{client_port}:{T.INTERNAL_CLIENT_PORT}/udp" - "{client_port}:{T.INTERNAL_CLIENT_PORT}/udp"
- "{trunk_port}:{T.INTERNAL_TRUNK_PORT}/tcp" - "{trunk_port}:{T.INTERNAL_TRUNK_PORT}/tcp"
- "{http_port}:{T.INTERNAL_HTTP_PORT}/tcp" - "{http_port}:{T.INTERNAL_HTTP_PORT}/tcp"{sat_port_line}
healthcheck: healthcheck:
test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/{T.INTERNAL_HTTP_PORT}) 2>/dev/null'"] test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/{T.INTERNAL_HTTP_PORT}) 2>/dev/null'"]
interval: 2s interval: 2s
+202
View File
@@ -47,6 +47,10 @@ TEST_PREFIX_FIRST = T.first_prefix(T.TEST_PEER["prefix"]) # first prefix for TG
TEST_RX_SECRET = T.TEST_PEER_RX["secret"] TEST_RX_SECRET = T.TEST_PEER_RX["secret"]
TEST_RX_PREFIX = T.prefix_str(T.TEST_PEER_RX["prefix"]) TEST_RX_PREFIX = T.prefix_str(T.TEST_PEER_RX["prefix"])
SAT_SECRET = T.SATELLITE["secret"]
SAT_ID = T.SATELLITE["id"]
ROLE_SATELLITE = 1
# V2 client auth credentials (must match [USERS]/[PASSWORDS] in configs) # V2 client auth credentials (must match [USERS]/[PASSWORDS] in configs)
CLIENT_CALLSIGN = T.TEST_CLIENTS[0]["callsign"] CLIENT_CALLSIGN = T.TEST_CLIENTS[0]["callsign"]
CLIENT_PASSWORD = T.TEST_CLIENTS[0]["password"] CLIENT_PASSWORD = T.TEST_CLIENTS[0]["password"]
@@ -248,6 +252,35 @@ class TrunkPeer:
self.sock = None self.sock = None
# ---------------------------------------------------------------------------
# SatellitePeer — fake satellite connecting to a parent reflector
# ---------------------------------------------------------------------------
class SatellitePeer(TrunkPeer):
"""Satellite peer — same wire format as TrunkPeer but role=SATELLITE."""
def connect_satellite(self, name=None):
"""Connect to the satellite port of a reflector."""
if name is None:
name = sorted(T.REFLECTORS)[0]
host = HOST
port = T.mapped_satellite_port(name)
self.connect(host, port)
def handshake(self, sat_id=SAT_ID, secret=SAT_SECRET, priority=None,
**kwargs):
"""Send MsgTrunkHello with ROLE_SATELLITE.
Unlike trunk peers, the parent does NOT send a hello back —
authentication is one-way (satellite proves identity to parent).
"""
if priority is None:
priority = struct.unpack("!I", os.urandom(4))[0]
hello = build_trunk_hello(sat_id, "", priority, secret,
role=ROLE_SATELLITE)
send_frame(self.sock, hello)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# ClientPeer — fake V2 SvxLink client (no SSL) # ClientPeer — fake V2 SvxLink client (no SSL)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -902,6 +935,175 @@ class TestTrunkIntegration(unittest.TestCase):
sender.close() sender.close()
receiver.close() receiver.close()
# ------------------------------------------------------------------
# Test 12: Satellite handshake and /status
# ------------------------------------------------------------------
def test_12_satellite_handshake(self):
"""Satellite connects to parent and appears in /status."""
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
try:
def sat_in_status():
status = get_status(*_http(self.PRIMARY))
sats = status.get("satellites", {})
info = sats.get(SAT_ID, {})
return info.get("authenticated", False)
wait_until(sat_in_status, timeout=5.0,
msg="satellite not visible in /status")
finally:
sat.close()
# ------------------------------------------------------------------
# Test 13: Satellite audio reaches parent's local clients
# ------------------------------------------------------------------
def test_13_satellite_audio_to_parent(self):
"""Audio sent by satellite is received by a V2 client on the parent."""
# V2 client on parent reflector
client = ClientPeer()
client_port = T.mapped_client_port(self.PRIMARY)
client.connect(HOST, client_port)
client.authenticate()
client.setup_udp(udp_port=client_port)
tg = int(TEST_PREFIX_FIRST + "010")
client.select_tg(tg)
time.sleep(0.3)
# Satellite connects and sends audio
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
try:
sat.send_talker_start(tg, "SAT_TX")
for _ in range(3):
sat.send_audio(tg, b"\xCA\xFE" * 80)
sat.send_flush(tg)
sat.send_talker_stop(tg)
msgs = client.recv_udp_all(timeout=3.0)
audio_count = sum(1 for t, _ in msgs if t == UDP_AUDIO)
self.assertGreater(audio_count, 0,
"V2 client on parent received no audio from satellite")
finally:
sat.close()
client.close()
# ------------------------------------------------------------------
# Test 14: Satellite receives audio from parent (trunk → satellite)
# ------------------------------------------------------------------
def test_14_satellite_receives_from_parent(self):
"""Trunk talker audio on the parent is forwarded to the satellite.
Trunk harness sends audio on a cluster TG via TRUNK_TEST.
The parent forwards trunk talker events to connected satellites.
"""
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
sender, _ = self._connect_peer()
try:
tg = T.CLUSTER_TGS[0]
sender.send_talker_start(tg, "TRUNK_TO_SAT")
wait_until(lambda: self._get_test_talkers().get(str(tg)) == "TRUNK_TO_SAT",
timeout=5.0, msg="trunk talker not visible")
for _ in range(3):
sender.send_audio(tg, b"\xBE\xEF" * 80)
sender.send_flush(tg)
sender.send_talker_stop(tg)
# Satellite should have received talker + audio + flush
sat.sock.settimeout(3.0)
got_audio = False
got_talker = False
try:
while True:
data = recv_frame(sat.sock)
msg_type, _ = parse_msg(data)
if msg_type == MSG_TRUNK_TALKER_START:
got_talker = True
elif msg_type == MSG_TRUNK_AUDIO:
got_audio = True
elif msg_type == MSG_TRUNK_HEARTBEAT:
continue
except (socket.timeout, ConnectionError, OSError):
pass
self.assertTrue(got_talker,
"satellite did not receive TalkerStart from trunk")
self.assertTrue(got_audio,
"satellite did not receive audio from trunk")
finally:
sender.close()
sat.close()
# ------------------------------------------------------------------
# Test 15: Satellite audio forwarded to trunk peers
# ------------------------------------------------------------------
def test_15_satellite_audio_to_trunk_peer(self):
"""Audio from satellite is forwarded by parent to trunk peers.
Satellite sends audio for a TG owned by reflector-b. Parent
should forward to reflector-b via trunk.
"""
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
other = [n for n in REFLECTOR_NAMES if n != self.PRIMARY][0]
other_prefix = T.first_prefix(T.REFLECTORS[other]["prefix"])
tg = int(other_prefix + "010")
try:
sat.send_talker_start(tg, "SAT_ROUTE")
for _ in range(3):
sat.send_audio(tg, b"\x00" * 160)
sat.send_flush(tg)
sat.send_talker_stop(tg)
time.sleep(0.5)
# Check logs on the other reflector for trunk talker
svc = T.service_name(other)
lines = docker_log_lines(svc, since_lines=30)
found = any(f"Trunk talker start on TG #{tg}" in line
for line in lines)
self.assertTrue(found,
f"reflector-{other} did not receive trunk talker for TG {tg} "
f"from satellite via parent")
finally:
sat.close()
# ------------------------------------------------------------------
# Test 16: Satellite disconnect cleanup
# ------------------------------------------------------------------
def test_16_satellite_disconnect_cleanup(self):
"""Abrupt satellite disconnect clears it from /status."""
sat = SatellitePeer()
sat.connect_satellite()
sat.handshake()
def sat_visible():
status = get_status(*_http(self.PRIMARY))
return SAT_ID in status.get("satellites", {})
wait_until(sat_visible, timeout=5.0,
msg="satellite not in /status before disconnect")
# Abrupt close
sat.sock.close()
sat.sock = None
def sat_gone():
status = get_status(*_http(self.PRIMARY))
return SAT_ID not in status.get("satellites", {})
wait_until(sat_gone, timeout=20.0,
msg="satellite not cleared from /status after disconnect")
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Custom test runner with clean, readable output # Custom test runner with clean, readable output
+10
View File
@@ -35,6 +35,13 @@ TEST_PEER_RX = {
# 9999: starts with test peer prefix "9" # 9999: starts with test peer prefix "9"
CLUSTER_TGS = [8000, 1201, 9999] CLUSTER_TGS = [8000, 1201, 9999]
# Satellite test config (parent is the first reflector in REFLECTORS)
SATELLITE = {
"id": "SAT_TEST",
"secret": "sat_secret",
"listen_port": 5303,
}
# V2 test client credentials (added to [USERS]/[PASSWORDS] in every config) # V2 test client credentials (added to [USERS]/[PASSWORDS] in every config)
TEST_CLIENTS = [ TEST_CLIENTS = [
{"callsign": "N0TEST", "group": "TestGroup", "password": "testpass"}, {"callsign": "N0TEST", "group": "TestGroup", "password": "testpass"},
@@ -88,5 +95,8 @@ def mapped_client_port(name: str) -> int:
def service_name(name: str) -> str: def service_name(name: str) -> str:
return f"reflector-{name}" return f"reflector-{name}"
def mapped_satellite_port(name: str) -> int:
return REFLECTORS[name]["trunk_port_base"] + 303
def trunk_section_name(peer_name: str) -> str: def trunk_section_name(peer_name: str) -> str:
return f"TRUNK_{peer_name.upper()}" return f"TRUNK_{peer_name.upper()}"