Skip to content

Commit abc6bcc

Browse files
committed
refactor: enhance hostname resolution for Zenoh router configuration
1 parent cc1add1 commit abc6bcc

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ Arguments:
449449
- `--zenoh-router`: Router target used only when `--rmw zenoh`.
450450
- (default): first host listed in the JSON topology file (e.g., `host1`)
451451
- `<host-name>` / `<ipv4>`: explicit host name or IPv4 address (e.g., `host2` / `192.168.1.10`)
452-
- `Manager`: the manager machine running `performance_test.py` (IP address auto-detected)
452+
- `Manager`: the manager machine running `performance_test.py`
453453

454454
Example:
455455

@@ -487,6 +487,8 @@ For `docker` and `native` modes, `--zenoh-router` selects the target:
487487
- `<host-name>` / `<ipv4>`: explicit hostname or IPv4 address
488488
- `Manager`: the machine running `performance_test.py`
489489

490+
The specified target (hostname or `Manager`) is automatically resolved to an IP address, which is then used as the `connect/endpoints` value in `ZENOH_CONFIG_OVERRIDE`.
491+
490492
`performance_test.py` also sets `ZENOH_CONFIG_OVERRIDE` so that every bench node connects to the router as a client:
491493

492494
- `mode="client"`

performance_test/performance_test.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,25 @@ def _resolve_zenoh_router_target(target, hosts):
4444
)
4545

4646

47+
def _hostname_to_ip(hostname):
48+
"""Resolve a hostname to an IPv4 address.
49+
50+
Docker containers do not inherit the host's /etc/hosts even with
51+
network_mode: host, so ZENOH_CONFIG_OVERRIDE must use a routable IP
52+
address rather than a hostname that may only appear in /etc/hosts.
53+
Falls back to the original value if resolution fails.
54+
"""
55+
if _looks_like_ipv4(hostname):
56+
return hostname
57+
try:
58+
return socket.gethostbyname(hostname)
59+
except socket.gaierror:
60+
return hostname
61+
62+
4763
def _build_zenoh_config_override(connect_host):
48-
return f'mode="client";connect/endpoints=["tcp/{connect_host}:7447"]'
64+
ip = _hostname_to_ip(connect_host)
65+
return f'mode="client";connect/endpoints=["tcp/{ip}:7447"]'
4966

5067

5168
_ROUTER_PORT = 7447

0 commit comments

Comments
 (0)