From ec01f98c26133f1e9fa373829fff01e98a95f2a7 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 12 Aug 2021 17:37:55 +0200 Subject: [PATCH] wip --- slsDetectorSoftware/include/sls/Detector.h | 5 + slsDetectorSoftware/src/CmdProxy.cpp | 96 ++++++++++++++++--- slsDetectorSoftware/src/CmdProxy.h | 4 + slsDetectorSoftware/src/Detector.cpp | 13 +++ slsDetectorSoftware/src/Module.cpp | 18 ++++ slsDetectorSoftware/src/Module.h | 3 + slsSupportLib/include/sls/ToString.h | 4 +- slsSupportLib/include/sls/sls_detector_defs.h | 31 +++++- slsSupportLib/src/ToString.cpp | 25 +++++ 9 files changed, 183 insertions(+), 16 deletions(-) diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 37790f857..7e8aef467 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -657,6 +657,11 @@ class Detector { /** [Jungfrau] bottom half [Gotthard2] veto debugging */ void setSourceUDPMAC2(const MacAddr mac, Positions pos = {}); + Result + getDestinationUDPList(const int entry, Positions pos = {}) const; + + void setDestinationUDPList(const defs::udpDestination, const int module_id); + Result getDestinationUDPIP(Positions pos = {}) const; /** IP of the interface in receiver that the detector sends data to */ diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index a2862c45a..7184236a5 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1368,6 +1368,86 @@ std::string CmdProxy::Trigger(int action) { /* Network Configuration (Detector<->Receiver) */ +IpAddr CmdProxy::getIpFromAuto() { + std::string rxHostname = + det->getRxHostname(std::vector{det_id}).squash("none"); + // Hostname could be ip try to decode otherwise look up the hostname + auto val = sls::IpAddr{rxHostname}; + if (val == 0) { + val = HostnameToIp(rxHostname.c_str()); + } + return val; +} + +defs::udpDestination CmdProxy::getUdpList() { + defs::udpDestination dest{}; + for (auto it : args) { + size_t pos = it.find('='); + std::string key = it.substr(0, pos); + std::string value = it.substr(pos + 1); + if (key == "ip") { + if (value == "auto") { + auto val = getIpFromAuto(); + LOG(logINFO) << "Setting udp_dstip of detector " << det_id + << " to " << val; + dest.ip = val.uint32(); + } else { + dest.ip = IpAddr(value).uint32(); + } + } else if (key == "ip2") { + if (value == "auto") { + auto val = getIpFromAuto(); + LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id + << " to " << val; + dest.ip2 = val.uint32(); + } else { + dest.ip2 = IpAddr(value).uint32(); + } + } else if (key == "mac") { + dest.mac = MacAddr(value).uint64(); + } else if (key == "mac2") { + dest.mac2 = MacAddr(value).uint64(); + } else if (key == "port") { + dest.port = StringTo(value); + } else if (key == "port2") { + dest.port2 = StringTo(value); + } + } + return dest; +} + +std::string CmdProxy::UDPDestinationList(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[entry=n_val] [ip=x.x.x.x] [(optional)ip2=x.x.x.x] " + "\n[mac=xx:xx:xx:xx:xx:xx] " + "[(optional)mac2=xx:xx:xx:xx:xx:xx]\n[port=value] " + "[(optional)port2=value\n\tThe order of ip, mac and port does " + "not matter. entry_value can be >0 only for Eiger and Jungfrau " + "where round robin is implemented. If 'auto' used, then ip is " + "set to ip of rx_hostname." + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + auto t = det->getDestinationUDPList(StringTo(args[0]), + std::vector{det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.empty()) { + WrongNumberOfParameters(1); + } + auto t = getUdpList(); + det->setDestinationUDPList(t, det_id); + os << ToString(args) << std::endl; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + std::string CmdProxy::UDPDestinationIP(int action) { std::ostringstream os; os << cmd << ' '; @@ -1387,13 +1467,7 @@ std::string CmdProxy::UDPDestinationIP(int action) { WrongNumberOfParameters(1); } if (args[0] == "auto") { - std::string rxHostname = - det->getRxHostname(std::vector{det_id}).squash("none"); - // Hostname could be ip try to decode otherwise look up the hostname - auto val = sls::IpAddr{rxHostname}; - if (val == 0) { - val = HostnameToIp(rxHostname.c_str()); - } + auto val = getIpFromAuto(); LOG(logINFO) << "Setting udp_dstip of detector " << det_id << " to " << val; det->setDestinationUDPIP(val, std::vector{det_id}); @@ -1429,13 +1503,7 @@ std::string CmdProxy::UDPDestinationIP2(int action) { WrongNumberOfParameters(1); } if (args[0] == "auto") { - std::string rxHostname = - det->getRxHostname(std::vector{det_id}).squash("none"); - // Hostname could be ip try to decode otherwise look up the hostname - auto val = sls::IpAddr{rxHostname}; - if (val == 0) { - val = HostnameToIp(rxHostname.c_str()); - } + auto val = getIpFromAuto(); LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id << " to " << val; det->setDestinationUDPIP2(val, std::vector{det_id}); diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index e12f65d71..232ca7298 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -855,6 +855,7 @@ class CmdProxy { /* Network Configuration (Detector<->Receiver) */ {"numinterfaces", &CmdProxy::numinterfaces}, {"selinterface", &CmdProxy::selinterface}, + {"udp_dstlist", &CmdProxy::UDPDestinationList}, {"udp_srcip", &CmdProxy::udp_srcip}, {"udp_srcip2", &CmdProxy::udp_srcip2}, {"udp_dstip", &CmdProxy::UDPDestinationIP}, @@ -1112,6 +1113,9 @@ class CmdProxy { std::string Scan(int action); std::string Trigger(int action); /* Network Configuration (Detector<->Receiver) */ + IpAddr getIpFromAuto(); + slsDetectorDefs::udpDestination getUdpList(); + std::string UDPDestinationList(int action); std::string UDPDestinationIP(int action); std::string UDPDestinationIP2(int action); /* Receiver Config */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index dea352e8d..044eda677 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -899,6 +899,19 @@ void Detector::setSourceUDPMAC2(const MacAddr mac, Positions pos) { pimpl->Parallel(&Module::setSourceUDPMAC2, pos, mac); } +Result +Detector::getDestinationUDPList(const int entry, Positions pos) const { + return pimpl->Parallel(&Module::getDestinationUDPList, pos, entry); +} + +void Detector::setDestinationUDPList(const defs::udpDestination dest, + const int module_id) { + if (module_id == -1 && size() > 1) { + throw sls::RuntimeError("Cannot set this parameter at detector level."); + } + pimpl->Parallel(&Module::setDestinationUDPList, {module_id}, dest); +} + Result Detector::getDestinationUDPIP(Positions pos) const { return pimpl->Parallel(&Module::getDestinationUDPIP, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index f44af4bea..d92672a0d 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -928,6 +928,24 @@ void Module::setSourceUDPMAC2(const sls::MacAddr mac) { sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr); } +slsDetectorDefs::udpDestination +Module::getDestinationUDPList(const int entry) const { + // return sendToDetector(F_GET_DEST_UDP_LIST); + return bla; +} + +void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) { + LOG(logINFO) << "setting stuff to " << dest; + bla.entry = dest.entry; + bla.ip = dest.ip; + bla.ip2 = dest.ip2; + bla.mac = dest.mac; + bla.mac2 = dest.mac2; + bla.port = dest.port; + bla.port2 = dest.port2; + // sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); +} + sls::IpAddr Module::getDestinationUDPIP() const { return sendToDetector(F_GET_DEST_UDP_IP); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 22abf7a94..909de0486 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -221,6 +221,8 @@ class Module : public virtual slsDetectorDefs { void setSourceUDPMAC(const sls::MacAddr mac); sls::MacAddr getSourceUDPMAC2() const; void setSourceUDPMAC2(const sls::MacAddr mac); + udpDestination getDestinationUDPList(const int entry) const; + void setDestinationUDPList(const defs::udpDestination dest); sls::IpAddr getDestinationUDPIP() const; void setDestinationUDPIP(const sls::IpAddr ip); sls::IpAddr getDestinationUDPIP2() const; @@ -744,6 +746,7 @@ class Module : public virtual slsDetectorDefs { const int moduleId; mutable sls::SharedMemory shm{0, 0}; + udpDestination bla{}; }; } // namespace sls \ No newline at end of file diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index 0f18a6d4c..bd102e2b2 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -55,7 +55,9 @@ std::ostream &operator<<(std::ostream &os, std::string ToString(const slsDetectorDefs::currentSrcParameters &r); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::currentSrcParameters &r); - +std::string ToString(const slsDetectorDefs::udpDestination &r); +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::udpDestination &r); const std::string &ToString(const std::string &s); /** Convert std::chrono::duration with specified output unit */ diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 61a3fd419..1f48a85f6 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -466,7 +466,7 @@ typedef struct { currentSrcParameters() : enable(0), fix(-1), normal(-1), select(0) {} /** [Gotthard2] enable or disable */ - currentSrcParameters(bool ena) + explicit currentSrcParameters(bool ena) : enable(static_cast(ena)), fix(-1), normal(-1), select(0) {} /** [Jungfrau](chipv1.0) enable current src with fix or no fix, @@ -489,6 +489,35 @@ typedef struct { } } __attribute__((packed)); + struct udpDestination { + int entry; + uint32_t ip{}; + uint32_t ip2{}; + uint64_t mac{}; + uint64_t mac2{}; + int port{}; + int port2{}; + udpDestination(); + bool operator==(const udpDestination &other) const { + return ((entry == other.entry) && (ip == other.ip) && + (ip2 == other.ip2) && (mac == other.mac) && + (mac2 == other.mac2) && (port == other.port) && + (port2 == other.port2)); + } + udpDestination operator=(const udpDestination &other) const { + if (this == &other) + return *this; + entry = other.entry; + ip = other.ip; + ip2 = other.ip2; + mac = other.mac; + mac2 = other.mac2; + port = other.port; + port2 = other.port2; + return *this; + } + } __attribute__((packed)); + /** * structure to udpate receiver */ diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index d20debaf8..aae1fbb06 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -148,6 +148,31 @@ std::ostream &operator<<(std::ostream &os, return os << ToString(r); } +std::string ToString(const slsDetectorDefs::udpDestination &r) { + std::ostringstream oss; + oss << '[' << std::endl + << "entry " << r.entry << std::endl + << "ip " << IpAddr(r.ip) << std::endl + << "mac " << MacAddr(r.mac) << std::endl + << "port " << r.port << std::endl; + if (r.port2 != 0) { + oss << "port2 " << r.port2 << std::endl; + } + if (r.ip2 != 0) { + oss << "ip2 " << IpAddr(r.ip2) << std::endl; + } + if (r.mac2 != 0) { + oss << "mac2 " << MacAddr(r.mac2) << std::endl; + } + oss << ']'; + return oss.str(); +} + +std::ostream &operator<<(std::ostream &os, + const slsDetectorDefs::udpDestination &r) { + return os << ToString(r); +} + std::string ToString(const defs::runStatus s) { switch (s) { case defs::ERROR: