This commit is contained in:
maliakal_d 2021-08-18 19:05:05 +02:00
parent d9f969ae6f
commit f8d8fcf48a
13 changed files with 405 additions and 330 deletions

View File

@ -25,7 +25,7 @@
// Global variable from slsDetectorServer_funcs // Global variable from slsDetectorServer_funcs
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from UDPPacketHeaderGenerator // Global variable from UDPPacketHeaderGenerator
@ -480,6 +480,7 @@ void setupDetector() {
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
initializePatternWord(); initializePatternWord();
#endif #endif
setupUDPCommParameters();
ALTERA_PLL_ResetPLLAndReconfiguration(); ALTERA_PLL_ResetPLLAndReconfiguration();
resetCore(); resetCore();
@ -1544,7 +1545,7 @@ int configureMAC() {
LOG(logINFOBLUE, ("\t1G MAC\n")); LOG(logINFOBLUE, ("\t1G MAC\n"));
if (updateDatabytesandAllocateRAM() == FAIL) if (updateDatabytesandAllocateRAM() == FAIL)
return -1; return -1;
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(0, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp 1G destination IP and port\n")); LOG(logERROR, ("could not set udp 1G destination IP and port\n"));
return FAIL; return FAIL;
} }
@ -2023,7 +2024,7 @@ void *start_timer(void *arg) {
imageData + srcOffset, dataSize); imageData + srcOffset, dataSize);
srcOffset += dataSize; srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, 0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber)); (long long unsigned int)virtual_currentFrameNumber));
@ -2140,10 +2141,10 @@ void readandSendUDPFrames(int *ret, char *mess) {
LOG(logDEBUG1, ("Reading from 1G UDP\n")); LOG(logDEBUG1, ("Reading from 1G UDP\n"));
// validate udp socket // validate udp socket
if (getUdPSocketDescriptor(0) <= 0) { if (getUdPSocketDescriptor(0, 0) <= 0) {
*ret = FAIL; *ret = FAIL;
sprintf(mess, "UDP Socket not created. sockfd:%d\n", sprintf(mess, "UDP Socket not created. sockfd:%d\n",
getUdPSocketDescriptor(0)); getUdPSocketDescriptor(0, 0));
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return; return;
} }
@ -2152,7 +2153,7 @@ void readandSendUDPFrames(int *ret, char *mess) {
while (readFrameFromFifo() == OK) { while (readFrameFromFifo() == OK) {
int bytesToSend = 0, n = 0; int bytesToSend = 0, n = 0;
while ((bytesToSend = fillUDPPacket(udpPacketData))) { while ((bytesToSend = fillUDPPacket(udpPacketData))) {
n += sendUDPPacket(0, udpPacketData, bytesToSend); n += sendUDPPacket(0, 0, udpPacketData, bytesToSend);
} }
if (n >= dataBytes) { if (n >= dataBytes) {
LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d " LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d "

View File

@ -1163,10 +1163,6 @@ int Beb_SetUpTransferParameters(short the_bit_mode) {
the_bit_mode != 32) the_bit_mode != 32)
return 0; return 0;
Beb_bit_mode = the_bit_mode; Beb_bit_mode = the_bit_mode;
// nimages = the_number_of_images;
// on_dst = 0;
return 1; return 1;
} }
@ -1209,7 +1205,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig,
if (!Beb_activated) if (!Beb_activated)
return 1; return 1;
if (dst_number > 64) if (dst_number >= 64)
return 0; return 0;
unsigned int maxnl = MAX_ROWS_PER_READOUT; unsigned int maxnl = MAX_ROWS_PER_READOUT;

View File

@ -21,7 +21,8 @@
// Global variable from slsDetectorServer_funcs // Global variable from slsDetectorServer_funcs
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern int numUdpDestinations;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
@ -689,6 +690,7 @@ void setupDetector() {
resetToDefaultDacs(0); resetToDefaultDacs(0);
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif #endif
LOG(logINFOBLUE, ("Setting Default Parameters\n")); LOG(logINFOBLUE, ("Setting Default Parameters\n"));
@ -1518,79 +1520,87 @@ enum timingMode getTiming() {
/* configure mac */ /* configure mac */
int configureMAC() { int configureMAC() {
uint32_t srcip = udpDetails[0].srcip;
uint32_t dstip = udpDetails[0].dstip;
uint64_t srcmac = udpDetails[0].srcmac;
uint64_t dstmac = udpDetails[0].dstmac;
int srcport = udpDetails[0].srcport;
int dstport = udpDetails[0].dstport;
int dstport2 = udpDetails[0].dstport2;
LOG(logINFOBLUE, ("Configuring MAC\n")); LOG(logINFOBLUE, ("Configuring MAC\n"));
char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50],
dst_ip[INET_ADDRSTRLEN];
getMacAddressinString(src_mac, 50, srcmac);
getMacAddressinString(dst_mac, 50, dstmac);
getIpAddressinString(src_ip, srcip);
getIpAddressinString(dst_ip, dstip);
LOG(logINFO, for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) {
("\tSource IP : %s\n" uint32_t srcip = udpDetails[0].srcip;
"\tSource MAC : %s\n" uint32_t dstip = udpDetails[0].dstip;
"\tSource Port : %d\n" uint64_t srcmac = udpDetails[0].srcmac;
"\tDest IP : %s\n" uint64_t dstmac = udpDetails[0].dstmac;
"\tDest MAC : %s\n" int srcport = udpDetails[0].srcport;
"\tDest Port : %d\n" int dstport = udpDetails[0].dstport;
"\tDest Port2 : %d\n", int dstport2 = udpDetails[0].dstport2;
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport, dstport2));
char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50],
dst_ip[INET_ADDRSTRLEN];
getMacAddressinString(src_mac, 50, srcmac);
getMacAddressinString(dst_mac, 50, dstmac);
getIpAddressinString(src_ip, srcip);
getIpAddressinString(dst_ip, dstip);
LOG(logINFO,
("\tSource IP : %s\n"
"\tSource MAC : %s\n"
"\tSource Port : %d\n"
"\tDest IP : %s\n"
"\tDest MAC : %s\n"
"\tDest Port : %d\n"
"\tDest Port2 : %d\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport, dstport2));
#ifdef VIRTUAL #ifdef VIRTUAL
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(iRxEntry, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port\n")); LOG(logERROR,
return FAIL; ("could not set udp destination IP and port [entry:%d]\n",
} iRxEntry));
if (setUDPDestinationDetails(1, dst_ip, dstport2) == FAIL) { return FAIL;
LOG(logERROR, ("could not set udp destination IP and port2\n")); }
return FAIL; if (setUDPDestinationDetails(iRxEntry, 1, dst_ip, dstport2) == FAIL) {
} LOG(logERROR,
return OK; ("could not set udp destination IP and port2 [entry:%d]\n",
iRxEntry));
return FAIL;
}
return OK;
#else #else
int beb_num = detid; int beb_num = detid;
int header_number = 0; int dst_port = dstport;
int dst_port = dstport; if (!top)
if (!top) dst_port = dstport2;
if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip,
srcport) &&
Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, iRxEntry, dst_mac,
dst_ip, dst_port)) {
LOG(logDEBUG1, ("\tset up left ok\n"));
} else {
return FAIL;
}
header_number = 32;
dst_port = dstport2; dst_port = dstport2;
if (!top)
dst_port = dstport;
if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip, if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip,
srcport) && srcport) &&
Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, header_number, dst_mac, Beb_SetUpUDPHeader(beb_num, send_to_ten_gig,
dst_ip, dst_port)) { iRxEntry + MAX_UDP_DESTINATION, dst_mac, dst_ip,
LOG(logDEBUG1, ("\tset up left ok\n")); dst_port)) {
} else { LOG(logDEBUG1, (" set up right ok\n"));
return FAIL; } else {
} return FAIL;
}
header_number = 32; on_dst = 0;
dst_port = dstport2;
if (!top)
dst_port = dstport;
if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip, for (int i = 0; i < 32; ++i)
srcport) && dst_requested[i] = 0; // clear dst requested
Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, header_number, dst_mac, nimages_per_request = eiger_nexposures * eiger_ntriggers;
dst_ip, dst_port)) {
LOG(logDEBUG1, (" set up right ok\n"));
} else {
return FAIL;
}
on_dst = 0;
for (int i = 0; i < 32; ++i)
dst_requested[i] = 0; // clear dst requested
nimages_per_request = eiger_nexposures * eiger_ntriggers;
#endif #endif
}
return OK; return OK;
} }
@ -2381,6 +2391,7 @@ void *start_timer(void *arg) {
if (!skipData) { if (!skipData) {
uint64_t frameNr = 0; uint64_t frameNr = 0;
getNextFrameNumber(&frameNr); getNextFrameNumber(&frameNr);
int iRxEntry = 0;
// loop over number of frames // loop over number of frames
for (int iframes = 0; iframes != numFrames; ++iframes) { for (int iframes = 0; iframes != numFrames; ++iframes) {
@ -2471,12 +2482,12 @@ void *start_timer(void *arg) {
} }
if (eiger_virtual_left_datastream && i >= startval && i <= endval) { if (eiger_virtual_left_datastream && i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_left); usleep(eiger_virtual_transmission_delay_left);
sendUDPPacket(0, packetData, packetsize); sendUDPPacket(iRxEntry, 0, packetData, packetsize);
LOG(logDEBUG1, ("Sent left packet: %d\n", i)); LOG(logDEBUG1, ("Sent left packet: %d\n", i));
} }
if (eiger_virtual_right_datastream && i >= startval && i <= endval) { if (eiger_virtual_right_datastream && i >= startval && i <= endval) {
usleep(eiger_virtual_transmission_delay_right); usleep(eiger_virtual_transmission_delay_right);
sendUDPPacket(1, packetData2, packetsize); sendUDPPacket(iRxEntry, 1, packetData2, packetsize);
LOG(logDEBUG1, ("Sent right packet: %d\n", i)); LOG(logDEBUG1, ("Sent right packet: %d\n", i));
} }
} }
@ -2492,6 +2503,10 @@ void *start_timer(void *arg) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
} }
} }
++iRxEntry;
if (iRxEntry == numUdpDestinations) {
iRxEntry = 0;
}
} }
setNextFrameNumber(frameNr + numFrames); setNextFrameNumber(frameNr + numFrames);
} }

