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

Implements the SCTPClient simple module. More...

#include <SCTPClient.h>

Inheritance diagram for inet::SCTPClient:
inet::SCTPSocket::CallbackInterface inet::ILifecycle

Classes

struct  PathStatus
 

Public Member Functions

 SCTPClient ()
 
virtual ~SCTPClient ()
 
- Public Member Functions inherited from inet::SCTPSocket::CallbackInterface
virtual ~CallbackInterface ()
 
virtual void socketDeleted (int assocId, void *yourPtr)
 
virtual void sendqueueFullArrived (int connId)
 
virtual void addressAddedArrived (int assocId, L3Address localAddr, L3Address remoteAddr)
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

typedef std::map< L3Address, PathStatusSCTPPathStatus
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
void connect ()
 
void close ()
 
void handleTimer (cMessage *msg)
 
void socketEstablished (int connId, void *yourPtr, unsigned long int buffer) override
 
void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent) override
 
void socketDataNotificationArrived (int connId, void *yourPtr, cPacket *msg) override
 
void socketPeerClosed (int connId, void *yourPtr) override
 
void socketClosed (int connId, void *yourPtr) override
 
void socketFailure (int connId, void *yourPtr, int code) override
 
void socketStatusArrived (int connId, void *yourPtr, SCTPStatusInfo *status) override
 
void setPrimaryPath (const char *addr)
 
void sendRequestArrived () override
 
void sendQueueRequest ()
 
void shutdownReceivedArrived (int connId) override
 
void sendqueueAbatedArrived (int connId, unsigned long int buffer) override
 
void msgAbandonedArrived (int assocId) override
 
void sendStreamResetNotification ()
 
void sendRequest (bool last=true)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

std::map< unsigned int, unsigned int > streamRequestLengthMap
 
std::map< unsigned int, unsigned int > streamRequestRatioMap
 
std::map< unsigned int, unsigned int > streamRequestRatioSendMap
 
int queueSize
 
unsigned int outStreams
 
unsigned int inStreams
 
bool echo
 
bool ordered
 
bool finishEndsSimulation
 
SCTPSocket socket
 
SCTPPathStatus sctpPathStatus
 
cMessage * timeMsg
 
cMessage * stopTimer
 
cMessage * primaryChangeTimer
 
int64 bufferSize
 
bool timer
 
bool sendAllowed
 
const char * stateNameStr
 
unsigned long int packetsSent
 
unsigned long int packetsRcvd
 
unsigned long int bytesSent
 
unsigned long int echoedBytesSent
 
unsigned long int bytesRcvd
 
unsigned long int numRequestsToSend
 
unsigned long int numPacketsToReceive
 
int numSessions
 
int numBroken
 
int chunksAbandoned
 

Static Protected Attributes

static simsignal_t sentPkSignal = registerSignal("sentPk")
 
static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 
static simsignal_t echoedPkSignal = registerSignal("echoedPk")
 

Detailed Description

Implements the SCTPClient simple module.

See the NED file for more info.

Member Typedef Documentation

Constructor & Destructor Documentation

inet::SCTPClient::SCTPClient ( )
43 {
44  timeMsg = nullptr;
45  stopTimer = nullptr;
46  primaryChangeTimer = nullptr;
47  numSessions = 0;
48  numBroken = 0;
49  packetsSent = 0;
50  packetsRcvd = 0;
51  bytesSent = 0;
52  echoedBytesSent = 0;
53  bytesRcvd = 0;
54  queueSize = 0;
55  outStreams = 1;
56  inStreams = 17;
57  echo = false;
58  ordered = true;
59  finishEndsSimulation = false;
60  bufferSize = 0;
61  timer = false;
62  sendAllowed = true;
63  numRequestsToSend = 0; // requests to send in this session
65  chunksAbandoned = 0;
66  stateNameStr = "unknown";
67 }
bool timer
Definition: SCTPClient.h:67
bool ordered
Definition: SCTPClient.h:57
unsigned long int numPacketsToReceive
Definition: SCTPClient.h:78
cMessage * stopTimer
Definition: SCTPClient.h:64
unsigned long int bytesSent
Definition: SCTPClient.h:74
unsigned long int echoedBytesSent
Definition: SCTPClient.h:75
cMessage * primaryChangeTimer
Definition: SCTPClient.h:65
cMessage * timeMsg
Definition: SCTPClient.h:63
int numBroken
Definition: SCTPClient.h:80
int64 bufferSize
Definition: SCTPClient.h:66
unsigned int outStreams
Definition: SCTPClient.h:54
unsigned long int packetsRcvd
Definition: SCTPClient.h:73
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
unsigned int inStreams
Definition: SCTPClient.h:55
unsigned long int packetsSent
Definition: SCTPClient.h:72
bool sendAllowed
Definition: SCTPClient.h:68
int chunksAbandoned
Definition: SCTPClient.h:81
bool echo
Definition: SCTPClient.h:56
int queueSize
Definition: SCTPClient.h:53
int numSessions
Definition: SCTPClient.h:79
unsigned long int bytesRcvd
Definition: SCTPClient.h:76
bool finishEndsSimulation
Definition: SCTPClient.h:58
const char * stateNameStr
Definition: SCTPClient.h:69
inet::SCTPClient::~SCTPClient ( )
virtual
70 {
71  cancelAndDelete(timeMsg);
72  cancelAndDelete(stopTimer);
73  cancelAndDelete(primaryChangeTimer);
74 }
cMessage * stopTimer
Definition: SCTPClient.h:64
cMessage * primaryChangeTimer
Definition: SCTPClient.h:65
cMessage * timeMsg
Definition: SCTPClient.h:63

