INET Framework for OMNeT++/OMNEST
inet::SCTPServer Class Reference

Implements the SCTPServer simple module. More...

#include <SCTPServer.h>

Inheritance diagram for inet::SCTPServer:
inet::ILifecycle

Classes

struct  ServerAssocStat
 

Public Member Functions

virtual ~SCTPServer ()
 
 SCTPServer ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

typedef std::map< int, ServerAssocStatServerAssocStatMap
 
typedef std::map< int, cOutVector * > BytesPerAssoc
 
typedef std::map< int, cOutVector * > EndToEndDelay
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
void handleTimer (cMessage *msg)
 
void sendOrSchedule (cMessage *msg)
 
cMessage * makeAbortNotification (SCTPCommand *msg)
 
cMessage * makeReceiveRequest (cMessage *msg)
 
cMessage * makeDefaultReceive ()
 
void generateAndSend ()
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

int inboundStreams
 
int outboundStreams
 
int queueSize
 
double delay
 
double delayFirstRead
 
bool finishEndsSimulation
 
bool echo
 
bool ordered
 
SCTPSocketsocket
 
cMessage * timeoutMsg
 
cMessage * delayTimer
 
cMessage * delayFirstReadTimer
 
int lastStream
 
int assocId
 
bool readInt
 
bool schedule
 
bool firstData
 
bool shutdownReceived
 
bool abortSent
 
EndToEndDelay endToEndDelay
 
int numSessions
 
int count
 
int notificationsReceived
 
unsigned long int bytesSent
 
unsigned long int packetsSent
 
unsigned long int packetsRcvd
 
unsigned long int numRequestsToSend
 
BytesPerAssoc bytesPerAssoc
 
ServerAssocStatMap serverAssocStatMap
 

Detailed Description

Implements the SCTPServer simple module.

See the NED file for more info.

Member Typedef Documentation

typedef std::map<int, cOutVector *> inet::SCTPServer::BytesPerAssoc
protected
typedef std::map<int, cOutVector *> inet::SCTPServer::EndToEndDelay
protected
typedef std::map<int, ServerAssocStat> inet::SCTPServer::ServerAssocStatMap
protected

Constructor & Destructor Documentation

inet::SCTPServer::~SCTPServer ( )
virtual
521 {
522  for (auto & elem : bytesPerAssoc)
523  delete elem.second;
524 
525  for (auto & elem : endToEndDelay)
526  delete elem.second;
527 
528  bytesPerAssoc.clear();
529  endToEndDelay.clear();
530  serverAssocStatMap.clear();
531  delete socket;
532  cancelAndDelete(timeoutMsg);
533  cancelAndDelete(delayTimer);
534  cancelAndDelete(delayFirstReadTimer);
535 }
cMessage * timeoutMsg
Definition: SCTPServer.h:63
BytesPerAssoc bytesPerAssoc
Definition: SCTPServer.h:83
SCTPSocket * socket
Definition: SCTPServer.h:62
cMessage * delayFirstReadTimer
Definition: SCTPServer.h:65
ServerAssocStatMap serverAssocStatMap
Definition: SCTPServer.h:84
cMessage * delayTimer
Definition: SCTPServer.h:64
EndToEndDelay endToEndDelay
Definition: SCTPServer.h:73
inet::SCTPServer::SCTPServer ( )
538 {
539  timeoutMsg = nullptr;
540  socket = nullptr;
541  delayFirstReadTimer = nullptr;
542  delayTimer = nullptr;
543  numSessions = 0;
544  packetsSent = 0;
545  packetsRcvd = 0;
546  bytesSent = 0;
548  inboundStreams = 17;
549  outboundStreams = 1;
550  queueSize = 0;
551  delay = 0;
552  delayFirstRead = 0;
553  finishEndsSimulation = true;
554  echo = false;
555  ordered = true;
556  lastStream = 0;
557  assocId = 0;
558  readInt = false;
559  schedule = false;
560  firstData = true;
561  shutdownReceived = false;
562  abortSent = false;
563  count = 0;
564  numRequestsToSend = 0;
565 }
cMessage * timeoutMsg
Definition: SCTPServer.h:63
bool ordered
Definition: SCTPServer.h:59
int queueSize
Definition: SCTPServer.h:54
int numSessions
Definition: SCTPServer.h:76
bool shutdownReceived
Definition: SCTPServer.h:71
int outboundStreams
Definition: SCTPServer.h:53
bool firstData
Definition: SCTPServer.h:70
unsigned long int packetsRcvd
Definition: SCTPServer.h:81
double delay
Definition: SCTPServer.h:55
int count
Definition: SCTPServer.h:77
bool readInt
Definition: SCTPServer.h:68
bool echo
Definition: SCTPServer.h:58
double delayFirstRead
Definition: SCTPServer.h:56
unsigned long int bytesSent
Definition: SCTPServer.h:79
SCTPSocket * socket
Definition: SCTPServer.h:62
unsigned long int numRequestsToSend
Definition: SCTPServer.h:82
unsigned long int packetsSent
Definition: SCTPServer.h:80
bool finishEndsSimulation
Definition: SCTPServer.h:57
int assocId
Definition: SCTPServer.h:67
int inboundStreams
Definition: SCTPServer.h:52
int notificationsReceived
Definition: SCTPServer.h:78
cMessage * delayFirstReadTimer
Definition: SCTPServer.h:65
bool schedule
Definition: SCTPServer.h:69
int lastStream
Definition: SCTPServer.h:66
bool abortSent
Definition: SCTPServer.h:72
cMessage * delayTimer
Definition: SCTPServer.h:64

