17#include <sys/socket.h>
28static void check(
bool ok,
const std::string& what) {
29 std::cout << (
ok ?
" ok " :
" FAIL ") << what << std::endl;
36 const std::string& bind_ip =
"") {
39 toml +=
"[network]\nbind_ip = \"" + bind_ip +
"\"\n\n";
40 toml +=
"[boards.a]\ntype = \"PT\"\nip = \"" + board_prefix +
".21\"\nboard_id = 21\n";
41 toml +=
"enabled = true\n\n";
42 toml +=
"[boards.b]\ntype = \"PT\"\nip = \"" + board_prefix +
".22\"\nboard_id = 22\n";
43 toml +=
"enabled = true\n";
48 std::cout <<
"=== DAQ interface resolution ===" << std::endl;
54 check(
r.ok,
"auto: loopback boards resolve without error");
55 check(
r.pinned,
"auto: loopback boards are pinned to a NIC");
56 check(
r.address.rfind(
"127.", 0) == 0,
57 "auto: pinned address is on loopback (got " +
r.address +
")");
64 check(
r.ok,
"no match: does not fail startup");
65 check(!
r.pinned,
"no match: reports itself as unpinned");
66 check(
r.address ==
"0.0.0.0",
"no match: falls back to 0.0.0.0");
72 check(
r.ok &&
r.pinned,
"explicit: accepted");
73 check(
r.address ==
"127.0.0.1",
"explicit: uses the configured address");
80 check(!
r.ok,
"explicit but absent: refuses to start");
81 check(!
r.pinned,
"explicit but absent: not reported as pinned");
87 int s1 = ::socket(AF_INET, SOCK_DGRAM, 0);
91 int s2 = ::socket(AF_INET, SOCK_DGRAM, 0);
95 int s3 = ::socket(AF_INET, SOCK_DGRAM, 0);
97 "bind: an address not on this host fails rather than silently not binding");
101 std::cout << (
g_failures ?
"FAILED" :
"PASSED") << std::endl;
Config load_from_string(const std::string &text)
Parse config from an in-memory TOML string (SequencerService / ActuatorCommander hold it so).
bool bindToDaqInterface(int sock, const std::string &address, const char *who)
bind() an already-created socket to address on an ephemeral port.
DaqBindResult resolveDaqBindAddress(const ::fsw::config::Config &cfg, const char *who)
Decide which local address board traffic should leave from, and log the decision.
The whole parsed config.toml, restricted to what C++ consumes.
static void check(bool ok, const std::string &what)
static fsw::config::Config makeConfig(const std::string &board_prefix, const std::string &bind_ip="")
A config with two boards on the given subnet, and an optional explicit [network].bind_ip.