Dev/fix port size (#805)

* port datatype changing from int to uint16_t
* throwing for -1 given for uint16_t ports
This commit is contained in:
maliakal_d 2023-09-28 09:36:39 +02:00 committed by GitHub
parent 77d13f0794
commit 9834b07b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 519 additions and 345 deletions

View File

@ -1789,8 +1789,8 @@ int configureMAC() {
uint32_t dstip = udpDetails[0].dstip; uint32_t dstip = udpDetails[0].dstip;
uint64_t srcmac = udpDetails[0].srcmac; uint64_t srcmac = udpDetails[0].srcmac;
uint64_t dstmac = udpDetails[0].dstmac; uint64_t dstmac = udpDetails[0].dstmac;
int srcport = udpDetails[0].srcport; uint16_t srcport = udpDetails[0].srcport;
int dstport = udpDetails[0].dstport; uint16_t dstport = udpDetails[0].dstport;
LOG(logINFOBLUE, ("Configuring MAC\n")); LOG(logINFOBLUE, ("Configuring MAC\n"));
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
@ -1802,10 +1802,10 @@ int configureMAC() {
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n", "\tDest Port : %hu\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
// 1 giga udp // 1 giga udp

View File

@ -1808,9 +1808,9 @@ int configureMAC() {
uint32_t dstip = udpDetails[iRxEntry].dstip; uint32_t dstip = udpDetails[iRxEntry].dstip;
uint64_t srcmac = udpDetails[iRxEntry].srcmac; uint64_t srcmac = udpDetails[iRxEntry].srcmac;
uint64_t dstmac = udpDetails[iRxEntry].dstmac; uint64_t dstmac = udpDetails[iRxEntry].dstmac;
int srcport = udpDetails[iRxEntry].srcport; uint16_t srcport = udpDetails[iRxEntry].srcport;
int dstport = udpDetails[iRxEntry].dstport; uint16_t dstport = udpDetails[iRxEntry].dstport;
int dstport2 = udpDetails[iRxEntry].dstport2; uint16_t dstport2 = udpDetails[iRxEntry].dstport2;
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN];
@ -1824,11 +1824,11 @@ int configureMAC() {
LOG(logINFO, LOG(logINFO,
("\tSource IP : %s\n" ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n" "\tDest Port : %hu\n"
"\tDest Port2 : %d\n", "\tDest Port2 : %hu\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport, dstport2)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport, dstport2));
} }

View File

@ -1902,8 +1902,8 @@ void setFirstUDPDestination(int value) {
} }
void setupHeader(int iRxEntry, int vetoInterface, uint32_t destip, void setupHeader(int iRxEntry, int vetoInterface, uint32_t destip,
uint64_t destmac, uint32_t destport, uint64_t sourcemac, uint64_t destmac, uint16_t destport, uint64_t sourcemac,
uint32_t sourceip, uint32_t sourceport) { uint32_t sourceip, uint16_t sourceport) {
// start addr // start addr
uint32_t addr = BASE_UDP_RAM; uint32_t addr = BASE_UDP_RAM;
@ -1995,10 +1995,10 @@ int configureMAC() {
uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2; uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2;
uint64_t dstmac = udpDetails[iRxEntry].dstmac; uint64_t dstmac = udpDetails[iRxEntry].dstmac;
uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2; uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2;
int srcport = udpDetails[iRxEntry].srcport; uint16_t srcport = udpDetails[iRxEntry].srcport;
int srcport2 = udpDetails[iRxEntry].srcport2; uint16_t srcport2 = udpDetails[iRxEntry].srcport2;
int dstport = udpDetails[iRxEntry].dstport; uint16_t dstport = udpDetails[iRxEntry].dstport;
int dstport2 = udpDetails[iRxEntry].dstport2; uint16_t dstport2 = udpDetails[iRxEntry].dstport2;
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN];
@ -2020,10 +2020,10 @@ int configureMAC() {
LOG(logINFO, ("\tData Interface \n")); LOG(logINFO, ("\tData Interface \n"));
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n\n", "\tDest Port : %hu\n\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
if (getVetoStream()) { if (getVetoStream()) {
@ -2039,10 +2039,10 @@ int configureMAC() {
LOG(logINFO, LOG(logINFO,
("\tSource IP2 : %s\n" ("\tSource IP2 : %s\n"
"\tSource MAC2 : %s\n" "\tSource MAC2 : %s\n"
"\tSource Port2: %d\n" "\tSource Port2: %hu\n"
"\tDest IP2 : %s\n" "\tDest IP2 : %s\n"
"\tDest MAC2 : %s\n" "\tDest MAC2 : %s\n"
"\tDest Port2 : %d\n\n", "\tDest Port2 : %hu\n\n",
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2));
} }
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -1425,8 +1425,8 @@ int configureMAC() {
uint32_t dstip = udpDetails[0].dstip; uint32_t dstip = udpDetails[0].dstip;
uint64_t srcmac = udpDetails[0].srcmac; uint64_t srcmac = udpDetails[0].srcmac;
uint64_t dstmac = udpDetails[0].dstmac; uint64_t dstmac = udpDetails[0].dstmac;
int srcport = udpDetails[0].srcport; uint16_t srcport = udpDetails[0].srcport;
int dstport = udpDetails[0].dstport; uint16_t dstport = udpDetails[0].dstport;
LOG(logINFOBLUE, ("Configuring MAC\n")); LOG(logINFOBLUE, ("Configuring MAC\n"));
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
@ -1438,10 +1438,10 @@ int configureMAC() {
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n", "\tDest Port : %hu\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -1532,8 +1532,8 @@ int getPrimaryInterface() {
} }
void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip,
uint64_t destmac, uint32_t destport, uint64_t sourcemac, uint64_t destmac, uint16_t destport, uint64_t sourcemac,
uint32_t sourceip, uint32_t sourceport) { uint32_t sourceip, uint16_t sourceport) {
// start addr // start addr
uint32_t addr = (type == INNER ? RXR_ENDPOINT_INNER_START_REG uint32_t addr = (type == INNER ? RXR_ENDPOINT_INNER_START_REG
@ -1628,10 +1628,10 @@ int configureMAC() {
uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2; uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2;
uint64_t dstmac = udpDetails[iRxEntry].dstmac; uint64_t dstmac = udpDetails[iRxEntry].dstmac;
uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2; uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2;
int srcport = udpDetails[iRxEntry].srcport; uint16_t srcport = udpDetails[iRxEntry].srcport;
int srcport2 = udpDetails[iRxEntry].srcport2; uint16_t srcport2 = udpDetails[iRxEntry].srcport2;
int dstport = udpDetails[iRxEntry].dstport; uint16_t dstport = udpDetails[iRxEntry].dstport;
int dstport2 = udpDetails[iRxEntry].dstport2; uint16_t dstport2 = udpDetails[iRxEntry].dstport2;
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN];
@ -1655,10 +1655,10 @@ int configureMAC() {
: (selInterface ? "Not Used" : "Used"))); : (selInterface ? "Not Used" : "Used")));
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n\n", "\tDest Port : %hu\n\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
LOG(logINFO, LOG(logINFO,
@ -1668,10 +1668,10 @@ int configureMAC() {
LOG(logINFO, LOG(logINFO,
("\tSource IP2 : %s\n" ("\tSource IP2 : %s\n"
"\tSource MAC2 : %s\n" "\tSource MAC2 : %s\n"
"\tSource Port2: %d\n" "\tSource Port2: %hu\n"
"\tDest IP2 : %s\n" "\tDest IP2 : %s\n"
"\tDest MAC2 : %s\n" "\tDest MAC2 : %s\n"
"\tDest Port2 : %d\n\n", "\tDest Port2 : %hu\n\n",
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2));
} }
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -1120,8 +1120,8 @@ int getPrimaryInterface() {
} }
void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip,
uint64_t destmac, uint32_t destport, uint64_t sourcemac, uint64_t destmac, uint16_t destport, uint64_t sourcemac,
uint32_t sourceip, uint32_t sourceport) { uint32_t sourceip, uint16_t sourceport) {
// start addr // start addr
uint32_t addr = (type == INNER ? RXR_ENDPOINT_INNER_START_REG uint32_t addr = (type == INNER ? RXR_ENDPOINT_INNER_START_REG
@ -1216,10 +1216,10 @@ int configureMAC() {
uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2; uint64_t srcmac2 = udpDetails[iRxEntry].srcmac2;
uint64_t dstmac = udpDetails[iRxEntry].dstmac; uint64_t dstmac = udpDetails[iRxEntry].dstmac;
uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2; uint64_t dstmac2 = udpDetails[iRxEntry].dstmac2;
int srcport = udpDetails[iRxEntry].srcport; uint16_t srcport = udpDetails[iRxEntry].srcport;
int srcport2 = udpDetails[iRxEntry].srcport2; uint16_t srcport2 = udpDetails[iRxEntry].srcport2;
int dstport = udpDetails[iRxEntry].dstport; uint16_t dstport = udpDetails[iRxEntry].dstport;
int dstport2 = udpDetails[iRxEntry].dstport2; uint16_t dstport2 = udpDetails[iRxEntry].dstport2;
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN];
@ -1243,10 +1243,10 @@ int configureMAC() {
: (selInterface ? "Not Used" : "Used"))); : (selInterface ? "Not Used" : "Used")));
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n\n", "\tDest Port : %hu\n\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
LOG(logINFO, LOG(logINFO,
@ -1256,10 +1256,10 @@ int configureMAC() {
LOG(logINFO, LOG(logINFO,
("\tSource IP2 : %s\n" ("\tSource IP2 : %s\n"
"\tSource MAC2 : %s\n" "\tSource MAC2 : %s\n"
"\tSource Port2: %d\n" "\tSource Port2: %hu\n"
"\tDest IP2 : %s\n" "\tDest IP2 : %s\n"
"\tDest MAC2 : %s\n" "\tDest MAC2 : %s\n"
"\tDest Port2 : %d\n\n", "\tDest Port2 : %hu\n\n",
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2));
} }
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -1963,8 +1963,8 @@ int configureMAC() {
uint32_t dstip = udpDetails[iRxEntry].dstip; uint32_t dstip = udpDetails[iRxEntry].dstip;
uint64_t srcmac = udpDetails[iRxEntry].srcmac; uint64_t srcmac = udpDetails[iRxEntry].srcmac;
uint64_t dstmac = udpDetails[iRxEntry].dstmac; uint64_t dstmac = udpDetails[iRxEntry].dstmac;
int srcport = udpDetails[iRxEntry].srcport; uint16_t srcport = udpDetails[iRxEntry].srcport;
int dstport = udpDetails[iRxEntry].dstport; uint16_t dstport = udpDetails[iRxEntry].dstport;
char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN], char src_mac[MAC_ADDRESS_SIZE], src_ip[INET_ADDRSTRLEN],
dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN]; dst_mac[MAC_ADDRESS_SIZE], dst_ip[INET_ADDRSTRLEN];
@ -1976,10 +1976,10 @@ int configureMAC() {
LOG(logINFOBLUE, ("\tEntry %d\n", iRxEntry)); LOG(logINFOBLUE, ("\tEntry %d\n", iRxEntry));
LOG(logINFO, ("\tSource IP : %s\n" LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n" "\tSource MAC : %s\n"
"\tSource Port : %d\n" "\tSource Port : %hu\n"
"\tDest IP : %s\n" "\tDest IP : %s\n"
"\tDest MAC : %s\n" "\tDest MAC : %s\n"
"\tDest Port : %d\n", "\tDest Port : %hu\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
} }
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -42,10 +42,10 @@ single detector.
enum interfaceType { OUTER, INNER }; enum interfaceType { OUTER, INNER };
typedef struct udpStruct_s { typedef struct udpStruct_s {
int srcport; uint16_t srcport;
int srcport2; uint16_t srcport2;
int dstport; uint16_t dstport;
int dstport2; uint16_t dstport2;
uint64_t srcmac; uint64_t srcmac;
uint64_t srcmac2; uint64_t srcmac2;
uint64_t dstmac; uint64_t dstmac;
@ -467,8 +467,8 @@ void setFirstUDPDestination(int value);
void selectPrimaryInterface(int val); void selectPrimaryInterface(int val);
int getPrimaryInterface(); int getPrimaryInterface();
void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip, void setupHeader(int iRxEntry, enum interfaceType type, uint32_t destip,
uint64_t destmac, uint32_t destport, uint64_t sourcemac, uint64_t destmac, uint16_t destport, uint64_t sourcemac,
uint32_t sourceip, uint32_t sourceport); uint32_t sourceip, uint16_t sourceport);
#endif #endif
#if defined(JUNGFRAUD) || defined(MOENCHD) || defined(GOTTHARD2D) || \ #if defined(JUNGFRAUD) || defined(MOENCHD) || defined(GOTTHARD2D) || \
defined(MYTHEN3D) || defined(CHIPTESTBOARDD) defined(MYTHEN3D) || defined(CHIPTESTBOARDD)
@ -516,7 +516,7 @@ void setDigitalIODelay(uint64_t pinMask, int delay);
// jungfrau/moench specific - powerchip, autocompdisable, clockdiv, asictimer, // jungfrau/moench specific - powerchip, autocompdisable, clockdiv, asictimer,
// clock, pll, flashing firmware // clock, pll, flashing firmware
#if defined(MOENCHED) #if defined(MOENCHD)
void setADCPipeline(int val); void setADCPipeline(int val);
int getADCPipeline(); int getADCPipeline();
#endif #endif

View File

@ -13,6 +13,7 @@
#include "slsDetectorServer_funcs.h" #include "slsDetectorServer_funcs.h"
#include <getopt.h> #include <getopt.h>
#include <limits.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -276,6 +277,15 @@ int main(int argc, char *argv[]) {
LOG(logERROR, ("Could not set handler function for SIGINT")); LOG(logERROR, ("Could not set handler function for SIGINT"));
} }
// validate control and stop port number
if (0 >= portno || portno > USHRT_MAX || 0 >= (portno + 1) ||
(portno + 1) > USHRT_MAX) {
LOG(logERROR, ("Invalid control server or stop server port "
"numbers (%d, %d). It must be in range 1 - %d",
portno, portno + 1, USHRT_MAX));
return -1;
}
if (sharedMemory_create(portno) == FAIL) { if (sharedMemory_create(portno) == FAIL) {
return -1; return -1;
} }

View File

@ -5366,11 +5366,11 @@ int get_dest_udp_mac2(int file_des) {
int set_dest_udp_port(int file_des) { int set_dest_udp_port(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int arg = 0; uint16_t arg = 0;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT16) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logINFO, ("Setting udp destination port: %u\n", arg)); LOG(logINFO, ("Setting udp destination port: %hu\n", arg));
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
@ -5381,30 +5381,30 @@ int set_dest_udp_port(int file_des) {
} }
} }
} }
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT16, NULL, 0);
} }
int get_dest_udp_port(int file_des) { int get_dest_udp_port(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int retval = -1; uint16_t retval = -1;
LOG(logDEBUG1, ("Getting destination port")); LOG(logDEBUG1, ("Getting destination port"));
// get only // get only
retval = udpDetails[0].dstport; retval = udpDetails[0].dstport;
LOG(logDEBUG, ("udp destination port retval: %u\n", retval)); LOG(logDEBUG, ("udp destination port retval: %hu\n", retval));
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT16, &retval, sizeof(retval));
} }
int set_dest_udp_port2(int file_des) { int set_dest_udp_port2(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int arg = 0; uint16_t arg = 0;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT16) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logINFO, ("Setting udp destination port2: %u\n", arg)); LOG(logINFO, ("Setting udp destination port2: %hu\n", arg));
#if !defined(JUNGFRAUD) && !defined(MOENCHD) && !defined(EIGERD) && \ #if !defined(JUNGFRAUD) && !defined(MOENCHD) && !defined(EIGERD) && \
!defined(GOTTHARD2D) !defined(GOTTHARD2D)
@ -5420,13 +5420,13 @@ int set_dest_udp_port2(int file_des) {
} }
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT16, NULL, 0);
} }
int get_dest_udp_port2(int file_des) { int get_dest_udp_port2(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int retval = -1; uint16_t retval = -1;
LOG(logDEBUG1, ("Getting destination port2\n")); LOG(logDEBUG1, ("Getting destination port2\n"));
#if !defined(JUNGFRAUD) && !defined(MOENCHD) && !defined(EIGERD) && \ #if !defined(JUNGFRAUD) && !defined(MOENCHD) && !defined(EIGERD) && \
@ -5435,9 +5435,9 @@ int get_dest_udp_port2(int file_des) {
#else #else
// get only // get only
retval = udpDetails[0].dstport2; retval = udpDetails[0].dstport2;
LOG(logDEBUG1, ("udp destination port2 retval: %u\n", retval)); LOG(logDEBUG1, ("udp destination port2 retval: %hu\n", retval));
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT16, &retval, sizeof(retval));
} }
int set_num_interfaces(int file_des) { int set_num_interfaces(int file_des) {
@ -6990,6 +6990,7 @@ int get_receiver_parameters(int file_des) {
int n = 0; int n = 0;
int i32 = 0; int i32 = 0;
int64_t i64 = 0; int64_t i64 = 0;
uint16_t u16 = 0;
uint32_t u32 = 0; uint32_t u32 = 0;
uint64_t u64 = 0; uint64_t u64 = 0;
@ -7032,8 +7033,8 @@ int get_receiver_parameters(int file_des) {
return printSocketReadError(); return printSocketReadError();
// udp dst port // udp dst port
i32 = udpDetails[0].dstport; u16 = udpDetails[0].dstport;
n += sendData(file_des, &i32, sizeof(i32), INT32); n += sendData(file_des, &u16, sizeof(u16), INT16);
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
@ -7051,8 +7052,8 @@ int get_receiver_parameters(int file_des) {
return printSocketReadError(); return printSocketReadError();
// udp dst port2 // udp dst port2
i32 = udpDetails[0].dstport2; u16 = udpDetails[0].dstport2;
n += sendData(file_des, &i32, sizeof(i32), INT32); n += sendData(file_des, &u16, sizeof(u16), INT16);
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
@ -9170,7 +9171,8 @@ int get_dest_udp_list(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
uint32_t arg = 0; uint32_t arg = 0;
uint32_t retvals[5] = {}; uint16_t retvals16[2] = {};
uint32_t retvals32[3] = {};
uint64_t retvals64[2] = {}; uint64_t retvals64[2] = {};
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
@ -9189,34 +9191,36 @@ int get_dest_udp_list(int file_des) {
MAX_UDP_DESTINATION - 1); MAX_UDP_DESTINATION - 1);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
retvals[0] = arg; // arg;
retvals[1] = udpDetails[arg].dstport; retvals16[0] = udpDetails[arg].dstport;
retvals[2] = udpDetails[arg].dstport2; retvals16[1] = udpDetails[arg].dstport2;
retvals[3] = udpDetails[arg].dstip; retvals32[0] = udpDetails[arg].dstip;
retvals[4] = udpDetails[arg].dstip2; retvals32[1] = udpDetails[arg].dstip2;
retvals64[0] = udpDetails[arg].dstmac; retvals64[0] = udpDetails[arg].dstmac;
retvals64[1] = udpDetails[arg].dstmac2; retvals64[1] = udpDetails[arg].dstmac2;
// swap ip // swap ip
retvals[3] = __builtin_bswap32(retvals[3]); retvals32[0] = __builtin_bswap32(retvals32[0]);
retvals[4] = __builtin_bswap32(retvals[4]); retvals32[1] = __builtin_bswap32(retvals32[1]);
// convert to string // convert to string
char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN];
getIpAddressinString(ip, retvals[3]); getIpAddressinString(ip, retvals32[0]);
getIpAddressinString(ip2, retvals[4]); getIpAddressinString(ip2, retvals32[1]);
char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE]; char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE];
getMacAddressinString(mac, MAC_ADDRESS_SIZE, retvals64[0]); getMacAddressinString(mac, MAC_ADDRESS_SIZE, retvals64[0]);
getMacAddressinString(mac2, MAC_ADDRESS_SIZE, retvals64[1]); getMacAddressinString(mac2, MAC_ADDRESS_SIZE, retvals64[1]);
LOG(logDEBUG1, LOG(logDEBUG1,
("Udp Dest. retval [%d]: [port %d, port2 %d, ip %s, ip2 %s, " ("Udp Dest. retval [%d]: [port %hu, port2 %hu, ip %s, ip2 %s, "
"mac %s, mac2 %s]\n", "mac %s, mac2 %s]\n",
retvals[0], retvals[1], retvals[2], ip, ip2, mac, mac2)); arg, retvals16[0], retvals16[1], ip, ip2, mac, mac2));
} }
#endif #endif
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) { if (ret != FAIL) {
sendData(file_des, retvals, sizeof(retvals), INT32); sendData(file_des, &arg, sizeof(arg), INT32);
sendData(file_des, retvals16, sizeof(retvals16), INT16);
sendData(file_des, retvals32, sizeof(retvals32), INT32);
sendData(file_des, retvals64, sizeof(retvals64), INT64); sendData(file_des, retvals64, sizeof(retvals64), INT64);
} }
return ret; return ret;
@ -9225,22 +9229,28 @@ int get_dest_udp_list(int file_des) {
int set_dest_udp_list(int file_des) { int set_dest_udp_list(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
uint32_t args[5] = {}; uint32_t arg = 0;
uint16_t args16[2] = {};
uint32_t args32[2] = {};
uint64_t args64[2] = {}; uint64_t args64[2] = {};
if (receiveData(file_des, args, sizeof(args), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
if (receiveData(file_des, args16, sizeof(args16), INT16) < 0)
return printSocketReadError();
if (receiveData(file_des, args32, sizeof(args32), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
if (receiveData(file_des, args64, sizeof(args64), INT64) < 0) if (receiveData(file_des, args64, sizeof(args64), INT64) < 0)
return printSocketReadError(); return printSocketReadError();
// swap ip // swap ip
args[3] = __builtin_bswap32(args[3]); args32[0] = __builtin_bswap32(args32[0]);
args[4] = __builtin_bswap32(args[4]); args32[1] = __builtin_bswap32(args32[1]);
// convert to string // convert to string
char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN];
getIpAddressinString(ip, args[3]); getIpAddressinString(ip, args32[0]);
getIpAddressinString(ip2, args[4]); getIpAddressinString(ip2, args32[1]);
char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE]; char mac[MAC_ADDRESS_SIZE], mac2[MAC_ADDRESS_SIZE];
getMacAddressinString(mac, MAC_ADDRESS_SIZE, args64[0]); getMacAddressinString(mac, MAC_ADDRESS_SIZE, args64[0]);
getMacAddressinString(mac2, MAC_ADDRESS_SIZE, args64[1]); getMacAddressinString(mac2, MAC_ADDRESS_SIZE, args64[1]);
@ -9251,11 +9261,11 @@ int set_dest_udp_list(int file_des) {
#else #else
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
int entry = args[0]; int entry = arg;
LOG(logINFOBLUE, LOG(logINFOBLUE,
("Setting udp dest. [%d]: [port %d, port2 %d, ip %s, ip2 %s, " ("Setting udp dest. [%d]: [port %hu, port2 %hu, ip %s, ip2 %s, "
"mac %s, mac2 %s]\n", "mac %s, mac2 %s]\n",
entry, args[1], args[2], ip, ip2, mac, mac2)); entry, args16[0], args16[1], ip, ip2, mac, mac2));
if (entry < 1 || entry >= MAX_UDP_DESTINATION) { if (entry < 1 || entry >= MAX_UDP_DESTINATION) {
ret = FAIL; ret = FAIL;
@ -9266,7 +9276,7 @@ int set_dest_udp_list(int file_des) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
#if defined(EIGERD) || defined(MYTHEN3D) #if defined(EIGERD) || defined(MYTHEN3D)
else if (args[4] != 0 || args64[1] != 0) { else if (args32[1] != 0 || args64[1] != 0) {
ret = FAIL; ret = FAIL;
strcpy(mess, "Could not set udp destination. ip2 and mac2 not " strcpy(mess, "Could not set udp destination. ip2 and mac2 not "
"implemented for this detector.\n"); "implemented for this detector.\n");
@ -9275,17 +9285,17 @@ int set_dest_udp_list(int file_des) {
#endif #endif
else { else {
if (check_detector_idle("set udp destination list entries") == OK) { if (check_detector_idle("set udp destination list entries") == OK) {
if (args[1] != 0) { if (args16[0] != 0) {
udpDetails[entry].dstport = args[1]; udpDetails[entry].dstport = args16[0];
} }
if (args[2] != 0) { if (args16[1] != 0) {
udpDetails[entry].dstport2 = args[2]; udpDetails[entry].dstport2 = args16[1];
} }
if (args[3] != 0) { if (args32[0] != 0) {
udpDetails[entry].dstip = args[3]; udpDetails[entry].dstip = args32[0];
} }
if (args[4] != 0) { if (args32[1] != 0) {
udpDetails[entry].dstip2 = args[4]; udpDetails[entry].dstip2 = args32[1];
} }
if (args64[0] != 0) { if (args64[0] != 0) {
udpDetails[entry].dstmac = args64[0]; udpDetails[entry].dstmac = args64[0];

View File

@ -66,7 +66,7 @@ class Detector {
/** connects to n servers at local host starting at specific control port. /** connects to n servers at local host starting at specific control port.
* Every virtual server will have a stop port (control port + 1) */ * Every virtual server will have a stop port (control port + 1) */
void setVirtualDetectorServers(int numServers, int startingPort); void setVirtualDetectorServers(int numServers, uint16_t startingPort);
/** Gets shared memory ID */ /** Gets shared memory ID */
int getShmId() const; int getShmId() const;
@ -791,20 +791,20 @@ class Detector {
*/ */
void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {}); void setDestinationUDPMAC2(const MacAddr mac, Positions pos = {});
Result<int> getDestinationUDPPort(Positions pos = {}) const; Result<uint16_t> getDestinationUDPPort(Positions pos = {}) const;
/** Default is 50001. \n If module_id is -1, ports for each module is /** Default is 50001. \n If module_id is -1, ports for each module is
* calculated (incremented by 1 if no 2nd interface) */ * calculated (incremented by 1 if no 2nd interface) */
void setDestinationUDPPort(int port, int module_id = -1); void setDestinationUDPPort(uint16_t port, int module_id = -1);
/** [Eiger] right port[Jungfrau][Moench] bottom half [Gotthard2] veto /** [Eiger] right port[Jungfrau][Moench] bottom half [Gotthard2] veto
* debugging */ * debugging */
Result<int> getDestinationUDPPort2(Positions pos = {}) const; Result<uint16_t> getDestinationUDPPort2(Positions pos = {}) const;
/** [Eiger] right port[Jungfrau][Moench] bottom half [Gotthard2] veto /** [Eiger] right port[Jungfrau][Moench] bottom half [Gotthard2] veto
* debugging \n Default is 50002. \n If module_id is -1, ports for each * debugging \n Default is 50002. \n If module_id is -1, ports for each
* module is calculated (incremented by 1 if no 2nd interface)*/ * module is calculated (incremented by 1 if no 2nd interface)*/
void setDestinationUDPPort2(int port, int module_id = -1); void setDestinationUDPPort2(uint16_t port, int module_id = -1);
/** Reconfigures Detector with UDP destination. More for debugging as the /** Reconfigures Detector with UDP destination. More for debugging as the
* configuration is done automatically when the detector has sufficient UDP * configuration is done automatically when the detector has sufficient UDP
@ -904,14 +904,14 @@ class Detector {
/** multiple rx hostnames. Single element will set it for all */ /** multiple rx hostnames. Single element will set it for all */
void setRxHostname(const std::vector<std::string> &name); void setRxHostname(const std::vector<std::string> &name);
Result<int> getRxPort(Positions pos = {}) const; Result<uint16_t> getRxPort(Positions pos = {}) const;
/** TCP port for client-receiver communication. \n /** TCP port for client-receiver communication. \n
* Default is 1954. \n Must be different if multiple receivers on same pc. * Default is 1954. \n Must be different if multiple receivers on same pc.
* \n Must be first command to set a receiver parameter to be able to * \n Must be first command to set a receiver parameter to be able to
* communicate. \n Multi command will automatically increment port for * communicate. \n Multi command will automatically increment port for
* individual modules.*/ * individual modules.*/
void setRxPort(int port, int module_id = -1); void setRxPort(uint16_t port, int module_id = -1);
Result<int> getRxFifoDepth(Positions pos = {}) const; Result<int> getRxFifoDepth(Positions pos = {}) const;
@ -1089,7 +1089,7 @@ class Detector {
*/ */
void setRxZmqStartingFrame(int fnum, Positions pos = {}); void setRxZmqStartingFrame(int fnum, Positions pos = {});
Result<int> getRxZmqPort(Positions pos = {}) const; Result<uint16_t> getRxZmqPort(Positions pos = {}) const;
/** Zmq port for data to be streamed out of the receiver. \n /** Zmq port for data to be streamed out of the receiver. \n
* Also restarts receiver zmq streaming if enabled. \n Default is 30001. \n * Also restarts receiver zmq streaming if enabled. \n Default is 30001. \n
@ -1098,7 +1098,7 @@ class Detector {
* no 2nd interface). \n Restarts receiver zmq sockets only if it was * no 2nd interface). \n Restarts receiver zmq sockets only if it was
* already enabled * already enabled
*/ */
void setRxZmqPort(int port, int module_id = -1); void setRxZmqPort(uint16_t port, int module_id = -1);
Result<IpAddr> getRxZmqIP(Positions pos = {}) const; Result<IpAddr> getRxZmqIP(Positions pos = {}) const;
@ -1108,7 +1108,7 @@ class Detector {
* receiver. */ * receiver. */
void setRxZmqIP(const IpAddr ip, Positions pos = {}); void setRxZmqIP(const IpAddr ip, Positions pos = {});
Result<int> getClientZmqPort(Positions pos = {}) const; Result<uint16_t> getClientZmqPort(Positions pos = {}) const;
/** Port number to listen to zmq data streamed out from receiver or /** Port number to listen to zmq data streamed out from receiver or
* intermediate process. \n Must be different for every detector (and udp * intermediate process. \n Must be different for every detector (and udp
@ -1117,7 +1117,7 @@ class Detector {
* sockets only if it was already enabled \n Default connects to receiver * sockets only if it was already enabled \n Default connects to receiver
* zmq streaming out port (30001). * zmq streaming out port (30001).
*/ */
void setClientZmqPort(int port, int module_id = -1); void setClientZmqPort(uint16_t port, int module_id = -1);
Result<IpAddr> getClientZmqIp(Positions pos = {}) const; Result<IpAddr> getClientZmqIp(Positions pos = {}) const;
@ -2068,18 +2068,18 @@ class Detector {
* * * *
* ************************************************/ * ************************************************/
Result<int> getControlPort(Positions pos = {}) const; Result<uint16_t> getControlPort(Positions pos = {}) const;
/** Detector Control TCP port (for client communication with Detector /** Detector Control TCP port (for client communication with Detector
* control server) Default is 1952. Normally unchanged. Set different ports * control server) Default is 1952. Normally unchanged. Set different ports
* for virtual servers on same pc */ * for virtual servers on same pc */
void setControlPort(int value, Positions pos = {}); void setControlPort(uint16_t value, Positions pos = {});
Result<int> getStopPort(Positions pos = {}) const; Result<uint16_t> getStopPort(Positions pos = {}) const;
/** Port number of the stop server on detector for detector-client tcp /** Port number of the stop server on detector for detector-client tcp
* interface. Default is 1953. Normally unchanged. */ * interface. Default is 1953. Normally unchanged. */
void setStopPort(int value, Positions pos = {}); void setStopPort(uint16_t value, Positions pos = {});
Result<bool> getDetectorLock(Positions pos = {}) const; Result<bool> getDetectorLock(Positions pos = {}) const;
@ -2112,7 +2112,7 @@ class Detector {
///@} ///@}
private: private:
std::vector<int> getPortNumbers(int start_port); std::vector<uint16_t> getValidPortNumbers(uint16_t start_port);
void updateRxRateCorrections(); void updateRxRateCorrections();
void setNumberofUDPInterfaces_(int n, Positions pos); void setNumberofUDPInterfaces_(int n, Positions pos);
}; };

View File

@ -197,7 +197,7 @@ std::string CmdProxy::VirtualServer(int action) {
throw RuntimeError("Cannot execute this at module level"); throw RuntimeError("Cannot execute this at module level");
} }
det->setVirtualDetectorServers(StringTo<int>(args[0]), det->setVirtualDetectorServers(StringTo<int>(args[0]),
StringTo<int>(args[1])); StringTo<uint16_t>(args[1]));
os << ToString(args); os << ToString(args);
} else { } else {
throw RuntimeError("Unknown action"); throw RuntimeError("Unknown action");

View File

@ -187,7 +187,6 @@ namespace sls {
return os.str(); \ return os.str(); \
} }
/** int or enum */
#define INTEGER_COMMAND_VEC_ID_GET(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \ #define INTEGER_COMMAND_VEC_ID_GET(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
std::string CMDNAME(const int action) { \ std::string CMDNAME(const int action) { \
std::ostringstream os; \ std::ostringstream os; \
@ -1976,14 +1975,14 @@ class CmdProxy {
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_GET(
udp_dstport, getDestinationUDPPort, setDestinationUDPPort, udp_dstport, getDestinationUDPPort, setDestinationUDPPort,
StringTo<int>, StringTo<uint16_t>,
"[n]\n\tPort number of the receiver (destination) udp " "[n]\n\tPort number of the receiver (destination) udp "
"interface. Default is 50001. \n\tIf multi command, ports for each " "interface. Default is 50001. \n\tIf multi command, ports for each "
"module is calculated (incremented by 1 if no 2nd interface)"); "module is calculated (incremented by 1 if no 2nd interface)");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_GET(
udp_dstport2, getDestinationUDPPort2, setDestinationUDPPort2, udp_dstport2, getDestinationUDPPort2, setDestinationUDPPort2,
StringTo<int>, StringTo<uint16_t>,
"[n]\n\t[Jungfrau][Moench][Eiger][Gotthard2] Port number of the " "[n]\n\t[Jungfrau][Moench][Eiger][Gotthard2] Port number of the "
"receiver (destination) udp interface 2. Default is 50002. " "receiver (destination) udp interface 2. Default is 50002. "
"\n\tIf multi command, ports for each module is calculated " "\n\tIf multi command, ports for each module is calculated "
@ -2041,7 +2040,7 @@ class CmdProxy {
/* Receiver Config */ /* Receiver Config */
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_GET(
rx_tcpport, getRxPort, setRxPort, StringTo<int>, rx_tcpport, getRxPort, setRxPort, StringTo<uint16_t>,
"[port]\n\tTCP port for client-receiver communication. Default is " "[port]\n\tTCP port for client-receiver communication. Default is "
"1954. Must be different if multiple receivers on same pc. Must be " "1954. Must be different if multiple receivers on same pc. Must be "
"first command to set a receiver parameter. Multi command will " "first command to set a receiver parameter. Multi command will "
@ -2172,7 +2171,7 @@ class CmdProxy {
"and then depending on the rx zmq frequency/ timer"); "and then depending on the rx zmq frequency/ timer");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_GET(
rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<int>, rx_zmqport, getRxZmqPort, setRxZmqPort, StringTo<uint16_t>,
"[port]\n\tZmq port for data to be streamed out of the receiver. " "[port]\n\tZmq port for data to be streamed out of the receiver. "
"Also restarts receiver zmq streaming if enabled. Default is 30001. " "Also restarts receiver zmq streaming if enabled. Default is 30001. "
"Modified only when using an intermediate process between receiver and " "Modified only when using an intermediate process between receiver and "
@ -2180,7 +2179,7 @@ class CmdProxy {
"Multi command will automatically increment for individual modules."); "Multi command will automatically increment for individual modules.");
INTEGER_COMMAND_VEC_ID_GET( INTEGER_COMMAND_VEC_ID_GET(
zmqport, getClientZmqPort, setClientZmqPort, StringTo<int>, zmqport, getClientZmqPort, setClientZmqPort, StringTo<uint16_t>,
"[port]\n\tZmq port in client(gui) or intermediate process for " "[port]\n\tZmq port in client(gui) or intermediate process for "
"data to be streamed to from receiver. Default connects to receiver " "data to be streamed to from receiver. Default connects to receiver "
"zmq streaming out port (30001). Modified only when using an " "zmq streaming out port (30001). Modified only when using an "
@ -2619,13 +2618,13 @@ class CmdProxy {
/* Insignificant */ /* Insignificant */
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID(
port, getControlPort, setControlPort, StringTo<int>, port, getControlPort, setControlPort, StringTo<uint16_t>,
"[n]\n\tPort number of the control server on detector for " "[n]\n\tPort number of the control server on detector for "
"detector-client tcp interface. Default is 1952. Normally unchanged. " "detector-client tcp interface. Default is 1952. Normally unchanged. "
"Set different ports for virtual servers on same pc."); "Set different ports for virtual servers on same pc.");
INTEGER_COMMAND_VEC_ID( INTEGER_COMMAND_VEC_ID(
stopport, getStopPort, setStopPort, StringTo<int>, stopport, getStopPort, setStopPort, StringTo<uint16_t>,
"[n]\n\tPort number of the stop server on detector for detector-client " "[n]\n\tPort number of the stop server on detector for detector-client "
"tcp interface. Default is 1953. Normally unchanged."); "tcp interface. Default is 1953. Normally unchanged.");

View File

@ -107,7 +107,9 @@ void Detector::setHostname(const std::vector<std::string> &hostname) {
pimpl->setHostname(hostname); pimpl->setHostname(hostname);
} }
void Detector::setVirtualDetectorServers(int numServers, int startingPort) { void Detector::setVirtualDetectorServers(int numServers,
uint16_t startingPort) {
validatePortRange(startingPort, numServers * 2);
pimpl->setVirtualDetectorServers(numServers, startingPort); pimpl->setVirtualDetectorServers(numServers, startingPort);
} }
@ -982,10 +984,10 @@ void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
throw RuntimeError("No modules added."); throw RuntimeError("No modules added.");
} }
bool previouslyClientStreaming = pimpl->getDataStreamingToClient(); bool previouslyClientStreaming = pimpl->getDataStreamingToClient();
int clientStartingPort = getClientZmqPort({0}).squash(0); uint16_t clientStartingPort = getClientZmqPort({0}).squash(0);
bool useReceiver = getUseReceiverFlag().squash(false); bool useReceiver = getUseReceiverFlag().squash(false);
bool previouslyReceiverStreaming = false; bool previouslyReceiverStreaming = false;
int rxStartingPort = 0; uint16_t rxStartingPort = 0;
if (useReceiver) { if (useReceiver) {
previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true); previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true);
rxStartingPort = getRxZmqPort({0}).squash(0); rxStartingPort = getRxZmqPort({0}).squash(0);
@ -1108,34 +1110,36 @@ void Detector::setDestinationUDPMAC2(const MacAddr mac, Positions pos) {
pimpl->Parallel(&Module::setDestinationUDPMAC2, pos, mac); pimpl->Parallel(&Module::setDestinationUDPMAC2, pos, mac);
} }
Result<int> Detector::getDestinationUDPPort(Positions pos) const { Result<uint16_t> Detector::getDestinationUDPPort(Positions pos) const {
return pimpl->Parallel(&Module::getDestinationUDPPort, pos); return pimpl->Parallel(&Module::getDestinationUDPPort, pos);
} }
void Detector::setDestinationUDPPort(int port, int module_id) { void Detector::setDestinationUDPPort(uint16_t port, int module_id) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<uint16_t> port_list = getValidPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setDestinationUDPPort, {idet}, pimpl->Parallel(&Module::setDestinationUDPPort, {idet},
port_list[idet]); port_list[idet]);
} }
} else { } else {
validatePortNumber(port);
pimpl->Parallel(&Module::setDestinationUDPPort, {module_id}, port); pimpl->Parallel(&Module::setDestinationUDPPort, {module_id}, port);
} }
} }
Result<int> Detector::getDestinationUDPPort2(Positions pos) const { Result<uint16_t> Detector::getDestinationUDPPort2(Positions pos) const {
return pimpl->Parallel(&Module::getDestinationUDPPort2, pos); return pimpl->Parallel(&Module::getDestinationUDPPort2, pos);
} }
void Detector::setDestinationUDPPort2(int port, int module_id) { void Detector::setDestinationUDPPort2(uint16_t port, int module_id) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<uint16_t> port_list = getValidPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setDestinationUDPPort2, {idet}, pimpl->Parallel(&Module::setDestinationUDPPort2, {idet},
port_list[idet]); port_list[idet]);
} }
} else { } else {
validatePortNumber(port);
pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port); pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port);
} }
} }
@ -1235,21 +1239,23 @@ void Detector::setRxHostname(const std::vector<std::string> &name) {
updateRxRateCorrections(); updateRxRateCorrections();
} }
Result<int> Detector::getRxPort(Positions pos) const { Result<uint16_t> Detector::getRxPort(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverPort, pos); return pimpl->Parallel(&Module::getReceiverPort, pos);
} }
void Detector::setRxPort(int port, int module_id) { void Detector::setRxPort(uint16_t port, int module_id) {
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list(size()); validatePortRange(port, size() - 1);
for (auto &it : port_list) {
it = port++; std::vector<uint16_t> port_list(size());
} std::iota(std::begin(port_list), std::end(port_list), port);
// no need to verify hostname-port combo as unique port(incremented) // no need to verify hostname-port combo as unique port(incremented)
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet]); pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet]);
} }
} else { } else {
validatePortNumber(port);
pimpl->verifyUniqueRxHost(port, module_id); pimpl->verifyUniqueRxHost(port, module_id);
pimpl->Parallel(&Module::setReceiverPort, {module_id}, port); pimpl->Parallel(&Module::setReceiverPort, {module_id}, port);
} }
@ -1440,20 +1446,21 @@ void Detector::setRxZmqStartingFrame(int fnum, Positions pos) {
pimpl->Parallel(&Module::setReceiverStreamingStartingFrame, pos, fnum); pimpl->Parallel(&Module::setReceiverStreamingStartingFrame, pos, fnum);
} }
Result<int> Detector::getRxZmqPort(Positions pos) const { Result<uint16_t> Detector::getRxZmqPort(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStreamingPort, pos); return pimpl->Parallel(&Module::getReceiverStreamingPort, pos);
} }
void Detector::setRxZmqPort(int port, int module_id) { void Detector::setRxZmqPort(uint16_t port, int module_id) {
bool previouslyReceiverStreaming = bool previouslyReceiverStreaming =
getRxZmqDataStream(std::vector<int>{module_id}).squash(false); getRxZmqDataStream(std::vector<int>{module_id}).squash(false);
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<uint16_t> port_list = getValidPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setReceiverStreamingPort, {idet}, pimpl->Parallel(&Module::setReceiverStreamingPort, {idet},
port_list[idet]); port_list[idet]);
} }
} else { } else {
validatePortNumber(port);
pimpl->Parallel(&Module::setReceiverStreamingPort, {module_id}, port); pimpl->Parallel(&Module::setReceiverStreamingPort, {module_id}, port);
} }
if (previouslyReceiverStreaming) { if (previouslyReceiverStreaming) {
@ -1475,19 +1482,20 @@ void Detector::setRxZmqIP(const IpAddr ip, Positions pos) {
} }
} }
Result<int> Detector::getClientZmqPort(Positions pos) const { Result<uint16_t> Detector::getClientZmqPort(Positions pos) const {
return pimpl->Parallel(&Module::getClientStreamingPort, pos); return pimpl->Parallel(&Module::getClientStreamingPort, pos);
} }
void Detector::setClientZmqPort(int port, int module_id) { void Detector::setClientZmqPort(uint16_t port, int module_id) {
bool previouslyClientStreaming = pimpl->getDataStreamingToClient(); bool previouslyClientStreaming = pimpl->getDataStreamingToClient();
if (module_id == -1) { if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port); std::vector<uint16_t> port_list = getValidPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel(&Module::setClientStreamingPort, {idet}, pimpl->Parallel(&Module::setClientStreamingPort, {idet},
port_list[idet]); port_list[idet]);
} }
} else { } else {
validatePortNumber(port);
pimpl->Parallel(&Module::setClientStreamingPort, {module_id}, port); pimpl->Parallel(&Module::setClientStreamingPort, {module_id}, port);
} }
if (previouslyClientStreaming) { if (previouslyClientStreaming) {
@ -2665,21 +2673,23 @@ void Detector::setADCInvert(uint32_t value, Positions pos) {
// Insignificant // Insignificant
Result<int> Detector::getControlPort(Positions pos) const { Result<uint16_t> Detector::getControlPort(Positions pos) const {
return pimpl->Parallel(&Module::getControlPort, pos); return pimpl->Parallel(&Module::getControlPort, pos);
} }
void Detector::setControlPort(int value, Positions pos) { void Detector::setControlPort(uint16_t value, Positions pos) {
validatePortNumber(value);
pimpl->verifyUniqueDetHost(value, pos); pimpl->verifyUniqueDetHost(value, pos);
pimpl->Parallel(&Module::setControlPort, pos, value); pimpl->Parallel(&Module::setControlPort, pos, value);
} }
Result<int> Detector::getStopPort(Positions pos) const { Result<uint16_t> Detector::getStopPort(Positions pos) const {
// not verifying unique stop port (control port is sufficient) // not verifying unique stop port (control port is sufficient)
return pimpl->Parallel(&Module::getStopPort, pos); return pimpl->Parallel(&Module::getStopPort, pos);
} }
void Detector::setStopPort(int value, Positions pos) { void Detector::setStopPort(uint16_t value, Positions pos) {
validatePortNumber(value);
pimpl->Parallel(&Module::setStopPort, pos, value); pimpl->Parallel(&Module::setStopPort, pos, value);
} }
@ -2714,13 +2724,17 @@ Result<ns> Detector::getMeasurementTime(Positions pos) const {
std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); } std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); }
std::vector<int> Detector::getPortNumbers(int start_port) { std::vector<uint16_t> Detector::getValidPortNumbers(uint16_t start_port) {
int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash( int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash(
"Number of UDP Interfaces is not consistent among modules"); "Number of UDP Interfaces is not consistent among modules");
std::vector<int> res;
validatePortRange(start_port, (size() - 1) * num_sockets_per_detector);
std::vector<uint16_t> res;
res.reserve(size()); res.reserve(size());
for (int idet = 0; idet < size(); ++idet) { for (int idet = 0; idet < size(); ++idet) {
res.push_back(start_port + (idet * num_sockets_per_detector)); uint16_t port = start_port + (idet * num_sockets_per_detector);
res.push_back(port);
} }
return res; return res;
} }