Member Function Documentation

void inet::SCTPServer::finish ( )
overrideprotectedvirtual
502 {
503  EV_INFO << getFullPath() << ": opened " << numSessions << " sessions\n";
504  EV_INFO << getFullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n";
505  for (auto & elem : serverAssocStatMap) {
506  EV_DETAIL << getFullPath() << " Assoc: " << elem.first << "\n";
507  EV_DETAIL << "\tstart time: " << elem.second.start << "\n";
508  EV_DETAIL << "\tstop time: " << elem.second.stop << "\n";
509  EV_DETAIL << "\tlife time: " << elem.second.lifeTime << "\n";
510  EV_DETAIL << "\treceived bytes:" << elem.second.rcvdBytes << "\n";
511  EV_DETAIL << "\tthroughput: " << (elem.second.rcvdBytes / elem.second.lifeTime.dbl()) * 8 << " bit/sec\n";
512  recordScalar("bytes rcvd", elem.second.rcvdBytes);
513  recordScalar("throughput", (elem.second.rcvdBytes / elem.second.lifeTime.dbl()) * 8);
514  }
515  EV_INFO << getFullPath() << "Over all " << packetsRcvd << " packets received\n ";
516  EV_INFO << getFullPath() << "Over all " << notificationsReceived << " notifications received\n ";
517  EV_INFO << "Server finished\n";
518 }
int numSessions
Definition: SCTPServer.h:76
unsigned long int packetsRcvd
Definition: SCTPServer.h:81
unsigned long int bytesSent
Definition: SCTPServer.h:79
unsigned long int packetsSent
Definition: SCTPServer.h:80
int notificationsReceived
Definition: SCTPServer.h:78
ServerAssocStatMap serverAssocStatMap
Definition: SCTPServer.h:84
void inet::SCTPServer::generateAndSend ( )
protected

Referenced by handleMessage(), and handleTimer().