Member Function Documentation

void inet::SCTPClient::close ( )
protected

Referenced by handleTimer(), socketDataArrived(), and socketPeerClosed().

196 {
197  stateNameStr = "closing";
198  socket.close();
199 }
void close(int id=-1)
Closes the local end of the connection.
Definition: SCTPSocket.cc:410
SCTPSocket socket
Definition: SCTPClient.h:61
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::connect ( )
protected

Referenced by handleTimer().

151 {
152  const char *connectAddress = par("connectAddress");
153  int connectPort = par("connectPort");
154  inStreams = par("inboundStreams");
155  outStreams = par("outboundStreams");
158  stateNameStr = "connecting";
159  EV_INFO << "issuing OPEN command, connect to address " << connectAddress << "\n";
160  bool streamReset = par("streamReset");
161  L3Address destination;
162  L3AddressResolver().tryResolve(connectAddress, destination);
163  if (destination.isUnspecified())
164  EV << "cannot resolve destination address: " << connectAddress << endl;
165  else {
166  socket.connect(destination, connectPort, streamReset, (int)par("prMethod"), (unsigned int)par("numRequestsPerSession"));
167  }
168 
169  if (streamReset) {
170  cMessage *cmsg = new cMessage("StreamReset");
171  cmsg->setKind(MSGKIND_RESET);
172  EV_INFO << "StreamReset Timer scheduled at " << simTime() << "\n";
173  scheduleAt(simTime() + par("streamRequestTime"), cmsg);
174  }
175 
176  for (unsigned int i = 0; i < outStreams; i++) {
177  streamRequestLengthMap[i] = par("requestLength");
178  streamRequestRatioMap[i] = 1;
180  }
181 
182  unsigned int streamNum = 0;
183  cStringTokenizer ratioTokenizer(par("streamRequestRatio").stringValue());
184  while (ratioTokenizer.hasMoreTokens()) {
185  const char *token = ratioTokenizer.nextToken();
186  streamRequestRatioMap[streamNum] = atoi(token);
187  streamRequestRatioSendMap[streamNum] = atoi(token);
188 
189  streamNum++;
190  }
191 
192  numSessions++;
193 }
void connect(L3Address remoteAddress, int32 remotePort, bool streamReset=false, int32 prMethod=0, uint32 numRequests=0)
Active OPEN to the given remote socket.
Definition: SCTPSocket.cc:237
unsigned int outStreams
Definition: SCTPClient.h:54
#define MSGKIND_RESET
Definition: SCTPClient.cc:33
unsigned int inStreams
Definition: SCTPClient.h:55
std::map< unsigned int, unsigned int > streamRequestRatioMap
Definition: SCTPClient.h:51
std::map< unsigned int, unsigned int > streamRequestLengthMap
Definition: SCTPClient.h:50
#define stringValue()
Definition: NedFunctions.cc:24
int numSessions
Definition: SCTPClient.h:79
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
SCTPSocket socket
Definition: SCTPClient.h:61
std::map< unsigned int, unsigned int > streamRequestRatioSendMap
Definition: SCTPClient.h:52
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::finish ( )
overrideprotectedvirtual
638 {
639  EV_INFO << getFullPath() << ": opened " << numSessions << " sessions\n";
640  EV_INFO << getFullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n";
641  EV_INFO << getFullPath() << ": received " << bytesRcvd << " bytes in " << packetsRcvd << " packets\n";
642  EV_INFO << "Client finished\n";
643 }
unsigned long int bytesSent
Definition: SCTPClient.h:74
unsigned long int packetsRcvd
Definition: SCTPClient.h:73
unsigned long int packetsSent
Definition: SCTPClient.h:72
int numSessions
Definition: SCTPClient.h:79
unsigned long int bytesRcvd
Definition: SCTPClient.h:76
void inet::SCTPClient::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
141 {
142  if (msg->isSelfMessage()) {
143  handleTimer(msg);
144  }
145  else {
146  socket.processMessage(msg);
147  }
148 }
void handleTimer(cMessage *msg)
Definition: SCTPClient.cc:413
SCTPSocket socket
Definition: SCTPClient.h:61
void processMessage(cMessage *msg)
Examines the message (which should have arrived from SCTPMain), updates socket state, and if there is a callback object installed (see setCallbackObject(), class CallbackInterface), dispatches to the appropriate method of it with the same yourPtr that you gave in the setCallbackObject() call.
Definition: SCTPSocket.cc:479
virtual bool inet::SCTPClient::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.

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

