From 2e0e501ca5e6c18b3bcd6410e0908510ba25e089 Mon Sep 17 00:00:00 2001 From: Audric Date: Mon, 15 Jun 2026 11:59:46 +0200 Subject: [PATCH] test(routable): add transit-chain topology + failing routable-prefix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an isolated 4-node chain topology (leaf → natlit → natlde → far) to exercise the planned ROUTABLE_PREFIXES feature. TG 26305 is owned by `far` (prefix 263) which is unreachable from `leaf` without transit; test_01 asserts forward + return audio delivery and fails until the C++ feature lands. test_02 asserts that BLACKLIST_TGS=26307 on leaf's uplink vetoes that specific TG while leaving 26305 unaffected. Files added/modified: tests/topology.py — ROUTABLE_REFLECTORS dict + port/secret helpers tests/generate_configs.py — generate_routable_reflector_conf/docker_compose + ROUTABLE_PREFIXES/BLACKLIST_TGS emission in per-peer trunk loop; routable in default run tests/test_routable.py — new test file (mirrors test_twin.py pattern) tests/docker-compose.routable.yml — generated chain compose (4 services) --- tests/docker-compose.routable.yml | 90 +++++++++ tests/generate_configs.py | 143 ++++++++++++++ tests/test_routable.py | 307 ++++++++++++++++++++++++++++++ tests/topology.py | 49 +++++ 4 files changed, 589 insertions(+) create mode 100644 tests/docker-compose.routable.yml create mode 100644 tests/test_routable.py diff --git a/tests/docker-compose.routable.yml b/tests/docker-compose.routable.yml new file mode 100644 index 0000000..084133c --- /dev/null +++ b/tests/docker-compose.routable.yml @@ -0,0 +1,90 @@ +services: + reflector-far: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ./configs/reflector-far.conf:/etc/svxlink/svxreflector.conf:ro + - pki-routable-far:/var/lib/svxlink/pki + ports: + - "54300:5300/tcp" + - "54300:5300/udp" + - "54302:5302/tcp" + - "57080:8080/tcp" + healthcheck: + test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/8080) 2>/dev/null'"] + interval: 2s + timeout: 2s + retries: 15 + networks: + - routable_mesh + + reflector-leaf: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ./configs/reflector-leaf.conf:/etc/svxlink/svxreflector.conf:ro + - pki-routable-leaf:/var/lib/svxlink/pki + ports: + - "51300:5300/tcp" + - "51300:5300/udp" + - "51302:5302/tcp" + - "54080:8080/tcp" + healthcheck: + test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/8080) 2>/dev/null'"] + interval: 2s + timeout: 2s + retries: 15 + networks: + - routable_mesh + + reflector-natlde: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ./configs/reflector-natlde.conf:/etc/svxlink/svxreflector.conf:ro + - pki-routable-natlde:/var/lib/svxlink/pki + ports: + - "53300:5300/tcp" + - "53300:5300/udp" + - "53302:5302/tcp" + - "56080:8080/tcp" + healthcheck: + test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/8080) 2>/dev/null'"] + interval: 2s + timeout: 2s + retries: 15 + networks: + - routable_mesh + + reflector-natlit: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ./configs/reflector-natlit.conf:/etc/svxlink/svxreflector.conf:ro + - pki-routable-natlit:/var/lib/svxlink/pki + ports: + - "52300:5300/tcp" + - "52300:5300/udp" + - "52302:5302/tcp" + - "55080:8080/tcp" + healthcheck: + test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/8080) 2>/dev/null'"] + interval: 2s + timeout: 2s + retries: 15 + networks: + - routable_mesh + +volumes: + pki-routable-far: + pki-routable-leaf: + pki-routable-natlde: + pki-routable-natlit: + +networks: + routable_mesh: + driver: bridge diff --git a/tests/generate_configs.py b/tests/generate_configs.py index aa5957e..015254b 100644 --- a/tests/generate_configs.py +++ b/tests/generate_configs.py @@ -64,6 +64,12 @@ def generate_reflector_conf(name: str) -> str: f"SECRET={secret}", f"REMOTE_PREFIX={T.prefix_str(peer['prefix'])}", ] + routable = r.get("routable", {}).get(peer_name) + if routable: + lines.append(f"ROUTABLE_PREFIXES={','.join(routable)}") + blacklist = r.get("blacklist", {}).get(peer_name) + if blacklist: + lines.append(f"BLACKLIST_TGS={blacklist}") # Test harness trunk sections lines += [ @@ -546,6 +552,111 @@ networks: """ +def generate_routable_reflector_conf(name: str) -> str: + """Generate svxreflector.conf for one reflector in the ROUTABLE chain topology.""" + r = T.ROUTABLE_REFLECTORS[name] + + lines = [ + "[GLOBAL]", + 'TIMESTAMP_FORMAT="%c"', + f"LISTEN_PORT={T.INTERNAL_CLIENT_PORT}", + "TG_FOR_V1_CLIENTS=999", + f"LOCAL_PREFIX={T.prefix_str(r['prefix'])}", + f"TRUNK_LISTEN_PORT={T.INTERNAL_TRUNK_PORT}", + f"HTTP_SRV_PORT={T.INTERNAL_HTTP_PORT}", + "COMMAND_PTY=/dev/shm/reflector_ctrl", + "TRUNK_DEBUG=1", + "", + "[SERVER_CERT]", + f"COMMON_NAME={T.service_name(name)}", + "", + "[USERS]", + ] + groups_seen = set() + for client in T.TEST_CLIENTS: + lines.append(f"{client['callsign']}={client['group']}") + groups_seen.add(client['group']) + lines += [ + "", + "[PASSWORDS]", + ] + for client in T.TEST_CLIENTS: + if client['group'] in groups_seen: + lines.append(f"{client['group']}={client['password']}") + groups_seen.discard(client['group']) + + # Trunk sections for each peer in the routable chain + for peer_name in sorted(r.get("peers", [])): + peer = T.ROUTABLE_REFLECTORS[peer_name] + section = T.trunk_section_name(name, peer_name) + secret = T.routable_trunk_secret(name, peer_name) + lines += [ + "", + f"[{section}]", + f"HOST={T.service_name(peer_name)}", + f"PORT={T.INTERNAL_TRUNK_PORT}", + f"SECRET={secret}", + f"REMOTE_PREFIX={T.prefix_str(peer['prefix'])}", + ] + routable = r.get("routable", {}).get(peer_name) + if routable: + lines.append(f"ROUTABLE_PREFIXES={','.join(routable)}") + blacklist = r.get("blacklist", {}).get(peer_name) + if blacklist: + lines.append(f"BLACKLIST_TGS={blacklist}") + + lines.append("") + return "\n".join(lines) + + +def generate_routable_docker_compose() -> str: + """Generate docker-compose.routable.yml for the routable chain topology.""" + services = [] + volumes = [] + + for name in sorted(T.ROUTABLE_REFLECTORS): + svc = T.service_name(name) + client_port = T.routable_mapped_client_port(name) + trunk_port = T.routable_mapped_trunk_port(name) + http_port = T.routable_mapped_http_port(name) + vol = f"pki-routable-{name}" + volumes.append(vol) + + services.append(f""" {svc}: + build: + context: .. + dockerfile: Dockerfile + volumes: + - ./configs/{svc}.conf:/etc/svxlink/svxreflector.conf:ro + - {vol}:/var/lib/svxlink/pki + ports: + - "{client_port}:{T.INTERNAL_CLIENT_PORT}/tcp" + - "{client_port}:{T.INTERNAL_CLIENT_PORT}/udp" + - "{trunk_port}:{T.INTERNAL_TRUNK_PORT}/tcp" + - "{http_port}:{T.INTERNAL_HTTP_PORT}/tcp" + healthcheck: + test: ["CMD-SHELL", "bash -c '(echo > /dev/tcp/localhost/{T.INTERNAL_HTTP_PORT}) 2>/dev/null'"] + interval: 2s + timeout: 2s + retries: 15 + networks: + - routable_mesh""") + + services_block = "\n\n".join(services) + volumes_block = "\n".join(f" {v}:" for v in volumes) + + return f"""services: +{services_block} + +volumes: +{volumes_block} + +networks: + routable_mesh: + driver: bridge +""" + + def main(): # Topology selection: --topology twin or TOPOLOGY=twin env var topology = os.environ.get("TOPOLOGY", "default") @@ -574,6 +685,23 @@ def main(): f.write(generate_twin_docker_compose()) print(f" wrote docker-compose.test.yml") + elif topology == "routable": + configs_dir = os.path.join(script_dir, "configs") + os.makedirs(configs_dir, exist_ok=True) + + print("Generating ROUTABLE topology configs...") + for name in sorted(T.ROUTABLE_REFLECTORS): + path = os.path.join(configs_dir, f"{T.service_name(name)}.conf") + content = generate_routable_reflector_conf(name) + with open(path, "w") as f: + f.write(content) + print(f" wrote {os.path.relpath(path, script_dir)}") + + compose_path = os.path.join(script_dir, "docker-compose.routable.yml") + with open(compose_path, "w") as f: + f.write(generate_routable_docker_compose()) + print(f" wrote docker-compose.routable.yml") + else: configs_dir = os.path.join(script_dir, "configs") os.makedirs(configs_dir, exist_ok=True) @@ -599,6 +727,21 @@ def main(): f.write(generate_docker_compose()) print(f" wrote docker-compose.test.yml") + # Always regenerate the routable chain topology (separate compose file, + # no conflict with the default mesh). + print("Generating ROUTABLE topology configs...") + for name in sorted(T.ROUTABLE_REFLECTORS): + path = os.path.join(configs_dir, f"{T.service_name(name)}.conf") + content = generate_routable_reflector_conf(name) + with open(path, "w") as f: + f.write(content) + print(f" wrote {os.path.relpath(path, script_dir)}") + + routable_compose_path = os.path.join(script_dir, "docker-compose.routable.yml") + with open(routable_compose_path, "w") as f: + f.write(generate_routable_docker_compose()) + print(f" wrote docker-compose.routable.yml") + if __name__ == "__main__": main() diff --git a/tests/test_routable.py b/tests/test_routable.py new file mode 100644 index 0000000..90ed8cd --- /dev/null +++ b/tests/test_routable.py @@ -0,0 +1,307 @@ +#!/usr/bin/env python3 +"""Integration tests for GeuReflector routable-prefix transit feature. + +Verifies that ROUTABLE_PREFIXES config allows a reflector to forward audio +toward a peer it does not own, enabling multi-hop transit across a chain. + +Topology used: ROUTABLE (generate_configs.py --topology routable) + - reflector-leaf (LOCAL_PREFIX=222100) — leaf uplink, ROUTABLE_PREFIXES=* toward natlit + - reflector-natlit (LOCAL_PREFIX=222) — national Italy, ROUTABLE_PREFIXES=263 toward natlde + - reflector-natlde (LOCAL_PREFIX=262) — national DE, ROUTABLE_PREFIXES=263 toward far + - reflector-far (LOCAL_PREFIX=263) — far peer that owns TG 263xx + +Chain: leaf --TRUNK_LEAF_NATLIT--> natlit --TRUNK_NATLDE_NATLIT--> natlde --TRUNK_FAR_NATLDE--> far + +Without ROUTABLE_PREFIXES the 263xx TG is unreachable from leaf (263 is not +owned by any hop until far). These tests assert the forward + return audio +paths once the feature is implemented. + +test_01 uses TG 26305 (flows normally — no blacklist match). +test_02 uses TG 26307 (blacklisted on leaf's uplink — far must hear nothing). + +Requires: Python 3.7+, stdlib only (+ topology.py from this directory). +Docker must be running and the ROUTABLE topology must have been generated: + cd tests && python3 generate_configs.py --topology routable + docker compose -f docker-compose.routable.yml up -d --build --wait +""" + +import os +import sys +import time +import unittest +from urllib.request import urlopen +from urllib.error import URLError +import json + +# Reuse the V2 mock client and wire helpers from test_trunk.py +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from test_trunk import ( # noqa: E402 + ClientPeer, UDP_AUDIO, UDP_FLUSH, + CLIENT_CALLSIGN, CLIENT_PASSWORD, + CLIENT2_CALLSIGN, CLIENT2_PASSWORD, +) + +# Ensure tests/ is on the path so topology can be imported +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import topology as T + +# --------------------------------------------------------------------------- +# Derived endpoints (routable topology) +# --------------------------------------------------------------------------- + +HOST = "127.0.0.1" + +ROUTABLE_NAMES = sorted(T.ROUTABLE_REFLECTORS) + +COMPOSE_FILE = "docker-compose.routable.yml" +TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +def _http(name: str): + return (HOST, T.routable_mapped_http_port(name)) + + +def _client_port(name: str) -> int: + return T.routable_mapped_client_port(name) + + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + +def get_status(host: str, port: int, timeout: float = 3.0) -> dict: + url = f"http://{host}:{port}/status" + with urlopen(url, timeout=timeout) as resp: + return json.loads(resp.read()) + + +def wait_until(predicate, timeout: float = 15.0, interval: float = 0.5, + msg: str = "condition not met"): + """Poll predicate() until it returns True or timeout expires.""" + deadline = time.monotonic() + timeout + last_exc = None + while time.monotonic() < deadline: + try: + if predicate(): + return + except Exception as e: + last_exc = e + time.sleep(interval) + detail = f" (last error: {last_exc})" if last_exc else "" + raise AssertionError(f"Timed out: {msg}{detail}") + + +def wait_for_reflector(host: str, port: int, timeout: float = 90.0): + """Wait until the reflector's /status endpoint responds.""" + def check(): + try: + get_status(host, port, timeout=2.0) + return True + except (URLError, OSError, json.JSONDecodeError): + return False + wait_until(check, timeout=timeout, interval=1.0, + msg=f"reflector at {host}:{port} not ready") + + +def wait_for_trunk_connected(host: str, port: int, trunk_section: str, + timeout: float = 30.0): + """Wait until a specific trunk section shows connected=True in /status.""" + def check(): + status = get_status(host, port) + return status.get("trunks", {}).get(trunk_section, {}).get("connected", False) + wait_until(check, timeout=timeout, + msg=f"trunk {trunk_section} on {host}:{port} not connected") + + +# --------------------------------------------------------------------------- +# Test class +# --------------------------------------------------------------------------- + +class TestRoutableIntegration(unittest.TestCase): + """Integration tests for the ROUTABLE_PREFIXES transit feature.""" + + @classmethod + def setUpClass(cls): + """Wait for all ROUTABLE reflectors to be healthy and mesh to stabilise.""" + D = "\033[2m" + G = "\033[32m" + RST = "\033[0m" + + sys.stderr.write(f" {D}waiting for routable reflectors...{RST}") + sys.stderr.flush() + for name in ROUTABLE_NAMES: + wait_for_reflector(*_http(name), timeout=90.0) + sys.stderr.write(f"\r\033[K {G}✔{RST} Routable reflectors up\n") + sys.stderr.flush() + + # Wait for trunk connections across the chain: + # leaf <--> natlit, natlit <--> natlde, natlde <--> far + sys.stderr.write(f" {D}waiting for trunk chain...{RST}") + sys.stderr.flush() + wait_for_trunk_connected(*_http("leaf"), "TRUNK_LEAF_NATLIT", timeout=30.0) + wait_for_trunk_connected(*_http("natlit"), "TRUNK_LEAF_NATLIT", timeout=30.0) + wait_for_trunk_connected(*_http("natlit"), "TRUNK_NATLDE_NATLIT", timeout=30.0) + wait_for_trunk_connected(*_http("natlde"), "TRUNK_NATLDE_NATLIT", timeout=30.0) + wait_for_trunk_connected(*_http("natlde"), "TRUNK_FAR_NATLDE", timeout=30.0) + wait_for_trunk_connected(*_http("far"), "TRUNK_FAR_NATLDE", timeout=30.0) + sys.stderr.write(f"\r\033[K {G}✔{RST} Trunk chain connected\n") + sys.stderr.flush() + + # Give interest-debounce timers a moment to settle + time.sleep(1.0) + + # ------------------------------------------------------------------ + # Test 01: explicit transit — leaf client can reach far client (TG 26305) + # ------------------------------------------------------------------ + def test_01_explicit_transit_forward_and_return(self): + """ROUTABLE_PREFIXES=* on leaf and ROUTABLE_PREFIXES=263 on natlit/natlde + must route TG 26305 all the way from leaf to far and back. + + leaf --[ROUTABLE_PREFIXES=*]--> natlit --[ROUTABLE_PREFIXES=263]--> natlde + --[ROUTABLE_PREFIXES=263]--> far + + Forward leg: leaf client selects TG 26305, far client selects 26305. + leaf sends 6 UDP audio frames + flush. + far must receive > 0 audio or flush packets. + + Return leg: far sends 6 UDP audio frames + flush. + leaf must receive > 0 audio or flush packets. + + NOTE: This test is expected to FAIL until ROUTABLE_PREFIXES is + implemented in the C++ reflector (Task 1 TDD anchor). + """ + tg = 26305 # owned by far (prefix 263); unreachable without transit + + leaf_port = _client_port("leaf") + far_port = _client_port("far") + + leaf_client = ClientPeer() + far_client = ClientPeer() + try: + # leaf client — selects TG 26305 + leaf_client.connect(HOST, leaf_port) + leaf_client.authenticate(callsign=CLIENT_CALLSIGN, + password=CLIENT_PASSWORD) + leaf_client.setup_udp(udp_port=leaf_port) + leaf_client.select_tg(tg) + + # far client — selects TG 26305 (owner side) + far_client.connect(HOST, far_port) + far_client.authenticate(callsign=CLIENT2_CALLSIGN, + password=CLIENT2_PASSWORD) + far_client.setup_udp(udp_port=far_port) + far_client.select_tg(tg) + + # Allow peer-interest debounce (500 ms each hop × 2 hops) + margin + time.sleep(2.0) + + # Drain any backlog before the measurement burst + leaf_client.recv_udp_all(timeout=0.05) + far_client.recv_udp_all(timeout=0.05) + + # --- Forward leg: leaf → far --- + for _ in range(6): + leaf_client.send_udp_audio(b"\xBE\xEF" * 80) + time.sleep(0.02) + leaf_client.send_udp_flush() + time.sleep(1.5) + + fwd_msgs = far_client.recv_udp_all(timeout=1.0) + fwd_audio = sum(1 for t, _ in fwd_msgs if t == UDP_AUDIO) + fwd_flush = sum(1 for t, _ in fwd_msgs if t == UDP_FLUSH) + self.assertGreater( + fwd_audio + fwd_flush, 0, + f"forward leg FAILED: far client heard 0 UDP frames for TG {tg}. " + f"ROUTABLE_PREFIXES transit is not yet implemented (expected failure).", + ) + + # --- Return leg: far → leaf --- + leaf_client.recv_udp_all(timeout=0.05) # flush stale + for _ in range(6): + far_client.send_udp_audio(b"\xCA\xFE" * 80) + time.sleep(0.02) + far_client.send_udp_flush() + time.sleep(1.5) + + ret_msgs = leaf_client.recv_udp_all(timeout=1.0) + ret_audio = sum(1 for t, _ in ret_msgs if t == UDP_AUDIO) + ret_flush = sum(1 for t, _ in ret_msgs if t == UDP_FLUSH) + self.assertGreater( + ret_audio + ret_flush, 0, + f"return leg FAILED: leaf client heard 0 UDP frames for TG {tg}. " + f"ROUTABLE_PREFIXES transit is not yet implemented (expected failure).", + ) + + finally: + leaf_client.close() + far_client.close() + + # ------------------------------------------------------------------ + # Test 02: wildcard + blacklist veto (TG 26307 blocked on leaf uplink) + # ------------------------------------------------------------------ + def test_02_wildcard_blacklist_veto(self): + """BLACKLIST_TGS=26307 on leaf's uplink must prevent TG 26307 from + reaching far, even though ROUTABLE_PREFIXES=* would otherwise route it. + + leaf selects TG 26307, far selects 26307. + leaf sends 6 UDP audio frames + flush. + far must receive EXACTLY 0 audio or flush packets. + + This test is expected to PASS once ROUTABLE_PREFIXES is implemented, + because the blacklist veto is a separate filter that suppresses the + specific TG before routable transit logic fires. Until the feature + lands, far also hears nothing (transit not working), so the assertion + holds trivially — but it documents the intended blacklist behaviour. + """ + tg = 26307 # blacklisted on leaf → natlit link; far must hear nothing + + leaf_port = _client_port("leaf") + far_port = _client_port("far") + + leaf_client = ClientPeer() + far_client = ClientPeer() + try: + # leaf client — selects TG 26307 + leaf_client.connect(HOST, leaf_port) + leaf_client.authenticate(callsign=CLIENT_CALLSIGN, + password=CLIENT_PASSWORD) + leaf_client.setup_udp(udp_port=leaf_port) + leaf_client.select_tg(tg) + + # far client — selects TG 26307 (owner side) + far_client.connect(HOST, far_port) + far_client.authenticate(callsign=CLIENT2_CALLSIGN, + password=CLIENT2_PASSWORD) + far_client.setup_udp(udp_port=far_port) + far_client.select_tg(tg) + + # Allow interest debounce to settle + time.sleep(2.0) + + # Drain backlog + far_client.recv_udp_all(timeout=0.05) + + # leaf sends audio — must NOT reach far + for _ in range(6): + leaf_client.send_udp_audio(b"\xDE\xAD" * 80) + time.sleep(0.02) + leaf_client.send_udp_flush() + time.sleep(1.5) + + veto_msgs = far_client.recv_udp_all(timeout=1.0) + veto_audio = sum(1 for t, _ in veto_msgs if t == UDP_AUDIO) + veto_flush = sum(1 for t, _ in veto_msgs if t == UDP_FLUSH) + self.assertEqual( + veto_audio + veto_flush, 0, + f"blacklist veto FAILED: far client received {veto_audio} audio " + f"+ {veto_flush} flush frames for TG {tg}, expected 0. " + f"BLACKLIST_TGS=26307 on leaf→natlit should suppress this TG.", + ) + + finally: + leaf_client.close() + far_client.close() + + +if __name__ == "__main__": + unittest.main(verbosity=2) diff --git a/tests/topology.py b/tests/topology.py index ea0799e..c17bab4 100644 --- a/tests/topology.py +++ b/tests/topology.py @@ -303,3 +303,52 @@ def twin_mapped_satellite_port(name: str) -> int: def twin_trunks_for(name: str) -> list: """Return all TWIN_TRUNKS entries that involve this reflector.""" return [t for t in TWIN_TRUNKS if name in t["peers"]] + + +# --------------------------------------------------------------------------- +# Routable-prefix chain (isolated topology, used by test_routable.py only) +# +# leaf 222100* --trunk--> natlit 222 --trunk--> natlde 262 --trunk--> far 263 +# +# `263` is a SIBLING of 222/262 (not nested), so it is unreachable without +# routable prefixes. The leaf uses "*" (default route to its only uplink); +# each backbone hop declares an explicit ROUTABLE_PREFIXES toward 263. +# +# blacklist on leaf's uplink vetoes TG 26307 exactly (test_02) while leaving +# TG 26305 (test_01) unaffected — the two tests use distinct TG numbers. +# --------------------------------------------------------------------------- +ROUTABLE_REFLECTORS = { + # name prefix trunk_port_base peers routable (per-peer additions) + "leaf": {"prefix": ["222100"], "trunk_port_base": 51000, + "peers": ["natlit"], "routable": {"natlit": ["*"]}, + "blacklist": {"natlit": "26307"}}, + "natlit": {"prefix": ["222"], "trunk_port_base": 52000, + "peers": ["leaf", "natlde"], "routable": {"natlde": ["263"]}}, + "natlde": {"prefix": ["262"], "trunk_port_base": 53000, + "peers": ["natlit", "far"], "routable": {"natlit": ["263"]}}, + "far": {"prefix": ["263"], "trunk_port_base": 54000, + "peers": ["natlde"]}, +} +ROUTABLE_NAMES = list(ROUTABLE_REFLECTORS.keys()) + + +# --------------------------------------------------------------------------- +# Routable topology helpers +# --------------------------------------------------------------------------- + +def routable_mapped_client_port(name: str) -> int: + return ROUTABLE_REFLECTORS[name]["trunk_port_base"] + 300 + + +def routable_mapped_trunk_port(name: str) -> int: + return ROUTABLE_REFLECTORS[name]["trunk_port_base"] + 302 + + +def routable_mapped_http_port(name: str) -> int: + return ROUTABLE_REFLECTORS[name]["trunk_port_base"] + 3080 + + +def routable_trunk_secret(name_a: str, name_b: str) -> str: + """Shared secret for a routable-topology link (sorted pair).""" + pair = tuple(sorted([name_a, name_b])) + return f"secret_routable_{pair[0]}_{pair[1]}"