110 {
111  cPacket *cmsg = new cPacket("SCTP_C_SEND");
112  SCTPSimpleMessage *msg = new SCTPSimpleMessage("Server");
113  int numBytes = par("requestLength");
114  msg->setDataArraySize(numBytes);
115 
116  for (int i = 0; i < numBytes; i++)
117  msg->setData(i, 's');
118 
119  msg->setDataLen(numBytes);
120  msg->setEncaps(false);
121  msg->setBitLength(numBytes * 8);
122  cmsg->encapsulate(msg);
123  SCTPSendInfo *cmd = new SCTPSendInfo("Send1");
124  cmd->setAssocId(assocId);
125  cmd->setSendUnordered(ordered ? COMPLETE_MESG_ORDERED : COMPLETE_MESG_UNORDERED);
127  cmd->setSid(lastStream);
128  cmd->setPrValue(par("prValue"));
129  cmd->setPrMethod(par("prMethod"));
130 
131  if (queueSize > 0 && numRequestsToSend > 0 && count < queueSize * 2)
132  cmd->setLast(false);
133  else
134  cmd->setLast(true);
135 
136  cmsg->setKind(SCTP_C_SEND);
137  cmsg->setControlInfo(cmd);
138  packetsSent++;
139  bytesSent += msg->getBitLength() / 8;
140  sendOrSchedule(cmsg);
141 }
void sendOrSchedule(cMessage *msg)
Definition: SCTPServer.cc:101
bool ordered
Definition: SCTPServer.h:59
int queueSize
Definition: SCTPServer.h:54
int outboundStreams
Definition: SCTPServer.h:53
int count
Definition: SCTPServer.h:77
Definition: SCTPCommand.h:33
unsigned long int bytesSent
Definition: SCTPServer.h:79
unsigned long int numRequestsToSend
Definition: SCTPServer.h:82
unsigned long int packetsSent
Definition: SCTPServer.h:80
int assocId
Definition: SCTPServer.h:67
int lastStream
Definition: SCTPServer.h:66
Definition: SCTPCommand.h:87
Definition: SCTPCommand.h:88
void inet::SCTPServer::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
185 {
186  // TODO: there is another memory leak somewhere...
187  int id = 0;
188  cMessage *cmsg;
189  if (msg->isSelfMessage())
190  handleTimer(msg);
191  else {
192  switch (msg->getKind()) {
193  case SCTP_I_PEER_CLOSED:
194  case SCTP_I_ABORT: {
195  SCTPCommand *command = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
196  assocId = command->getAssocId();
197  serverAssocStatMap[assocId].peerClosed = true;
198  if (par("numPacketsToReceivePerClient").longValue() == 0) {
199  if (serverAssocStatMap[assocId].abortSent == false) {
200  sendOrSchedule(makeAbortNotification(command->dup()));
201  serverAssocStatMap[assocId].abortSent = true;
202  }
203  }
204  else {
205  if (serverAssocStatMap[assocId].rcvdPackets == (unsigned int)par("numPacketsToReceivePerClient")
206  && serverAssocStatMap[assocId].abortSent == false)
207  {
208  sendOrSchedule(makeAbortNotification(command->dup()));
209  serverAssocStatMap[assocId].abortSent = true;
210  }
211  }
212  if (delayTimer->isScheduled())
213  cancelEvent(delayTimer);
214  if (delayFirstReadTimer->isScheduled())
215  cancelEvent(delayFirstReadTimer);
216  delete command;
217  delete msg;
218  break;
219  }
220 
221  case SCTP_I_ESTABLISHED: {
222  count = 0;
223  SCTPConnectInfo *connectInfo = check_and_cast<SCTPConnectInfo *>(msg->removeControlInfo());
224  numSessions++;
225  assocId = connectInfo->getAssocId();
226  inboundStreams = connectInfo->getInboundStreams();
227  outboundStreams = connectInfo->getOutboundStreams();
228  serverAssocStatMap[assocId].rcvdPackets = par("numPacketsToReceivePerClient");
229  serverAssocStatMap[assocId].sentPackets = par("numPacketsToSendPerClient");
230  serverAssocStatMap[assocId].rcvdBytes = 0;
231  serverAssocStatMap[assocId].start = 0;
232  serverAssocStatMap[assocId].stop = 0;
233  serverAssocStatMap[assocId].lifeTime = 0;
234  serverAssocStatMap[assocId].abortSent = false;
235  serverAssocStatMap[assocId].peerClosed = false;
236  char text[50];
237  sprintf(text, "App: Received Bytes of assoc %d", assocId);
238  bytesPerAssoc[assocId] = new cOutVector(text);
239  sprintf(text, "App: EndToEndDelay of assoc %d", assocId);
240  endToEndDelay[assocId] = new cOutVector(text);
241 
242  delete connectInfo;
243  delete msg;
244  if (par("numPacketsToSendPerClient").longValue() > 0) {
245  auto i = serverAssocStatMap.find(assocId);
246  numRequestsToSend = i->second.sentPackets;
247  if (par("thinkTime").doubleValue() > 0) {
248  generateAndSend();
249  timeoutMsg->setKind(SCTP_C_SEND);
250  scheduleAt(simTime() + par("thinkTime"), timeoutMsg);
252  i->second.sentPackets = numRequestsToSend;
253  }
254  else {
255  if (queueSize == 0) {
256  while (numRequestsToSend > 0) {
257  generateAndSend();
259  i->second.sentPackets = numRequestsToSend;
260  }
261  }
262  else if (queueSize > 0) {
263  while (numRequestsToSend > 0 && count++ < queueSize * 2) {
264  generateAndSend();
266  i->second.sentPackets = numRequestsToSend;
267  }
268 
269  cMessage *cmsg = new cMessage("SCTP_C_QUEUE_MSGS_LIMIT");
270  SCTPInfo *qinfo = new SCTPInfo("Info1");
271  qinfo->setText(queueSize);
272  cmsg->setKind(SCTP_C_QUEUE_MSGS_LIMIT);
273  qinfo->setAssocId(id);
274  cmsg->setControlInfo(qinfo);
275  sendOrSchedule(cmsg);
276  }
277  auto j = serverAssocStatMap.find(assocId);
278  if (j->second.rcvdPackets == 0 && par("waitToClose").doubleValue() > 0) {
279  char as[5];
280  sprintf(as, "%d", assocId);
281  cMessage *abortMsg = new cMessage(as);
282  abortMsg->setKind(SCTP_I_ABORT);
283  scheduleAt(simTime() + par("waitToClose"), abortMsg);
284  }
285  else {
286  EV_INFO << "no more packets to send, call shutdown for assoc " << assocId << "\n";
287  cMessage *cmsg = new cMessage("ShutdownRequest");
288  SCTPCommand *cmd = new SCTPCommand("Send5");
289  cmsg->setKind(SCTP_C_SHUTDOWN);
290  cmd->setAssocId(assocId);
291  cmsg->setControlInfo(cmd);
292  sendOrSchedule(cmsg);
293  }
294  }
295  }
296  break;
297  }
298 
301 
302  if (schedule == false) {
303  if (delayFirstRead > 0 && !delayFirstReadTimer->isScheduled()) {
304  cmsg = makeReceiveRequest(msg);
305  scheduleAt(simTime() + delayFirstRead, cmsg);
306  scheduleAt(simTime() + delayFirstRead, delayFirstReadTimer);
307  }
308  else if (readInt && firstData) {
309  firstData = false;
310  cmsg = makeReceiveRequest(msg);
311  scheduleAt(simTime() + par("readingInterval"), delayTimer);
312  sendOrSchedule(cmsg);
313  }
314  else if (delayFirstRead == 0 && readInt == false) {
315  cmsg = makeReceiveRequest(msg);
316  sendOrSchedule(cmsg);
317  }
318  }
319  else {
320  EV_INFO << simTime() << " makeReceiveRequest\n";
321  cmsg = makeReceiveRequest(msg);
322  sendOrSchedule(cmsg);
323  }
324  delete msg;
325  break;
326  }
327 
328  case SCTP_I_DATA: {
330  packetsRcvd++;
331  EV_INFO << simTime() << " server: data arrived. " << packetsRcvd << " Packets received now\n";
332  SCTPRcvInfo *ind = check_and_cast<SCTPRcvInfo *>(msg->removeControlInfo());
333  id = ind->getAssocId();
334  auto j = serverAssocStatMap.find(id);
335  auto k = bytesPerAssoc.find(id);
336  if (j->second.rcvdBytes == 0)
337  j->second.start = simTime();
338 
339  j->second.rcvdBytes += PK(msg)->getByteLength();
340  k->second->record(j->second.rcvdBytes);
341 
342  if (!echo) {
343  if (par("numPacketsToReceivePerClient").longValue() > 0) {
344  j->second.rcvdPackets--;
345  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
346  auto m = endToEndDelay.find(id);
347  m->second->record(simTime() - smsg->getCreationTime());
348  EV_INFO << "server: Data received. Left packets to receive=" << j->second.rcvdPackets << "\n";
349 
350  if (j->second.rcvdPackets == 0) {
351  if (serverAssocStatMap[assocId].peerClosed == true && serverAssocStatMap[assocId].abortSent == false) {
353  serverAssocStatMap[assocId].abortSent = true;
354  j->second.stop = simTime();
355  j->second.lifeTime = j->second.stop - j->second.start;
356  delete msg;
357  break;
358  }
359  else {
360  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
361  SCTPInfo *qinfo = new SCTPInfo("Info2");
362  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
363  qinfo->setAssocId(id);
364  cmsg->setControlInfo(qinfo);
365  sendOrSchedule(cmsg);
366  j->second.stop = simTime();
367  j->second.lifeTime = j->second.stop - j->second.start;
368  }
369  }
370  }
371  delete msg;
372  }
373  else {
374  SCTPSendInfo *cmd = new SCTPSendInfo("SCTP_C_SEND");
375  cmd->setAssocId(id);
376  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
377  auto n = endToEndDelay.find(id);
378  n->second->record(simTime() - smsg->getCreationTime());
379  cPacket *cmsg = new cPacket("SCTP_C_SEND");
380  bytesSent += smsg->getBitLength() / 8;
381  cmd->setSendUnordered(cmd->getSendUnordered());
383  cmd->setPrValue(0);
384  cmd->setSid(lastStream);
385  cmd->setLast(true);
386  cmsg->encapsulate(smsg);
387  cmsg->setKind(SCTP_C_SEND);
388  cmsg->setControlInfo(cmd);
389  packetsSent++;
390  sendOrSchedule(cmsg);
391  }
392  delete ind;
393  break;
394  }
395 
397  SCTPCommand *command = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
398  id = command->getAssocId();
399  EV_INFO << "server: SCTP_I_SHUTDOWN_RECEIVED for assoc " << id << "\n";
400  auto i = serverAssocStatMap.find(id);
401  if (i->second.sentPackets == 0 || par("numPacketsToSendPerClient").longValue() == 0) {
402  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
403  SCTPInfo *qinfo = new SCTPInfo("Info3");
404  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
405  qinfo->setAssocId(id);
406  cmsg->setControlInfo(qinfo);
407  sendOrSchedule(cmsg);
408  i->second.stop = simTime();
409  i->second.lifeTime = i->second.stop - i->second.start;
410  }
411  delete command;
412  shutdownReceived = true;
413  delete msg;
414  break;
415  }
416 
419  EV_INFO << "Streams have been resetted\n";
420  delete msg;
421  break;
422  }
423 
424  case SCTP_I_CLOSED: {
425  SCTPCommand *command = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
426  id = command->getAssocId();
427  EV_INFO << "server: SCTP_I_CLOSED for assoc " << id << endl;
428  ServerAssocStatMap::iterator i = serverAssocStatMap.find(id);
429  i->second.stop = simTime();
430  i->second.lifeTime = i->second.stop - i->second.start;
431  if (delayTimer->isScheduled())
432  cancelEvent(delayTimer);
434  endSimulation();
435  delete command;
436  delete msg;
437  break;
438  }
439 
440  default:
441  delete msg;
442  break;
443  }
444  }
445 }
void sendOrSchedule(cMessage *msg)
Definition: SCTPServer.cc:101
cMessage * timeoutMsg
Definition: SCTPServer.h:63
void generateAndSend()
Definition: SCTPServer.cc:109
int queueSize
Definition: SCTPServer.h:54
int numSessions
Definition: SCTPServer.h:76
Definition: SCTPCommand.h:80
bool shutdownReceived
Definition: SCTPServer.h:71
int outboundStreams
Definition: SCTPServer.h:53
bool firstData
Definition: SCTPServer.h:70
unsigned long int packetsRcvd
Definition: SCTPServer.h:81
Definition: SCTPCommand.h:67
int count
Definition: SCTPServer.h:77
Definition: SCTPCommand.h:33
Definition: SCTPCommand.h:43
Definition: SCTPCommand.h:79
Definition: SCTPCommand.h:63
bool readInt
Definition: SCTPServer.h:68
bool echo
Definition: SCTPServer.h:58
double delayFirstRead
Definition: SCTPServer.h:56
Definition: SCTPCommand.h:65
void handleTimer(cMessage *msg)
Definition: SCTPServer.cc:447
Definition: SCTPCommand.h:42
BytesPerAssoc bytesPerAssoc
Definition: SCTPServer.h:83
Definition: SCTPCommand.h:75
Definition: SCTPCommand.h:44
unsigned long int bytesSent
Definition: SCTPServer.h:79
Definition: SCTPCommand.h:66
cMessage * makeAbortNotification(SCTPCommand *msg)
Definition: SCTPServer.cc:169
Definition: SCTPCommand.h:64
unsigned long int numRequestsToSend
Definition: SCTPServer.h:82
unsigned long int packetsSent
Definition: SCTPServer.h:80
Definition: SCTPCommand.h:72
bool finishEndsSimulation
Definition: SCTPServer.h:57
int assocId
Definition: SCTPServer.h:67
int inboundStreams
Definition: SCTPServer.h:52
int notificationsReceived
Definition: SCTPServer.h:78
#define PK(msg)
Definition: INETDefs.h:92
cMessage * delayFirstReadTimer
Definition: SCTPServer.h:65
cMessage * makeReceiveRequest(cMessage *msg)
Definition: SCTPServer.cc:143
bool schedule
Definition: SCTPServer.h:69
int lastStream
Definition: SCTPServer.h:66
bool abortSent
Definition: SCTPServer.h:72
const double k
Definition: QAM16Modulation.cc:24
ServerAssocStatMap serverAssocStatMap
Definition: SCTPServer.h:84
cMessage * delayTimer
Definition: SCTPServer.h:64
EndToEndDelay endToEndDelay
Definition: SCTPServer.h:73
value< double, units::m > m
Definition: Units.h:1047
virtual bool inet::SCTPServer::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
inlineoverrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