Referenced by handleMessage().

414 {
415  switch (msg->getKind()) {
416  case MSGKIND_CONNECT:
417  EV_DEBUG << "starting session call connect\n";
418  connect();
419  break;
420 
421  case MSGKIND_SEND:
422  if (((!timer && numRequestsToSend > 0) || timer)) {
423  if (sendAllowed) {
424  sendRequest();
425  if (!timer)
427  }
428  if (par("thinkTime").doubleValue() > 0)
429  scheduleAt(simTime() + par("thinkTime"), timeMsg);
430 
431  if ((!timer && numRequestsToSend == 0) && par("waitToClose").doubleValue() == 0) {
432  socket.shutdown();
433  if (timeMsg->isScheduled())
434  cancelEvent(timeMsg);
435 
436  if (finishEndsSimulation) {
437  endSimulation();
438  }
439  }
440  }
441  else if ((!timer && numRequestsToSend == 0) && par("waitToClose").doubleValue() == 0) {
442  socket.shutdown();
443  if (timeMsg->isScheduled())
444  cancelEvent(timeMsg);
445 
446  if (finishEndsSimulation) {
447  endSimulation();
448  }
449  }
450  break;
451 
452  case MSGKIND_ABORT:
453  close();
454  break;
455 
456  case MSGKIND_PRIMARY:
457  setPrimaryPath(par("newPrimary"));
458  break;
459 
460  case MSGKIND_RESET:
461  EV_INFO << "StreamReset Timer expired at Client at " << simTime() << "...send notification\n";
463  delete msg;
464  break;
465 
466  case MSGKIND_STOP:
467  numRequestsToSend = 0;
468  sendAllowed = false;
469  printf("time is over: send abort\n");
470  socket.abort();
471 
472  if (timeMsg->isScheduled())
473  cancelEvent(timeMsg);
474 
475  if (finishEndsSimulation) {
476  endSimulation();
477  }
478  break;
479 
480  default:
481  throw cRuntimeError("unknown selfmessage kind = %d ", msg->getKind());
482  break;
483  }
484 }
bool timer
Definition: SCTPClient.h:67
#define MSGKIND_ABORT
Definition: SCTPClient.cc:31
#define MSGKIND_STOP
Definition: SCTPClient.cc:34
#define MSGKIND_SEND
Definition: SCTPClient.cc:30
cMessage * timeMsg
Definition: SCTPClient.h:63
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
void close()
Definition: SCTPClient.cc:195
void abort()
Aborts the association.
Definition: SCTPSocket.cc:439
#define MSGKIND_RESET
Definition: SCTPClient.cc:33
void connect()
Definition: SCTPClient.cc:150
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
#define MSGKIND_CONNECT
Definition: SCTPClient.cc:29
void sendRequest(bool last=true)
Definition: SCTPClient.cc:351
bool sendAllowed
Definition: SCTPClient.h:68
void setPrimaryPath(const char *addr)
Definition: SCTPClient.cc:563
SCTPSocket socket
Definition: SCTPClient.h:61
void sendStreamResetNotification()
Definition: SCTPClient.cc:587
#define MSGKIND_PRIMARY
Definition: SCTPClient.cc:32
bool finishEndsSimulation
Definition: SCTPClient.h:58
void inet::SCTPClient::initialize ( int  stage)
overrideprotectedvirtual
77 {
78  cSimpleModule::initialize(stage);
79 
80  EV_DEBUG << "initialize SCTP Client stage " << stage << endl;
81  if (stage == INITSTAGE_LOCAL) {
82  echo = par("echo").boolValue();
83  ordered = par("ordered").boolValue();
84  finishEndsSimulation = par("finishEndsSimulation").boolValue();
85  queueSize = par("queueSize");
86  WATCH(numRequestsToSend);
87  recordScalar("ums", (int)par("requestLength"));
88 
89  timeMsg = new cMessage("CliAppTimer");
90  timeMsg->setKind(MSGKIND_CONNECT);
91  scheduleAt(par("startTime"), timeMsg);
92 
93  stopTimer = nullptr;
94  primaryChangeTimer = nullptr;
95 
96  WATCH(numSessions);
97  WATCH(numBroken);
98  WATCH(packetsSent);
99  WATCH(packetsRcvd);
100  WATCH(bytesSent);
101  WATCH(bytesRcvd);
102  }
103  else if (stage == INITSTAGE_APPLICATION_LAYER) {
104  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
105  bool isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
106  if (!isOperational)
107  throw cRuntimeError("This module doesn't support starting in node DOWN state");
108 
109  // parameters
110  const char *addressesString = par("localAddress");
111  AddressVector addresses = L3AddressResolver().resolve(cStringTokenizer(addressesString).asVector());
112  int port = par("localPort");
113  socket.setOutputGate(gate("sctpOut"));
114  if (addresses.size() == 0)
115  socket.bind(port);
116  else
117  socket.bindx(addresses, port);
118 
120 
121  stateNameStr = "waiting";
122 
123  simtime_t stopTime = par("stopTime");
124  if (stopTime >= SIMTIME_ZERO) {
125  stopTimer = new cMessage("StopTimer");
126  stopTimer->setKind(MSGKIND_STOP);
127  scheduleAt(par("stopTime"), stopTimer);
128  timer = true;
129  }
130 
131  simtime_t primaryTime = par("primaryTime");
132  if (primaryTime != SIMTIME_ZERO) {
133  primaryChangeTimer = new cMessage("PrimaryTime");
135  scheduleAt(primaryTime, primaryChangeTimer);
136  }
137  }
138 }
bool timer
Definition: SCTPClient.h:67
bool ordered
Definition: SCTPClient.h:57
cMessage * stopTimer
Definition: SCTPClient.h:64
#define MSGKIND_STOP
Definition: SCTPClient.cc:34
void setCallbackObject(CallbackInterface *cb, void *yourPtr=nullptr)
Sets a callback object, to be used with processMessage().
Definition: SCTPSocket.cc:473
void bindx(AddressVector localAddr, int localPort)
Definition: SCTPSocket.cc:165
unsigned long int bytesSent
Definition: SCTPClient.h:74
cMessage * primaryChangeTimer
Definition: SCTPClient.h:65
cMessage * timeMsg
Definition: SCTPClient.h:63
int numBroken
Definition: SCTPClient.h:80
unsigned long int packetsRcvd
Definition: SCTPClient.h:73
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
std::vector< L3Address > AddressVector
Definition: SCTPCommand_m.h:41
#define MSGKIND_CONNECT
Definition: SCTPClient.cc:29
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 packetsSent
Definition: SCTPClient.h:72
bool echo
Definition: SCTPClient.h:56
int queueSize
Definition: SCTPClient.h:53
int numSessions
Definition: SCTPClient.h:79
unsigned long int bytesRcvd
Definition: SCTPClient.h:76
SCTPSocket socket
Definition: SCTPClient.h:61
void setOutputGate(cGate *toSctp)
Sets the gate on which to send to SCTP.
Definition: SCTPSocket.h:177
#define MSGKIND_PRIMARY
Definition: SCTPClient.cc:32
bool finishEndsSimulation
Definition: SCTPClient.h:58
const char * stateNameStr
Definition: SCTPClient.h:69
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
void inet::SCTPClient::msgAbandonedArrived ( int  assocId)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

