diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index 7d6d1dfad..38995bb54 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -25,7 +25,7 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern const enum detectorType myDetectorType; // Global variable from UDPPacketHeaderGenerator @@ -480,6 +480,7 @@ void setupDetector() { sharedMemory_setStatus(IDLE); initializePatternWord(); #endif + setupUDPCommParameters(); ALTERA_PLL_ResetPLLAndReconfiguration(); resetCore(); @@ -1544,7 +1545,7 @@ int configureMAC() { LOG(logINFOBLUE, ("\t1G MAC\n")); if (updateDatabytesandAllocateRAM() == FAIL) 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")); return FAIL; } @@ -2023,7 +2024,7 @@ void *start_timer(void *arg) { imageData + srcOffset, dataSize); srcOffset += dataSize; - sendUDPPacket(0, packetData, packetSize); + sendUDPPacket(0, 0, packetData, packetSize); } LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, (long long unsigned int)virtual_currentFrameNumber)); @@ -2140,10 +2141,10 @@ void readandSendUDPFrames(int *ret, char *mess) { LOG(logDEBUG1, ("Reading from 1G UDP\n")); // validate udp socket - if (getUdPSocketDescriptor(0) <= 0) { + if (getUdPSocketDescriptor(0, 0) <= 0) { *ret = FAIL; sprintf(mess, "UDP Socket not created. sockfd:%d\n", - getUdPSocketDescriptor(0)); + getUdPSocketDescriptor(0, 0)); LOG(logERROR, (mess)); return; } @@ -2152,7 +2153,7 @@ void readandSendUDPFrames(int *ret, char *mess) { while (readFrameFromFifo() == OK) { int bytesToSend = 0, n = 0; while ((bytesToSend = fillUDPPacket(udpPacketData))) { - n += sendUDPPacket(0, udpPacketData, bytesToSend); + n += sendUDPPacket(0, 0, udpPacketData, bytesToSend); } if (n >= dataBytes) { LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d " diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index 6bc68a9d4..19c1513c5 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -1163,10 +1163,6 @@ int Beb_SetUpTransferParameters(short the_bit_mode) { the_bit_mode != 32) return 0; Beb_bit_mode = the_bit_mode; - - // nimages = the_number_of_images; - // on_dst = 0; - return 1; } @@ -1209,7 +1205,7 @@ int Beb_RequestNImages(unsigned int beb_number, int ten_gig, if (!Beb_activated) return 1; - if (dst_number > 64) + if (dst_number >= 64) return 0; unsigned int maxnl = MAX_ROWS_PER_READOUT; diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 215e808aa..e2bed03c2 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -21,7 +21,8 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; +extern int numUdpDestinations; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c @@ -689,6 +690,7 @@ void setupDetector() { resetToDefaultDacs(0); #ifdef VIRTUAL sharedMemory_setStatus(IDLE); + setupUDPCommParameters(); #endif LOG(logINFOBLUE, ("Setting Default Parameters\n")); @@ -1518,79 +1520,87 @@ enum timingMode getTiming() { /* configure mac */ 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")); - 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)); + for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) { + 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; + + 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 - if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { - LOG(logERROR, ("could not set udp destination IP and port\n")); - return FAIL; - } - if (setUDPDestinationDetails(1, dst_ip, dstport2) == FAIL) { - LOG(logERROR, ("could not set udp destination IP and port2\n")); - return FAIL; - } - return OK; + if (setUDPDestinationDetails(iRxEntry, 0, dst_ip, dstport) == FAIL) { + LOG(logERROR, + ("could not set udp destination IP and port [entry:%d]\n", + iRxEntry)); + return FAIL; + } + if (setUDPDestinationDetails(iRxEntry, 1, dst_ip, dstport2) == FAIL) { + LOG(logERROR, + ("could not set udp destination IP and port2 [entry:%d]\n", + iRxEntry)); + return FAIL; + } + return OK; #else - int beb_num = detid; - int header_number = 0; - int dst_port = dstport; - if (!top) + int beb_num = detid; + int dst_port = dstport; + 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; + if (!top) + dst_port = dstport; - if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip, - srcport) && - Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, header_number, dst_mac, - dst_ip, dst_port)) { - LOG(logDEBUG1, ("\tset up left ok\n")); - } else { - return FAIL; - } + if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip, + srcport) && + Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, + iRxEntry + MAX_UDP_DESTINATION, dst_mac, dst_ip, + dst_port)) { + LOG(logDEBUG1, (" set up right ok\n")); + } else { + return FAIL; + } - header_number = 32; - dst_port = dstport2; - if (!top) - dst_port = dstport; + on_dst = 0; - if (Beb_SetBebSrcHeaderInfos(beb_num, send_to_ten_gig, src_mac, src_ip, - srcport) && - Beb_SetUpUDPHeader(beb_num, send_to_ten_gig, header_number, dst_mac, - 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; + for (int i = 0; i < 32; ++i) + dst_requested[i] = 0; // clear dst requested + nimages_per_request = eiger_nexposures * eiger_ntriggers; #endif + } return OK; } @@ -2381,6 +2391,7 @@ void *start_timer(void *arg) { if (!skipData) { uint64_t frameNr = 0; getNextFrameNumber(&frameNr); + int iRxEntry = 0; // loop over number of frames 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) { usleep(eiger_virtual_transmission_delay_left); - sendUDPPacket(0, packetData, packetsize); + sendUDPPacket(iRxEntry, 0, packetData, packetsize); LOG(logDEBUG1, ("Sent left packet: %d\n", i)); } if (eiger_virtual_right_datastream && i >= startval && i <= endval) { usleep(eiger_virtual_transmission_delay_right); - sendUDPPacket(1, packetData2, packetsize); + sendUDPPacket(iRxEntry, 1, packetData2, packetsize); LOG(logDEBUG1, ("Sent right packet: %d\n", i)); } } @@ -2492,6 +2503,10 @@ void *start_timer(void *arg) { usleep((periodNs - timeNs) / 1000); } } + ++iRxEntry; + if (iRxEntry == numUdpDestinations) { + iRxEntry = 0; + } } setNextFrameNumber(frameNr + numFrames); } diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 86c4d3828..fc09b7763 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -24,7 +24,7 @@ extern int debugflag; extern int updateFlag; extern int checkModuleFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c @@ -417,6 +417,7 @@ void setupDetector() { memset(adcConfiguration, 0, sizeof(adcConfiguration)); #ifdef VIRTUAL sharedMemory_setStatus(IDLE); + setupUDPCommParameters(); #endif // pll defines @@ -1786,11 +1787,11 @@ int configureMAC() { src_ip2, src_mac2, srcport2, dst_ip2, dst_mac2, dstport2)); #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")); 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 " "interface 2\n")); return FAIL; @@ -2915,7 +2916,7 @@ void *start_timer(void *arg) { memcpy(packetData + sizeof(sls_detector_header), imageData, datasize); // send 1 packet = 1 frame - sendUDPPacket(0, packetData, packetsize); + sendUDPPacket(0, 0, packetData, packetsize); // second interface (veto) char packetData2[vetopacketsize]; @@ -2929,7 +2930,7 @@ void *start_timer(void *arg) { memcpy(packetData2 + sizeof(veto_header), vetoData, vetodatasize); // 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", (i10gbe ? "(+veto)" : ""), frameNr, repeatNr, diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index c0c127617..453493943 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -21,7 +21,7 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern const enum detectorType myDetectorType; // Variables that will be exported @@ -376,6 +376,7 @@ void setupDetector() { #ifdef VIRTUAL sharedMemory_setStatus(IDLE); + setupUDPCommParameters(); #endif // Initialization @@ -1355,7 +1356,7 @@ int configureMAC() { src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); #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")); return FAIL; } @@ -1641,7 +1642,7 @@ void *start_timer(void *arg) { memcpy(packetData + 4, imageData + srcOffset, dataSize); srcOffset += dataSize; - sendUDPPacket(0, packetData, packetSize); + sendUDPPacket(0, 0, packetData, packetSize); } LOG(logINFO, ("Sent frame: %d [%d]\n", frameNr, virtual_currentFrameNumber)); diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 3abdf8f5e..3fc6b37a1 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -23,7 +23,8 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; +extern int numUdpDestinations; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c @@ -393,6 +394,7 @@ void setupDetector() { chipConfigured = 0; #ifdef VIRTUAL sharedMemory_setStatus(IDLE); + setupUDPCommParameters(); #endif // get chip version @@ -1422,32 +1424,7 @@ void calcChecksum(udp_header *udp) { 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")); - 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 selInterface = getPrimaryInterface(); @@ -1455,63 +1432,91 @@ int configureMAC() { LOG(logINFO, ("\tInterface : %d %s\n\n", selInterface, (selInterface ? "Inner" : "Outer"))); - 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)); + for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) { + 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(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)); + 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); + + 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 - if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) { - LOG(logERROR, - ("could not set udp destination IP and port for interface 1\n")); - return FAIL; - } - if (numInterfaces == 2 && - setUDPDestinationDetails(1, dst_ip2, dstport2) == FAIL) { - LOG(logERROR, - ("could not set udp destination IP and port for interface 2\n")); - return FAIL; - } - return OK; + if (setUDPDestinationDetails(iRxEntry, 0, dst_ip, dstport) == FAIL) { + LOG(logERROR, ("could not set udp destination IP and port for " + "interface 1 [entry:%d] \n", + iRxEntry)); + return FAIL; + } + if (numInterfaces == 2 && + setUDPDestinationDetails(iRxEntry, 1, dst_ip2, dstport2) == FAIL) { + LOG(logERROR, ("could not set udp destination IP and port for " + "interface 2 [entry:%d]\n", + iRxEntry)); + return FAIL; + } + return OK; #endif - // default one rxr entry (others not yet implemented in client yet) - int iRxEntry = 0; - if (numInterfaces == 2) { - // 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) { + if (numInterfaces == 2) { + // bottom setupHeader(iRxEntry, OUTER, dstip, dstmac, dstport, srcmac, srcip, srcport); - } else { - setupHeader(iRxEntry, INNER, dstip, dstmac, dstport, srcmac, srcip, + // 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, + srcport); + } else { + setupHeader(iRxEntry, INNER, dstip, dstmac, dstport, srcmac, srcip, + srcport2); + } + } } setNumberofUDPInterfaces(numInterfaces); @@ -2339,6 +2344,7 @@ void *start_timer(void *arg) { { uint64_t frameNr = 0; getNextFrameNumber(&frameNr); + int iRxEntry = 0; for (int iframes = 0; iframes != numFrames; ++iframes) { usleep(transmissionDelayUs); @@ -2383,7 +2389,7 @@ void *start_timer(void *arg) { srcOffset += dataSize; if (i >= startval && i <= endval) { - sendUDPPacket(0, packetData, packetsize); + sendUDPPacket(iRxEntry, 0, packetData, packetsize); LOG(logDEBUG1, ("Sent packet: %d [interface 0]\n", i)); } } @@ -2410,10 +2416,14 @@ void *start_timer(void *arg) { srcOffset2 += dataSize; if (i >= startval && i <= endval) { - sendUDPPacket(1, packetData2, packetsize); + sendUDPPacket(iRxEntry, 1, packetData2, packetsize); LOG(logDEBUG1, ("Sent packet: %d [interface 1]\n", pnum)); } } + ++iRxEntry; + if (iRxEntry == numUdpDestinations) { + iRxEntry = 0; + } } LOG(logINFO, ("Sent frame: %d\n", iframes)); clock_gettime(CLOCK_REALTIME, &end); diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 3839f4c7f..4029c5469 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -23,7 +23,7 @@ // Global variable from slsDetectorServer_funcs extern int debugflag; extern int updateFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern const enum detectorType myDetectorType; // Global variable from UDPPacketHeaderGenerator @@ -487,6 +487,7 @@ void setupDetector() { sharedMemory_setStatus(IDLE); initializePatternWord(); #endif + setupUDPCommParameters(); ALTERA_PLL_ResetPLLAndReconfiguration(); resetCore(); @@ -1209,7 +1210,7 @@ int configureMAC() { LOG(logINFOBLUE, ("\t1G MAC\n")); if (updateDatabytesandAllocateRAM() == FAIL) 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")); return FAIL; } @@ -1687,7 +1688,7 @@ void *start_timer(void *arg) { imageData + srcOffset, dataSize); srcOffset += dataSize; - sendUDPPacket(0, packetData, packetSize); + sendUDPPacket(0, 0, packetData, packetSize); } LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, (long long unsigned int)virtual_currentFrameNumber)); @@ -1806,10 +1807,10 @@ void readandSendUDPFrames(int *ret, char *mess) { LOG(logDEBUG1, ("Reading from 1G UDP\n")); // validate udp socket - if (getUdPSocketDescriptor(0) <= 0) { + if (getUdPSocketDescriptor(0, 0) <= 0) { *ret = FAIL; sprintf(mess, "UDP Socket not created. sockfd:%d\n", - getUdPSocketDescriptor(0)); + getUdPSocketDescriptor(0, 0)); LOG(logERROR, (mess)); return; } @@ -1818,7 +1819,7 @@ void readandSendUDPFrames(int *ret, char *mess) { while (readFrameFromFifo() == OK) { int bytesToSend = 0, n = 0; while ((bytesToSend = fillUDPPacket(udpPacketData))) { - n += sendUDPPacket(0, udpPacketData, bytesToSend); + n += sendUDPPacket(0, 0, udpPacketData, bytesToSend); } if (n >= dataBytes) { LOG(logINFO, (" Frame %lld sent (%d packets, %d databytes, n:%d " diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 96575edff..47ea022c4 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -25,7 +25,7 @@ extern int debugflag; extern int updateFlag; extern int checkModuleFlag; -extern udpStruct udpDetails; +extern udpStruct udpDetails[MAX_UDP_DESTINATION]; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c @@ -429,6 +429,7 @@ void setupDetector() { } #ifdef VIRTUAL sharedMemory_setStatus(IDLE); + setupUDPCommParameters(); #endif // pll defines @@ -1746,7 +1747,7 @@ int configureMAC() { src_ip, src_mac, srcport, dst_ip, dst_mac, dstport)); #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")); return FAIL; } @@ -2290,7 +2291,7 @@ void *start_timer(void *arg) { imageData + srcOffset, dataSize); srcOffset += dataSize; - sendUDPPacket(0, packetData, packetSize); + sendUDPPacket(0, 0, packetData, packetSize); } LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr, (long long unsigned int)virtual_currentFrameNumber)); diff --git a/slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h b/slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h index 01d9226eb..3ba9f251d 100644 --- a/slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h +++ b/slsDetectorServers/slsDetectorServer/include/communication_funcs_UDP.h @@ -1,35 +1,15 @@ #pragma once -/** - * Get UDP socket desicriptor - * @param udp port index - */ -int getUdPSocketDescriptor(int index); -/** - * Set udp destination - * @param index udp port index - * @param ip udp destination ip - * @param port udp destination port - */ -int setUDPDestinationDetails(int index, const char *ip, +void setupUDPCommParameters(); + +int getUdPSocketDescriptor(int iRxEntry, int index); + +void setNumberOfUDPDestinations(int value); + +int setUDPDestinationDetails(int iRxEntry, int index, const char *ip, unsigned short int port); - -/** - * Create udp socket - * @param index udp port index - */ int createUDPSocket(int index); -/** - * 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); +int sendUDPPacket(int iRxEntry, int index, const char *buf, int length); -/** - * Close udp socket - * @index udp port index - */ void closeUDPSocket(int index); diff --git a/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c b/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c index f001f3629..bd8b45101 100644 --- a/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c +++ b/slsDetectorServers/slsDetectorServer/src/communication_funcs_UDP.c @@ -13,25 +13,35 @@ #include #include -int udpSockfd[2] = {-1, -1}; -struct addrinfo *udpServerAddrInfo[2] = {0, 0}; -unsigned short int udpDestinationPort[2] = {0, 0}; -char udpDestinationIp[2][INET_ADDRSTRLEN] = {"", ""}; +int udpSockfd[MAX_UDP_DESTINATION][2] = {}; +struct addrinfo *udpServerAddrInfo[MAX_UDP_DESTINATION][2] = {}; +unsigned short int udpDestinationPort[MAX_UDP_DESTINATION][2] = {}; +char udpDestinationIp[MAX_UDP_DESTINATION][2][INET_ADDRSTRLEN] = {}; +extern int numUdpDestinations; -// DEFAULT_TX_UDP_PORT;// src port -int getUdPSocketDescriptor(int index) { return udpSockfd[index]; } +void setupUDPCommParameters() { + 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) { - udpDestinationPort[index] = port; + udpDestinationPort[iRxEntry][index] = port; size_t len = strlen(ip); - memset(udpDestinationIp[index], 0, INET_ADDRSTRLEN); - strncpy(udpDestinationIp[index], ip, + memset(udpDestinationIp[iRxEntry][index], 0, INET_ADDRSTRLEN); + strncpy(udpDestinationIp[iRxEntry][index], ip, len > INET_ADDRSTRLEN ? INET_ADDRSTRLEN : len); - if (udpServerAddrInfo[index]) { - freeaddrinfo(udpServerAddrInfo[index]); - udpServerAddrInfo[index] = 0; + if (udpServerAddrInfo[iRxEntry][index]) { + freeaddrinfo(udpServerAddrInfo[iRxEntry][index]); + udpServerAddrInfo[iRxEntry][index] = 0; } // convert ip to internet address @@ -43,21 +53,21 @@ int setUDPDestinationDetails(int index, const char *ip, hints.ai_protocol = 0; char sport[100]; memset(sport, 0, 100); - sprintf(sport, "%d", udpDestinationPort[index]); - int err = getaddrinfo(udpDestinationIp[index], sport, &hints, - &udpServerAddrInfo[index]); + sprintf(sport, "%d", udpDestinationPort[iRxEntry][index]); + int err = getaddrinfo(udpDestinationIp[iRxEntry][index], sport, &hints, + &udpServerAddrInfo[iRxEntry][index]); 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", - udpDestinationIp[index], udpDestinationPort[index], err, + udpDestinationIp[iRxEntry][index], udpDestinationPort[iRxEntry][index], iRxEntry, err, gai_strerror(err))); return FAIL; } - if (udpServerAddrInfo[index] == NULL) { - LOG(logERROR, ("Failed to resolve remote socket address %s at port %d " + if (udpServerAddrInfo[iRxEntry][index] == NULL) { + LOG(logERROR, ("Failed to resolve remote socket address %s at port %d [entry:%d]." "(getaddrinfo returned NULL)\n", - udpDestinationIp[index], udpDestinationPort[index])); - udpServerAddrInfo[index] = 0; + udpDestinationIp[iRxEntry][index], udpDestinationPort[iRxEntry][index], iRxEntry)); + udpServerAddrInfo[iRxEntry][index] = 0; return FAIL; } @@ -65,49 +75,54 @@ int setUDPDestinationDetails(int index, const char *ip, } 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; - } + + for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) { - if (udpSockfd[index] != -1) { - LOG(logERROR, ("Strange that Udp socket was still open. Closing it to " - "create a new one\n")); - close(udpSockfd[index]); - udpSockfd[index] = -1; - } + LOG(logDEBUG2, ("Creating UDP Socket %d [entry:%d]\n", index, iRxEntry)); + if (!strlen(udpDestinationIp[iRxEntry][index])) { + LOG(logERROR, ("No destination UDP ip specified for socket %d [entry:%d].\n", index, iRxEntry)); + return FAIL; + } - // Creating socket file descriptor - udpSockfd[index] = socket(udpServerAddrInfo[index]->ai_family, - udpServerAddrInfo[index]->ai_socktype, - udpServerAddrInfo[index]->ai_protocol); - 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])); + if (udpSockfd[iRxEntry][index] != -1) { + LOG(logERROR, ("Strange that Udp socket was still open [socket:%d, entry:%d]. Closing it to " + "create a new one.\n", index, iRxEntry)); + close(udpSockfd[iRxEntry][index]); + udpSockfd[iRxEntry][index] = -1; + } - // 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\n", udpDestinationPort[index], - 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; } -int sendUDPPacket(int index, const char *buf, int length) { - int n = sendto(udpSockfd[index], buf, length, 0, - udpServerAddrInfo[index]->ai_addr, - udpServerAddrInfo[index]->ai_addrlen); +int sendUDPPacket(int iRxEntry, int index, const char *buf, int length) { + int n = sendto(udpSockfd[iRxEntry][index], buf, length, 0, + udpServerAddrInfo[iRxEntry][index]->ai_addr, + udpServerAddrInfo[iRxEntry][index]->ai_addrlen); // udp sends atomically, no need to handle partial data if (n == -1) { LOG(logERROR, - ("Could not send udp packet for socket %d. (Error code:%d, %s)\n", - index, n, errno, gai_strerror(errno))); + ("Could not send udp packet for socket %d [entry:%d]. (Error code:%d, %s)\n", + index, iRxEntry, errno, gai_strerror(errno))); } else { LOG(logDEBUG2, ("%d bytes sent\n", n)); } @@ -115,9 +130,11 @@ int sendUDPPacket(int index, const char *buf, int length) { } void closeUDPSocket(int index) { - if (udpSockfd[index] != -1) { - LOG(logINFO, ("Udp client socket closed\n")); - close(udpSockfd[index]); - udpSockfd[index] = -1; + for (int iRxEntry = 0; iRxEntry != numUdpDestinations; ++iRxEntry) { + if (udpSockfd[iRxEntry][index] != -1) { + LOG(logINFO, ("Udp client socket closed\n")); + close(udpSockfd[iRxEntry][index]); + udpSockfd[iRxEntry][index] = -1; + } } } diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 7636990dc..d081a0433 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -50,9 +50,9 @@ int debugflag = 0; int updateFlag = 0; int checkModuleFlag = 1; -const int MAX_UDP_DESTINATION = 32; -udpStruct udpDetails[MAX_UDP_DESTINATION] = {32410, 32411, 50001, 50002, 0, 0, - 0, 0, 0, 0, 0, 0}; +udpStruct udpDetails[MAX_UDP_DESTINATION]; +int numUdpDestinations = 1; + int configured = FAIL; char configureMessage[MAX_STR_LENGTH] = "udp parameters not configured yet"; int maxydet = -1; @@ -82,6 +82,11 @@ void init_detector() { #ifdef VIRTUAL LOG(logINFO, ("This is a VIRTUAL detector\n")); #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) { basictests(); initControlServer(); @@ -4918,50 +4923,52 @@ int check_detector_idle(const char *s) { } int is_udp_configured() { - if (udpDetails[0].dstip == 0) { - strcpy(configureMessage, "udp destination ip not configured\n"); - LOG(logWARNING, ("%s", configureMessage)); - return FAIL; - } - if (udpDetails[0].srcip == 0) { - strcpy(configureMessage, "udp source ip not configured\n"); - LOG(logWARNING, ("%s", configureMessage)); - return FAIL; - } - if (udpDetails[0].srcmac == 0) { - strcpy(configureMessage, "udp source mac not configured\n"); - LOG(logWARNING, ("%s", configureMessage)); - return FAIL; - } - if (udpDetails[0].dstmac == 0) { - strcpy(configureMessage, "udp destination mac not configured\n"); - LOG(logWARNING, ("%s", configureMessage)); - return FAIL; - } + for (int i = 0; i != numUdpDestinations; ++i) { + if (udpDetails[i].dstip == 0) { + strcpy(configureMessage, "udp destination ip not configured\n"); + LOG(logWARNING, ("%s", configureMessage)); + return FAIL; + } + if (udpDetails[i].srcip == 0) { + strcpy(configureMessage, "udp source ip not configured\n"); + LOG(logWARNING, ("%s", configureMessage)); + return FAIL; + } + if (udpDetails[i].srcmac == 0) { + strcpy(configureMessage, "udp source mac not configured\n"); + LOG(logWARNING, ("%s", configureMessage)); + return FAIL; + } + if (udpDetails[i].dstmac == 0) { + strcpy(configureMessage, "udp destination mac not configured\n"); + LOG(logWARNING, ("%s", configureMessage)); + return FAIL; + } #if defined(JUNGFRAUD) || defined(GOTTHARD2D) - if (getNumberofUDPInterfaces() == 2) { - if (udpDetails[0].srcip2 == 0) { - strcpy(configureMessage, "udp source ip2 not configured\n"); - LOG(logWARNING, ("%s", configureMessage)); - return FAIL; + if (getNumberofUDPInterfaces() == 2) { + if (udpDetails[i].srcip2 == 0) { + strcpy(configureMessage, "udp source ip2 not configured\n"); + LOG(logWARNING, ("%s", configureMessage)); + 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 + } return OK; } @@ -8988,14 +8995,17 @@ int get_dest_udp_list(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); uint32_t arg = 0; - uint32_t retvals[5]{}; - uint64_t retvals64[2]{}; + uint32_t retvals[5] = {}; + 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)); #if !defined(EIGERD) && !defined(JUNGFRAUD) functionNotImplemented(); #else - if (arg < 0 || arg > MAX_UDP_DESTINATION) { + if (arg > MAX_UDP_DESTINATION) { ret = FAIL; sprintf( mess, @@ -9008,24 +9018,30 @@ int get_dest_udp_list(int file_des) { retvals[2] = udpDetails[arg].dstport2; retvals[3] = udpDetails[arg].dstip; retvals[4] = udpDetails[arg].dstip2; - retvals_64[0] = udpDetails[arg].dstmac; - retvals_64[1] = udpDetails[arg].dstmac2; + retvals64[0] = udpDetails[arg].dstmac; + 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]; getIpAddressinString(ip, retvals[3]); getIpAddressinString(ip2, retvals[4]); char mac[50], mac2[50]; - getMacAddressinString(mac, 50, retvals_64[0]); - getMacAddressinString(mac2, 50, retvals_64[1]); + getMacAddressinString(mac, 50, retvals64[0]); + getMacAddressinString(mac2, 50, retvals64[1]); LOG(logDEBUG1, - ("Udp Dest. retval [%d]: [port:%d, port2:%d, ip:%s, ip2:%s, " - "mac:%s, mac2:%s]\n", + ("Udp Dest. retval [%d]: [port %d, port2 %d, ip %s, ip2 %s, " + "mac %s, mac2 %s]\n", retvals[0], retvals[1], retvals[2], ip, ip2, mac, mac2)); } #endif Server_SendResult(file_des, INT32, NULL, 0); if (ret != FAIL) { 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; } @@ -9033,33 +9049,65 @@ int get_dest_udp_list(int file_des) { int set_dest_udp_list(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - uint32_t args[5]{}; - uint64_t args_64[2]{}; + uint32_t args[5] = {}; + uint64_t args64[2] = {}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) return printSocketReadError(); - if (receiveData(file_des, args_64, sizeof(args_64), INT64) < 0) + if (receiveData(file_des, args64, sizeof(args64), INT64) < 0) return printSocketReadError(); + // swap ip + args[3] = __builtin_bswap32(args[3]); + args[4] = __builtin_bswap32(args[4]); - - LOG(logINFOBLUE, ("Setting current source [enable:%d, fix:%d, select:%lld, " - "normal:%d]\n", - enable, fix, (long long int)select, normal)); + // convert to string + char ip[INET_ADDRSTRLEN], ip2[INET_ADDRSTRLEN]; + getIpAddressinString(ip, args[3]); + getIpAddressinString(ip2, args[4]); + char mac[50], mac2[50]; + getMacAddressinString(mac, 50, args64[0]); + getMacAddressinString(mac2, 50, args64[1]); #if !defined(EIGERD) && !defined(JUNGFRAUD) functionNotImplemented(); #else // only set if (Server_VerifyLock() == OK) { - if (arg < 1 || arg > MAX_UDP_DESTINATION) { - ret = FAIL; - sprintf( - mess, - "Could not set udp destination. Invalid entry. Options: 1 - %d\n", - MAX_UDP_DESTINATION); - LOG(logERROR, (mess)); - } else { - + int entry = args[0]; + LOG(logINFOBLUE, + ("Setting udp dest. [%d]: [port %d, port2 %d, ip %s, ip2 %s, " + "mac %s, mac2 %s]\n", + entry, args[1], args[2], ip, ip2, mac, mac2)); + + 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 return Server_SendResult(file_des, INT32, NULL, 0); diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 8c5278ea5..4560f135e 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -948,14 +948,14 @@ void Module::setDestinationUDPList(const slsDetectorDefs::udpDestination dest) { // set them in the default way so the receivers are also set up if (dest.entry_ == 0) { setDestinationUDPPort(dest.port_); - setDestinationUDPIP(dest.ip_); - setDestinationUDPMAC(dest.mac_); + setDestinationUDPIP(IpAddr(dest.ip_)); + setDestinationUDPMAC(MacAddr(dest.mac_)); if (dest.port_ != 0) { setDestinationUDPPort2(dest.port2_); } if (dest.ip2_ != 0) { - setDestinationUDPIP2(dest.ip2_); - setDestinationUDPMAC2(dest.mac2_); + setDestinationUDPIP2(IpAddr(dest.ip2_)); + setDestinationUDPMAC2(MacAddr(dest.mac2_)); } } else { sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr); diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 6b8049b80..cd0efaba9 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -36,6 +36,10 @@ #define DEFAULT_UDP_PORTNO 50001 #define DEFAULT_ZMQ_CL_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_JSON_HEADER_VERSION 0x4