100  { Enter_Method_Silent(); throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName()); return true; }
void inet::SCTPServer::handleTimer ( cMessage *  msg)
protected

Referenced by handleMessage().

448 {
449  if (msg == delayTimer) {
450  EV_INFO << simTime() << " delayTimer expired\n";
452  scheduleAt(simTime() + par("readingInterval"), delayTimer);
453  return;
454  }
455  else if (msg == delayFirstReadTimer) {
456  delayFirstRead = 0;
457 
458  if (readInt && !delayTimer->isScheduled()) {
459  double tempInterval = par("readingInterval");
460  scheduleAt(simTime() + (simtime_t)tempInterval, delayTimer);
461  scheduleAt(simTime() + (simtime_t)tempInterval, makeDefaultReceive());
462  }
463  return;
464  }
465 
466  switch (msg->getKind()) {
467  case SCTP_C_SEND:
468  if (numRequestsToSend > 0) {
469  generateAndSend();
470  if (par("thinkTime").doubleValue() > 0)
471  scheduleAt(simTime() + par("thinkTime"), timeoutMsg);
473  }
474  break;
475 
476  case SCTP_I_ABORT: {
477  cMessage *cmsg = new cMessage("SCTP_C_CLOSE", SCTP_C_CLOSE);
478  SCTPCommand *cmd = new SCTPCommand("Send6");
479  int id = atoi(msg->getName());
480  cmd->setAssocId(id);
481  cmsg->setControlInfo(cmd);
482  sendOrSchedule(cmsg);
483  }
484  break;
485 
486  case SCTP_C_RECEIVE:
487  EV_INFO << simTime() << " SCTPServer:SCTP_C_RECEIVE\n";
488  if (readInt || delayFirstRead > 0)
489  schedule = false;
490  else
491  schedule = true;
492  sendOrSchedule(msg);
493  break;
494 
495  default:
496  EV_INFO << "MsgKind =" << msg->getKind() << " unknown\n";
497  break;
498  }
499 }
void sendOrSchedule(cMessage *msg)
Definition: SCTPServer.cc:101
cMessage * timeoutMsg
Definition: SCTPServer.h:63
void generateAndSend()
Definition: SCTPServer.cc:109
Definition: SCTPCommand.h:33
bool readInt
Definition: SCTPServer.h:68
Definition: SCTPCommand.h:37
double delayFirstRead
Definition: SCTPServer.h:56
unsigned long int numRequestsToSend
Definition: SCTPServer.h:82
Definition: SCTPCommand.h:72
cMessage * delayFirstReadTimer
Definition: SCTPServer.h:65
bool schedule
Definition: SCTPServer.h:69
cMessage * makeDefaultReceive()
Definition: SCTPServer.cc:157
Definition: SCTPCommand.h:34
cMessage * delayTimer
Definition: SCTPServer.h:64
void inet::SCTPServer::initialize ( int  stage)
overrideprotectedvirtual
37 {
38  EV_DEBUG << "initialize SCTP Server stage " << stage << endl;
39 
40  cSimpleModule::initialize(stage);
41 
42  if (stage == INITSTAGE_LOCAL) {
43  WATCH(numSessions);
44  WATCH(packetsSent);
45  WATCH(packetsRcvd);
46  WATCH(bytesSent);
47  WATCH(numRequestsToSend);
48 
49  // parameters
50  finishEndsSimulation = par("finishEndsSimulation").boolValue();
51 
52  inboundStreams = par("inboundStreams");
53  outboundStreams = par("outboundStreams");
54  ordered = par("ordered").boolValue();
55  queueSize = par("queueSize");
56  timeoutMsg = new cMessage("SrvAppTimer");
57  delayTimer = new cMessage("delayTimer");
58  delayTimer->setContextPointer(this);
59  delayFirstReadTimer = new cMessage("delayFirstReadTimer");
60 
61  echo = par("echo");
62  delay = par("echoDelay");
63  delayFirstRead = par("delayFirstRead");
64  cPar *delT = &par("readingInterval");
65  if (delT->isNumeric() && (double)*delT == 0)
66  readInt = false;
67  else
68  readInt = true;
69  }
70  else if (stage == INITSTAGE_APPLICATION_LAYER) {
71  const char *addressesString = par("localAddress");
72  AddressVector addresses = L3AddressResolver().resolve(cStringTokenizer(addressesString).asVector());
73  int port = par("localPort");
74  int messagesToPush = par("messagesToPush");
75 
76  socket = new SCTPSocket();
77  socket->setOutputGate(gate("sctpOut"));
80 
81  if (addresses.size() == 0)
82  socket->bind(port);
83  else
84  socket->bindx(addresses, port);
85 
86  socket->listen(true, par("streamReset").boolValue(), par("numPacketsToSendPerClient").longValue(), messagesToPush);
87  EV_INFO << "SCTPServer::initialized listen port=" << port << "\n";
88  cStringTokenizer tokenizer(par("streamPriorities").stringValue());
89  for (unsigned int streamNum = 0; tokenizer.hasMoreTokens(); streamNum++) {
90  const char *token = tokenizer.nextToken();
91  socket->setStreamPriority(streamNum, (unsigned int)atoi(token));
92  }
93 
94  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
95  bool isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
96  if (!isOperational)
97  throw cRuntimeError("This module doesn't support starting in node DOWN state");
98  }
99 }
cMessage * timeoutMsg
Definition: SCTPServer.h:63
bool ordered
Definition: SCTPServer.h:59
int queueSize
Definition: SCTPServer.h:54
int numSessions
Definition: SCTPServer.h:76
int outboundStreams
Definition: SCTPServer.h:53
unsigned long int packetsRcvd
Definition: SCTPServer.h:81
void bindx(AddressVector localAddr, int localPort)
Definition: SCTPSocket.cc:165
double delay
Definition: SCTPServer.h:55
bool readInt
Definition: SCTPServer.h:68
bool echo
Definition: SCTPServer.h:58
std::vector< L3Address > AddressVector
Definition: SCTPCommand_m.h:41
double delayFirstRead
Definition: SCTPServer.h:56
void bind(int localPort)
Bind the socket to a local port number.
Definition: SCTPSocket.cc:136
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
unsigned long int bytesSent
Definition: SCTPServer.h:79
SCTPSocket * socket
Definition: SCTPServer.h:62
unsigned long int numRequestsToSend
Definition: SCTPServer.h:82
unsigned long int packetsSent
Definition: SCTPServer.h:80
bool finishEndsSimulation
Definition: SCTPServer.h:57
int inboundStreams
Definition: SCTPServer.h:52
#define stringValue()
Definition: NedFunctions.cc:24
cMessage * delayFirstReadTimer
Definition: SCTPServer.h:65
void setInboundStreams(int streams)
Definition: SCTPSocket.h:183
void setOutboundStreams(int streams)
Setter and getter methods for socket and API Parameters.
Definition: SCTPSocket.h:182
void setStreamPriority(uint32 stream, uint32 priority)
Definition: SCTPSocket.cc:611
void listen(bool fork=true, bool streamReset=false, uint32 requests=0, uint32 messagesToPush=0)
Initiates passive OPEN.
Definition: SCTPSocket.cc:177
void setOutputGate(cGate *toSctp)
Sets the gate on which to send to SCTP.
Definition: SCTPSocket.h:177
cMessage * delayTimer
Definition: SCTPServer.h:64
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
cMessage * inet::SCTPServer::makeAbortNotification ( SCTPCommand msg)
protected