603 {
604  chunksAbandoned++;
605 }
int chunksAbandoned
Definition: SCTPClient.h:81
virtual int inet::SCTPClient::numInitStages ( ) const
inlineoverrideprotectedvirtual
87 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::SCTPClient::refreshDisplay ( ) const
overrideprotectedvirtual
202 {
203  getDisplayString().setTagArg("t", 0, stateNameStr);
204 }
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::sendqueueAbatedArrived ( int  connId,
unsigned long int  buffer 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

608 {
609  bufferSize = buffer;
610  sendAllowed = true;
611 
612  while ((((!timer && numRequestsToSend > 0) || timer) && sendAllowed && bufferSize > 0) ||
613  (((!timer && numRequestsToSend > 0) || timer) && sendAllowed && buffer == 0))
614  {
615  if (!timer && numRequestsToSend == 1)
616  sendRequest(true);
617  else
618  sendRequest(false);
619 
620  if (!timer && (--numRequestsToSend == 0))
621  sendAllowed = false;
622  }
623 
624  if ((!timer && numRequestsToSend == 0) && par("waitToClose").doubleValue() == 0) {
625  EV_INFO << "socketEstablished:no more packets to send, call shutdown\n";
626  socket.shutdown();
627 
628  if (timeMsg->isScheduled())
629  cancelEvent(timeMsg);
630 
631  if (finishEndsSimulation) {
632  endSimulation();
633  }
634  }
635 }
bool timer
Definition: SCTPClient.h:67
cMessage * timeMsg
Definition: SCTPClient.h:63
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
int64 bufferSize
Definition: SCTPClient.h:66
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
void sendRequest(bool last=true)
Definition: SCTPClient.cc:351
bool sendAllowed
Definition: SCTPClient.h:68
SCTPSocket socket
Definition: SCTPClient.h:61
bool finishEndsSimulation
Definition: SCTPClient.h:58
void inet::SCTPClient::sendQueueRequest ( )
protected

Referenced by socketEstablished().

286 {
287  cMessage *cmsg = new cMessage("SCTP_C_QUEUE_MSGS_LIMIT");
288  SCTPInfo *qinfo = new SCTPInfo();
289  qinfo->setText(queueSize);
290  cmsg->setKind(SCTP_C_QUEUE_MSGS_LIMIT);
291  qinfo->setAssocId(socket.getConnectionId());
292  cmsg->setControlInfo(qinfo);
293  EV_INFO << "Sending queue request ..." << endl;
294  socket.sendRequest(cmsg);
295 }
void sendRequest(cMessage *msg)
Send request.
Definition: SCTPSocket.cc:405
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
Definition: SCTPCommand.h:42
int queueSize
Definition: SCTPClient.h:53
SCTPSocket socket
Definition: SCTPClient.h:61
void inet::SCTPClient::sendRequest ( bool  last = true)
protected

Referenced by handleTimer(), sendqueueAbatedArrived(), sendRequestArrived(), and socketEstablished().

352 {
353  // find next stream
354  unsigned int nextStream = 0;
355  for (unsigned int i = 0; i < outStreams; i++) {
357  nextStream = i;
358  }
359 
360  // no stream left, reset map
361  if (nextStream == 0 && streamRequestRatioSendMap[nextStream] == 0) {
362  for (unsigned int i = 0; i < outStreams; i++) {
365  nextStream = i;
366  }
367  }
368 
369  if (nextStream == 0 && streamRequestRatioSendMap[nextStream] == 0) {
370  throw cRuntimeError("Invalid setting of streamRequestRatio: only 0 weightings");
371  }
372 
373  unsigned int sendBytes = streamRequestLengthMap[nextStream];
374  streamRequestRatioSendMap[nextStream]--;
375 
376  if (sendBytes < 1)
377  sendBytes = 1;
378 
379  cPacket *cmsg = new cPacket("SCTP_C_SEND");
380  SCTPSimpleMessage *msg = new SCTPSimpleMessage("data");
381 
382  msg->setDataArraySize(sendBytes);
383 
384  for (unsigned int i = 0; i < sendBytes; i++)
385  msg->setData(i, 'a');
386 
387  msg->setDataLen(sendBytes);
388  msg->setEncaps(false);
389  msg->setByteLength(sendBytes);
390  msg->setCreationTime(simTime());
391  cmsg->encapsulate(msg);
393 
394  // send SCTPMessage with SCTPSimpleMessage enclosed
395  EV_INFO << "Sending request ..." << endl;
396  bufferSize -= sendBytes;
397 
398  if (bufferSize < 0)
399  last = true;
400 
401  SCTPSendInfo* sendCommand = new SCTPSendInfo;
402  sendCommand->setLast(last);
403  sendCommand->setPrMethod(par("prMethod"));
404  sendCommand->setPrValue(par("prValue"));
405  sendCommand->setSid(nextStream);
406  cmsg->setControlInfo(sendCommand);
407 
408  emit(sentPkSignal, msg);
409  socket.sendMsg(cmsg);
410  bytesSent += sendBytes;
411 }
bool ordered
Definition: SCTPClient.h:57
unsigned long int bytesSent
Definition: SCTPClient.h:74
int64 bufferSize
Definition: SCTPClient.h:66
unsigned int outStreams
Definition: SCTPClient.h:54
Definition: SCTPCommand.h:38
std::map< unsigned int, unsigned int > streamRequestRatioMap
Definition: SCTPClient.h:51
std::map< unsigned int, unsigned int > streamRequestLengthMap
Definition: SCTPClient.h:50
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
static simsignal_t sentPkSignal
Definition: SCTPClient.h:82
SCTPSocket socket
Definition: SCTPClient.h:61
std::map< unsigned int, unsigned int > streamRequestRatioSendMap
Definition: SCTPClient.h:52
Definition: SCTPCommand.h:39
void inet::SCTPClient::sendRequestArrived ( )
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

298 {
299  int count = 0;
300 
301  EV_INFO << "sendRequestArrived numRequestsToSend=" << numRequestsToSend << "\n";
302 
303  while (((!timer && numRequestsToSend > 0) || timer) && count++ < queueSize && sendAllowed) {
304  sendRequest(count == queueSize);
305 
306  if (!timer)
307  numRequestsToSend--;
308 
309  if ((!timer && numRequestsToSend == 0)) {
310  EV_INFO << "no more packets to send, call shutdown\n";
311  socket.shutdown();
312 
313  if (timeMsg->isScheduled())
314  cancelEvent(timeMsg);
315 
317  endSimulation();
318  }
319  }
320 }
bool timer
Definition: SCTPClient.h:67
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
cMessage * timeMsg
Definition: SCTPClient.h:63
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
void sendRequest(bool last=true)
Definition: SCTPClient.cc:351
bool sendAllowed
Definition: SCTPClient.h:68
int queueSize
Definition: SCTPClient.h:53
SCTPSocket socket
Definition: SCTPClient.h:61
bool finishEndsSimulation
Definition: SCTPClient.h:58
void inet::SCTPClient::sendStreamResetNotification ( )
protected

Referenced by handleTimer().

588 {
589  unsigned int type = par("streamResetType");
590  if (type >= 6 && type <= 9) {
591  cMessage *cmsg = new cMessage("SCTP_C_STREAM_RESET");
592  SCTPResetInfo *rinfo = new SCTPResetInfo();
593  rinfo->setAssocId(socket.getConnectionId());
594  rinfo->setRemoteAddr(socket.getRemoteAddr());
595  rinfo->setRequestType((unsigned short int)type);
596  cmsg->setKind(SCTP_C_STREAM_RESET);
597  cmsg->setControlInfo(rinfo);
598  socket.sendNotification(cmsg);
599  }
600 }
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
L3Address getRemoteAddr()
Definition: SCTPSocket.h:167
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
SCTPSocket socket
Definition: SCTPClient.h:61
Definition: SCTPCommand.h:45
void inet::SCTPClient::setPrimaryPath ( const char *  addr)
protected

Referenced by handleTimer().

564 {
565  cMessage *cmsg = new cMessage("SCTP_C_PRIMARY");
566  SCTPPathInfo *pinfo = new SCTPPathInfo();
567 
568  if (strcmp(str, "") != 0) {
569  pinfo->setRemoteAddress(L3Address(str));
570  }
571  else {
572  str = par("newPrimary");
573  if (strcmp(str, "") != 0)
574  pinfo->setRemoteAddress(L3Address(str));
575  else {
576  str = par("connectAddress");
577  pinfo->setRemoteAddress(L3Address(str));
578  }
579  }
580 
581  pinfo->setAssocId(socket.getConnectionId());
582  cmsg->setKind(SCTP_C_PRIMARY);
583  cmsg->setControlInfo(pinfo);
584  socket.sendNotification(cmsg);
585 }
Definition: SCTPCommand.h:40
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
SCTPSocket socket
Definition: SCTPClient.h:61
void inet::SCTPClient::shutdownReceivedArrived ( int  connId)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

501 {
502  if (numRequestsToSend == 0) {
503  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
504  SCTPInfo *qinfo = new SCTPInfo();
505  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
506  qinfo->setAssocId(connId);
507  cmsg->setControlInfo(qinfo);
508  socket.sendNotification(cmsg);
509  }
510 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
Definition: SCTPCommand.h:44
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
SCTPSocket socket
Definition: SCTPClient.h:61
void inet::SCTPClient::socketClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

522 {
523  // *redefine* to start another session etc.
524  EV_INFO << "connection closed\n";
525  stateNameStr = "closed";
526 
527  if (primaryChangeTimer) {
528  cancelEvent(primaryChangeTimer);
529  delete primaryChangeTimer;
530  primaryChangeTimer = nullptr;
531  }
532 }
cMessage * primaryChangeTimer
Definition: SCTPClient.h:65
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
overrideprotectedvirtual

Implements inet::SCTPSocket::CallbackInterface.

323 {
324  packetsRcvd++;
325 
326  EV_INFO << "Client received packet Nr " << packetsRcvd << " from SCTP\n";
327  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
328  emit(rcvdPkSignal, msg);
329  bytesRcvd += msg->getByteLength();
330 
331  if (echo) {
332  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
333  cPacket *cmsg = new cPacket("SCTP_C_SEND");
334  echoedBytesSent += smsg->getByteLength();
335  emit(echoedPkSignal, smsg);
336  cmsg->encapsulate(smsg);
337  cmsg->setKind(ind->getSendUnordered() ? SCTP_C_SEND_UNORDERED : SCTP_C_SEND_ORDERED);
338  packetsSent++;
339  socket.sendMsg(cmsg);
340  }
341 
342  if (par("numPacketsToReceive").longValue() > 0) {
344  if (numPacketsToReceive == 0)
345  close();
346  }
347 
348  delete ind;
349 }
unsigned long int numPacketsToReceive
Definition: SCTPClient.h:78
unsigned long int echoedBytesSent
Definition: SCTPClient.h:75
static simsignal_t rcvdPkSignal
Definition: SCTPClient.h:83
void close()
Definition: SCTPClient.cc:195
unsigned long int packetsRcvd
Definition: SCTPClient.h:73
Definition: SCTPCommand.h:38
unsigned long int packetsSent
Definition: SCTPClient.h:72
bool echo
Definition: SCTPClient.h:56
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
static simsignal_t echoedPkSignal
Definition: SCTPClient.h:84
unsigned long int bytesRcvd
Definition: SCTPClient.h:76
SCTPSocket socket
Definition: SCTPClient.h:61
Definition: SCTPCommand.h:39
void inet::SCTPClient::socketDataNotificationArrived ( int  connId,
void *  yourPtr,
cPacket *  msg 
)
overrideprotectedvirtual

Implements inet::SCTPSocket::CallbackInterface.

487 {
488  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
489  cMessage *cmsg = new cMessage("SCTP_C_RECEIVE");
490  SCTPSendInfo *cmd = new SCTPSendInfo();
491  cmd->setAssocId(ind->getAssocId());
492  cmd->setSid(ind->getSid());
493  cmd->setNumMsgs(ind->getNumMsgs());
494  cmsg->setKind(SCTP_C_RECEIVE);
495  cmsg->setControlInfo(cmd);
496  delete ind;
497  socket.sendNotification(cmsg);
498 }
Definition: SCTPCommand.h:37
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
SCTPSocket socket
Definition: SCTPClient.h:61
void inet::SCTPClient::socketEstablished ( int  connId,
void *  yourPtr,
unsigned long int  buffer 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

207 {
208  int count = 0;
209  EV_INFO << "SCTPClient: connected\n";
210  stateNameStr = "connected";
211  bufferSize = buffer;
212  // determine number of requests in this session
213  numRequestsToSend = par("numRequestsPerSession");
214  numPacketsToReceive = par("numPacketsToReceive");
215 
216  if (numRequestsToSend < 1)
217  numRequestsToSend = 0;
218 
219  EV_INFO << "SCTPClient:numRequestsToSend=" << numRequestsToSend << "\n";
220 
221  // perform first request (next one will be sent when reply arrives)
222  if ((numRequestsToSend > 0 && !timer) || timer) {
223  if (par("thinkTime").doubleValue() > 0) {
224  if (sendAllowed) {
225  sendRequest();
226 
227  if (!timer)
228  numRequestsToSend--;
229  }
230 
231  timeMsg->setKind(MSGKIND_SEND);
232  scheduleAt(simTime() + par("thinkTime"), timeMsg);
233  }
234  else {
235  if (queueSize > 0) {
236  while (((!timer && numRequestsToSend > 0) || timer) && count++ < queueSize * 2 && sendAllowed) {
237  if (count == queueSize * 2)
238  sendRequest();
239  else
240  sendRequest(false);
241 
242  if (!timer) {
243  if (--numRequestsToSend == 0)
244  sendAllowed = false;
245  }
246  }
247 
248  if (((!timer && numRequestsToSend > 0) || timer) && sendAllowed)
250  }
251  else {
252  while ((((!timer && numRequestsToSend > 0) || timer) && sendAllowed && bufferSize > 0) ||
253  (((!timer && numRequestsToSend > 0) || timer) && sendAllowed && buffer == 0))
254  {
255  if (!timer && numRequestsToSend == 1)
256  sendRequest(true);
257  else
258  sendRequest(false);
259 
260  if (!timer && (--numRequestsToSend == 0))
261  sendAllowed = false;
262  }
263  }
264  }
265 
266  if ((!timer && numPacketsToReceive == 0) && par("waitToClose").doubleValue() > 0) {
267  timeMsg->setKind(MSGKIND_ABORT);
268  scheduleAt(simTime() + par("waitToClose"), timeMsg);
269  }
270 
271  if ((!timer && numRequestsToSend == 0) && par("waitToClose").doubleValue() == 0) {
272  EV_INFO << "socketEstablished:no more packets to send, call shutdown\n";
273  socket.shutdown();
274 
275  if (timeMsg->isScheduled())
276  cancelEvent(timeMsg);
277 
278  if (finishEndsSimulation) {
279  endSimulation();
280  }
281  }
282  }
283 }
bool timer
Definition: SCTPClient.h:67
#define MSGKIND_ABORT
Definition: SCTPClient.cc:31
unsigned long int numPacketsToReceive
Definition: SCTPClient.h:78
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
#define MSGKIND_SEND
Definition: SCTPClient.cc:30
cMessage * timeMsg
Definition: SCTPClient.h:63
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
int64 bufferSize
Definition: SCTPClient.h:66
unsigned long int numRequestsToSend
Definition: SCTPClient.h:77
void sendRequest(bool last=true)
Definition: SCTPClient.cc:351
bool sendAllowed
Definition: SCTPClient.h:68
void sendQueueRequest()
Definition: SCTPClient.cc:285
int queueSize
Definition: SCTPClient.h:53
SCTPSocket socket
Definition: SCTPClient.h:61
bool finishEndsSimulation
Definition: SCTPClient.h:58
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::socketFailure ( int  connId,
void *  yourPtr,
int  code 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

535 {
536  // subclasses may override this function, and add code try to reconnect after a delay.
537  EV_WARN << "connection broken\n";
538  stateNameStr = "broken";
539  numBroken++;
540  // reconnect after a delay
541  timeMsg->setKind(MSGKIND_CONNECT);
542  scheduleAt(simTime() + par("reconnectInterval"), timeMsg);
543 }
cMessage * timeMsg
Definition: SCTPClient.h:63
int numBroken
Definition: SCTPClient.h:80
#define MSGKIND_CONNECT
Definition: SCTPClient.cc:29
const char * stateNameStr
Definition: SCTPClient.h:69
void inet::SCTPClient::socketPeerClosed ( int  connId,
void *  yourPtr 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

513 {
514  // close the connection (if not already closed)
516  EV_INFO << "remote SCTP closed, closing here as well\n";
517  close();
518  }
519 }
void close()
Definition: SCTPClient.cc:195
int getState()
Returns the socket state, one of NOT_BOUND, CLOSED, LISTENING, CONNECTING, CONNECTED, etc.
Definition: SCTPSocket.h:154
Definition: SCTPSocket.h:87
SCTPSocket socket
Definition: SCTPClient.h:61
void inet::SCTPClient::socketStatusArrived ( int  connId,
void *  yourPtr,
SCTPStatusInfo status 
)
overrideprotectedvirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

546 {
547  struct PathStatus ps;
548  auto i = sctpPathStatus.find(status->getPathId());
549 
550  if (i != sctpPathStatus.end()) {
551  ps = i->second;
552  ps.active = status->getActive();
553  }
554  else {
555  ps.active = status->getActive();
556  ps.pid = status->getPathId();
557  ps.primaryPath = false;
558  sctpPathStatus[ps.pid] = ps;
559  }
560  delete status;
561 }
SCTPPathStatus sctpPathStatus
Definition: SCTPClient.h:62

Member Data Documentation

int64 inet::SCTPClient::bufferSize
protected
unsigned long int inet::SCTPClient::bytesRcvd
protected
unsigned long int inet::SCTPClient::bytesSent
protected
int inet::SCTPClient::chunksAbandoned
protected

Referenced by msgAbandonedArrived(), and SCTPClient().

bool inet::SCTPClient::echo
protected
unsigned long int inet::SCTPClient::echoedBytesSent
protected

Referenced by SCTPClient(), and socketDataArrived().

simsignal_t inet::SCTPClient::echoedPkSignal = registerSignal("echoedPk")
staticprotected

Referenced by socketDataArrived().

bool inet::SCTPClient::finishEndsSimulation
protected
unsigned int inet::SCTPClient::inStreams
protected

Referenced by connect(), and SCTPClient().

int inet::SCTPClient::numBroken
protected
unsigned long int inet::SCTPClient::numPacketsToReceive
protected
unsigned long int inet::SCTPClient::numRequestsToSend
protected
int inet::SCTPClient::numSessions
protected
bool inet::SCTPClient::ordered
protected

Referenced by initialize(), SCTPClient(), and sendRequest().

unsigned int inet::SCTPClient::outStreams
protected

Referenced by connect(), SCTPClient(), and sendRequest().

unsigned long int inet::SCTPClient::packetsRcvd
protected
unsigned long int inet::SCTPClient::packetsSent
protected
cMessage* inet::SCTPClient::primaryChangeTimer
protected
int inet::SCTPClient::queueSize
protected
simsignal_t inet::SCTPClient::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by socketDataArrived().

SCTPPathStatus inet::SCTPClient::sctpPathStatus
protected

Referenced by socketStatusArrived().

bool inet::SCTPClient::sendAllowed
protected
simsignal_t inet::SCTPClient::sentPkSignal = registerSignal("sentPk")
staticprotected

Referenced by sendRequest().

const char* inet::SCTPClient::stateNameStr
protected
cMessage* inet::SCTPClient::stopTimer
protected

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

std::map<unsigned int, unsigned int> inet::SCTPClient::streamRequestLengthMap
protected

Referenced by connect(), and sendRequest().

std::map<unsigned int, unsigned int> inet::SCTPClient::streamRequestRatioMap
protected

Referenced by connect(), and sendRequest().

std::map<unsigned int, unsigned int> inet::SCTPClient::streamRequestRatioSendMap
protected

Referenced by connect(), and sendRequest().

bool inet::SCTPClient::timer
protected

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