mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
replace udpDestination struct with a class that accepts ipaddr
This commit is contained in:
@ -666,10 +666,10 @@ class Detector {
|
|||||||
/** [Jungfrau] bottom half [Gotthard2] veto debugging */
|
/** [Jungfrau] bottom half [Gotthard2] veto debugging */
|
||||||
void setSourceUDPMAC2(const MacAddr mac, Positions pos = {});
|
void setSourceUDPMAC2(const MacAddr mac, Positions pos = {});
|
||||||
|
|
||||||
Result<defs::udpDestination>
|
Result<UdpDestination> getDestinationUDPList(const uint32_t entry,
|
||||||
getDestinationUDPList(const uint32_t entry, Positions pos = {}) const;
|
Positions pos = {}) const;
|
||||||
|
|
||||||
void setDestinationUDPList(const defs::udpDestination, const int module_id);
|
void setDestinationUDPList(const UdpDestination, const int module_id);
|
||||||
|
|
||||||
/** [Jungfrau][Eiger] */
|
/** [Jungfrau][Eiger] */
|
||||||
Result<int> getNumberofUDPDestinations(Positions pos = {}) const;
|
Result<int> getNumberofUDPDestinations(Positions pos = {}) const;
|
||||||
|
@ -1379,15 +1379,8 @@ IpAddr CmdProxy::getIpFromAuto() {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
defs::udpDestination CmdProxy::getUdpList() {
|
UdpDestination CmdProxy::getUdpEntry() {
|
||||||
uint32_t entry{};
|
UdpDestination udpDestination{};
|
||||||
uint32_t port{};
|
|
||||||
uint32_t port2{};
|
|
||||||
uint32_t ip{};
|
|
||||||
uint32_t ip2{};
|
|
||||||
uint64_t mac{};
|
|
||||||
uint64_t mac2{};
|
|
||||||
|
|
||||||
bool hasEntry = false;
|
bool hasEntry = false;
|
||||||
|
|
||||||
for (auto it : args) {
|
for (auto it : args) {
|
||||||
@ -1395,40 +1388,40 @@ defs::udpDestination CmdProxy::getUdpList() {
|
|||||||
std::string key = it.substr(0, pos);
|
std::string key = it.substr(0, pos);
|
||||||
std::string value = it.substr(pos + 1);
|
std::string value = it.substr(pos + 1);
|
||||||
if (key == "entry") {
|
if (key == "entry") {
|
||||||
entry = StringTo<int>(value);
|
udpDestination.setEntry(StringTo<int>(value));
|
||||||
hasEntry = true;
|
hasEntry = true;
|
||||||
} else if (key == "ip") {
|
} else if (key == "ip") {
|
||||||
if (value == "auto") {
|
if (value == "auto") {
|
||||||
auto val = getIpFromAuto();
|
auto val = getIpFromAuto();
|
||||||
LOG(logINFO) << "Setting udp_dstip of detector " << det_id
|
LOG(logINFO) << "Setting udp_dstip of detector " << det_id
|
||||||
<< " to " << val;
|
<< " to " << val;
|
||||||
ip = val.uint32();
|
udpDestination.setIp(val);
|
||||||
} else {
|
} else {
|
||||||
ip = IpAddr(value).uint32();
|
udpDestination.setIp(IpAddr(value));
|
||||||
}
|
}
|
||||||
} else if (key == "ip2") {
|
} else if (key == "ip2") {
|
||||||
if (value == "auto") {
|
if (value == "auto") {
|
||||||
auto val = getIpFromAuto();
|
auto val = getIpFromAuto();
|
||||||
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
|
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
|
||||||
<< " to " << val;
|
<< " to " << val;
|
||||||
ip2 = val.uint32();
|
udpDestination.setIp2(val);
|
||||||
} else {
|
} else {
|
||||||
ip2 = IpAddr(value).uint32();
|
udpDestination.setIp2(IpAddr(value));
|
||||||
}
|
}
|
||||||
} else if (key == "mac") {
|
} else if (key == "mac") {
|
||||||
mac = MacAddr(value).uint64();
|
udpDestination.setMac(MacAddr(value));
|
||||||
} else if (key == "mac2") {
|
} else if (key == "mac2") {
|
||||||
mac2 = MacAddr(value).uint64();
|
udpDestination.setMac2(MacAddr(value));
|
||||||
} else if (key == "port") {
|
} else if (key == "port") {
|
||||||
port = StringTo<uint32_t>(value);
|
udpDestination.setPort(StringTo<uint32_t>(value));
|
||||||
} else if (key == "port2") {
|
} else if (key == "port2") {
|
||||||
port2 = StringTo<uint32_t>(value);
|
udpDestination.setPort2(StringTo<uint32_t>(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasEntry) {
|
if (!hasEntry) {
|
||||||
throw sls::RuntimeError("Found no entry argument.");
|
throw sls::RuntimeError("Found no entry argument.");
|
||||||
}
|
}
|
||||||
return defs::udpDestination(entry, port, ip, mac, port2, ip2, mac2);
|
return udpDestination;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CmdProxy::UDPDestinationList(int action) {
|
std::string CmdProxy::UDPDestinationList(int action) {
|
||||||
@ -1454,7 +1447,7 @@ std::string CmdProxy::UDPDestinationList(int action) {
|
|||||||
if (args.empty()) {
|
if (args.empty()) {
|
||||||
WrongNumberOfParameters(1);
|
WrongNumberOfParameters(1);
|
||||||
}
|
}
|
||||||
auto t = getUdpList();
|
auto t = getUdpEntry();
|
||||||
det->setDestinationUDPList(t, det_id);
|
det->setDestinationUDPList(t, det_id);
|
||||||
os << ToString(args) << std::endl;
|
os << ToString(args) << std::endl;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1117,7 +1117,7 @@ class CmdProxy {
|
|||||||
std::string Trigger(int action);
|
std::string Trigger(int action);
|
||||||
/* Network Configuration (Detector<->Receiver) */
|
/* Network Configuration (Detector<->Receiver) */
|
||||||
IpAddr getIpFromAuto();
|
IpAddr getIpFromAuto();
|
||||||
slsDetectorDefs::udpDestination getUdpList();
|
UdpDestination getUdpEntry();
|
||||||
std::string UDPDestinationList(int action);
|
std::string UDPDestinationList(int action);
|
||||||
std::string UDPDestinationIP(int action);
|
std::string UDPDestinationIP(int action);
|
||||||
std::string UDPDestinationIP2(int action);
|
std::string UDPDestinationIP2(int action);
|
||||||
|
@ -908,12 +908,12 @@ void Detector::setSourceUDPMAC2(const MacAddr mac, Positions pos) {
|
|||||||
pimpl->Parallel(&Module::setSourceUDPMAC2, pos, mac);
|
pimpl->Parallel(&Module::setSourceUDPMAC2, pos, mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<defs::udpDestination>
|
Result<UdpDestination> Detector::getDestinationUDPList(const uint32_t entry,
|
||||||
Detector::getDestinationUDPList(const uint32_t entry, Positions pos) const {
|
Positions pos) const {
|
||||||
return pimpl->Parallel(&Module::getDestinationUDPList, pos, entry);
|
return pimpl->Parallel(&Module::getDestinationUDPList, pos, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Detector::setDestinationUDPList(const defs::udpDestination dest,
|
void Detector::setDestinationUDPList(const UdpDestination dest,
|
||||||
const int module_id) {
|
const int module_id) {
|
||||||
if (module_id == -1 && size() > 1) {
|
if (module_id == -1 && size() > 1) {
|
||||||
throw sls::RuntimeError("Cannot set this parameter at detector level.");
|
throw sls::RuntimeError("Cannot set this parameter at detector level.");
|
||||||
|
@ -939,31 +939,30 @@ void Module::setSourceUDPMAC2(const sls::MacAddr mac) {
|
|||||||
sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr);
|
sendToDetector(F_SET_SOURCE_UDP_MAC2, mac, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
slsDetectorDefs::udpDestination
|
sls::UdpDestination Module::getDestinationUDPList(const uint32_t entry) const {
|
||||||
Module::getDestinationUDPList(const uint32_t entry) const {
|
return sendToDetector<sls::UdpDestination>(F_GET_DEST_UDP_LIST, entry);
|
||||||
return sendToDetector<udpDestination>(F_GET_DEST_UDP_LIST, entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) {
|
void Module::setDestinationUDPList(const sls::UdpDestination dest) {
|
||||||
// set them in the default way so the receivers are also set up
|
// set them in the default way so the receivers are also set up
|
||||||
if (dest.entry_ == 0) {
|
if (dest.getEntry() == 0) {
|
||||||
if (dest.port_ != 0) {
|
if (dest.getPort() != 0) {
|
||||||
setDestinationUDPPort(dest.port_);
|
setDestinationUDPPort(dest.getPort());
|
||||||
}
|
}
|
||||||
if (dest.ip_ != 0) {
|
if (dest.getIp() != 0) {
|
||||||
setDestinationUDPIP(IpAddr(dest.ip_));
|
setDestinationUDPIP(IpAddr(dest.getIp()));
|
||||||
}
|
}
|
||||||
if (dest.mac_ != 0) {
|
if (dest.getMac() != 0) {
|
||||||
setDestinationUDPMAC(MacAddr(dest.mac_));
|
setDestinationUDPMAC(MacAddr(dest.getMac()));
|
||||||
}
|
}
|
||||||
if (dest.port2_ != 0) {
|
if (dest.getPort2() != 0) {
|
||||||
setDestinationUDPPort2(dest.port2_);
|
setDestinationUDPPort2(dest.getPort2());
|
||||||
}
|
}
|
||||||
if (dest.ip2_ != 0) {
|
if (dest.getIp2() != 0) {
|
||||||
setDestinationUDPIP2(IpAddr(dest.ip2_));
|
setDestinationUDPIP2(IpAddr(dest.getIp2()));
|
||||||
}
|
}
|
||||||
if (dest.mac2_ != 0) {
|
if (dest.getMac2() != 0) {
|
||||||
setDestinationUDPMAC2(MacAddr(dest.mac2_));
|
setDestinationUDPMAC2(MacAddr(dest.getMac2()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr);
|
sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr);
|
||||||
|
@ -222,8 +222,8 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
void setSourceUDPMAC(const sls::MacAddr mac);
|
void setSourceUDPMAC(const sls::MacAddr mac);
|
||||||
sls::MacAddr getSourceUDPMAC2() const;
|
sls::MacAddr getSourceUDPMAC2() const;
|
||||||
void setSourceUDPMAC2(const sls::MacAddr mac);
|
void setSourceUDPMAC2(const sls::MacAddr mac);
|
||||||
udpDestination getDestinationUDPList(const uint32_t entry) const;
|
sls::UdpDestination getDestinationUDPList(const uint32_t entry) const;
|
||||||
void setDestinationUDPList(const defs::udpDestination dest);
|
void setDestinationUDPList(const sls::UdpDestination dest);
|
||||||
int getNumberofUDPDestinations() const;
|
int getNumberofUDPDestinations() const;
|
||||||
void setNumberofUDPDestinations(const int value);
|
void setNumberofUDPDestinations(const int value);
|
||||||
int getFirstUDPDestination() const;
|
int getFirstUDPDestination() const;
|
||||||
|
@ -55,9 +55,6 @@ std::ostream &operator<<(std::ostream &os,
|
|||||||
std::string ToString(const slsDetectorDefs::currentSrcParameters &r);
|
std::string ToString(const slsDetectorDefs::currentSrcParameters &r);
|
||||||
std::ostream &operator<<(std::ostream &os,
|
std::ostream &operator<<(std::ostream &os,
|
||||||
const slsDetectorDefs::currentSrcParameters &r);
|
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);
|
const std::string &ToString(const std::string &s);
|
||||||
|
|
||||||
/** Convert std::chrono::duration with specified output unit */
|
/** Convert std::chrono::duration with specified output unit */
|
||||||
|
@ -59,11 +59,70 @@ class MacAddr {
|
|||||||
constexpr uint64_t uint64() const noexcept { return addr_; }
|
constexpr uint64_t uint64() const noexcept { return addr_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UdpDestination {
|
||||||
|
private:
|
||||||
|
uint32_t entry_{};
|
||||||
|
uint32_t port_{};
|
||||||
|
uint32_t port2_{};
|
||||||
|
uint32_t ip_{};
|
||||||
|
uint32_t ip2_{};
|
||||||
|
uint64_t mac_{};
|
||||||
|
uint64_t mac2_{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr UdpDestination() noexcept = default;
|
||||||
|
explicit constexpr UdpDestination(uint32_t entry, uint32_t port = 0,
|
||||||
|
IpAddr ip = {}, MacAddr mac = {},
|
||||||
|
uint32_t port2 = 0, IpAddr ip2 = {},
|
||||||
|
MacAddr mac2 = {})
|
||||||
|
: entry_(entry), port_(port), port2_(port2), ip_(ip.uint32()),
|
||||||
|
ip2_(ip2.uint32()), mac_(mac.uint64()), mac2_(mac2.uint64()) {}
|
||||||
|
|
||||||
|
uint32_t getEntry() const noexcept { return entry_; }
|
||||||
|
|
||||||
|
void setEntry(const uint32_t value) { entry_ = value; }
|
||||||
|
|
||||||
|
uint32_t getPort() const noexcept { return port_; }
|
||||||
|
|
||||||
|
void setPort(const uint32_t value) { port_ = value; }
|
||||||
|
|
||||||
|
uint32_t getPort2() const noexcept { return port2_; }
|
||||||
|
|
||||||
|
void setPort2(const uint32_t value) { port2_ = value; }
|
||||||
|
|
||||||
|
IpAddr getIp() const noexcept { return IpAddr(ip_); }
|
||||||
|
|
||||||
|
void setIp(const IpAddr value) { ip_ = value.uint32(); }
|
||||||
|
|
||||||
|
IpAddr getIp2() const noexcept { return IpAddr(ip2_); }
|
||||||
|
|
||||||
|
void setIp2(const IpAddr value) { ip2_ = value.uint32(); }
|
||||||
|
|
||||||
|
MacAddr getMac() const noexcept { return MacAddr(mac_); }
|
||||||
|
|
||||||
|
void setMac(const MacAddr value) { mac_ = value.uint64(); }
|
||||||
|
|
||||||
|
MacAddr getMac2() const noexcept { return MacAddr(mac2_); }
|
||||||
|
|
||||||
|
void setMac2(const MacAddr value) { mac2_ = value.uint64(); }
|
||||||
|
|
||||||
|
std::string str() const;
|
||||||
|
|
||||||
|
constexpr bool operator==(const UdpDestination &other) const {
|
||||||
|
return ((entry_ == other.entry_) && (port_ == other.port_) &&
|
||||||
|
(port2_ == other.port2_) && (ip_ == other.ip_) &&
|
||||||
|
(ip2_ == other.ip2_) && (mac_ == other.mac_) &&
|
||||||
|
(mac2_ == other.mac2_));
|
||||||
|
}
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const UdpDestination &dest);
|
||||||
|
|
||||||
IpAddr HostnameToIp(const char *hostname);
|
IpAddr HostnameToIp(const char *hostname);
|
||||||
std::string IpToInterfaceName(const std::string &ip);
|
std::string IpToInterfaceName(const std::string &ip);
|
||||||
MacAddr InterfaceNameToMac(const std::string &inf);
|
MacAddr InterfaceNameToMac(const std::string &inf);
|
||||||
IpAddr InterfaceNameToIp(const std::string &ifn);
|
IpAddr InterfaceNameToIp(const std::string &ifn);
|
||||||
std::ostream &operator<<(std::ostream &out, const IpAddr &addr);
|
|
||||||
std::ostream &operator<<(std::ostream &out, const MacAddr &addr);
|
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
||||||
|
@ -494,28 +494,6 @@ typedef struct {
|
|||||||
}
|
}
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
struct udpDestination {
|
|
||||||
uint32_t entry_{};
|
|
||||||
uint32_t port_{};
|
|
||||||
uint32_t port2_{};
|
|
||||||
uint32_t ip_{};
|
|
||||||
uint32_t ip2_{};
|
|
||||||
uint64_t mac_{};
|
|
||||||
uint64_t mac2_{};
|
|
||||||
udpDestination() {}
|
|
||||||
udpDestination(uint32_t entry, uint32_t port = 0, uint32_t ip = 0, uint64_t mac = 0,
|
|
||||||
uint32_t port2 = 0, uint32_t ip2 = 0, uint64_t mac2 = 0)
|
|
||||||
: entry_(entry), port_(port), port2_(port2), ip_(ip), ip2_(ip2),
|
|
||||||
mac_(mac), mac2_(mac2) {}
|
|
||||||
|
|
||||||
bool operator==(const udpDestination &other) const {
|
|
||||||
return ((entry_ == other.entry_) && (port_ == other.port_) &&
|
|
||||||
(port2_ == other.port2_) && (ip_ == other.ip_) &&
|
|
||||||
(ip2_ == other.ip2_) && (mac_ == other.mac_) &&
|
|
||||||
(mac2_ == other.mac2_));
|
|
||||||
}
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* structure to udpate receiver
|
* structure to udpate receiver
|
||||||
*/
|
*/
|
||||||
|
@ -148,31 +148,6 @@ std::ostream &operator<<(std::ostream &os,
|
|||||||
return os << ToString(r);
|
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) {
|
std::string ToString(const defs::runStatus s) {
|
||||||
switch (s) {
|
switch (s) {
|
||||||
case defs::ERROR:
|
case defs::ERROR:
|
||||||
|
@ -69,6 +69,26 @@ std::string MacAddr::str() const { return to_hex(':'); }
|
|||||||
|
|
||||||
std::string MacAddr::hex() const { return to_hex(); }
|
std::string MacAddr::hex() const { return to_hex(); }
|
||||||
|
|
||||||
|
std::string UdpDestination::str() const {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << '[' << std::endl
|
||||||
|
<< "entry " << entry_ << std::endl
|
||||||
|
<< "ip " << ip_ << std::endl
|
||||||
|
<< "mac " << mac_ << std::endl
|
||||||
|
<< "port " << port_ << std::endl;
|
||||||
|
if (port2_ != 0) {
|
||||||
|
oss << "port2 " << port2_ << std::endl;
|
||||||
|
}
|
||||||
|
if (ip2_ != 0) {
|
||||||
|
oss << "ip2 " << ip2_ << std::endl;
|
||||||
|
}
|
||||||
|
if (mac2_ != 0) {
|
||||||
|
oss << "mac2 " << mac2_ << std::endl;
|
||||||
|
}
|
||||||
|
oss << ']';
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const IpAddr &addr) {
|
std::ostream &operator<<(std::ostream &out, const IpAddr &addr) {
|
||||||
return out << addr.str();
|
return out << addr.str();
|
||||||
}
|
}
|
||||||
@ -77,6 +97,10 @@ std::ostream &operator<<(std::ostream &out, const MacAddr &addr) {
|
|||||||
return out << addr.str();
|
return out << addr.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const UdpDestination &dest) {
|
||||||
|
return out << dest.str();
|
||||||
|
}
|
||||||
|
|
||||||
IpAddr HostnameToIp(const char *hostname) {
|
IpAddr HostnameToIp(const char *hostname) {
|
||||||
addrinfo hints;
|
addrinfo hints;
|
||||||
addrinfo *result = nullptr;
|
addrinfo *result = nullptr;
|
||||||
|
Reference in New Issue
Block a user