Referenced by handleMessage().

170 {
171  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg);
172  cMessage *cmsg = new cMessage("SCTP_C_ABORT");
173  SCTPSendInfo *cmd = new SCTPSendInfo("Send4");
174  assocId = ind->getAssocId();
175  cmd->setAssocId(assocId);
176  cmd->setSid(ind->getSid());
177  cmd->setNumMsgs(ind->getNumMsgs());
178  cmsg->setControlInfo(cmd);
179  delete ind;
180  cmsg->setKind(SCTP_C_ABORT);
181  return cmsg;
182 }
Definition: SCTPCommand.h:35
int assocId
Definition: SCTPServer.h:67
cMessage * inet::SCTPServer::makeDefaultReceive ( )
protected

Referenced by handleTimer().

158 {
159  cMessage *cmsg = new cMessage("DefaultReceive");
160  SCTPSendInfo *cmd = new SCTPSendInfo("Send3");
161  cmd->setAssocId(assocId);
162  cmd->setSid(0);
163  cmd->setNumMsgs(1);
164  cmsg->setKind(SCTP_C_RECEIVE);
165  cmsg->setControlInfo(cmd);
166  return cmsg;
167 }
Definition: SCTPCommand.h:37
int assocId
Definition: SCTPServer.h:67
cMessage * inet::SCTPServer::makeReceiveRequest ( cMessage *  msg)
protected

