This commit is contained in:
maliakal_d 2021-08-12 17:37:55 +02:00
parent eb652557b6
commit ec01f98c26
9 changed files with 183 additions and 16 deletions

View File

@ -657,6 +657,11 @@ class Detector {
/** [Jungfrau] bottom half [Gotthard2] veto debugging */
void setSourceUDPMAC2(const MacAddr mac, Positions pos = {});
Result<defs::udpDestination>
getDestinationUDPList(const int entry, Positions pos = {}) const;
void setDestinationUDPList(const defs::udpDestination, const int module_id);
Result<IpAddr> getDestinationUDPIP(Positions pos = {}) const;
/** IP of the interface in receiver that the detector sends data to */

View File

@ -1368,6 +1368,86 @@ std::string CmdProxy::Trigger(int action) {
/* Network Configuration (Detector<->Receiver) */
IpAddr CmdProxy::getIpFromAuto() {
std::string rxHostname =
det->getRxHostname(std::vector<int>{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<int>(value);
} else if (key == "port2") {
dest.port2 = StringTo<int>(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<int>(args[0]),
std::vector<int>{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<int>{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<int>{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<int>{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<int>{det_id});

View File

@ -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 */

View File

@ -899,6 +899,19 @@ void Detector::setSourceUDPMAC2(const MacAddr mac, Positions pos) {
pimpl->Parallel(&Module::setSourceUDPMAC2, pos, mac);
}
Result<defs::udpDestination>
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<IpAddr> Detector::getDestinationUDPIP(Positions pos) const {
return pimpl->Parallel(&Module::getDestinationUDPIP, pos);
}

View File

@ -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<udpDestination>(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<sls::IpAddr>(F_GET_DEST_UDP_IP);
}

View File

@ -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<sharedSlsDetector> shm{0, 0};
udpDestination bla{};
};
} // namespace sls

View File

@ -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 */

View File

@ -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<int>(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
*/

View File

@ -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: