Expose HDStack FBP inventory through the reporting MUX

master
Simon 2 weeks ago
parent 5c8f946892
commit e1e89231ee

@ -87,7 +87,8 @@ def config_reports(_config, _factory):
report_server = _factory(_config)
report_server.clients = []
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server)
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server,
interface=_config['REPORTS'].get('REPORT_INTERFACE', ''))
reporting = task.LoopingCall(reporting_loop, logger, report_server)
reporting.start(_config['REPORTS']['REPORT_INTERVAL'])

@ -646,7 +646,8 @@ def config_reports(_config, _factory):
report_server = _factory(_config)
report_server.clients = []
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server)
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server,
interface=_config['REPORTS'].get('REPORT_INTERFACE', ''))
reporting = task.LoopingCall(reporting_loop, logger, report_server)
reporting.start(_config['REPORTS']['REPORT_INTERVAL'])

@ -214,6 +214,7 @@ def build_config(_config_file):
'REPORT': config.getboolean(section, 'REPORT', fallback=True),
'REPORT_INTERVAL': config.getint(section, 'REPORT_INTERVAL', fallback=60),
'REPORT_PORT': config.getint(section, 'REPORT_PORT', fallback=4321),
'REPORT_INTERFACE': config.get(section, 'REPORT_INTERFACE', fallback=''),
'REPORT_CLIENTS': config.get(section, 'REPORT_CLIENTS',fallback='*').split(',')
})
@ -409,6 +410,7 @@ def build_config(_config_file):
'TG2_ACL': 'PERMIT:ALL',
'RELAX_CHECKS': config.getboolean(section, 'RELAX_CHECKS', fallback=True),
'ENHANCED_OBP': config.getboolean(section, 'ENHANCED_OBP',fallback=True),
'REPORT_INTERNAL': config.getboolean(section, 'REPORT_INTERNAL', fallback=False),
'VER' : config.getint(section, 'PROTO_VER', fallback=5)
}})

@ -22,8 +22,9 @@ worker reports -> reporting MUX -> existing dashboard/reporting consumer
The aggregator owns all OpenBridge/FBP links from the main `freedmr.cfg` and
has no HBP `MASTER`, `PEER` or `XLXPEER` system. The optional `bridge.py`
process retains its own configuration and rules. The reporting MUX reads only
worker reports; aggregator and bridge reporting are not included.
process retains its own configuration and rules. The reporting MUX relays
worker calls and bridge state. A separate, loopback-only aggregator source
provides FBP link inventory, never additional calls or bridge-state events.
## Installer and container configuration
@ -341,6 +342,20 @@ worker 4 -> 4325
worker 5 -> 4326
```
The aggregator inventory listener uses `REPORT_PORT + worker count + 1`
(4324 with two workers, 4327 with five), binds only to `127.0.0.1`, and accepts
only loopback clients. It is collision-checked with the other generated ports.
There is no new public port. `REPORT_INTERFACE` defaults to the previous
all-interface binding for ordinary deployments.
The MUX's `--inventory-backend NUMBER,HOST,PORT` accepts only enabled FBP
configuration entries and only public inventory fields. It excludes passphrases,
HBP peers, bridge state and all call events. Inventory entries carry
`REPORT_INVENTORY_ONLY=True`: consumers must not infer that an absence of call
events means the link is idle. Generated HDStack FBP links carry the display-only
`REPORT_INTERNAL=True` flag; external links default to false. These fields do
not affect packet forwarding. Existing consumers may ignore the added fields.
The MUX preserves the existing netstring reporting protocol and the main
configuration's `REPORT_CLIENTS` allow-list. It merges worker configuration
and bridge snapshots and relays worker bridge events. System names are
@ -351,12 +366,13 @@ prefixed with the stable worker number to prevent collisions:
2:SYSTEM-001
```
Only the system-name field is changed. The reporting protocol contains trusted
Worker reports retain their existing contents apart from the system-name prefix.
The reporting protocol contains trusted
Python pickle data and must remain on a trusted network.
A failed or malformed worker reporting source is isolated from healthy
sources. Reporting failure does not affect the proxy or DMR traffic. If main
reporting is disabled, worker reporting and the MUX are both disabled.
reporting is disabled, worker and aggregator reporting and the MUX are disabled.
## Limitations