Referenced by handleMessage().

144 {
145  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
146  cMessage *cmsg = new cMessage("ReceiveRequest");
147  SCTPSendInfo *cmd = new SCTPSendInfo("Send2");
148  cmd->setAssocId(ind->getAssocId());
149  cmd->setSid(ind->getSid());
150  cmd->setNumMsgs(ind->getNumMsgs());
151  cmsg->setKind(SCTP_C_RECEIVE);
152  cmsg->setControlInfo(cmd);
153  delete ind;
154  return cmsg;
155 }
Definition: SCTPCommand.h:37
virtual int inet::SCTPServer::numInitStages ( ) const
inlineoverrideprotectedvirtual
88 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::SCTPServer::sendOrSchedule ( cMessage *  msg)
protected

Referenced by generateAndSend(), handleMessage(), and handleTimer().

102 {
103  if (delay == 0)
104  send(msg, "sctpOut");
105  else
106  scheduleAt(simTime() + delay, msg);
107 }
double delay
Definition: SCTPServer.h:55

Member Data Documentation

bool inet::SCTPServer::abortSent
protected

Referenced by handleMessage(), and SCTPServer().

int inet::SCTPServer::assocId
protected
BytesPerAssoc inet::SCTPServer::bytesPerAssoc
protected

Referenced by handleMessage(), and ~SCTPServer().