View File

@ -242,7 +242,8 @@ std::string DetectorImpl::exec(const char *cmd) {
return result; return result;
} }
void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) { void DetectorImpl::setVirtualDetectorServers(const int numdet,
const uint16_t port) {
std::vector<std::string> hostnames; std::vector<std::string> hostnames;
for (int i = 0; i < numdet; ++i) { for (int i = 0; i < numdet; ++i) {
// * 2 is for control and stop port // * 2 is for control and stop port
@ -283,7 +284,7 @@ void DetectorImpl::addModule(const std::string &name) {
LOG(logINFO) << "Adding module " << name; LOG(logINFO) << "Adding module " << name;
auto host = verifyUniqueDetHost(name); auto host = verifyUniqueDetHost(name);
std::string hostname = host.first; std::string hostname = host.first;
int port = host.second; uint16_t port = host.second;
// get type by connecting // get type by connecting
detectorType type = Module::getTypeFromDetector(hostname, port); detectorType type = Module::getTypeFromDetector(hostname, port);
@ -1583,41 +1584,41 @@ defs::xy DetectorImpl::calculatePosition(int moduleIndex,
return pos; return pos;
} }
void DetectorImpl::verifyUniqueDetHost(const int port, void DetectorImpl::verifyUniqueDetHost(const uint16_t port,
std::vector<int> positions) const { std::vector<int> positions) const {
// port for given positions // port for given positions
if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) {
positions.resize(modules.size()); positions.resize(modules.size());
std::iota(begin(positions), end(positions), 0); std::iota(begin(positions), end(positions), 0);
} }
std::vector<std::pair<std::string, int>> hosts(size()); std::vector<std::pair<std::string, uint16_t>> hosts(size());
for (auto it : positions) { for (auto it : positions) {
hosts[it].second = port; hosts[it].second = port;
} }
verifyUniqueHost(true, hosts); verifyUniqueHost(true, hosts);
} }
void DetectorImpl::verifyUniqueRxHost(const int port, void DetectorImpl::verifyUniqueRxHost(const uint16_t port,
const int moduleId) const { const int moduleId) const {
std::vector<std::pair<std::string, int>> hosts(size()); std::vector<std::pair<std::string, uint16_t>> hosts(size());
hosts[moduleId].second = port; hosts[moduleId].second = port;
verifyUniqueHost(false, hosts); verifyUniqueHost(false, hosts);
} }
std::pair<std::string, int> std::pair<std::string, uint16_t>
DetectorImpl::verifyUniqueDetHost(const std::string &name) { DetectorImpl::verifyUniqueDetHost(const std::string &name) {
// extract port // extract port
// C++17 could be auto [hostname, port] = ParseHostPort(name); // C++17 could be auto [hostname, port] = ParseHostPort(name);
auto res = ParseHostPort(name); auto res = ParseHostPort(name);
std::string hostname = res.first; std::string hostname = res.first;
int port = res.second; uint16_t port = res.second;
if (port == 0) { if (port == 0) {
port = DEFAULT_TCP_CNTRL_PORTNO; port = DEFAULT_TCP_CNTRL_PORTNO;
} }
int detSize = size(); int detSize = size();
// mod not yet added // mod not yet added
std::vector<std::pair<std::string, int>> hosts(detSize + 1); std::vector<std::pair<std::string, uint16_t>> hosts(detSize + 1);
hosts[detSize].first = hostname; hosts[detSize].first = hostname;
hosts[detSize].second = port; hosts[detSize].second = port;
@ -1625,7 +1626,7 @@ DetectorImpl::verifyUniqueDetHost(const std::string &name) {
return std::make_pair(hostname, port); return std::make_pair(hostname, port);
} }
std::pair<std::string, int> std::pair<std::string, uint16_t>
DetectorImpl::verifyUniqueRxHost(const std::string &name, DetectorImpl::verifyUniqueRxHost(const std::string &name,
std::vector<int> positions) const { std::vector<int> positions) const {
// no checks if setting to none // no checks if setting to none
@ -1636,7 +1637,7 @@ DetectorImpl::verifyUniqueRxHost(const std::string &name,
// C++17 could be auto [hostname, port] = ParseHostPort(name); // C++17 could be auto [hostname, port] = ParseHostPort(name);
auto res = ParseHostPort(name); auto res = ParseHostPort(name);
std::string hostname = res.first; std::string hostname = res.first;
int port = res.second; uint16_t port = res.second;
// hostname and port for given positions // hostname and port for given positions
if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) { if (positions.empty() || (positions.size() == 1 && positions[0] == -1)) {
@ -1644,7 +1645,7 @@ DetectorImpl::verifyUniqueRxHost(const std::string &name,
std::iota(begin(positions), end(positions), 0); std::iota(begin(positions), end(positions), 0);
} }
std::vector<std::pair<std::string, int>> hosts(size()); std::vector<std::pair<std::string, uint16_t>> hosts(size());
for (auto it : positions) { for (auto it : positions) {
hosts[it].first = hostname; hosts[it].first = hostname;
hosts[it].second = port; hosts[it].second = port;
@ -1654,7 +1655,7 @@ DetectorImpl::verifyUniqueRxHost(const std::string &name,
return std::make_pair(hostname, port); return std::make_pair(hostname, port);
} }
std::vector<std::pair<std::string, int>> std::vector<std::pair<std::string, uint16_t>>
DetectorImpl::verifyUniqueRxHost(const std::vector<std::string> &names) const { DetectorImpl::verifyUniqueRxHost(const std::vector<std::string> &names) const {
if ((int)names.size() != size()) { if ((int)names.size() != size()) {
throw RuntimeError( throw RuntimeError(
@ -1663,7 +1664,7 @@ DetectorImpl::verifyUniqueRxHost(const std::vector<std::string> &names) const {
} }
// extract ports // extract ports
std::vector<std::pair<std::string, int>> hosts; std::vector<std::pair<std::string, uint16_t>> hosts;
for (const auto &name : names) { for (const auto &name : names) {
hosts.push_back(ParseHostPort(name)); hosts.push_back(ParseHostPort(name));
} }
@ -1673,7 +1674,7 @@ DetectorImpl::verifyUniqueRxHost(const std::vector<std::string> &names) const {
} }
void DetectorImpl::verifyUniqueHost( void DetectorImpl::verifyUniqueHost(
bool isDet, std::vector<std::pair<std::string, int>> &hosts) const { bool isDet, std::vector<std::pair<std::string, uint16_t>> &hosts) const {
// fill from shm if not provided // fill from shm if not provided
for (int i = 0; i != size(); ++i) { for (int i = 0; i != size(); ++i) {
@ -1689,7 +1690,7 @@ void DetectorImpl::verifyUniqueHost(
// remove the ones without a hostname // remove the ones without a hostname
hosts.erase(std::remove_if(hosts.begin(), hosts.end(), hosts.erase(std::remove_if(hosts.begin(), hosts.end(),
[](const std::pair<std::string, int> &x) { [](const std::pair<std::string, uint16_t> &x) {
return (x.first == "none" || return (x.first == "none" ||
x.first.empty()); x.first.empty());
}), }),

View File

@ -220,7 +220,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
* @param numdet number of modules * @param numdet number of modules
* @param port starting port number * @param port starting port number
*/ */
void setVirtualDetectorServers(const int numdet, const int port); void setVirtualDetectorServers(const int numdet, const uint16_t port);
/** Sets the hostname of all sls modules in shared memory and updates /** Sets the hostname of all sls modules in shared memory and updates
* local cache */ * local cache */
@ -307,14 +307,16 @@ class DetectorImpl : public virtual slsDetectorDefs {
void setDefaultDac(defs::dacIndex index, int defaultValue, void setDefaultDac(defs::dacIndex index, int defaultValue,
defs::detectorSettings sett, Positions pos); defs::detectorSettings sett, Positions pos);
void verifyUniqueDetHost(const int port, std::vector<int> positions) const; void verifyUniqueDetHost(const uint16_t port,
void verifyUniqueRxHost(const int port, const int moduleId) const; std::vector<int> positions) const;
void verifyUniqueRxHost(const uint16_t port, const int moduleId) const;
std::pair<std::string, int> verifyUniqueDetHost(const std::string &name); std::pair<std::string, uint16_t>
std::pair<std::string, int> verifyUniqueDetHost(const std::string &name);
std::pair<std::string, uint16_t>
verifyUniqueRxHost(const std::string &name, verifyUniqueRxHost(const std::string &name,
std::vector<int> positions) const; std::vector<int> positions) const;
std::vector<std::pair<std::string, int>> std::vector<std::pair<std::string, uint16_t>>
verifyUniqueRxHost(const std::vector<std::string> &names) const; verifyUniqueRxHost(const std::vector<std::string> &names) const;
defs::ROI getRxROI() const; defs::ROI getRxROI() const;
@ -439,9 +441,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
defs::xy getPortGeometry() const; defs::xy getPortGeometry() const;
defs::xy calculatePosition(int moduleIndex, defs::xy geometry) const; defs::xy calculatePosition(int moduleIndex, defs::xy geometry) const;
void void verifyUniqueHost(
verifyUniqueHost(bool isDet, bool isDet, std::vector<std::pair<std::string, uint16_t>> &hosts) const;
std::vector<std::pair<std::string, int>> &hosts) const;
const int detectorIndex{0}; const int detectorIndex{0};
SharedMemory<sharedDetector> shm{0, -1}; SharedMemory<sharedDetector> shm{0, -1};

View File

@ -165,11 +165,15 @@ std::string Module::getReceiverSoftwareVersion() const {
// static function // static function
slsDetectorDefs::detectorType slsDetectorDefs::detectorType
Module::getTypeFromDetector(const std::string &hostname, int cport) { Module::getTypeFromDetector(const std::string &hostname, uint16_t cport) {
LOG(logDEBUG1) << "Getting Module type "; LOG(logDEBUG1) << "Getting Module type ";
ClientSocket socket("Detector", hostname, cport); ClientSocket socket("Detector", hostname, cport);
socket.Send(F_GET_DETECTOR_TYPE); socket.Send(F_GET_DETECTOR_TYPE);
socket.Receive<int>(); // TODO! Should we look at this OK/FAIL? if (socket.Receive<int>() == FAIL) {
throw RuntimeError("Detector (" + hostname + ", " +
std::to_string(cport) +
") returned error at getting detector type");
}
auto retval = socket.Receive<detectorType>(); auto retval = socket.Receive<detectorType>();
LOG(logDEBUG1) << "Module type is " << retval; LOG(logDEBUG1) << "Module type is " << retval;
return retval; return retval;
@ -1241,22 +1245,22 @@ void Module::setDestinationUDPMAC2(const MacAddr mac) {
sendToDetector(F_SET_DEST_UDP_MAC2, mac, nullptr); sendToDetector(F_SET_DEST_UDP_MAC2, mac, nullptr);
} }
int Module::getDestinationUDPPort() const { uint16_t Module::getDestinationUDPPort() const {
return sendToDetector<int>(F_GET_DEST_UDP_PORT); return sendToDetector<uint16_t>(F_GET_DEST_UDP_PORT);
} }
void Module::setDestinationUDPPort(const int port) { void Module::setDestinationUDPPort(const uint16_t port) {
sendToDetector(F_SET_DEST_UDP_PORT, port, nullptr); sendToDetector(F_SET_DEST_UDP_PORT, port, nullptr);
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
sendToReceiver(F_SET_RECEIVER_UDP_PORT, port, nullptr); sendToReceiver(F_SET_RECEIVER_UDP_PORT, port, nullptr);
} }
} }
int Module::getDestinationUDPPort2() const { uint16_t Module::getDestinationUDPPort2() const {
return sendToDetector<int>(F_GET_DEST_UDP_PORT2); return sendToDetector<uint16_t>(F_GET_DEST_UDP_PORT2);
} }
void Module::setDestinationUDPPort2(const int port) { void Module::setDestinationUDPPort2(const uint16_t port) {
sendToDetector(F_SET_DEST_UDP_PORT2, port, nullptr); sendToDetector(F_SET_DEST_UDP_PORT2, port, nullptr);
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
sendToReceiver(F_SET_RECEIVER_UDP_PORT2, port, nullptr); sendToReceiver(F_SET_RECEIVER_UDP_PORT2, port, nullptr);
@ -1354,7 +1358,8 @@ std::string Module::getReceiverHostname() const {
return std::string(shm()->rxHostname); return std::string(shm()->rxHostname);
} }
void Module::setReceiverHostname(const std::string &hostname, const int port, void Module::setReceiverHostname(const std::string &hostname,
const uint16_t port,
const bool initialChecks) { const bool initialChecks) {
{ {
std::ostringstream oss; std::ostringstream oss;
@ -1427,14 +1432,11 @@ void Module::setReceiverHostname(const std::string &hostname, const int port,
updateReceiverStreamingIP(); updateReceiverStreamingIP();
} }
int Module::getReceiverPort() const { return shm()->rxTCPPort; } uint16_t Module::getReceiverPort() const { return shm()->rxTCPPort; }
int Module::setReceiverPort(int port_number) { void Module::setReceiverPort(uint16_t port_number) {
if (port_number >= 0 && port_number != shm()->rxTCPPort) {
shm()->rxTCPPort = port_number; shm()->rxTCPPort = port_number;
} }
return shm()->rxTCPPort;
}
int Module::getReceiverFifoDepth() const { int Module::getReceiverFifoDepth() const {
return sendToReceiver<int>(F_SET_RECEIVER_FIFO_DEPTH, GET_FLAG); return sendToReceiver<int>(F_SET_RECEIVER_FIFO_DEPTH, GET_FLAG);
@ -1645,11 +1647,11 @@ void Module::setReceiverStreamingStartingFrame(int fnum) {
sendToReceiver(F_SET_RECEIVER_STREAMING_START_FNUM, fnum, nullptr); sendToReceiver(F_SET_RECEIVER_STREAMING_START_FNUM, fnum, nullptr);
} }
int Module::getReceiverStreamingPort() const { uint16_t Module::getReceiverStreamingPort() const {
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_PORT); return sendToReceiver<uint16_t>(F_GET_RECEIVER_STREAMING_PORT);
} }
void Module::setReceiverStreamingPort(int port) { void Module::setReceiverStreamingPort(uint16_t port) {
sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr); sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr);
} }
@ -1668,9 +1670,9 @@ void Module::setReceiverStreamingIP(const IpAddr ip) {
sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr); sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr);
} }
int Module::getClientStreamingPort() const { return shm()->zmqport; } uint16_t Module::getClientStreamingPort() const { return shm()->zmqport; }
void Module::setClientStreamingPort(int port) { shm()->zmqport = port; } void Module::setClientStreamingPort(uint16_t port) { shm()->zmqport = port; }
IpAddr Module::getClientStreamingIP() const { return shm()->zmqip; } IpAddr Module::getClientStreamingIP() const { return shm()->zmqip; }
@ -2839,15 +2841,17 @@ void Module::setADCInvert(uint32_t value) {
} }
// Insignificant // Insignificant
int Module::getControlPort() const { return shm()->controlPort; } uint16_t Module::getControlPort() const { return shm()->controlPort; }
void Module::setControlPort(int port_number) { void Module::setControlPort(uint16_t port_number) {
shm()->controlPort = port_number; shm()->controlPort = port_number;
} }
int Module::getStopPort() const { return shm()->stopPort; } uint16_t Module::getStopPort() const { return shm()->stopPort; }
void Module::setStopPort(int port_number) { shm()->stopPort = port_number; } void Module::setStopPort(uint16_t port_number) {
shm()->stopPort = port_number;
}
bool Module::getLockDetector() const { bool Module::getLockDetector() const {
return sendToDetector<int>(F_LOCK_SERVER, GET_FLAG); return sendToDetector<int>(F_LOCK_SERVER, GET_FLAG);

View File

@ -19,7 +19,7 @@ namespace sls {
class ServerInterface; class ServerInterface;
#define MODULE_SHMAPIVERSION 0x190726 #define MODULE_SHMAPIVERSION 0x190726
#define MODULE_SHMVERSION 0x200402 #define MODULE_SHMVERSION 0x230913
/** /**
* @short structure allocated in shared memory to store Module settings for * @short structure allocated in shared memory to store Module settings for
@ -36,8 +36,8 @@ struct sharedModule {
/** END OF FIXED PATTERN -----------------------------------------------*/ /** END OF FIXED PATTERN -----------------------------------------------*/
slsDetectorDefs::xy numberOfModule; slsDetectorDefs::xy numberOfModule;
int controlPort; uint16_t controlPort;
int stopPort; uint16_t stopPort;
char settingsDir[MAX_STR_LENGTH]; char settingsDir[MAX_STR_LENGTH];
/** list of the energies at which the Module has been trimmed */ /** list of the energies at which the Module has been trimmed */
StaticVector<int, MAX_TRIMEN> trimEnergies; StaticVector<int, MAX_TRIMEN> trimEnergies;
@ -46,11 +46,11 @@ struct sharedModule {
slsDetectorDefs::xy nChip; slsDetectorDefs::xy nChip;
int nDacs; int nDacs;
char rxHostname[MAX_STR_LENGTH]; char rxHostname[MAX_STR_LENGTH];
int rxTCPPort; uint16_t rxTCPPort;
/** if rxHostname and rxTCPPort can be connected to */ /** if rxHostname and rxTCPPort can be connected to */
bool useReceiverFlag; bool useReceiverFlag;
/** Listening tcp port from gui (only data) */ /** Listening tcp port from gui (only data) */
int zmqport; uint16_t zmqport;
/** Listening tcp ip address from gui (only data) **/ /** Listening tcp ip address from gui (only data) **/
IpAddr zmqip; IpAddr zmqip;
int numUDPInterfaces; int numUDPInterfaces;
@ -102,7 +102,7 @@ class Module : public virtual slsDetectorDefs {
std::string getReceiverSoftwareVersion() const; std::string getReceiverSoftwareVersion() const;
static detectorType static detectorType
getTypeFromDetector(const std::string &hostname, getTypeFromDetector(const std::string &hostname,
int cport = DEFAULT_TCP_CNTRL_PORTNO); uint16_t cport = DEFAULT_TCP_CNTRL_PORTNO);
/** Get Detector type from shared memory */ /** Get Detector type from shared memory */
detectorType getDetectorType() const; detectorType getDetectorType() const;
@ -261,10 +261,10 @@ class Module : public virtual slsDetectorDefs {
void setDestinationUDPMAC(const MacAddr mac); void setDestinationUDPMAC(const MacAddr mac);
MacAddr getDestinationUDPMAC2() const; MacAddr getDestinationUDPMAC2() const;
void setDestinationUDPMAC2(const MacAddr mac); void setDestinationUDPMAC2(const MacAddr mac);
int getDestinationUDPPort() const; uint16_t getDestinationUDPPort() const;
void setDestinationUDPPort(int udpport); void setDestinationUDPPort(uint16_t udpport);
int getDestinationUDPPort2() const; uint16_t getDestinationUDPPort2() const;
void setDestinationUDPPort2(int udpport); void setDestinationUDPPort2(uint16_t udpport);
void reconfigureUDPDestination(); void reconfigureUDPDestination();
void validateUDPConfiguration(); void validateUDPConfiguration();
std::string printReceiverConfiguration(); std::string printReceiverConfiguration();
@ -286,10 +286,10 @@ class Module : public virtual slsDetectorDefs {
* ************************************************/ * ************************************************/
bool getUseReceiverFlag() const; bool getUseReceiverFlag() const;
std::string getReceiverHostname() const; std::string getReceiverHostname() const;
void setReceiverHostname(const std::string &hostname, const int port, void setReceiverHostname(const std::string &hostname, const uint16_t port,
const bool initialChecks); const bool initialChecks);
int getReceiverPort() const; uint16_t getReceiverPort() const;
int setReceiverPort(int port_number); void setReceiverPort(uint16_t port_number);
int getReceiverFifoDepth() const; int getReceiverFifoDepth() const;
void setReceiverFifoDepth(int n_frames); void setReceiverFifoDepth(int n_frames);
bool getReceiverSilentMode() const; bool getReceiverSilentMode() const;
@ -349,12 +349,12 @@ class Module : public virtual slsDetectorDefs {
void setReceiverStreamingTimer(int time_in_ms = 200); void setReceiverStreamingTimer(int time_in_ms = 200);
int getReceiverStreamingStartingFrame() const; int getReceiverStreamingStartingFrame() const;
void setReceiverStreamingStartingFrame(int fnum); void setReceiverStreamingStartingFrame(int fnum);
int getReceiverStreamingPort() const; uint16_t getReceiverStreamingPort() const;
void setReceiverStreamingPort(int port); void setReceiverStreamingPort(uint16_t port);
IpAddr getReceiverStreamingIP() const; IpAddr getReceiverStreamingIP() const;
void setReceiverStreamingIP(const IpAddr ip); void setReceiverStreamingIP(const IpAddr ip);
int getClientStreamingPort() const; uint16_t getClientStreamingPort() const;
void setClientStreamingPort(int port); void setClientStreamingPort(uint16_t port);
IpAddr getClientStreamingIP() const; IpAddr getClientStreamingIP() const;
void setClientStreamingIP(const IpAddr ip); void setClientStreamingIP(const IpAddr ip);
int getReceiverStreamingHwm() const; int getReceiverStreamingHwm() const;
@ -597,10 +597,10 @@ class Module : public virtual slsDetectorDefs {
* Insignificant * * Insignificant *
* * * *
* ************************************************/ * ************************************************/
int getControlPort() const; uint16_t getControlPort() const;
void setControlPort(int port_number); void setControlPort(uint16_t port_number);
int getStopPort() const; uint16_t getStopPort() const;
void setStopPort(int port_number); void setStopPort(uint16_t port_number);
bool getLockDetector() const; bool getLockDetector() const;
void setLockDetector(bool lock); void setLockDetector(bool lock);
IpAddr getLastClientIP() const; IpAddr getLastClientIP() const;

View File

@ -11,6 +11,26 @@ namespace sls {
using test::GET; using test::GET;
using test::PUT; using test::PUT;
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action) {
Detector det;
CmdProxy proxy(&det);
std::vector<std::string> arg(arguments);
if (arg.empty())
arg.push_back("0");
int test_values[3] = {77797, -1, 0};
for (int i = 0; i != 3; ++i) {
int port_number = test_values[i];
arg[arg.size() - 1] = std::to_string(port_number);
REQUIRE_THROWS(proxy.Call(command, arg, detector_id, action));
/*REQUIRE_THROWS_WITH(proxy.Call(command, arguments, detector_id,
action), "Invalid port range. Must be between 1 - 65535.");*/
}
}
void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) { void test_dac(defs::dacIndex index, const std::string &dacname, int dacvalue) {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);

View File

@ -5,6 +5,10 @@
namespace sls { namespace sls {
void test_valid_port(const std::string &command,
const std::vector<std::string> &arguments, int detector_id,
int action);
void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname, void test_dac(slsDetectorDefs::dacIndex index, const std::string &dacname,
int dacvalue); int dacvalue);
void test_onchip_dac(slsDetectorDefs::dacIndex index, void test_onchip_dac(slsDetectorDefs::dacIndex index,

View File

@ -5,6 +5,7 @@
#include "sls/Detector.h" #include "sls/Detector.h"
#include "sls/Version.h" #include "sls/Version.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#include "test-CmdProxy-global.h"
#include <sstream> #include <sstream>
#include "sls/versionAPI.h" #include "sls/versionAPI.h"
@ -223,7 +224,7 @@ TEST_CASE("rx_tcpport", "[.cmd][.rx]") {
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto prev_val = det.getRxPort(); auto prev_val = det.getRxPort();
int port = 3500; uint16_t port = 3500;
proxy.Call("rx_tcpport", {std::to_string(port)}, -1, PUT); proxy.Call("rx_tcpport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss; std::ostringstream oss;
@ -237,6 +238,22 @@ TEST_CASE("rx_tcpport", "[.cmd][.rx]") {
proxy.Call("rx_tcpport", {}, i, GET, oss); proxy.Call("rx_tcpport", {}, i, GET, oss);
REQUIRE(oss.str() == "rx_tcpport " + std::to_string(port + i) + '\n'); REQUIRE(oss.str() == "rx_tcpport " + std::to_string(port + i) + '\n');
} }
test_valid_port("rx_tcpport", {}, -1, PUT);
test_valid_port("rx_tcpport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("rx_tcpport", {"65535"}, -1, PUT));
auto rxHostname = det.getRxHostname().squash("none");
if (rxHostname != "none") {
std::ostringstream oss;
for (int i = 0; i != det.size(); ++i) {
oss << rxHostname << ":" << 65536 + i << "+";
}
REQUIRE_THROWS(proxy.Call("rx_hostname", {oss.str()}, -1, PUT));
}
}
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
det.setRxPort(prev_val[i], i); det.setRxPort(prev_val[i], i);
} }
@ -810,7 +827,7 @@ TEST_CASE("rx_zmqport", "[.cmd][.rx]") {
proxy.Call("numinterfaces", {"2"}, -1, PUT); proxy.Call("numinterfaces", {"2"}, -1, PUT);
socketsperdetector *= 2; socketsperdetector *= 2;
} }
int port = 3500; uint16_t port = 3500;
proxy.Call("rx_zmqport", {std::to_string(port)}, -1, PUT); proxy.Call("rx_zmqport", {std::to_string(port)}, -1, PUT);
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
std::ostringstream oss; std::ostringstream oss;
@ -828,6 +845,14 @@ TEST_CASE("rx_zmqport", "[.cmd][.rx]") {
std::to_string(port + i * socketsperdetector) + std::to_string(port + i * socketsperdetector) +
'\n'); '\n');
} }
test_valid_port("rx_zmqport", {}, -1, PUT);
test_valid_port("rx_zmqport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("rx_zmqport", {"65535"}, -1, PUT));
}
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
det.setRxZmqPort(prev_val_zmqport[i], i); det.setRxZmqPort(prev_val_zmqport[i], i);
} }

View File

@ -5,6 +5,7 @@
#include "sls/Detector.h" #include "sls/Detector.h"
#include "sls/file_utils.h" #include "sls/file_utils.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#include "test-CmdProxy-global.h"
#include <chrono> #include <chrono>
#include <sstream> #include <sstream>
@ -76,7 +77,13 @@ TEST_CASE("hostname", "[.cmd]") {
REQUIRE_NOTHROW(proxy.Call("hostname", {}, -1, GET)); REQUIRE_NOTHROW(proxy.Call("hostname", {}, -1, GET));
} }
// virtual: not testing TEST_CASE("virtual", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call("virtual", {}, -1, GET));
test_valid_port("virtual", {"1"}, -1, PUT);
REQUIRE_THROWS(proxy.Call("virtual", {"3", "65534"}, -1, PUT));
}
TEST_CASE("versions", "[.cmd]") { TEST_CASE("versions", "[.cmd]") {
Detector det; Detector det;
@ -2693,6 +2700,12 @@ TEST_CASE("udp_dstport", "[.cmd]") {
proxy.Call("udp_dstport", {"50084"}, -1, PUT, oss); proxy.Call("udp_dstport", {"50084"}, -1, PUT, oss);
REQUIRE(oss.str() == "udp_dstport 50084\n"); REQUIRE(oss.str() == "udp_dstport 50084\n");
} }
test_valid_port("udp_dstport", {}, -1, PUT);
test_valid_port("udp_dstport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("udp_dstport", {"65535"}, -1, PUT));
}
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
det.setDestinationUDPPort(prev_val[i], {i}); det.setDestinationUDPPort(prev_val[i], {i});
} }
@ -2781,9 +2794,19 @@ TEST_CASE("udp_dstport2", "[.cmd]") {
proxy.Call("udp_dstport2", {"50084"}, -1, PUT, oss); proxy.Call("udp_dstport2", {"50084"}, -1, PUT, oss);
REQUIRE(oss.str() == "udp_dstport2 50084\n"); REQUIRE(oss.str() == "udp_dstport2 50084\n");
} }
test_valid_port("udp_dstport2", {}, -1, PUT);
test_valid_port("udp_dstport2", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("udp_dstport2", {"65535"}, -1, PUT));
}
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
if (prev_val[i] != 0) {
det.setDestinationUDPPort2(prev_val[i], {i}); det.setDestinationUDPPort2(prev_val[i], {i});
} }
}
} else { } else {
REQUIRE_THROWS(proxy.Call("udp_dstport2", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("udp_dstport2", {}, -1, GET));
} }
@ -2976,7 +2999,7 @@ TEST_CASE("zmqport", "[.cmd]") {
det.setNumberofUDPInterfaces(2); det.setNumberofUDPInterfaces(2);
socketsperdetector *= 2; socketsperdetector *= 2;
} }
int port = 3500; uint16_t port = 3500;
auto port_str = std::to_string(port); auto port_str = std::to_string(port);
{ {
std::ostringstream oss; std::ostringstream oss;
@ -3005,6 +3028,12 @@ TEST_CASE("zmqport", "[.cmd]") {
std::to_string(port + i * socketsperdetector) + std::to_string(port + i * socketsperdetector) +
'\n'); '\n');
} }
test_valid_port("zmqport", {}, -1, PUT);
test_valid_port("zmqport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("zmqport", {"65535"}, -1, PUT));
}
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
det.setNumberofUDPInterfaces(prev); det.setNumberofUDPInterfaces(prev);
} }
@ -3384,6 +3413,12 @@ TEST_CASE("port", "[.cmd]") {
proxy.Call("port", {}, 0, GET, oss); proxy.Call("port", {}, 0, GET, oss);
REQUIRE(oss.str() == "port 1942\n"); REQUIRE(oss.str() == "port 1942\n");
} }
test_valid_port("port", {}, -1, PUT);
test_valid_port("port", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("port", {"65536"}, -1, PUT));
}
det.setControlPort(prev_val, {0}); det.setControlPort(prev_val, {0});
} }
@ -3401,6 +3436,12 @@ TEST_CASE("stopport", "[.cmd]") {
proxy.Call("stopport", {}, 0, GET, oss); proxy.Call("stopport", {}, 0, GET, oss);
REQUIRE(oss.str() == "stopport 1942\n"); REQUIRE(oss.str() == "stopport 1942\n");
} }
test_valid_port("stopport", {}, -1, PUT);
test_valid_port("stopport", {}, 0, PUT);
// should fail for the second module
if (det.size() > 1) {
REQUIRE_THROWS(proxy.Call("stopport", {"65536"}, -1, PUT));
}
det.setStopPort(prev_val, {0}); det.setStopPort(prev_val, {0});
} }

View File

@ -28,7 +28,7 @@ class Receiver : private virtual slsDetectorDefs {
* throws an exception in case of failure * throws an exception in case of failure
* @param tcpip_port_no TCP/IP port number * @param tcpip_port_no TCP/IP port number
*/ */
Receiver(int tcpip_port_no = 1954); Receiver(uint16_t tcpip_port_no = 1954);
~Receiver(); ~Receiver();

View File

@ -23,7 +23,7 @@ void BinaryDataFile::CreateFirstBinaryDataFile(const std::string &fNamePrefix,
const uint64_t fIndex, const uint64_t fIndex,
const bool ovEnable, const bool ovEnable,
const bool sMode, const bool sMode,
const uint32_t uPortNumber, const uint16_t uPortNumber,
const uint32_t mFramesPerFile) { const uint32_t mFramesPerFile) {
subFileIndex = 0; subFileIndex = 0;

View File

@ -16,7 +16,7 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File {
void CloseFile() override; void CloseFile() override;
void CreateFirstBinaryDataFile(const std::string &fNamePrefix, void CreateFirstBinaryDataFile(const std::string &fNamePrefix,
const uint64_t fIndex, const bool ovEnable, const uint64_t fIndex, const bool ovEnable,
const bool sMode, const uint32_t uPortNumber, const bool sMode, const uint16_t uPortNumber,
const uint32_t mFramesPerFile) override; const uint32_t mFramesPerFile) override;
void WriteToFile(char *imageData, sls_receiver_header &header, void WriteToFile(char *imageData, sls_receiver_header &header,

View File

@ -41,10 +41,9 @@ ClientInterface::~ClientInterface() {
tcpThread->join(); tcpThread->join();
} }
ClientInterface::ClientInterface(int portNumber) ClientInterface::ClientInterface(uint16_t portNumber)
: detType(GOTTHARD), : detType(GOTTHARD), portNumber(portNumber), server(portNumber) {
portNumber(portNumber > 0 ? portNumber : DEFAULT_TCP_RX_PORTNO), validatePortNumber(portNumber);
server(portNumber) {
functionTable(); functionTable();
parentThreadId = gettid(); parentThreadId = gettid();
tcpThread = tcpThread =
@ -1064,9 +1063,12 @@ int ClientInterface::get_file_format(Interface &socket) {
} }
int ClientInterface::set_streaming_port(Interface &socket) { int ClientInterface::set_streaming_port(Interface &socket) {
auto port = socket.Receive<int>(); auto port = socket.Receive<uint16_t>();
if (port < 0) { try {
throw RuntimeError("Invalid zmq port " + std::to_string(port)); validatePortNumber(port);
} catch (...) {
throw RuntimeError(
"Could not set streaming (zmq) port number. Invalid value.");
} }
verifyIdle(socket); verifyIdle(socket);
impl()->setStreamingPort(port); impl()->setStreamingPort(port);
@ -1074,7 +1076,7 @@ int ClientInterface::set_streaming_port(Interface &socket) {
} }
int ClientInterface::get_streaming_port(Interface &socket) { int ClientInterface::get_streaming_port(Interface &socket) {
int retval = impl()->getStreamingPort(); uint16_t retval = impl()->getStreamingPort();
LOG(logDEBUG1) << "streaming port:" << retval; LOG(logDEBUG1) << "streaming port:" << retval;
return socket.sendResult(retval); return socket.sendResult(retval);
} }
@ -1449,7 +1451,7 @@ int ClientInterface::set_udp_ip2(Interface &socket) {
} }
int ClientInterface::set_udp_port(Interface &socket) { int ClientInterface::set_udp_port(Interface &socket) {
auto arg = socket.Receive<int>(); auto arg = socket.Receive<uint16_t>();
verifyIdle(socket); verifyIdle(socket);
LOG(logDEBUG1) << "Setting UDP Port:" << arg; LOG(logDEBUG1) << "Setting UDP Port:" << arg;
impl()->setUDPPortNumber(arg); impl()->setUDPPortNumber(arg);
@ -1457,7 +1459,7 @@ int ClientInterface::set_udp_port(Interface &socket) {
} }
int ClientInterface::set_udp_port2(Interface &socket) { int ClientInterface::set_udp_port2(Interface &socket) {
auto arg = socket.Receive<int>(); auto arg = socket.Receive<uint16_t>();
verifyIdle(socket); verifyIdle(socket);
if (detType != JUNGFRAU && detType != MOENCH && detType != EIGER && if (detType != JUNGFRAU && detType != MOENCH && detType != EIGER &&
detType != GOTTHARD2) { detType != GOTTHARD2) {

View File

@ -17,7 +17,7 @@ class ServerInterface;
class ClientInterface : private virtual slsDetectorDefs { class ClientInterface : private virtual slsDetectorDefs {
enum numberMode { DEC, HEX }; enum numberMode { DEC, HEX };
detectorType detType; detectorType detType;
int portNumber{0}; uint16_t portNumber{0};
ServerSocket server; ServerSocket server;
std::unique_ptr<Implementation> receiver; std::unique_ptr<Implementation> receiver;
std::unique_ptr<std::thread> tcpThread; std::unique_ptr<std::thread> tcpThread;
@ -29,7 +29,7 @@ class ClientInterface : private virtual slsDetectorDefs {
public: public:
virtual ~ClientInterface(); virtual ~ClientInterface();
ClientInterface(int portNumber = -1); ClientInterface(uint16_t portNumber = DEFAULT_TCP_RX_PORTNO);
std::string getReceiverVersion(); std::string getReceiverVersion();
//***callback functions*** //***callback functions***

View File

@ -127,7 +127,7 @@ void DataProcessor::CreateFirstFiles(const std::string &fileNamePrefix,
const uint64_t fileIndex, const uint64_t fileIndex,
const bool overWriteEnable, const bool overWriteEnable,
const bool silentMode, const bool silentMode,
const uint32_t udpPortNumber, const uint16_t udpPortNumber,
const uint64_t numImages, const uint64_t numImages,
const bool detectorDataStream) { const bool detectorDataStream) {
if (dataFile == nullptr) { if (dataFile == nullptr) {

View File

@ -56,7 +56,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
void CreateFirstFiles(const std::string &fileNamePrefix, void CreateFirstFiles(const std::string &fileNamePrefix,
const uint64_t fileIndex, const bool overWriteEnable, const uint64_t fileIndex, const bool overWriteEnable,
const bool silentMode, const uint32_t udpPortNumber, const bool silentMode, const uint16_t udpPortNumber,
const uint64_t numImages, const uint64_t numImages,
const bool detectorDataStream); const bool detectorDataStream);
#ifdef HDF5C #ifdef HDF5C

View File

@ -84,8 +84,8 @@ void DataStreamer::RecordFirstIndex(uint64_t fnum, size_t firstImageIndex) {
<< ", First Streamer Index:" << fnum; << ", First Streamer Index:" << fnum;
} }
void DataStreamer::CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm) { void DataStreamer::CreateZmqSockets(uint16_t port, const IpAddr ip, int hwm) {
uint32_t portnum = port + index; uint16_t portnum = port + index;
std::string sip = ip.str(); std::string sip = ip.str();
try { try {
zmqSocket = new ZmqSocket(portnum, (ip != 0 ? sip.c_str() : nullptr)); zmqSocket = new ZmqSocket(portnum, (ip != 0 ? sip.c_str() : nullptr));

View File

@ -48,7 +48,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
* @param ip streaming source ip * @param ip streaming source ip
* @param hwm streaming high water mark * @param hwm streaming high water mark
*/ */
void CreateZmqSockets(uint32_t port, const IpAddr ip, int hwm); void CreateZmqSockets(uint16_t port, const IpAddr ip, int hwm);
void CloseZmqSocket(); void CloseZmqSocket();
void RestreamStop(); void RestreamStop();

View File

@ -58,7 +58,7 @@ class File : private virtual slsDetectorDefs {
virtual void CreateFirstHDF5DataFile( virtual void CreateFirstHDF5DataFile(
const std::string &fileNamePrefix, const uint64_t fileIndex, const std::string &fileNamePrefix, const uint64_t fileIndex,
const bool overWriteEnable, const bool silentMode, const bool overWriteEnable, const bool silentMode,
const uint32_t udpPortNumber, const uint32_t maxFramesPerFile, const uint16_t udpPortNumber, const uint32_t maxFramesPerFile,
const uint64_t numImages, const uint32_t nPixelsX, const uint64_t numImages, const uint32_t nPixelsX,
const uint32_t nPixelsY, const uint32_t dynamicRange) { const uint32_t nPixelsY, const uint32_t dynamicRange) {
LOG(logERROR) LOG(logERROR)
@ -70,7 +70,7 @@ class File : private virtual slsDetectorDefs {
const uint64_t fileIndex, const uint64_t fileIndex,
const bool overWriteEnable, const bool overWriteEnable,
const bool silentMode, const bool silentMode,
const uint32_t udpPortNumber, const uint16_t udpPortNumber,
const uint32_t maxFramesPerFile) { const uint32_t maxFramesPerFile) {
LOG(logERROR) LOG(logERROR)
<< "This is a generic function CreateFirstBinaryDataFile that " << "This is a generic function CreateFirstBinaryDataFile that "

View File

@ -88,7 +88,7 @@ void HDF5DataFile::CloseFile() {
void HDF5DataFile::CreateFirstHDF5DataFile( void HDF5DataFile::CreateFirstHDF5DataFile(
const std::string &fNamePrefix, const uint64_t fIndex, const bool owEnable, const std::string &fNamePrefix, const uint64_t fIndex, const bool owEnable,
const bool sMode, const uint32_t uPortNumber, const uint32_t mFramesPerFile, const bool sMode, const uint16_t uPortNumber, const uint32_t mFramesPerFile,
const uint64_t nImages, const uint32_t nX, const uint32_t nY, const uint64_t nImages, const uint32_t nX, const uint32_t nY,
const uint32_t dr) { const uint32_t dr) {

View File

@ -25,7 +25,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
void CreateFirstHDF5DataFile(const std::string &fNamePrefix, void CreateFirstHDF5DataFile(const std::string &fNamePrefix,
const uint64_t fIndex, const bool owEnable, const uint64_t fIndex, const bool owEnable,
const bool sMode, const uint32_t uPortNumber, const bool sMode, const uint16_t uPortNumber,
const uint32_t mFramesPerFile, const uint32_t mFramesPerFile,
const uint64_t nImages, const uint32_t nX, const uint64_t nImages, const uint32_t nX,
const uint32_t nY, const uint32_t dr) override; const uint32_t nY, const uint32_t dr) override;
@ -69,7 +69,7 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
uint64_t fileIndex{0}; uint64_t fileIndex{0};
bool overWriteEnable{false}; bool overWriteEnable{false};
bool silentMode{false}; bool silentMode{false};
uint32_t udpPortNumber{0}; uint16_t udpPortNumber{0};
static const int EIGER_NUM_PIXELS{256 * 2 * 256}; static const int EIGER_NUM_PIXELS{256 * 2 * 256};
static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2}; static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2};

View File

@ -1140,17 +1140,17 @@ void Implementation::setEthernetInterface2(const std::string &c) {
LOG(logINFO) << "Ethernet Interface 2: " << eth[1]; LOG(logINFO) << "Ethernet Interface 2: " << eth[1];
} }
uint32_t Implementation::getUDPPortNumber() const { return udpPortNum[0]; } uint16_t Implementation::getUDPPortNumber() const { return udpPortNum[0]; }
void Implementation::setUDPPortNumber(const uint32_t i) { void Implementation::setUDPPortNumber(const uint16_t i) {
udpPortNum[0] = i; udpPortNum[0] = i;
listener[0]->SetUdpPortNumber(i); listener[0]->SetUdpPortNumber(i);
LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0]; LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0];
} }
uint32_t Implementation::getUDPPortNumber2() const { return udpPortNum[1]; } uint16_t Implementation::getUDPPortNumber2() const { return udpPortNum[1]; }
void Implementation::setUDPPortNumber2(const uint32_t i) { void Implementation::setUDPPortNumber2(const uint16_t i) {
udpPortNum[1] = i; udpPortNum[1] = i;
if (listener.size() > 1) { if (listener.size() > 1) {
listener[1]->SetUdpPortNumber(i); listener[1]->SetUdpPortNumber(i);
@ -1251,9 +1251,9 @@ void Implementation::setStreamingStartingFrameNumber(const uint32_t fnum) {
LOG(logINFO) << "Streaming Start Frame num: " << streamingStartFnum; LOG(logINFO) << "Streaming Start Frame num: " << streamingStartFnum;
} }
uint32_t Implementation::getStreamingPort() const { return streamingPort; } uint16_t Implementation::getStreamingPort() const { return streamingPort; }
void Implementation::setStreamingPort(const uint32_t i) { void Implementation::setStreamingPort(const uint16_t i) {
streamingPort = i; streamingPort = i;
LOG(logINFO) << "Streaming Port: " << streamingPort; LOG(logINFO) << "Streaming Port: " << streamingPort;
} }

View File

@ -117,11 +117,11 @@ class Implementation : private virtual slsDetectorDefs {
std::string getEthernetInterface2() const; std::string getEthernetInterface2() const;
/* [Jungfrau][Moench] */ /* [Jungfrau][Moench] */
void setEthernetInterface2(const std::string &c); void setEthernetInterface2(const std::string &c);
uint32_t getUDPPortNumber() const; uint16_t getUDPPortNumber() const;
void setUDPPortNumber(const uint32_t i); void setUDPPortNumber(const uint16_t i);
uint32_t getUDPPortNumber2() const; uint16_t getUDPPortNumber2() const;
/* [Eiger][Jungfrau][Moench] */ /* [Eiger][Jungfrau][Moench] */
void setUDPPortNumber2(const uint32_t i); void setUDPPortNumber2(const uint16_t i);
int getUDPSocketBufferSize() const; int getUDPSocketBufferSize() const;
void setUDPSocketBufferSize(const int s); void setUDPSocketBufferSize(const int s);
int getActualUDPSocketBufferSize() const; int getActualUDPSocketBufferSize() const;
@ -140,8 +140,8 @@ class Implementation : private virtual slsDetectorDefs {
void setStreamingTimer(const uint32_t time_in_ms); void setStreamingTimer(const uint32_t time_in_ms);
uint32_t getStreamingStartingFrameNumber() const; uint32_t getStreamingStartingFrameNumber() const;
void setStreamingStartingFrameNumber(const uint32_t fnum); void setStreamingStartingFrameNumber(const uint32_t fnum);
uint32_t getStreamingPort() const; uint16_t getStreamingPort() const;
void setStreamingPort(const uint32_t i); void setStreamingPort(const uint16_t i);
IpAddr getStreamingSourceIP() const; IpAddr getStreamingSourceIP() const;
void setStreamingSourceIP(const IpAddr ip); void setStreamingSourceIP(const IpAddr ip);
int getStreamingHwm() const; int getStreamingHwm() const;
@ -336,7 +336,7 @@ class Implementation : private virtual slsDetectorDefs {
// network configuration (UDP) // network configuration (UDP)
std::array<std::string, MAX_NUMBER_OF_LISTENING_THREADS> eth; std::array<std::string, MAX_NUMBER_OF_LISTENING_THREADS> eth;
std::array<uint32_t, MAX_NUMBER_OF_LISTENING_THREADS> udpPortNum{ std::array<uint16_t, MAX_NUMBER_OF_LISTENING_THREADS> udpPortNum{
{DEFAULT_UDP_DST_PORTNO, DEFAULT_UDP_DST_PORTNO + 1}}; {DEFAULT_UDP_DST_PORTNO, DEFAULT_UDP_DST_PORTNO + 1}};
int actualUDPSocketBufferSize{0}; int actualUDPSocketBufferSize{0};
@ -345,7 +345,7 @@ class Implementation : private virtual slsDetectorDefs {
uint32_t streamingFrequency{1}; uint32_t streamingFrequency{1};
uint32_t streamingTimerInMs{DEFAULT_STREAMING_TIMER_IN_MS}; uint32_t streamingTimerInMs{DEFAULT_STREAMING_TIMER_IN_MS};
uint32_t streamingStartFnum{0}; uint32_t streamingStartFnum{0};
uint32_t streamingPort{0}; uint16_t streamingPort{0};
IpAddr streamingSrcIP = IpAddr{}; IpAddr streamingSrcIP = IpAddr{};
int streamingHwm{-1}; int streamingHwm{-1};
std::map<std::string, std::string> additionalJsonHeader; std::map<std::string, std::string> additionalJsonHeader;

View File

@ -71,7 +71,7 @@ void Listener::SetFifo(Fifo *f) { fifo = f; }
void Listener::SetGeneralData(GeneralData *g) { generalData = g; } void Listener::SetGeneralData(GeneralData *g) { generalData = g; }
void Listener::SetUdpPortNumber(const uint32_t portNumber) { void Listener::SetUdpPortNumber(const uint16_t portNumber) {
udpPortNumber = portNumber; udpPortNumber = portNumber;
} }

View File

@ -39,7 +39,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
void SetFifo(Fifo *f); void SetFifo(Fifo *f);
void SetGeneralData(GeneralData *g); void SetGeneralData(GeneralData *g);
void SetUdpPortNumber(const uint32_t portNumber); void SetUdpPortNumber(const uint16_t portNumber);
void SetEthernetInterface(const std::string e); void SetEthernetInterface(const std::string e);
void SetActivate(bool enable); void SetActivate(bool enable);
void SetDetectorDatastream(bool enable); void SetDetectorDatastream(bool enable);
@ -112,7 +112,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
std::atomic<runStatus> *status; std::atomic<runStatus> *status;
std::unique_ptr<UdpRxSocket> udpSocket{nullptr}; std::unique_ptr<UdpRxSocket> udpSocket{nullptr};
uint32_t udpPortNumber{0}; uint16_t udpPortNumber{0};
std::string eth; std::string eth;
bool activated{false}; bool activated{false};
bool detectorDataStream{true}; bool detectorDataStream{true};

View File

@ -3,6 +3,7 @@
/* Creates the slsMultiReceiver for running multiple receivers form a single /* Creates the slsMultiReceiver for running multiple receivers form a single
* binary */ * binary */
#include "sls/Receiver.h" #include "sls/Receiver.h"
#include "sls/ToString.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
@ -36,14 +37,12 @@ void sigInterruptHandler(int p) { sem_post(&semaphore); }
/** /**
* prints usage of this example program * prints usage of this example program
*/ */
void printHelp() { std::string getHelpMessage() {
cprintf( return std::string(
RESET, "\n\nUsage:\n"
"Usage:\n" "./slsMultiReceiver(detReceiver) [start_tcp_port (non-zero and 16 "
"./slsMultiReceiver(detReceiver) [start_tcp_port] " "bit)] [num_receivers] [optional: 1 for call back (print frame header "
"[num_receivers] [optional: 1 for call back (print frame header for " "for debugging), 0 for none (default)]\n\n");
"debugging), 0 for none (default)]\n\n");
exit(EXIT_FAILURE);
} }
/** /**
@ -140,25 +139,31 @@ int main(int argc, char *argv[]) {
/** - set default values */ /** - set default values */
int numReceivers = 1; int numReceivers = 1;
int startTCPPort = 1954; uint16_t startTCPPort = 1954;
int withCallback = 0; int withCallback = 0;
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
/** - get number of receivers and start tcp port from command line /** - get number of receivers and start tcp port from command line
* arguments */ * arguments */
if (argc != 3 && argc != 4) try {
printHelp(); if (argc == 3 || argc == 4) {
if ((argc == 3) && ((!sscanf(argv[1], "%d", &startTCPPort)) || startTCPPort = sls::StringTo<uint16_t>(argv[1]);
(!sscanf(argv[2], "%d", &numReceivers)))) if (startTCPPort == 0) {
printHelp(); throw;
if ((argc == 4) && ((!sscanf(argv[1], "%d", &startTCPPort)) || }
(!sscanf(argv[2], "%d", &numReceivers)) || numReceivers = std::stoi(argv[2]);
(!sscanf(argv[3], "%d", &withCallback)))) if (argc == 4) {
printHelp(); withCallback = std::stoi(argv[3]);
}
} else
throw;
} catch (...) {
throw std::runtime_error(getHelpMessage());
}
cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid()); cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
cprintf(RESET, "Number of Receivers: %d\n", numReceivers); cprintf(RESET, "Number of Receivers: %d\n", numReceivers);
cprintf(RESET, "Start TCP Port: %d\n", startTCPPort); cprintf(RESET, "Start TCP Port: %hu\n", startTCPPort);
cprintf(RESET, "Callback Enable: %d\n", withCallback); cprintf(RESET, "Callback Enable: %d\n", withCallback);
/** - Catch signal SIGINT to close files and call destructors properly */ /** - Catch signal SIGINT to close files and call destructors properly */

View File

@ -2,6 +2,7 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#include "sls/Receiver.h" #include "sls/Receiver.h"
#include "ClientInterface.h" #include "ClientInterface.h"
#include "sls/ToString.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
#include "sls/sls_detector_exceptions.h" #include "sls/sls_detector_exceptions.h"
@ -29,7 +30,7 @@ Receiver::~Receiver() = default;
Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) { Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
// options // options
int tcpip_port_no = 1954; uint16_t tcpip_port_no = 1954;
uid_t userid = -1; uid_t userid = -1;
// parse command line for config // parse command line for config
@ -51,6 +52,15 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
int option_index = 0; int option_index = 0;
int c = 0; int c = 0;
std::string help_message =
"\nUsage: " + std::string(argv[0]) + " [arguments]\n" +
"Possible arguments are:\n" +
"\t-t, --rx_tcpport <port> : TCP Communication Port with "
"client. Non-zero and 16 bit.\n" +
"\t-u, --uid <user id> : Set effective user id if receiver "
"\n" +
"\t started with privileges. \n\n";
while (c != -1) { while (c != -1) {
c = getopt_long(argc, argv, "hvf:t:u:", long_options, &option_index); c = getopt_long(argc, argv, "hvf:t:u:", long_options, &option_index);
@ -61,12 +71,18 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
switch (c) { switch (c) {
case 't': case 't':
sscanf(optarg, "%d", &tcpip_port_no); try {
tcpip_port_no = sls::StringTo<uint16_t>(optarg);
validatePortNumber(tcpip_port_no);
} catch (...) {
throw RuntimeError("Could not scan TCP port number." +
help_message);
}
break; break;
case 'u': case 'u':
if (sscanf(optarg, "%u", &userid) != 1) { if (sscanf(optarg, "%u", &userid) != 1) {
throw RuntimeError("Could not scan uid"); throw RuntimeError("Could not scan uid" + help_message);
} }
break; break;
@ -76,19 +92,9 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':
std::cout << help_message << std::endl;
exit(EXIT_SUCCESS);
default: default:
std::cout << std::endl;
std::string help_message =
"Usage: " + std::string(argv[0]) + " [arguments]\n" +
"Possible arguments are:\n" +
"\t-t, --rx_tcpport <port> : TCP Communication Port with "
"client. \n" +
"\t-u, --uid <user id> : Set effective user id if receiver "
"\n" +
"\t started with privileges. \n\n";
// std::cout << help_message << std::endl;
throw RuntimeError(help_message); throw RuntimeError(help_message);
} }
} }
@ -118,7 +124,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no); tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
} }
Receiver::Receiver(int tcpip_port_no) { Receiver::Receiver(uint16_t tcpip_port_no) {
// might throw an exception // might throw an exception
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no); tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
} }

View File

@ -316,6 +316,7 @@ template <> defs::vetoAlgorithm StringTo(const std::string &s);
template <> defs::gainMode StringTo(const std::string &s); template <> defs::gainMode StringTo(const std::string &s);
template <> defs::polarity StringTo(const std::string &s); template <> defs::polarity StringTo(const std::string &s);
template <> uint16_t StringTo(const std::string &s);
template <> uint32_t StringTo(const std::string &s); template <> uint32_t StringTo(const std::string &s);
template <> uint64_t StringTo(const std::string &s); template <> uint64_t StringTo(const std::string &s);
template <> int StringTo(const std::string &s); template <> int StringTo(const std::string &s);

View File

@ -7,6 +7,7 @@ UDP socket class to receive data. The intended use is in the
receiver listener loop. Should be used RAII style... receiver listener loop. Should be used RAII style...
*/ */
#include <stdint.h>
#include <sys/types.h> //ssize_t #include <sys/types.h> //ssize_t
namespace sls { namespace sls {
@ -15,8 +16,8 @@ class UdpRxSocket {
int sockfd_{-1}; int sockfd_{-1};
public: public:
UdpRxSocket(int port, ssize_t packet_size, const char *hostname = nullptr, UdpRxSocket(uint16_t port, ssize_t packet_size,
int kernel_buffer_size = 0); const char *hostname = nullptr, int kernel_buffer_size = 0);
~UdpRxSocket(); ~UdpRxSocket();
bool ReceivePacket(char *dst) noexcept; bool ReceivePacket(char *dst) noexcept;
int getBufferSize() const; int getBufferSize() const;

View File

@ -103,7 +103,7 @@ class ZmqSocket {
* @param hostname_or_ip hostname or ip of server * @param hostname_or_ip hostname or ip of server
* @param portnumber port number * @param portnumber port number
*/ */
ZmqSocket(const char *const hostname_or_ip, const uint32_t portnumber); ZmqSocket(const char *const hostname_or_ip, const uint16_t portnumber);
/** /**
* Constructor for a server * Constructor for a server
@ -111,7 +111,7 @@ class ZmqSocket {
* @param portnumber port number * @param portnumber port number
* @param ethip is the ip of the ethernet interface to stream zmq from * @param ethip is the ip of the ethernet interface to stream zmq from
*/ */
ZmqSocket(const uint32_t portnumber, const char *ethip); ZmqSocket(const uint16_t portnumber, const char *ethip);
/** Returns high water mark for outbound messages */ /** Returns high water mark for outbound messages */
int GetSendHighWaterMark(); int GetSendHighWaterMark();
@ -143,7 +143,7 @@ class ZmqSocket {
* Returns Port Number * Returns Port Number
* @returns Port Number * @returns Port Number
*/ */
uint32_t GetPortNumber() { return portno; } uint16_t GetPortNumber() { return portno; }
/** /**
* Returns Server Address * Returns Server Address
@ -251,7 +251,7 @@ class ZmqSocket {
}; };
/** Port Number */ /** Port Number */
uint32_t portno; uint16_t portno;
/** Socket descriptor */ /** Socket descriptor */
mySocketDescriptors sockfd; mySocketDescriptors sockfd;

View File

@ -64,8 +64,8 @@ class MacAddr {
struct UdpDestination { struct UdpDestination {
uint32_t entry{}; uint32_t entry{};
uint32_t port{}; uint16_t port{};
uint32_t port2{}; uint16_t port2{};
IpAddr ip; IpAddr ip;
IpAddr ip2; IpAddr ip2;
MacAddr mac; MacAddr mac;
@ -88,5 +88,6 @@ 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);
void validatePortNumber(uint16_t port);
void validatePortRange(uint16_t startPort, int numPorts);
} // namespace sls } // namespace sls

View File

@ -556,10 +556,10 @@ enum streamingInterface {
int moduleIndex{0}; int moduleIndex{0};
char hostname[MAX_STR_LENGTH]; char hostname[MAX_STR_LENGTH];
int udpInterfaces{1}; int udpInterfaces{1};
int udp_dstport{0}; uint16_t udp_dstport{0};
uint32_t udp_dstip{0U}; uint32_t udp_dstip{0U};
uint64_t udp_dstmac{0LU}; uint64_t udp_dstmac{0LU};
int udp_dstport2{0}; uint16_t udp_dstport2{0};
uint32_t udp_dstip2{0U}; uint32_t udp_dstip2{0U};
uint64_t udp_dstmac2{0LU}; uint64_t udp_dstmac2{0LU};
int64_t frames{0}; int64_t frames{0};

View File

@ -60,6 +60,6 @@ bool is_int(const std::string &s);
bool replace_first(std::string *s, const std::string &substr, bool replace_first(std::string *s, const std::string &substr,
const std::string &repl); const std::string &repl);
std::pair<std::string, int> ParseHostPort(const std::string &s); std::pair<std::string, uint16_t> ParseHostPort(const std::string &s);
} // namespace sls } // namespace sls

View File

@ -4,10 +4,10 @@
#define RELEASE "developer" #define RELEASE "developer"
#define APILIB "developer 0x230224" #define APILIB "developer 0x230224"
#define APIRECEIVER "developer 0x230224" #define APIRECEIVER "developer 0x230224"
#define APICTB "developer 0x230829" #define APICTB "developer 0x230922"
#define APIGOTTHARD "developer 0x230829" #define APIGOTTHARD "developer 0x230922"
#define APIGOTTHARD2 "developer 0x230829" #define APIGOTTHARD2 "developer 0x230922"
#define APIJUNGFRAU "developer 0x230829" #define APIJUNGFRAU "developer 0x230922"
#define APIMYTHEN3 "developer 0x230829" #define APIMYTHEN3 "developer 0x230922"
#define APIMOENCH "developer 0x230829" #define APIMOENCH "developer 0x230922"
#define APIEIGER "developer 0x230829" #define APIEIGER "developer 0x230922"

View File

@ -1083,6 +1083,17 @@ template <> defs::polarity StringTo(const std::string &s) {
throw RuntimeError("Unknown polarity mode " + s); throw RuntimeError("Unknown polarity mode " + s);
} }
template <> uint16_t StringTo(const std::string &s) {
int base = s.find("0x") != std::string::npos ? 16 : 10;
int value = std::stoi(s, nullptr, base);
if (value < std::numeric_limits<uint16_t>::min() ||
value > std::numeric_limits<uint16_t>::max()) {
throw RuntimeError("Cannot scan uint16_t from string '" + s +
"'. Value must be in range 0 - 65535.");
}
return static_cast<uint16_t>(value);
}
template <> uint32_t StringTo(const std::string &s) { template <> uint32_t StringTo(const std::string &s) {
int base = s.find("0x") != std::string::npos ? 16 : 10; int base = s.find("0x") != std::string::npos ? 16 : 10;
return std::stoul(s, nullptr, base); return std::stoul(s, nullptr, base);

View File

@ -15,8 +15,8 @@
namespace sls { namespace sls {
UdpRxSocket::UdpRxSocket(int port, ssize_t packet_size, const char *hostname, UdpRxSocket::UdpRxSocket(uint16_t port, ssize_t packet_size,
int kernel_buffer_size) const char *hostname, int kernel_buffer_size)
: packet_size_(packet_size) { : packet_size_(packet_size) {
struct addrinfo hints {}; struct addrinfo hints {};
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;

View File

@ -15,7 +15,7 @@ namespace sls {
using namespace rapidjson; using namespace rapidjson;
ZmqSocket::ZmqSocket(const char *const hostname_or_ip, ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
const uint32_t portnumber) const uint16_t portnumber)
: portno(portnumber), sockfd(false) { : portno(portnumber), sockfd(false) {
// Extra check that throws if conversion fails, could be removed // Extra check that throws if conversion fails, could be removed
auto ipstr = HostnameToIp(hostname_or_ip).str(); auto ipstr = HostnameToIp(hostname_or_ip).str();
@ -55,7 +55,7 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
<< GetReceiveHighWaterMark(); << GetReceiveHighWaterMark();
} }
ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip) ZmqSocket::ZmqSocket(const uint16_t portnumber, const char *ethip)
: portno(portnumber), sockfd(true) { : portno(portnumber), sockfd(true) {
// create context // create context
sockfd.contextDescriptor = zmq_ctx_new(); sockfd.contextDescriptor = zmq_ctx_new();
@ -289,24 +289,24 @@ int ZmqSocket::ReceiveHeader(const int index, zmqHeader &zHeader,
header_buffer.get(), MAX_STR_LENGTH, 0); header_buffer.get(), MAX_STR_LENGTH, 0);
if (bytes_received > 0) { if (bytes_received > 0) {
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(BLUE, "Header %d [%d] Length: %d Header:%s \n", index, portno, cprintf(BLUE, "Header %d [%hu] Length: %d Header:%s \n", index, portno,
bytes_received, header_buffer.get()); bytes_received, header_buffer.get());
#endif #endif
if (ParseHeader(index, bytes_received, header_buffer.get(), zHeader, if (ParseHeader(index, bytes_received, header_buffer.get(), zHeader,
version)) { version)) {
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(RED, "Parsed Header %d [%d] Length: %d Header:%s \n", index, cprintf(RED, "Parsed Header %d [%hu] Length: %d Header:%s \n",
portno, bytes_received, header_buffer.get()); index, portno, bytes_received, header_buffer.get());
#endif #endif
if (!zHeader.data) { if (!zHeader.data) {
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(RED, "%d [%d] Received end of acquisition\n", index, cprintf(RED, "%d [%hu] Received end of acquisition\n", index,
portno); portno);
#endif #endif
return 0; return 0;
} }
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(GREEN, "%d [%d] data\n", index, portno); cprintf(GREEN, "%d [%hu] data\n", index, portno);
#endif #endif
return 1; return 1;
} }

View File

@ -10,6 +10,7 @@
#include <cstring> #include <cstring>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <iomanip> #include <iomanip>
#include <limits>
#include <net/if.h> #include <net/if.h>
#include <netdb.h> #include <netdb.h>
#include <sstream> #include <sstream>
@ -203,4 +204,18 @@ MacAddr InterfaceNameToMac(const std::string &inf) {
return MacAddr(mac); return MacAddr(mac);
} }
void validatePortNumber(uint16_t port) {
// random local port. might work if internal = bad practise
if (port == 0) {
throw RuntimeError("Invalid port number. Must be between 1 - 65535.");
}
}
void validatePortRange(uint16_t startPort, int numPorts) {
validatePortNumber(startPort);
if ((startPort + numPorts) > std::numeric_limits<uint16_t>::max()) {
throw RuntimeError("Invalid port range. Must be between 1 - 65535.");
}
}
} // namespace sls } // namespace sls

View File

@ -4,9 +4,12 @@
#include "sls/string_utils.h" #include "sls/string_utils.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/network_utils.h" #include "sls/network_utils.h"
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
#include <sls/ToString.h>
#include <sstream> #include <sstream>
namespace sls { namespace sls {
std::vector<std::string> split(const std::string &strToSplit, char delimeter) { std::vector<std::string> split(const std::string &strToSplit, char delimeter) {
@ -50,15 +53,15 @@ bool replace_first(std::string *s, const std::string &substr,
return false; return false;
} }
std::pair<std::string, int> ParseHostPort(const std::string &s) { std::pair<std::string, uint16_t> ParseHostPort(const std::string &s) {
// TODO deal with to many :, port not there? // TODO deal with to many :, port not there?
// no port return hostname as is and port as 0 // no port return hostname as is and port as 0
std::string host; std::string host;
int port{0}; uint16_t port{0};
auto res = split(s, ':'); auto res = split(s, ':');
host = res[0]; host = res[0];
if (res.size() > 1) { if (res.size() > 1) {
port = std::stoi(res[1]); port = StringTo<uint16_t>(res[1]);
} }
return std::make_pair(host, port); return std::make_pair(host, port);
} }

View File

@ -6,7 +6,7 @@
namespace sls { namespace sls {
TEST_CASE("Throws when cannot create socket") { TEST_CASE("Throws when cannot create socket") {
REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 5076001)); REQUIRE_THROWS(ZmqSocket("sdiasodjajpvv", 50001));
} }
TEST_CASE("Get port number for sub") { TEST_CASE("Get port number for sub") {

View File

@ -115,7 +115,7 @@ TEST_CASE("Copy construct a MacAddr") {
} }
TEST_CASE("udp dst struct basic properties") { TEST_CASE("udp dst struct basic properties") {
static_assert(sizeof(UdpDestination) == 36, static_assert(sizeof(UdpDestination) == 32,
"udpDestination struct size does not match"); "udpDestination struct size does not match");
UdpDestination dst{}; UdpDestination dst{};
REQUIRE(dst.entry == 0); REQUIRE(dst.entry == 0);