@ -5,3 +5,11 @@
This fixes release-page creation behind the HTTPS redirect without changing
runtime containers. See the [v1.6.4 release notes](release-notes-v1.6.4.md)
for the current runtime release.
## HDStack FreeBridge Inventory
- Add loopback-only aggregator reporting to the existing MUX as an inventory-only
source, allowing the dashboard to display external FBP links. Aggregator call
events and bridge snapshots are excluded, preserving worker/SQL event counts.
- Mark generated internal HDStack links for optional dashboard filtering.
- No routing, RF, FBP wire-format, public-port or data-admission changes.

@ -98,7 +98,8 @@ def config_reports(_config, _factory):
report_server = _factory(_config)
report_server.clients = deque()
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server)
reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server,
interface=_config['REPORTS'].get('REPORT_INTERFACE', ''))
reporting = task.LoopingCall(reporting_loop, logger, report_server)
reporting.start(_config['REPORTS']['REPORT_INTERVAL'])

@ -140,7 +140,7 @@ def generate_hdstack(
report_port + number for number in range(1, instances + 1)
)
if report_enabled:
for port in worker_report_ports:
for port in (*worker_report_ports, report_port + instances + 1):
_validate_port(port, 'worker report port')
data_gateway_enabled, data_gateway_ports, data_gateway_target_ports = (
@ -167,7 +167,10 @@ def generate_hdstack(
aggregator['GLOBAL']['HDSTACK_INSTANCES'] = str(instances)
aggregator['GLOBAL']['HDSTACK_BASE_SERVER_ID'] = str(base_server_id)
aggregator['GLOBAL']['GEN_STAT_BRIDGES'] = 'True'
aggregator['REPORTS']['REPORT'] = 'False'
aggregator['REPORTS']['REPORT'] = str(report_enabled)
aggregator['REPORTS']['REPORT_PORT'] = str(report_port + instances + 1)
aggregator['REPORTS']['REPORT_INTERFACE'] = '127.0.0.1'
aggregator['REPORTS']['REPORT_CLIENTS'] = '127.0.0.1'
aggregator['GLOBAL']['DATA_GATEWAY'] = 'False'
for section in source.sections():
if section != 'DATA-GATEWAY' and _mode(source, section) == 'OPENBRIDGE':
@ -575,6 +578,7 @@ def _validate_generated_port_collisions(
reserve(port, 'worker {} Loro reporting'.format(number))
if report_enabled:
reserve(report_port, 'report MUX')
reserve(report_port + instances + 1, 'aggregator inventory report')
for number, port in enumerate(worker_report_ports, 1):
reserve(port, 'worker {} reporting'.format(number))
@ -652,6 +656,7 @@ def _add_internal_openbridge(
'TGID_ACL': 'PERMIT:ALL',
'RELAX_CHECKS': 'False',
'ENHANCED_OBP': 'True',
'REPORT_INTERNAL': 'True',
'PROTO_VER': '5',
})
@ -781,6 +786,8 @@ def _supervisor_config(
command.extend(('--client', client))
for number, port in enumerate(worker_report_ports, 1):
command.extend(('--backend', '{},127.0.0.1,{}'.format(number, port)))
command.extend(('--inventory-backend', '{},127.0.0.1,{}'.format(
len(worker_report_ports) + 1, report_port + len(worker_report_ports) + 1)))
parts.append(
_program(
'report-mux',

@ -97,8 +97,9 @@ class ReportMuxClient(NetstringReceiver):
class ReportMuxFactory(Factory):
protocol = ReportMuxClient
def __init__(self, allowed_clients=('*',)):
def __init__(self, allowed_clients=('*',), inventory_backends=()):
self.allowed_clients = frozenset(allowed_clients)
self.inventory_backends = frozenset(inventory_backends)
self.clients = set()
self._config_by_backend = {}
self._bridges_by_backend = {}
@ -124,9 +125,22 @@ class ReportMuxFactory(Factory):
def ingest(self, backend_number, message):
opcode = message[:1]
inventory_only = backend_number in self.inventory_backends
if inventory_only and opcode != REPORT_OPCODES['CONFIG_SND']:
return
try:
if opcode == REPORT_OPCODES['CONFIG_SND']:
config = pickle.loads(message[1:])
if inventory_only:
# Inventory is not a second source of calls, bridge state or secrets.
fields = ('MODE', 'ENABLED', 'NETWORK_ID', 'TARGET_IP',
'TARGET_PORT', 'ENHANCED_OBP', 'VER', 'REPORT_INTERNAL')
config = {
name: dict({key: value[key] for key in fields if key in value},
REPORT_INVENTORY_ONLY=True)
for name, value in config.items()
if value.get('MODE') == 'OPENBRIDGE' and value.get('ENABLED')
}
self._config_by_backend[backend_number] = prefix_config(
backend_number,
config,
@ -204,7 +218,8 @@ class ReportMuxSource(NetstringReceiver):
def connectionMade(self):
self.sendString(REPORT_OPCODES['CONFIG_REQ'])
self.sendString(REPORT_OPCODES['BRIDGE_REQ'])
if self._factory.backend_number not in self._factory.mux.inventory_backends:
self.sendString(REPORT_OPCODES['BRIDGE_REQ'])
def stringReceived(self, data):
self._factory.mux.ingest(self._factory.backend_number, data)
@ -270,6 +285,8 @@ if __name__ == '__main__':
help='numbered source as NUMBER,HOST,PORT; repeat for each backend',
)
parser.add_argument('--listen-interface', default='127.0.0.1')
parser.add_argument('--inventory-backend', action='append', type=parse_backend,
default=[], help='FBP inventory only, as NUMBER,HOST,PORT')
parser.add_argument('--listen-port', type=int, default=4321)
parser.add_argument(
'--client',
@ -278,7 +295,8 @@ if __name__ == '__main__':
)
args = parser.parse_args()
backend_numbers = [number for number, _host, _port in args.backend]
backends = args.backend + args.inventory_backend
backend_numbers = [number for number, _host, _port in backends]
if len(set(backend_numbers)) != len(backend_numbers):
parser.error('backend numbers must be unique')
@ -288,9 +306,10 @@ if __name__ == '__main__':
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
mux = ReportMuxFactory(args.client or ('*',))
mux = ReportMuxFactory(args.client or ('*',),
[number for number, _host, _port in args.inventory_backend])
reactor.listenTCP(args.listen_port, mux, interface=args.listen_interface)
for backend_number, host, port in args.backend:
for backend_number, host, port in backends:
reactor.connectTCP(
host,
port,

@ -87,7 +87,10 @@ class HDStackRuntimeTests(unittest.TestCase):
layout = self.generate()
aggregator = _read_config(layout.aggregator_config)
self.assertFalse(aggregator.getboolean('REPORTS', 'REPORT'))
self.assertTrue(aggregator.getboolean('REPORTS', 'REPORT'))
self.assertEqual(aggregator.get('REPORTS', 'REPORT_INTERFACE'), '127.0.0.1')
self.assertEqual(aggregator.getint('REPORTS', 'REPORT_PORT'), 4324)
self.assertTrue(aggregator.getboolean('OBP-HDSTACK-WORKER-1', 'REPORT_INTERNAL'))
self.assertTrue(aggregator.getboolean('GLOBAL', 'GEN_STAT_BRIDGES'))
self.assertNotIn('SYSTEM', aggregator.sections())
self.assertNotIn('ECHO', aggregator.sections())
@ -309,7 +312,7 @@ class HDStackRuntimeTests(unittest.TestCase):
)
self.assertEqual(loro.get('LOGGER', 'LOG_NAME'), 'ECHO-{}'.format(number))
def test_reporting_mux_uses_workers_only_and_preserves_client_acl(self):
def test_reporting_mux_adds_inventory_only_and_preserves_client_acl(self):
layout = self.generate()
supervisor = layout.supervisor_config.read_text(encoding='utf-8')
workers = [_read_config(path) for path in layout.worker_configs]
@ -321,6 +324,7 @@ class HDStackRuntimeTests(unittest.TestCase):
self.assertIn('--backend 2,127.0.0.1,4323', supervisor)
self.assertNotIn('--backend 0,', supervisor)
self.assertNotIn('--backend 3,', supervisor)
self.assertIn('--inventory-backend 3,127.0.0.1,4324', supervisor)
self.assertEqual(
[worker.getint('REPORTS', 'REPORT_PORT') for worker in workers],
[4322, 4323],

@ -51,7 +51,7 @@ class HDStackUdpBlackBoxTests(unittest.TestCase):
with tempfile.TemporaryDirectory(prefix='freedmr-hdstack-udp-') as directory:
temporary = Path(directory)
hbp_base = free_udp_port_range(4)
report_base = _free_tcp_port_range(3)
report_base = _free_tcp_port_range(4)
proxy_port = free_udp_port()
main_config = temporary / 'freedmr.cfg'
@ -163,6 +163,8 @@ class HDStackUdpBlackBoxTests(unittest.TestCase):
'1,127.0.0.1,{}'.format(report_base + 1),
'--backend',
'2,127.0.0.1,{}'.format(report_base + 2),
'--inventory-backend',
'3,127.0.0.1,{}'.format(report_base + 3),
],
temporary / 'mux.log',
)
@ -246,6 +248,11 @@ class HDStackUdpBlackBoxTests(unittest.TestCase):
self.assertTrue(any(name.startswith('1:') for name in combined))
self.assertTrue(any(name.startswith('2:') for name in combined))
self.assertFalse(any(name.startswith('0:') for name in combined))
self.assertTrue(any(name.startswith('3:') for name in combined))
for name, value in combined.items():
if name.startswith('3:'):
self.assertTrue(value['REPORT_INVENTORY_ONLY'])
self.assertNotIn('PASSPHRASE', value)
monitor_source = os.environ.get('FREEDMR_MONITOR_SOURCE')
if monitor_source:
@ -267,6 +274,9 @@ class HDStackUdpBlackBoxTests(unittest.TestCase):
{
'1:OBP-HDSTACK-AGGREGATOR',
'2:OBP-HDSTACK-AGGREGATOR',
'3:OBP-HDSTACK-WORKER-1',
'3:OBP-HDSTACK-WORKER-2',
'3:OBP-HDSTACK-BRIDGE',
},
)
finally:

@ -17,6 +17,32 @@ from tests.harness.fdmr_monitor_compat import (
class ReportMuxTests(unittest.TestCase):
def test_inventory_excludes_secrets_non_fbp_and_all_call_events(self):
mux = report_mux.ReportMuxFactory(inventory_backends=(3,))
client = _FakeReportClient()
mux.add_client(client)
worker = {'SYSTEM': {'MODE': 'MASTER', 'PEERS': {}}}
mux.ingest(1, _report_message('CONFIG_SND', worker))
mux.ingest(3, _report_message('CONFIG_SND', {
'external': dict(MODE='OPENBRIDGE', ENABLED=True, NETWORK_ID=b'1234',
PASSPHRASE=b'secret', REPORT_INTERNAL=False),
'disabled': dict(MODE='OPENBRIDGE', ENABLED=False),
'not-fbp': dict(MODE='MASTER', ENABLED=True)}))
self.assertEqual(pickle.loads(client.messages[-1][1:]), {
'1:SYSTEM': worker['SYSTEM'], '3:external': dict(MODE='OPENBRIDGE',
ENABLED=True, NETWORK_ID=b'1234', REPORT_INTERNAL=False,
REPORT_INVENTORY_ONLY=True)})
before = list(client.messages)
mux.ingest(3, _report_message('BRIDGE_SND', {'235': []}))
mux.ingest(3, REPORT_OPCODES['BRDG_EVENT'] + b'GROUP VOICE,START,RX,external,1,2,3,1,235')
self.assertEqual(client.messages, before)
source = report_mux.ReportMuxSourceFactory(3, mux).buildProtocol(_FakeAddress('127.0.0.1'))
transport = StringTransport()
source.makeConnection(transport)
self.assertEqual(transport.value(), _netstring(REPORT_OPCODES['CONFIG_REQ']))
mux.backend_disconnected(3)
self.assertEqual(pickle.loads(client.messages[-1][1:]), {'1:SYSTEM': worker['SYSTEM']})
def test_merges_config_and_disambiguates_colliding_system_names(self):
mux = report_mux.ReportMuxFactory()
client = _FakeReportClient()

Loading…
Cancel
Save

Powered by TurnKey Linux.