unsigned long int inet::SCTPServer::bytesSent
protected
int inet::SCTPServer::count
protected
double inet::SCTPServer::delay
protected
double inet::SCTPServer::delayFirstRead
protected
cMessage* inet::SCTPServer::delayFirstReadTimer
protected
cMessage* inet::SCTPServer::delayTimer
protected
bool inet::SCTPServer::echo
protected
EndToEndDelay inet::SCTPServer::endToEndDelay
protected

Referenced by handleMessage(), and ~SCTPServer().

bool inet::SCTPServer::finishEndsSimulation
protected
bool inet::SCTPServer::firstData
protected

Referenced by handleMessage(), and SCTPServer().

int inet::SCTPServer::inboundStreams
protected
int inet::SCTPServer::lastStream
protected
int inet::SCTPServer::notificationsReceived
protected

Referenced by finish(), handleMessage(), and SCTPServer().

unsigned long int inet::SCTPServer::numRequestsToSend
protected
int inet::SCTPServer::numSessions
protected
bool inet::SCTPServer::ordered
protected
int inet::SCTPServer::outboundStreams
protected
unsigned long int inet::SCTPServer::packetsRcvd
protected
unsigned long int inet::SCTPServer::packetsSent
protected
int inet::SCTPServer::queueSize
protected
bool inet::SCTPServer::readInt
protected
bool inet::SCTPServer::schedule
protected
ServerAssocStatMap inet::SCTPServer::serverAssocStatMap
protected

Referenced by finish(), handleMessage(), and ~SCTPServer().

bool inet::SCTPServer::shutdownReceived
protected

Referenced by handleMessage(), and SCTPServer().

SCTPSocket* inet::SCTPServer::socket
protected

Referenced by initialize(), SCTPServer(), and ~SCTPServer().

cMessage* inet::SCTPServer::timeoutMsg
protected

The documentation for this class was generated from the following files: