fixed multicast updated tests
This commit is contained in:
@@ -424,6 +424,7 @@ $TestApp = {
|
||||
Port = 44500
|
||||
MulticastGroup = "239.0.0.1"
|
||||
DataPort = 44503
|
||||
Interface = "127.0.0.1"
|
||||
MaxPayloadSize = 1400
|
||||
PublishingMode = "Accumulate"
|
||||
MinRefreshRate = 100
|
||||
|
||||
@@ -279,6 +279,7 @@ $App = {
|
||||
Port = 44500
|
||||
MulticastGroup = "239.0.0.1"
|
||||
DataPort = 44503
|
||||
Interface = "127.0.0.1"
|
||||
MaxPayloadSize = 1400
|
||||
PublishingMode = "Accumulate"
|
||||
MinRefreshRate = 100
|
||||
|
||||
@@ -411,6 +411,7 @@ $App = {
|
||||
Port = 44500
|
||||
MulticastGroup = "239.0.0.1"
|
||||
DataPort = 44503
|
||||
Interface = "127.0.0.1"
|
||||
MaxPayloadSize = 1400
|
||||
PublishingMode = "Accumulate"
|
||||
MinRefreshRate = 100
|
||||
|
||||
@@ -64,6 +64,7 @@ $E2EMulticastTest = {
|
||||
Port = 44600
|
||||
MulticastGroup = "239.0.0.1"
|
||||
DataPort = 44610
|
||||
Interface = "127.0.0.1"
|
||||
MaxPayloadSize = 65507
|
||||
PublishingMode = "Strict"
|
||||
Signals = {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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} }} }}")
|
||||
|
||||
Reference in New Issue
Block a user