fixed multicast updated tests

This commit is contained in:
Martino Ferrari
2026-07-25 16:46:25 +02:00
parent 3e0a481c13
commit 915a192b16
16 changed files with 542 additions and 75 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+39
View File
@@ -17,6 +17,8 @@ expected, not an error.
"""
import argparse
import os
import re
import subprocess
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
@@ -25,6 +27,41 @@ import scenarios as S # noqa: E402
PRODUCER_HZ = 1000 # LinuxTimer frequency (Hz)
def _iface_to_ip(name):
"""Resolve a network interface name (e.g. ``"wlan0"``) to its first IPv4
address via ``ip -4 addr show <name>``. Returns ``"127.0.0.1"`` on failure."""
try:
out = subprocess.check_output(
["ip", "-4", "addr", "show", name],
stderr=subprocess.DEVNULL, text=True)
m = re.search(r"inet\s+(\d+\.\d+\.\d+\.\d+)", out)
if m:
return m.group(1)
except (subprocess.CalledProcessError, FileNotFoundError, OSError):
pass
return "127.0.0.1"
def _mcast_interface_ip(group):
"""Return the IPv4 address of the OS-selected interface for a multicast
group. MARTe2's ``BasicUDPSocket::Join`` expects an IP address (passed to
``inet_addr``), not an interface name.
Uses ``ip route get <group>`` to find the outgoing device, then resolves
its IP. Falls back to ``"127.0.0.1"`` if the route or device lookup fails.
"""
try:
out = subprocess.check_output(
["ip", "route", "get", group],
stderr=subprocess.DEVNULL, text=True)
m = re.search(r"dev\s+(\S+)", out)
if m:
return _iface_to_ip(m.group(1))
except (subprocess.CalledProcessError, FileNotFoundError, OSError):
pass
return "127.0.0.1"
def _ndims(elements):
return 0 if elements == 1 else 1
@@ -78,6 +115,8 @@ def _streamer_block(src, scenario):
if scenario["network"] == "multicast":
parts.append(f'MulticastGroup = "{src["multicast_group"]}"')
parts.append(f"DataPort = {src['data_port']}")
iface = src.get("interface") or _mcast_interface_ip(src["multicast_group"])
parts.append(f'Interface = "{iface}"')
sigs = " ".join(_streamer_sig(sig) for sig in s)
return (f" +Streamer_{src['id']} = {{ Class = UDPStreamer "
f"{' '.join(parts)} Signals = {{ {sigs} }} }}")