esrf changes: rx_udpsocksize sets/gets udp socket buffer size to be set, rx_realudpsocksize gets the real udp sock size buffer. At receiver config and at rx_udpsocksize command, dummy udp sockets created to know if set udp sock size fails (if fail, set to previous value), and also to get the real udp sock buffer size

This commit is contained in:
2018-05-01 11:55:48 +02:00
parent 99281e2690
commit 1152555663
18 changed files with 537 additions and 86 deletions

View File

@ -20,7 +20,8 @@ const string Listener::TypeName = "Listener";
Listener::Listener(int& ret, int ind, detectorType dtype, Fifo*& f, runStatus* s,
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr) :
uint32_t* portno, char* e, int* act, uint64_t* nf, uint32_t* dr,
uint32_t* us, uint32_t* as) :
ThreadObject(ind),
runningFlag(0),
generalData(0),
@ -44,7 +45,9 @@ Listener::Listener(int& ret, int ind, detectorType dtype, Fifo*& f, runStatus* s
carryOverPacket(0),
listeningPacket(0),
udpSocketAlive(0),
silentMode(false)
silentMode(false),
udpSocketBufferSize(us),
actualUDPSocketBufferSize(as)
{
ret = FAIL;
if(ThreadObject::CreateThread() == OK)
@ -182,15 +185,17 @@ int Listener::CreateUDPSockets() {
//if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
strncpy(eth,"", MAX_STR_LENGTH);
memset(eth, 0, MAX_STR_LENGTH);
}
if(!strlen(eth)){
FILE_LOG(logWARNING) << "eth is empty. Listening to all";
}
ShutDownUDPSocket();
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize);
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize,
*udpSocketBufferSize);
int iret = udpSocket->getErrorStatus();
if(!iret){
FILE_LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
@ -200,6 +205,10 @@ int Listener::CreateUDPSockets() {
}
udpSocketAlive = true;
sem_init(&semaphore_socket,1,0);
// doubled due to kernel bookkeeping (could also be less due to permissions)
*actualUDPSocketBufferSize = udpSocket->getActualUDPSocketBufferSize();
return OK;
}
@ -225,6 +234,54 @@ void Listener::SetSilentMode(bool mode) {
}
int Listener::CreateDummySocketForUDPSocketBufferSize(uint32_t s) {
uint32_t temp = *udpSocketBufferSize;
*udpSocketBufferSize = s;
if (!(*activated))
return OK;
//if eth is mistaken with ip address
if (strchr(eth,'.') != NULL){
memset(eth, 0, MAX_STR_LENGTH);
}
// shutdown if any open
if(udpSocket){
udpSocket->ShutDownSocket();
delete udpSocket;
}
//create dummy socket
udpSocket = new genericSocket(*udpPortNumber, genericSocket::UDP,
generalData->packetSize, (strlen(eth)?eth:NULL), generalData->headerPacketSize,
*udpSocketBufferSize);
int iret = udpSocket->getErrorStatus();
if (iret){
FILE_LOG(logERROR) << "Could not create a test UDP socket on port " << *udpPortNumber << " error: " << iret;
return FAIL;
}
// doubled due to kernel bookkeeping (could also be less due to permissions)
*actualUDPSocketBufferSize = udpSocket->getActualUDPSocketBufferSize();
if (*actualUDPSocketBufferSize != (s*2))
*udpSocketBufferSize = temp;
// shutdown socket
if(udpSocket){
udpSocketAlive = false;
udpSocket->ShutDownSocket();
delete udpSocket;
udpSocket = 0;
}
return OK;
}
void Listener::ThreadExecution() {
char* buffer;
int rc = 0;

View File

@ -65,6 +65,8 @@ void UDPBaseImplementation::initializeMembers(){
for(int i=0;i<MAX_NUMBER_OF_LISTENING_THREADS;i++){
udpPortNum[i] = DEFAULT_UDP_PORTNO + i;
}
udpSocketBufferSize = 0;
actualUDPSocketBufferSize = 0;
//***file parameters***
fileFormatType = BINARY;
@ -99,9 +101,13 @@ UDPBaseImplementation::~UDPBaseImplementation(){}
*************************************************************************/
/**initial parameters***/
int* UDPBaseImplementation::getMultiDetectorSize() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return (int*) numDet;}
int* UDPBaseImplementation::getMultiDetectorSize() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return (int*) numDet;}
int UDPBaseImplementation::getDetectorPositionId() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return detID;}
int UDPBaseImplementation::getDetectorPositionId() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return detID;}
char *UDPBaseImplementation::getDetectorHostname() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
@ -128,7 +134,9 @@ bool UDPBaseImplementation::getGapPixelsEnable() const {
}
/***file parameters***/
slsReceiverDefs::fileFormat UDPBaseImplementation::getFileFormat() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileFormatType;}
slsReceiverDefs::fileFormat UDPBaseImplementation::getFileFormat() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileFormatType;}
char *UDPBaseImplementation::getFileName() const{
@ -157,28 +165,48 @@ char *UDPBaseImplementation::getFilePath() const{
return output;
}
uint64_t UDPBaseImplementation::getFileIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileIndex;}
uint64_t UDPBaseImplementation::getFileIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileIndex;}
int UDPBaseImplementation::getScanTag() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return scanTag;}
int UDPBaseImplementation::getScanTag() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return scanTag;}
bool UDPBaseImplementation::getFileWriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fileWriteEnable;}
bool UDPBaseImplementation::getFileWriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fileWriteEnable;}
bool UDPBaseImplementation::getOverwriteEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return overwriteEnable;}
bool UDPBaseImplementation::getOverwriteEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return overwriteEnable;}
bool UDPBaseImplementation::getDataCompressionEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dataCompressionEnable;}
bool UDPBaseImplementation::getDataCompressionEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataCompressionEnable;}
/***acquisition count parameters***/
uint64_t UDPBaseImplementation::getTotalFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return 0;}
uint64_t UDPBaseImplementation::getTotalFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return 0;}
uint64_t UDPBaseImplementation::getFramesCaught() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return 0;}
uint64_t UDPBaseImplementation::getFramesCaught() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return 0;}
int64_t UDPBaseImplementation::getAcquisitionIndex() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return -1;}
int64_t UDPBaseImplementation::getAcquisitionIndex() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return -1;}
/***connection parameters***/
uint32_t UDPBaseImplementation::getUDPPortNumber() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[0];}
uint32_t UDPBaseImplementation::getUDPPortNumber() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[0];}
uint32_t UDPBaseImplementation::getUDPPortNumber2() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return udpPortNum[1];}
uint32_t UDPBaseImplementation::getUDPPortNumber2() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpPortNum[1];}
char *UDPBaseImplementation::getEthernetInterface() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
@ -191,38 +219,70 @@ char *UDPBaseImplementation::getEthernetInterface() const{
/***acquisition parameters***/
int UDPBaseImplementation::getShortFrameEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return shortFrameEnable;}
int UDPBaseImplementation::getShortFrameEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return shortFrameEnable;}
uint32_t UDPBaseImplementation::getFrameToGuiFrequency() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return frameToGuiFrequency;}
uint32_t UDPBaseImplementation::getFrameToGuiFrequency() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameToGuiFrequency;}
uint32_t UDPBaseImplementation::getFrameToGuiTimer() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return frameToGuiTimerinMS;}
uint32_t UDPBaseImplementation::getFrameToGuiTimer() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return frameToGuiTimerinMS;}
bool UDPBaseImplementation::getDataStreamEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dataStreamEnable;}
bool UDPBaseImplementation::getDataStreamEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dataStreamEnable;}
uint64_t UDPBaseImplementation::getAcquisitionPeriod() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return acquisitionPeriod;}
uint64_t UDPBaseImplementation::getAcquisitionPeriod() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionPeriod;}
uint64_t UDPBaseImplementation::getAcquisitionTime() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return acquisitionTime;}
uint64_t UDPBaseImplementation::getAcquisitionTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return acquisitionTime;}
uint64_t UDPBaseImplementation::getSubExpTime() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return subExpTime;}
uint64_t UDPBaseImplementation::getSubExpTime() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return subExpTime;}
uint64_t UDPBaseImplementation::getNumberOfFrames() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return numberOfFrames;}
uint64_t UDPBaseImplementation::getNumberOfFrames() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfFrames;}
uint64_t UDPBaseImplementation::getNumberofSamples() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return numberOfSamples;}
uint64_t UDPBaseImplementation::getNumberofSamples() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return numberOfSamples;}
uint32_t UDPBaseImplementation::getDynamicRange() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return dynamicRange;}
uint32_t UDPBaseImplementation::getDynamicRange() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return dynamicRange;}
bool UDPBaseImplementation::getTenGigaEnable() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return tengigaEnable;}
bool UDPBaseImplementation::getTenGigaEnable() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return tengigaEnable;}
uint32_t UDPBaseImplementation::getFifoDepth() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return fifoDepth;}
uint32_t UDPBaseImplementation::getFifoDepth() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return fifoDepth;}
/***receiver status***/
slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return status;}
slsReceiverDefs::runStatus UDPBaseImplementation::getStatus() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return status;}
uint32_t UDPBaseImplementation::getSilentMode() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; return silentMode;}
uint32_t UDPBaseImplementation::getSilentMode() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return silentMode;}
int UDPBaseImplementation::getActivate() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return activated;}
int UDPBaseImplementation::getActivate() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return activated;}
uint32_t UDPBaseImplementation::getStreamingPort() const{FILE_LOG(logDEBUG) << __AT__ << " starting"; return streamingPort;}
uint32_t UDPBaseImplementation::getStreamingPort() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
return streamingPort;}
char *UDPBaseImplementation::getStreamingSourceIP() const{
FILE_LOG(logDEBUG) << __AT__ << " starting";
@ -243,6 +303,16 @@ char *UDPBaseImplementation::getAdditionalJsonHeader() const{
return output;
}
uint32_t UDPBaseImplementation::getUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return udpSocketBufferSize;
}
uint32_t UDPBaseImplementation::getActualUDPSocketBufferSize() const {
FILE_LOG(logDEBUG) << __AT__ << " starting";
return actualUDPSocketBufferSize;
}
/*************************************************************************
* Setters ***************************************************************
* They modify the local cache of configuration or detector parameters ***
@ -614,6 +684,14 @@ void UDPBaseImplementation::setAdditionalJsonHeader(const char c[]){
FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader;
}
int UDPBaseImplementation::setUDPSocketBufferSize(const uint32_t s) {
FILE_LOG(logDEBUG) << __AT__ << " starting";
udpSocketBufferSize = s;
return OK;
}
int UDPBaseImplementation::restreamStop() {
FILE_LOG(logERROR) << __AT__ << " doing nothing...";
FILE_LOG(logERROR) << __AT__ << " must be overridden by child classes";

View File

@ -360,6 +360,7 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
}
numThreads = generalData->threadsPerReceiver;
fifoDepth = generalData->defaultFifoDepth;
udpSocketBufferSize = generalData->defaultUdpSocketBufferSize;
//local network parameters
SetLocalNetworkParameters();
@ -375,11 +376,14 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
for ( int i = 0; i < numThreads; ++i ) {
int ret = FAIL;
Listener* l = new Listener(ret, i, myDetectorType, fifo[i], &status, &udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange);
Listener* l = new Listener(ret, i, myDetectorType, fifo[i], &status,
&udpPortNum[i], eth, &activated, &numberOfFrames, &dynamicRange,
&udpSocketBufferSize, &actualUDPSocketBufferSize);
DataProcessor* p = NULL;
if (ret == OK)
p = new DataProcessor(ret, i, fifo[i], &fileFormatType,
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable, &dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS,
fileWriteEnable, &dataStreamEnable, &gapPixelsEnable,
&dynamicRange, &frameToGuiFrequency, &frameToGuiTimerinMS,
rawDataReadyCallBack, rawDataModifyReadyCallBack, pRawDataReady);
// error in creating threads
@ -406,6 +410,9 @@ int UDPStandardImplementation::setDetectorType(const detectorType d) {
SetThreadPriorities();
// check udp socket buffer size
setUDPSocketBufferSize(udpSocketBufferSize);
FILE_LOG(logDEBUG) << " Detector type set to " << getDetectorType(d);
return OK;
}
@ -629,6 +636,10 @@ void UDPStandardImplementation::closeFiles() {
dataProcessor[0]->EndofAcquisition(maxIndexCaught);
}
int UDPStandardImplementation::setUDPSocketBufferSize(const uint32_t s) {
if (listener.size())
return listener[0]->CreateDummySocketForUDPSocketBufferSize(s);
}
int UDPStandardImplementation::restreamStop() {
bool ret = OK;
@ -666,8 +677,8 @@ void UDPStandardImplementation::SetLocalNetworkParameters() {
MAX_SOCKET_INPUT_PACKET_QUEUE);
} else {
const char *msg = "Could not change max length of"
"input packet queue (net.core.netdev_max_backlog): no root privileges?";
cprintf(RED, "WARNING: %s\n", msg);
"input packet queue (net.core.netdev_max_backlog). No Root Privileges?";
FILE_LOG(logWARNING) << msg;
}
}
}
@ -678,7 +689,7 @@ void UDPStandardImplementation::SetThreadPriorities() {
for (vector<Listener*>::const_iterator it = listener.begin(); it != listener.end(); ++it){
if ((*it)->SetThreadPriority(LISTENER_PRIORITY) == FAIL) {
FILE_LOG(logWARNING) << "No root privileges to prioritize listener threads";
FILE_LOG(logWARNING) << "Could not prioritize listener threads. No Root Privileges?";
return;
}
}

View File

@ -294,6 +294,9 @@ const char* slsReceiverTCPIPInterface::getFunctionName(enum recFuncs func) {
case F_ENABLE_GAPPIXELS_IN_RECEIVER:return "F_ENABLE_GAPPIXELS_IN_RECEIVER";
case F_RESTREAM_STOP_FROM_RECEIVER: return "F_RESTREAM_STOP_FROM_RECEIVER";
case F_ADDITIONAL_JSON_HEADER: return "F_ADDITIONAL_JSON_HEADER";
case F_RECEIVER_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_UDP_SOCK_BUF_SIZE";
case F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE: return "F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE";
default: return "Unknown Function";
}
}
@ -343,6 +346,8 @@ int slsReceiverTCPIPInterface::function_table(){
flist[F_ENABLE_GAPPIXELS_IN_RECEIVER] = &slsReceiverTCPIPInterface::enable_gap_pixels;
flist[F_RESTREAM_STOP_FROM_RECEIVER] = &slsReceiverTCPIPInterface::restream_stop;
flist[F_ADDITIONAL_JSON_HEADER] = &slsReceiverTCPIPInterface::set_additional_json_header;
flist[F_RECEIVER_UDP_SOCK_BUF_SIZE] = &slsReceiverTCPIPInterface::set_udp_socket_buffer_size;
flist[F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE]= &slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size;
#ifdef VERYVERBOSE
for (int i = 0; i < NUM_REC_FUNCTIONS ; i++) {
@ -2610,3 +2615,86 @@ int slsReceiverTCPIPInterface::set_additional_json_header() {
// return ok/fail
return ret;
}
int slsReceiverTCPIPInterface::set_udp_socket_buffer_size() {
ret = OK;
memset(mess, 0, sizeof(mess));
int index = -1;
int retval = -1;
// receive arguments
if (mySock->ReceiveDataOnly(&index,sizeof(index)) < 0 )
return printSocketReadError();
// execute action
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL)
invalidReceiverObject();
else {
// set
if(index >= 0) {
if (mySock->differentClients && lockStatus)
receiverlocked();
else if (receiverBase->getStatus() != IDLE)
receiverNotIdle();
else {
if (receiverBase->setUDPSocketBufferSize(index) == FAIL) {
ret = FAIL;
strcpy(mess, "Could not create dummy UDP Socket to test buffer size\n");
FILE_LOG(logERROR) << mess;
}
}
}
//get
retval=receiverBase->getUDPSocketBufferSize();
if(index >= 0 && retval != index) {
ret = FAIL;
strcpy(mess, "Could not set UDP Socket buffer size\n");
FILE_LOG(logERROR) << mess;
}
}
#endif
#ifdef VERYVERBOSE
FILE_LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval;
#endif
if (ret == OK && mySock->differentClients)
ret = FORCE_UPDATE;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
if (ret == FAIL)
mySock->SendDataOnly(mess,sizeof(mess));
mySock->SendDataOnly(&retval,sizeof(retval));
// return ok/fail
return ret;
}
int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(){
ret = OK;
int retval = -1;
// execute action
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
if (receiverBase == NULL)
invalidReceiverObject();
else retval = receiverBase->getActualUDPSocketBufferSize();
#endif
if (ret == OK && mySock->differentClients)
ret = FORCE_UPDATE;
// send answer
mySock->SendDataOnly(&ret,sizeof(ret));
mySock->SendDataOnly(&retval,sizeof(retval));
// return ok/fail
return ret;
}