View File

@ -24,7 +24,7 @@
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern int checkModuleFlag; extern int checkModuleFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
@ -417,6 +417,7 @@ void setupDetector() {
memset(adcConfiguration, 0, sizeof(adcConfiguration)); memset(adcConfiguration, 0, sizeof(adcConfiguration));
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif #endif
// pll defines // pll defines
@ -1786,11 +1787,11 @@ int configureMAC() {
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2));
#ifdef VIRTUAL #ifdef VIRTUAL
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(0, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port\n")); LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL; return FAIL;
} }
if (i10gbe && setUDPDestinationDetails(1, dst_ip2, dstport2) == FAIL) { if (i10gbe && setUDPDestinationDetails(0, 1, dst_ip2, dstport2) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port for " LOG(logERROR, ("could not set udp destination IP and port for "
"interface 2\n")); "interface 2\n"));
return FAIL; return FAIL;
@ -2915,7 +2916,7 @@ void *start_timer(void *arg) {
memcpy(packetData + sizeof(sls_detector_header), imageData, memcpy(packetData + sizeof(sls_detector_header), imageData,
datasize); datasize);
// send 1 packet = 1 frame // send 1 packet = 1 frame
sendUDPPacket(0, packetData, packetsize); sendUDPPacket(0, 0, packetData, packetsize);
// second interface (veto) // second interface (veto)
char packetData2[vetopacketsize]; char packetData2[vetopacketsize];
@ -2929,7 +2930,7 @@ void *start_timer(void *arg) {
memcpy(packetData2 + sizeof(veto_header), vetoData, memcpy(packetData2 + sizeof(veto_header), vetoData,
vetodatasize); vetodatasize);
// send 1 packet = 1 frame // send 1 packet = 1 frame
sendUDPPacket(1, packetData2, vetopacketsize); sendUDPPacket(0, 1, packetData2, vetopacketsize);
} }
LOG(logINFO, ("Sent frame %s: %d (bursts/ triggers: %d) [%lld]\n", LOG(logINFO, ("Sent frame %s: %d (bursts/ triggers: %d) [%lld]\n",
(i10gbe ? "(+veto)" : ""), frameNr, repeatNr, (i10gbe ? "(+veto)" : ""), frameNr, repeatNr,

View File

@ -21,7 +21,7 @@
// Global variable from slsDetectorServer_funcs // Global variable from slsDetectorServer_funcs
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Variables that will be exported // Variables that will be exported
@ -376,6 +376,7 @@ void setupDetector() {
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif #endif
// Initialization // Initialization
@ -1355,7 +1356,7 @@ int configureMAC() {
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
#ifdef VIRTUAL #ifdef VIRTUAL
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(0, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp 1G destination IP and port\n")); LOG(logERROR, ("could not set udp 1G destination IP and port\n"));
return FAIL; return FAIL;
} }
@ -1641,7 +1642,7 @@ void *start_timer(void *arg) {
memcpy(packetData + 4, imageData + srcOffset, dataSize); memcpy(packetData + 4, imageData + srcOffset, dataSize);
srcOffset += dataSize; srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, 0, packetData, packetSize);
} }
LOG(logINFO, LOG(logINFO,
("Sent frame: %d [%d]\n", frameNr, virtual_currentFrameNumber)); ("Sent frame: %d [%d]\n", frameNr, virtual_currentFrameNumber));

View File

@ -23,7 +23,8 @@
// Global variable from slsDetectorServer_funcs // Global variable from slsDetectorServer_funcs
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern int numUdpDestinations;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
@ -393,6 +394,7 @@ void setupDetector() {
chipConfigured = 0; chipConfigured = 0;
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif #endif
// get chip version // get chip version
@ -1422,32 +1424,7 @@ void calcChecksum(udp_header *udp) {
int configureMAC() { int configureMAC() {
uint32_t srcip = udpDetails[0].srcip;
uint32_t srcip2 = udpDetails[0].srcip2;
uint32_t dstip = udpDetails[0].dstip;
uint32_t dstip2 = udpDetails[0].dstip2;
uint64_t srcmac = udpDetails[0].srcmac;
uint64_t srcmac2 = udpDetails[0].srcmac2;
uint64_t dstmac = udpDetails[0].dstmac;
uint64_t dstmac2 = udpDetails[0].dstmac2;
int srcport = udpDetails[0].srcport;
int srcport2 = udpDetails[0].srcport2;
int dstport = udpDetails[0].dstport;
int dstport2 = udpDetails[0].dstport2;
LOG(logINFOBLUE, ("Configuring MAC\n")); LOG(logINFOBLUE, ("Configuring MAC\n"));
char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50],
dst_ip[INET_ADDRSTRLEN];
getMacAddressinString(src_mac, 50, srcmac);
getMacAddressinString(dst_mac, 50, dstmac);
getIpAddressinString(src_ip, srcip);
getIpAddressinString(dst_ip, dstip);
char src_mac2[50], src_ip2[INET_ADDRSTRLEN], dst_mac2[50],
dst_ip2[INET_ADDRSTRLEN];
getMacAddressinString(src_mac2, 50, srcmac2);
getMacAddressinString(dst_mac2, 50, dstmac2);
getIpAddressinString(src_ip2, srcip2);
getIpAddressinString(dst_ip2, dstip2);
int numInterfaces = getNumberofUDPInterfaces(); int numInterfaces = getNumberofUDPInterfaces();
int selInterface = getPrimaryInterface(); int selInterface = getPrimaryInterface();
@ -1455,63 +1432,91 @@ int configureMAC() {
LOG(logINFO, ("\tInterface : %d %s\n\n", selInterface, LOG(logINFO, ("\tInterface : %d %s\n\n", selInterface,
(selInterface ? "Inner" : "Outer"))); (selInterface ? "Inner" : "Outer")));
LOG(logINFO, ("\tOuter %s\n", (numInterfaces == 2) for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) {
? "(Bottom)" uint32_t srcip = udpDetails[0].srcip;
: (selInterface ? "Not Used" : "Used"))); uint32_t srcip2 = udpDetails[0].srcip2;
LOG(logINFO, ("\tSource IP : %s\n" uint32_t dstip = udpDetails[0].dstip;
"\tSource MAC : %s\n" uint32_t dstip2 = udpDetails[0].dstip2;
"\tSource Port : %d\n" uint64_t srcmac = udpDetails[0].srcmac;
"\tDest IP : %s\n" uint64_t srcmac2 = udpDetails[0].srcmac2;
"\tDest MAC : %s\n" uint64_t dstmac = udpDetails[0].dstmac;
"\tDest Port : %d\n", uint64_t dstmac2 = udpDetails[0].dstmac2;
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); int srcport = udpDetails[0].srcport;
int srcport2 = udpDetails[0].srcport2;
int dstport = udpDetails[0].dstport;
int dstport2 = udpDetails[0].dstport2;
LOG(logINFO, ("\tInner %s\n", (numInterfaces == 2) char src_mac[50], src_ip[INET_ADDRSTRLEN], dst_mac[50],
? "(Top)" dst_ip[INET_ADDRSTRLEN];
: (selInterface ? "Used" : "Not Used"))); getMacAddressinString(src_mac, 50, srcmac);
LOG(logINFO, ("\tSource IP2 : %s\n" getMacAddressinString(dst_mac, 50, dstmac);
"\tSource MAC2 : %s\n" getIpAddressinString(src_ip, srcip);
"\tSource Port2: %d\n" getIpAddressinString(dst_ip, dstip);
"\tDest IP2 : %s\n" char src_mac2[50], src_ip2[INET_ADDRSTRLEN], dst_mac2[50],
"\tDest MAC2 : %s\n" dst_ip2[INET_ADDRSTRLEN];
"\tDest Port2 : %d\n", getMacAddressinString(src_mac2, 50, srcmac2);
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); getMacAddressinString(dst_mac2, 50, dstmac2);
getIpAddressinString(src_ip2, srcip2);
getIpAddressinString(dst_ip2, dstip2);
LOG(logINFO, ("\tOuter %s\n", (numInterfaces == 2)
? "(Bottom)"
: (selInterface ? "Not Used" : "Used")));
LOG(logINFO, ("\tSource IP : %s\n"
"\tSource MAC : %s\n"
"\tSource Port : %d\n"
"\tDest IP : %s\n"
"\tDest MAC : %s\n"
"\tDest Port : %d\n",
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
LOG(logINFO, ("\tInner %s\n", (numInterfaces == 2)
? "(Top)"
: (selInterface ? "Used" : "Not Used")));
LOG(logINFO, ("\tSource IP2 : %s\n"
"\tSource MAC2 : %s\n"
"\tSource Port2: %d\n"
"\tDest IP2 : %s\n"
"\tDest MAC2 : %s\n"
"\tDest Port2 : %d\n",
src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2));
#ifdef VIRTUAL #ifdef VIRTUAL
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(iRxEntry, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, LOG(logERROR, ("could not set udp destination IP and port for "
("could not set udp destination IP and port for interface 1\n")); "interface 1 [entry:%d] \n",
return FAIL; iRxEntry));
} return FAIL;
if (numInterfaces == 2 && }
setUDPDestinationDetails(1, dst_ip2, dstport2) == FAIL) { if (numInterfaces == 2 &&
LOG(logERROR, setUDPDestinationDetails(iRxEntry, 1, dst_ip2, dstport2) == FAIL) {
("could not set udp destination IP and port for interface 2\n")); LOG(logERROR, ("could not set udp destination IP and port for "
return FAIL; "interface 2 [entry:%d]\n",
} iRxEntry));
return OK; return FAIL;
}
return OK;
#endif #endif
// default one rxr entry (others not yet implemented in client yet)
int iRxEntry = 0;
if (numInterfaces == 2) { if (numInterfaces == 2) {
// bottom // bottom
setupHeader(iRxEntry, OUTER, dstip, dstmac, dstport, srcmac, srcip,
srcport);
// top
setupHeader(iRxEntry, INNER, dstip2, dstmac2, dstport2, srcmac2, srcip2,
srcport2);
}
// single interface
else {
// default
if (selInterface == 0) {
setupHeader(iRxEntry, OUTER, dstip, dstmac, dstport, srcmac, srcip, setupHeader(iRxEntry, OUTER, dstip, dstmac, dstport, srcmac, srcip,
srcport); srcport);
} else { // top
setupHeader(iRxEntry, INNER, dstip, dstmac, dstport, srcmac, srcip, setupHeader(iRxEntry, INNER, dstip2, dstmac2, dstport2, srcmac2, srcip2,
srcport2); srcport2);
} }
// single interface
else {
// default
if (selInterface == 0) {
setupHeader(iRxEntry, OUTER, dstip, dstmac, dstport, srcmac, srcip,
srcport);
} else {
setupHeader(iRxEntry, INNER, dstip, dstmac, dstport, srcmac, srcip,
srcport2);
}
}
} }
setNumberofUDPInterfaces(numInterfaces); setNumberofUDPInterfaces(numInterfaces);
@ -2339,6 +2344,7 @@ void *start_timer(void *arg) {
{ {
uint64_t frameNr = 0; uint64_t frameNr = 0;
getNextFrameNumber(&frameNr); getNextFrameNumber(&frameNr);
int iRxEntry = 0;
for (int iframes = 0; iframes != numFrames; ++iframes) { for (int iframes = 0; iframes != numFrames; ++iframes) {
usleep(transmissionDelayUs); usleep(transmissionDelayUs);
@ -2383,7 +2389,7 @@ void *start_timer(void *arg) {
srcOffset += dataSize; srcOffset += dataSize;
if (i >= startval && i <= endval) { if (i >= startval && i <= endval) {
sendUDPPacket(0, packetData, packetsize); sendUDPPacket(iRxEntry, 0, packetData, packetsize);
LOG(logDEBUG1, ("Sent packet: %d [interface 0]\n", i)); LOG(logDEBUG1, ("Sent packet: %d [interface 0]\n", i));
} }
} }
@ -2410,10 +2416,14 @@ void *start_timer(void *arg) {
srcOffset2 += dataSize; srcOffset2 += dataSize;
if (i >= startval && i <= endval) { if (i >= startval && i <= endval) {
sendUDPPacket(1, packetData2, packetsize); sendUDPPacket(iRxEntry, 1, packetData2, packetsize);
LOG(logDEBUG1, ("Sent packet: %d [interface 1]\n", pnum)); LOG(logDEBUG1, ("Sent packet: %d [interface 1]\n", pnum));
} }
} }
++iRxEntry;
if (iRxEntry == numUdpDestinations) {
iRxEntry = 0;
}
} }
LOG(logINFO, ("Sent frame: %d\n", iframes)); LOG(logINFO, ("Sent frame: %d\n", iframes));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);

View File

@ -23,7 +23,7 @@
// Global variable from slsDetectorServer_funcs // Global variable from slsDetectorServer_funcs
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from UDPPacketHeaderGenerator // Global variable from UDPPacketHeaderGenerator
@ -487,6 +487,7 @@ void setupDetector() {
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
initializePatternWord(); initializePatternWord();
#endif #endif
setupUDPCommParameters();
ALTERA_PLL_ResetPLLAndReconfiguration(); ALTERA_PLL_ResetPLLAndReconfiguration();
resetCore(); resetCore();
@ -1209,7 +1210,7 @@ int configureMAC() {
LOG(logINFOBLUE, ("\t1G MAC\n")); LOG(logINFOBLUE, ("\t1G MAC\n"));
if (updateDatabytesandAllocateRAM() == FAIL) if (updateDatabytesandAllocateRAM() == FAIL)
return -1; return -1;
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(0, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp 1G destination IP and port\n")); LOG(logERROR, ("could not set udp 1G destination IP and port\n"));
return FAIL; return FAIL;
} }
@ -1687,7 +1688,7 @@ void *start_timer(void *arg) {
imageData + srcOffset, dataSize); imageData + srcOffset, dataSize);
srcOffset += dataSize; srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, 0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber)); (long long unsigned int)virtual_currentFrameNumber));
@ -1806,10 +1807,10 @@ void readandSendUDPFrames(int *ret, char *mess) {
LOG(logDEBUG1, ("Reading from 1G UDP\n")); LOG(logDEBUG1, ("Reading from 1G UDP\n"));
// validate udp socket // validate udp socket
if (getUdPSocketDescriptor(0) <= 0) { if (getUdPSocketDescriptor(0, 0) <= 0) {
*ret = FAIL; *ret = FAIL;
sprintf(mess, "UDP Socket not created. sockfd:%d\n", sprintf(mess, "UDP Socket not created. sockfd:%d\n",
getUdPSocketDescriptor(0)); getUdPSocketDescriptor(0, 0));
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return; return;
} }
@ -1818,7 +1819,7 @@ void readandSendUDPFrames(int *ret, char *mess) {
while (readFrameFromFifo() == OK) { while (readFrameFromFifo() == OK) {
int bytesToSend = 0, n = 0; int bytesToSend = 0, n = 0;
while ((bytesToSend = fillUDPPacket(udpPacketData))) { while ((bytesToSend = fillUDPPacket(udpPacketData))) {
n += sendUDPPacket(0, udpPacketData, bytesToSend); n += sendUDPPacket(0, 0, udpPacketData, bytesToSend);
} }
if (n >= dataBytes) { if (n >= dataBytes) {
LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d " LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d "

View File

@ -25,7 +25,7 @@
extern int debugflag; extern int debugflag;
extern int updateFlag; extern int updateFlag;
extern int checkModuleFlag; extern int checkModuleFlag;
extern udpStruct udpDetails; extern udpStruct udpDetails[MAX_UDP_DESTINATION];
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
@ -429,6 +429,7 @@ void setupDetector() {
} }
#ifdef VIRTUAL #ifdef VIRTUAL
sharedMemory_setStatus(IDLE); sharedMemory_setStatus(IDLE);
setupUDPCommParameters();
#endif #endif
// pll defines // pll defines
@ -1746,7 +1747,7 @@ int configureMAC() {
src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); src_ip, src_mac, srcport, dst_ip, dst_mac, dstport));
#ifdef VIRTUAL #ifdef VIRTUAL
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { if (setUDPDestinationDetails(0, 0, dst_ip, dstport) == FAIL) {
LOG(logERROR, ("could not set udp destination IP and port\n")); LOG(logERROR, ("could not set udp destination IP and port\n"));
return FAIL; return FAIL;
} }
@ -2290,7 +2291,7 @@ void *start_timer(void *arg) {
imageData + srcOffset, dataSize); imageData + srcOffset, dataSize);
srcOffset += dataSize; srcOffset += dataSize;
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, 0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber)); (long long unsigned int)virtual_currentFrameNumber));

View File

@ -1,35 +1,15 @@
#pragma once #pragma once
/**
* Get UDP socket desicriptor
* @param udp port index
*/
int getUdPSocketDescriptor(int index);
/** void setupUDPCommParameters();
* Set udp destination
* @param index udp port index int getUdPSocketDescriptor(int iRxEntry, int index);
* @param ip udp destination ip
* @param port udp destination port void setNumberOfUDPDestinations(int value);
*/
int setUDPDestinationDetails(int index, const char *ip, int setUDPDestinationDetails(int iRxEntry, int index, const char *ip,
unsigned short int port); unsigned short int port);
/**
* Create udp socket
* @param index udp port index
*/
int createUDPSocket(int index); int createUDPSocket(int index);
/** int sendUDPPacket(int iRxEntry, int index, const char *buf, int length);
* Writes to socket file descriptor
* @param index udp port index
* @param buf pointer to memory to write
* @param length length of buffer to write to socket
*/
int sendUDPPacket(int index, const char *buf, int length);
/**
* Close udp socket
* @index udp port index
*/
void closeUDPSocket(int index); void closeUDPSocket(int index);

View File

@ -13,25 +13,35 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
int udpSockfd[2] = {-1, -1}; int udpSockfd[MAX_UDP_DESTINATION][2] = {};
struct addrinfo *udpServerAddrInfo[2] = {0, 0}; struct addrinfo *udpServerAddrInfo[MAX_UDP_DESTINATION][2] = {};
unsigned short int udpDestinationPort[2] = {0, 0}; unsigned short int udpDestinationPort[MAX_UDP_DESTINATION][2] = {};
char udpDestinationIp[2][INET_ADDRSTRLEN] = {"", ""}; char udpDestinationIp[MAX_UDP_DESTINATION][2][INET_ADDRSTRLEN] = {};
extern int numUdpDestinations;
// DEFAULT_TX_UDP_PORT;// src port void setupUDPCommParameters() {
int getUdPSocketDescriptor(int index) { return udpSockfd[index]; } for (int i = 0; i != MAX_UDP_DESTINATION; i++) {
udpSockfd[i][0] = -1;
udpSockfd[i][1] = -1;
}
memset(udpServerAddrInfo, 0, sizeof(udpServerAddrInfo));
memset(udpDestinationIp, 0, sizeof(udpDestinationIp));
}
int setUDPDestinationDetails(int index, const char *ip, int getUdPSocketDescriptor(int iRxEntry, int index) { return udpSockfd[iRxEntry][index]; }
int setUDPDestinationDetails(int iRxEntry, int index, const char *ip,
unsigned short int port) { unsigned short int port) {
udpDestinationPort[index] = port; udpDestinationPort[iRxEntry][index] = port;
size_t len = strlen(ip); size_t len = strlen(ip);
memset(udpDestinationIp[index], 0, INET_ADDRSTRLEN); memset(udpDestinationIp[iRxEntry][index], 0, INET_ADDRSTRLEN);
strncpy(udpDestinationIp[index], ip, strncpy(udpDestinationIp[iRxEntry][index], ip,
len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len); len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len);
if (udpServerAddrInfo[index]) { if (udpServerAddrInfo[iRxEntry][index]) {
freeaddrinfo(udpServerAddrInfo[index]); freeaddrinfo(udpServerAddrInfo[iRxEntry][index]);
udpServerAddrInfo[index] = 0; udpServerAddrInfo[iRxEntry][index] = 0;
} }
// convert ip to internet address // convert ip to internet address
@ -43,21 +53,21 @@ int setUDPDestinationDetails(int index, const char *ip,
hints.ai_protocol = 0; hints.ai_protocol = 0;
char sport[100]; char sport[100];
memset(sport, 0, 100); memset(sport, 0, 100);
sprintf(sport, "%d", udpDestinationPort[index]); sprintf(sport, "%d", udpDestinationPort[iRxEntry][index]);
int err = getaddrinfo(udpDestinationIp[index], sport, &hints, int err = getaddrinfo(udpDestinationIp[iRxEntry][index], sport, &hints,
&udpServerAddrInfo[index]); &udpServerAddrInfo[iRxEntry][index]);
if (err != 0) { if (err != 0) {
LOG(logERROR, ("Failed to resolve remote socket address %s at port %d. " LOG(logERROR, ("Failed to resolve remote socket address %s at port %d [entry:%d]. "
"(Error code:%d, %s)\n", "(Error code:%d, %s)\n",
udpDestinationIp[index], udpDestinationPort[index], err, udpDestinationIp[iRxEntry][index], udpDestinationPort[iRxEntry][index], iRxEntry, err,
gai_strerror(err))); gai_strerror(err)));
return FAIL; return FAIL;
} }
if (udpServerAddrInfo[index] == NULL) { if (udpServerAddrInfo[iRxEntry][index] == NULL) {
LOG(logERROR, ("Failed to resolve remote socket address %s at port %d " LOG(logERROR, ("Failed to resolve remote socket address %s at port %d [entry:%d]."
"(getaddrinfo returned NULL)\n", "(getaddrinfo returned NULL)\n",
udpDestinationIp[index], udpDestinationPort[index])); udpDestinationIp[iRxEntry][index], udpDestinationPort[iRxEntry][index], iRxEntry));
udpServerAddrInfo[index] = 0; udpServerAddrInfo[iRxEntry][index] = 0;
return FAIL; return FAIL;
} }
@ -65,49 +75,54 @@ int setUDPDestinationDetails(int index, const char *ip,
} }
int createUDPSocket(int index) { int createUDPSocket(int index) {
LOG(logDEBUG2, ("Creating UDP Socket %d\n", index));
if (!strlen(udpDestinationIp[index])) {
LOG(logERROR, ("No destination UDP ip specified.\n"));
return FAIL;
}
if (udpSockfd[index] != -1) { for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) {
LOG(logERROR, ("Strange that Udp socket was still open. Closing it to "
"create a new one\n"));
close(udpSockfd[index]);
udpSockfd[index] = -1;
}
// Creating socket file descriptor LOG(logDEBUG2, ("Creating UDP Socket %d [entry:%d]\n", index, iRxEntry));
udpSockfd[index] = socket(udpServerAddrInfo[index]->ai_family, if (!strlen(udpDestinationIp[iRxEntry][index])) {
udpServerAddrInfo[index]->ai_socktype, LOG(logERROR, ("No destination UDP ip specified for socket %d [entry:%d].\n", index, iRxEntry));
udpServerAddrInfo[index]->ai_protocol); return FAIL;
if (udpSockfd[index] == -1) { }
LOG(logERROR, ("UDP socket at port %d failed. (Error code:%d, %s)\n",
udpDestinationPort[index], errno, gai_strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Udp client socket created for server (port %d, ip:%s)\n",
udpDestinationPort[index], udpDestinationIp[index]));
// Using connect expects that the receiver (udp server) exists to listen to if (udpSockfd[iRxEntry][index] != -1) {
// these packets connecting allows to use "send/write" instead of "sendto", LOG(logERROR, ("Strange that Udp socket was still open [socket:%d, entry:%d]. Closing it to "
// avoiding checking for server address for each packet using write without "create a new one.\n", index, iRxEntry));
// a connect will end in segv close(udpSockfd[iRxEntry][index]);
LOG(logINFO, ("Udp client socket connected\n", udpDestinationPort[index], udpSockfd[iRxEntry][index] = -1;
udpDestinationIp[index])); }
// Creating socket file descriptor
udpSockfd[iRxEntry][index] = socket(udpServerAddrInfo[iRxEntry][index]->ai_family,
udpServerAddrInfo[iRxEntry][index]->ai_socktype,
udpServerAddrInfo[iRxEntry][index]->ai_protocol);
if (udpSockfd[iRxEntry][index] == -1) {
LOG(logERROR, ("UDP socket at port %d failed [entry:%d]. (Error code:%d, %s)\n",
udpDestinationPort[iRxEntry][index], iRxEntry, errno, gai_strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Udp client socket created for server (entry:%d, port %d, ip:%s)\n",
iRxEntry, udpDestinationPort[iRxEntry][index], udpDestinationIp[iRxEntry][index]));
// Using connect expects that the receiver (udp server) exists to listen to
// these packets connecting allows to use "send/write" instead of "sendto",
// avoiding checking for server address for each packet using write without
// a connect will end in segv
LOG(logINFO, ("Udp client socket connected [%d, %d, %s]\n", iRxEntry, udpDestinationPort[iRxEntry][index],
udpDestinationIp[iRxEntry][index]));
}
return OK; return OK;
} }
int sendUDPPacket(int index, const char *buf, int length) { int sendUDPPacket(int iRxEntry, int index, const char *buf, int length) {
int n = sendto(udpSockfd[index], buf, length, 0, int n = sendto(udpSockfd[iRxEntry][index], buf, length, 0,
udpServerAddrInfo[index]->ai_addr, udpServerAddrInfo[iRxEntry][index]->ai_addr,
udpServerAddrInfo[index]->ai_addrlen); udpServerAddrInfo[iRxEntry][index]->ai_addrlen);
// udp sends atomically, no need to handle partial data // udp sends atomically, no need to handle partial data
if (n == -1) { if (n == -1) {
LOG(logERROR, LOG(logERROR,
("Could not send udp packet for socket %d. (Error code:%d, %s)\n", ("Could not send udp packet for socket %d [entry:%d]. (Error code:%d, %s)\n",
index, n, errno, gai_strerror(errno))); index, iRxEntry, errno, gai_strerror(errno)));
} else { } else {
LOG(logDEBUG2, ("%d bytes sent\n", n)); LOG(logDEBUG2, ("%d bytes sent\n", n));
} }
@ -115,9 +130,11 @@ int sendUDPPacket(int index, const char *buf, int length) {
} }
void closeUDPSocket(int index) { void closeUDPSocket(int index) {
if (udpSockfd[index] != -1) { for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) {
LOG(logINFO, ("Udp client socket closed\n")); if (udpSockfd[iRxEntry][index] != -1) {
close(udpSockfd[index]); LOG(logINFO, ("Udp client socket closed\n"));
udpSockfd[index] = -1; close(udpSockfd[iRxEntry][index]);
udpSockfd[iRxEntry][index] = -1;
}
} }
} }

View File

@ -50,9 +50,9 @@ int debugflag = 0;
int updateFlag = 0; int updateFlag = 0;
int checkModuleFlag = 1; int checkModuleFlag = 1;
const int MAX_UDP_DESTINATION = 32; udpStruct udpDetails[MAX_UDP_DESTINATION];
udpStruct udpDetails[MAX_UDP_DESTINATION] = {32410, 32411, 50001, 50002, 0, 0, int numUdpDestinations = 1;
0, 0, 0, 0, 0, 0};
int configured = FAIL; int configured = FAIL;
char configureMessage[MAX_STR_LENGTH] = "udp parameters not configured yet"; char configureMessage[MAX_STR_LENGTH] = "udp parameters not configured yet";
int maxydet = -1; int maxydet = -1;
@ -82,6 +82,11 @@ void init_detector() {
#ifdef VIRTUAL #ifdef VIRTUAL
LOG(logINFO, ("This is a VIRTUAL detector\n")); LOG(logINFO, ("This is a VIRTUAL detector\n"));
#endif #endif
memset(udpDetails, 0, sizeof(udpDetails));
udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO;
udpDetails[0].srcport2 = DEFAULT_UDP_SRC_PORTNO + 1;
udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO;
udpDetails[0].dstport2 = DEFAULT_UDP_DST_PORTNO + 1;
if (isControlServer) { if (isControlServer) {
basictests(); basictests();
initControlServer(); initControlServer();
@ -4918,50 +4923,52 @@ int check_detector_idle(const char *s) {
} }
int is_udp_configured() { int is_udp_configured() {
if (udpDetails[0].dstip == 0) { for (int i = 0; i != numUdpDestinations; ++i) {
strcpy(configureMessage, "udp destination ip not configured\n"); if (udpDetails[i].dstip == 0) {
LOG(logWARNING, ("%s", configureMessage)); strcpy(configureMessage, "udp destination ip not configured\n");
return FAIL; LOG(logWARNING, ("%s", configureMessage));
} return FAIL;
if (udpDetails[0].srcip == 0) { }
strcpy(configureMessage, "udp source ip not configured\n"); if (udpDetails[i].srcip == 0) {
LOG(logWARNING, ("%s", configureMessage)); strcpy(configureMessage, "udp source ip not configured\n");
return FAIL; LOG(logWARNING, ("%s", configureMessage));
} return FAIL;
if (udpDetails[0].srcmac == 0) { }
strcpy(configureMessage, "udp source mac not configured\n"); if (udpDetails[i].srcmac == 0) {
LOG(logWARNING, ("%s", configureMessage)); strcpy(configureMessage, "udp source mac not configured\n");
return FAIL; LOG(logWARNING, ("%s", configureMessage));
} return FAIL;
if (udpDetails[0].dstmac == 0) { }
strcpy(configureMessage, "udp destination mac not configured\n"); if (udpDetails[i].dstmac == 0) {
LOG(logWARNING, ("%s", configureMessage)); strcpy(configureMessage, "udp destination mac not configured\n");
return FAIL; LOG(logWARNING, ("%s", configureMessage));
} return FAIL;
}
#if defined(JUNGFRAUD) || defined(GOTTHARD2D) #if defined(JUNGFRAUD) || defined(GOTTHARD2D)
if (getNumberofUDPInterfaces() == 2) { if (getNumberofUDPInterfaces() == 2) {
if (udpDetails[0].srcip2 == 0) { if (udpDetails[i].srcip2 == 0) {
strcpy(configureMessage, "udp source ip2 not configured\n"); strcpy(configureMessage, "udp source ip2 not configured\n");
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
}
if (udpDetails[i].dstip2 == 0) {
strcpy(configureMessage, "udp destination ip2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
if (udpDetails[i].srcmac2 == 0) {
strcpy(configureMessage, "udp source mac2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
if (udpDetails[i].dstmac2 == 0) {
strcpy(configureMessage, "udp destination mac2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
} }
if (udpDetails[0].dstip2 == 0) {
strcpy(configureMessage, "udp destination ip2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
if (udpDetails[0].srcmac2 == 0) {
strcpy(configureMessage, "udp source mac2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
if (udpDetails[0].dstmac2 == 0) {
strcpy(configureMessage, "udp destination mac2 not configured\n");
LOG(logWARNING, ("%s", configureMessage));
return FAIL;
}
}
#endif #endif
}
return OK; return OK;
} }
@ -8988,14 +8995,17 @@ 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]{}; uint32_t retvals[5] = {};
uint64_t retvals64[2]{}; uint64_t retvals64[2] = {};
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Getting udp destination list for entry %d\n", arg)); LOG(logDEBUG1, ("Getting udp destination list for entry %d\n", arg));
#if !defined(EIGERD) && !defined(JUNGFRAUD) #if !defined(EIGERD) && !defined(JUNGFRAUD)
functionNotImplemented(); functionNotImplemented();
#else #else
if (arg < 0 || arg > MAX_UDP_DESTINATION) { if (arg > MAX_UDP_DESTINATION) {
ret = FAIL; ret = FAIL;
sprintf( sprintf(
mess, mess,
@ -9008,24 +9018,30 @@ int get_dest_udp_list(int file_des) {
retvals[2] = udpDetails[arg].dstport2; retvals[2] = udpDetails[arg].dstport2;
retvals[3] = udpDetails[arg].dstip; retvals[3] = udpDetails[arg].dstip;
retvals[4] = udpDetails[arg].dstip2; retvals[4] = udpDetails[arg].dstip2;
retvals_64[0] = udpDetails[arg].dstmac; retvals64[0] = udpDetails[arg].dstmac;
retvals_64[1] = udpDetails[arg].dstmac2; retvals64[1] = udpDetails[arg].dstmac2;
// swap ip
retvals[3] = __builtin_bswap32(retvals[3]);
retvals[4] = __builtin_bswap32(retvals[4]);
// convert to string
char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN];
getIpAddressinString(ip, retvals[3]); getIpAddressinString(ip, retvals[3]);
getIpAddressinString(ip2, retvals[4]); getIpAddressinString(ip2, retvals[4]);
char mac[50], mac2[50]; char mac[50], mac2[50];
getMacAddressinString(mac, 50, retvals_64[0]); getMacAddressinString(mac, 50, retvals64[0]);
getMacAddressinString(mac2, 50, retvals_64[1]); getMacAddressinString(mac2, 50, retvals64[1]);
LOG(logDEBUG1, LOG(logDEBUG1,
("Udp Dest. retval [%d]: [port:%d, port2:%d, ip:%s, ip2:%s, " ("Udp Dest. retval [%d]: [port %d, port2 %d, ip %s, ip2 %s, "
"mac:%s, mac2:%s]\n", "mac %s, mac2 %s]\n",
retvals[0], retvals[1], retvals[2], ip, ip2, mac, mac2)); retvals[0], retvals[1], retvals[2], 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, retvals, sizeof(retvals), INT32);
sendData(file_des, retvals_64, sizeof(retvals_64), INT64); sendData(file_des, retvals64, sizeof(retvals64), INT64);
} }
return ret; return ret;
} }
@ -9033,33 +9049,65 @@ 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 args[5] = {};
uint64_t args_64[2]{}; uint64_t args64[2] = {};
if (receiveData(file_des, args, sizeof(args), INT32) < 0) if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
if (receiveData(file_des, args_64, sizeof(args_64), INT64) < 0) if (receiveData(file_des, args64, sizeof(args64), INT64) < 0)
return printSocketReadError(); return printSocketReadError();
// swap ip
args[3] = __builtin_bswap32(args[3]);
args[4] = __builtin_bswap32(args[4]);
// convert to string
LOG(logINFOBLUE, ("Setting current source [enable:%d, fix:%d, select:%lld, " char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN];
"normal:%d]\n", getIpAddressinString(ip, args[3]);
enable, fix, (long long int)select, normal)); getIpAddressinString(ip2, args[4]);
char mac[50], mac2[50];
getMacAddressinString(mac, 50, args64[0]);
getMacAddressinString(mac2, 50, args64[1]);
#if !defined(EIGERD) && !defined(JUNGFRAUD) #if !defined(EIGERD) && !defined(JUNGFRAUD)
functionNotImplemented(); functionNotImplemented();
#else #else
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
if (arg < 1 || arg > MAX_UDP_DESTINATION) { int entry = args[0];
ret = FAIL; LOG(logINFOBLUE,
sprintf( ("Setting udp dest. [%d]: [port %d, port2 %d, ip %s, ip2 %s, "
mess, "mac %s, mac2 %s]\n",
"Could not set udp destination. Invalid entry. Options: 1 - %d\n", entry, args[1], args[2], ip, ip2, mac, mac2));
MAX_UDP_DESTINATION);
LOG(logERROR, (mess));
} else {
if (entry < 1 || entry > MAX_UDP_DESTINATION) {
ret = FAIL;
sprintf(
mess,
"Could not set udp destination. Invalid entry. Options: 1 - %d\n",
MAX_UDP_DESTINATION);
LOG(logERROR, (mess));
}
#ifdef EIGERD
else if (args[4] != 0 || args64[1] != 0) {
ret = FAIL;
strcpy(
mess,
"Could not set udp destination. ip2 and mac2 not implemented for this detector.\n");
LOG(logERROR, (mess));
}
#endif
else {
if (check_detector_idle("set udp destination list entries") == OK) {
udpDetails[entry].dstport = args[1];
udpDetails[entry].dstport2 = args[2];
udpDetails[entry].dstip = args[3];
udpDetails[entry].dstip2 = args[4];
udpDetails[entry].dstmac = args64[0];
udpDetails[entry].dstmac2 = args64[1];
configure_mac();
}
}
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);

View File

@ -948,14 +948,14 @@ void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) {
// set them in the default way so the receivers are also set up // set them in the default way so the receivers are also set up
if (dest.entry_ == 0) { if (dest.entry_ == 0) {
setDestinationUDPPort(dest.port_); setDestinationUDPPort(dest.port_);
setDestinationUDPIP(dest.ip_); setDestinationUDPIP(IpAddr(dest.ip_));
setDestinationUDPMAC(dest.mac_); setDestinationUDPMAC(MacAddr(dest.mac_));
if (dest.port_ != 0) { if (dest.port_ != 0) {
setDestinationUDPPort2(dest.port2_); setDestinationUDPPort2(dest.port2_);
} }
if (dest.ip2_ != 0) { if (dest.ip2_ != 0) {
setDestinationUDPIP2(dest.ip2_); setDestinationUDPIP2(IpAddr(dest.ip2_));
setDestinationUDPMAC2(dest.mac2_); setDestinationUDPMAC2(MacAddr(dest.mac2_));
} }
} else { } else {
sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr);

View File

@ -36,6 +36,10 @@
#define DEFAULT_UDP_PORTNO 50001 #define DEFAULT_UDP_PORTNO 50001
#define DEFAULT_ZMQ_CL_PORTNO 30001 #define DEFAULT_ZMQ_CL_PORTNO 30001
#define DEFAULT_ZMQ_RX_PORTNO 30001 #define DEFAULT_ZMQ_RX_PORTNO 30001
#define DEFAULT_UDP_SRC_PORTNO 32410
#define DEFAULT_UDP_DST_PORTNO 50001
#define MAX_UDP_DESTINATION 32
#define SLS_DETECTOR_HEADER_VERSION 0x2 #define SLS_DETECTOR_HEADER_VERSION 0x2
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x4 #define SLS_DETECTOR_JSON_HEADER_VERSION 0x4