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

Accepts any number of incoming connections, and sends back whatever arrives on them. More...

#include <SCTPNatPeer.h>

Inheritance diagram for inet::SCTPNatPeer:
inet::SCTPSocket::CallbackInterface

Classes

struct  pathStatus
 

Public Types

typedef std::map< L3Address, pathStatusSCTPPathStatus
 

Public Member Functions

 SCTPNatPeer ()
 
virtual ~SCTPNatPeer ()
 
void initialize () override
 
void handleMessage (cMessage *msg) override
 
void finish () override
 
void handleTimer (cMessage *msg)
 
void generateAndSend ()
 
void connect (L3Address connectAddress, int32 connectPort)
 
void connectx (AddressVector connectAddressList, int32 connectPort)
 
void socketEstablished (int32, void *, unsigned long int buffer) override
 Does nothing but update statistics/status. More...
 
void socketDataArrived (int32 connId, void *yourPtr, cPacket *msg, bool urgent) override
 Does nothing but update statistics/status. More...
 
void socketDataNotificationArrived (int32 connId, void *yourPtr, cPacket *msg) override
 
void socketPeerClosed (int32 connId, void *yourPtr) override
 Since remote SCTP closed, invokes close(). More...
 
void socketClosed (int32 connId, void *yourPtr) override
 Does nothing but update statistics/status. More...
 
void socketFailure (int32 connId, void *yourPtr, int32 code) override
 Does nothing but update statistics/status. More...
 
void socketStatusArrived (int32 connId, void *yourPtr, SCTPStatusInfo *status) override
 Redefine to handle incoming SCTPStatusInfo. More...
 
void msgAbandonedArrived (int32 assocId) override
 
void setPrimaryPath ()
 
void sendStreamResetNotification ()
 
void sendRequestArrived () override
 
void sendQueueRequest ()
 
void shutdownReceivedArrived (int32 connId) override
 
void sendqueueFullArrived (int32 connId) override
 
void addressAddedArrived (int32 assocId, L3Address localAddr, L3Address remoteAddr) override
 
void setStatusString (const char *s)
 
- Public Member Functions inherited from inet::SCTPSocket::CallbackInterface
virtual ~CallbackInterface ()
 
virtual void socketDataArrived (int assocId, void *yourPtr, cPacket *msg, bool urgent)=0
 
virtual void socketDataNotificationArrived (int assocId, void *yourPtr, cPacket *msg)=0
 
virtual void socketEstablished (int assocId, void *yourPtr, unsigned long int buffer)
 
virtual void socketPeerClosed (int assocId, void *yourPtr)
 
virtual void socketClosed (int assocId, void *yourPtr)
 
virtual void socketFailure (int assocId, void *yourPtr, int code)
 
virtual void socketStatusArrived (int assocId, void *yourPtr, SCTPStatusInfo *status)
 
virtual void socketDeleted (int assocId, void *yourPtr)
 
virtual void msgAbandonedArrived (int assocId)
 
virtual void shutdownReceivedArrived (int connId)
 
virtual void sendqueueFullArrived (int connId)
 
virtual void sendqueueAbatedArrived (int connId, unsigned long int buffer)
 
virtual void addressAddedArrived (int assocId, L3Address localAddr, L3Address remoteAddr)
 

Public Attributes

SCTPPathStatus sctpPathStatus
 

Protected Types

typedef std::map< int32, int64RcvdPacketsPerAssoc
 
typedef std::map< int32, int64SentPacketsPerAssoc
 
typedef std::map< int32, int64RcvdBytesPerAssoc
 
typedef std::map< int32, cOutVector * > BytesPerAssoc
 
typedef std::map< int32, cDoubleHistogram * > HistEndToEndDelay
 
typedef std::map< int32, cOutVector * > EndToEndDelay
 

Protected Member Functions

void sendOrSchedule (cMessage *msg)
 
void sendRequest (bool last=true)
 

Protected Attributes

int32 notifications
 
int32 serverAssocId
 
SCTPSocket clientSocket
 
SCTPSocket peerSocket
 
SCTPSocket rendezvousSocket
 
double delay
 
bool echo
 
bool schedule
 
bool shutdownReceived
 
int64 bytesSent
 
int32 packetsSent
 
int32 packetsRcvd
 
int32 numSessions
 
int32 numRequestsToSend
 
bool ordered
 
int32 queueSize
 
cMessage * timeoutMsg
 
cMessage * timeMsg
 
int32 outboundStreams
 
int32 inboundStreams
 
int32 bytesRcvd
 
int32 echoedBytesSent
 
int32 lastStream
 
bool sendAllowed
 
int32 chunksAbandoned
 
int32 numPacketsToReceive
 
bool rendezvous
 
L3Address peerAddress
 
int32 peerPort
 
AddressVector peerAddressList
 
AddressVector localAddressList
 
RcvdPacketsPerAssoc rcvdPacketsPerAssoc
 
SentPacketsPerAssoc sentPacketsPerAssoc
 
RcvdBytesPerAssoc rcvdBytesPerAssoc
 
BytesPerAssoc bytesPerAssoc
 
HistEndToEndDelay histEndToEndDelay
 
EndToEndDelay endToEndDelay
 

Detailed Description

Accepts any number of incoming connections, and sends back whatever arrives on them.

Member Typedef Documentation

typedef std::map<int32, cOutVector *> inet::SCTPNatPeer::BytesPerAssoc
protected
typedef std::map<int32, cOutVector *> inet::SCTPNatPeer::EndToEndDelay
protected
typedef std::map<int32, cDoubleHistogram *> inet::SCTPNatPeer::HistEndToEndDelay
protected
typedef std::map<int32, int64> inet::SCTPNatPeer::RcvdBytesPerAssoc
protected
typedef std::map<int32, int64> inet::SCTPNatPeer::RcvdPacketsPerAssoc
protected
typedef std::map<int32, int64> inet::SCTPNatPeer::SentPacketsPerAssoc
protected

Constructor & Destructor Documentation

inet::SCTPNatPeer::SCTPNatPeer ( )
42 {
43  timeMsg = nullptr;
44  timeoutMsg = nullptr;
45  numSessions = 0;
46  packetsSent = 0;
47  packetsRcvd = 0;
48  bytesSent = 0;
49  notifications = 0;
50  serverAssocId = 0;
51  delay = 0;
52  echo = false;
53  schedule = false;
54  shutdownReceived = false;
55  sendAllowed = true;
57  ordered = true;
58  queueSize = 0;
59  outboundStreams = 1;
60  inboundStreams = 1;
61  bytesRcvd = 0;
62  echoedBytesSent = 0;
63  lastStream = 0;
64  chunksAbandoned = 0;
66  rendezvous = false;
67  peerPort = 0;
68 }
cMessage * timeoutMsg
Definition: SCTPNatPeer.h:49
int32 chunksAbandoned
Definition: SCTPNatPeer.h:57
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
int32 numSessions
Definition: SCTPNatPeer.h:45
int32 packetsRcvd
Definition: SCTPNatPeer.h:44
int32 packetsSent
Definition: SCTPNatPeer.h:43
bool shutdownReceived
Definition: SCTPNatPeer.h:40
int32 lastStream
Definition: SCTPNatPeer.h:55
int32 queueSize
Definition: SCTPNatPeer.h:48
bool rendezvous
Definition: SCTPNatPeer.h:59
int32 inboundStreams
Definition: SCTPNatPeer.h:52
bool echo
Definition: SCTPNatPeer.h:38
int32 bytesRcvd
Definition: SCTPNatPeer.h:53
bool schedule
Definition: SCTPNatPeer.h:39
int32 numPacketsToReceive
Definition: SCTPNatPeer.h:58
cMessage * timeMsg
Definition: SCTPNatPeer.h:50
bool sendAllowed
Definition: SCTPNatPeer.h:56
int32 notifications
Definition: SCTPNatPeer.h:32
bool ordered
Definition: SCTPNatPeer.h:47
int32 echoedBytesSent
Definition: SCTPNatPeer.h:54
int64 bytesSent
Definition: SCTPNatPeer.h:42
int32 outboundStreams
Definition: SCTPNatPeer.h:51
double delay
Definition: SCTPNatPeer.h:37
int32 peerPort
Definition: SCTPNatPeer.h:61
int32 serverAssocId
Definition: SCTPNatPeer.h:33
inet::SCTPNatPeer::~SCTPNatPeer ( )
virtual
71 {
72  cancelAndDelete(timeMsg);
73  cancelAndDelete(timeoutMsg);
74 }
cMessage * timeoutMsg
Definition: SCTPNatPeer.h:49
cMessage * timeMsg
Definition: SCTPNatPeer.h:50

Member Function Documentation

void inet::SCTPNatPeer::addressAddedArrived ( int32  assocId,
L3Address  localAddr,
L3Address  remoteAddr 
)
override
858 {
859  EV << getFullPath() << ": addressAddedArrived for remoteAddr " << remoteAddr << "\n";
860  localAddressList.push_back(localAddr);
861  clientSocket.addAddress(localAddr);
862  if (rendezvous) {
863  NatMessage *msg = new NatMessage("Rendezvous");
864  msg->setKind(SCTP_C_NAT_INFO);
865  msg->setMulti((bool)par("multi"));
866  msg->setPeer1(par("ownName"));
867  msg->setPeer1AddressesArraySize(2);
868  msg->setPeer1Addresses(0, L3Address());
869  msg->setPeer1Addresses(1, L3Address());
870  msg->setPortPeer1(par("localPort"));
871  msg->setPeer2(par("peerName"));
872  msg->setPeer2AddressesArraySize(2);
873  msg->setPeer2Addresses(0, L3Address());
874  msg->setPeer2Addresses(1, L3Address());
875  msg->setPortPeer2(0);
876  cPacket* cmsg = new cPacket(msg->getName());
877  SCTPSimpleMessage *smsg = new SCTPSimpleMessage("nat_data");
878  smsg->setEncaps(true);
879  smsg->encapsulate(msg);
880  smsg->setCreationTime(simTime());
881  smsg->setByteLength(16);
882  smsg->setDataLen(16);
883  cmsg->encapsulate(smsg);
884 
885  SCTPSendInfo* sendCommand = new SCTPSendInfo;
886  sendCommand->setLast(true);
887  sendCommand->setAssocId(assocId);
888  cmsg->setControlInfo(sendCommand);
889 
890  clientSocket.sendMsg(cmsg);
891  }
892 }
AddressVector localAddressList
Definition: SCTPNatPeer.h:63
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
bool rendezvous
Definition: SCTPNatPeer.h:59
void addAddress(L3Address addr)
Definition: SCTPSocket.cc:159
Definition: SCTPCommand.h:48
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
void inet::SCTPNatPeer::connect ( L3Address  connectAddress,
int32  connectPort 
)
187 {
190 
191  EV << "issuing OPEN command\n";
192  EV << "Assoc " << clientSocket.getConnectionId() << "::connect to address " << connectAddress << ", port " << connectPort << "\n";
193  bool streamReset = par("streamReset");
194  clientSocket.connect(connectAddress, connectPort, streamReset, (int32)par("prMethod"), (uint32)par("numRequestsPerSession"));
195  numSessions++;
196 
197  if (!streamReset)
198  streamReset = false;
199  else if (streamReset == true) {
200  cMessage *cmsg = new cMessage("StreamReset");
201  cmsg->setKind(MSGKIND_RESET);
202  EV << "StreamReset Timer scheduled at " << simTime() << "\n";
203  scheduleAt(simTime() + (double)par("streamRequestTime"), cmsg);
204  }
205  uint32 streamNum = 0;
206  cStringTokenizer tokenizer(par("streamPriorities").stringValue());
207  while (tokenizer.hasMoreTokens()) {
208  const char *token = tokenizer.nextToken();
209  clientSocket.setStreamPriority(streamNum, (uint32)atoi(token));
210 
211  streamNum++;
212  }
213 }
int32 numSessions
Definition: SCTPNatPeer.h:45
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
#define MSGKIND_RESET
Definition: SCTPNatPeer.cc:36
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
int32 inboundStreams
Definition: SCTPNatPeer.h:52
int32_t int32
Definition: Compat.h:31
uint32_t uint32
Definition: Compat.h:30
#define stringValue()
Definition: NedFunctions.cc:24
void setInboundStreams(int streams)
Definition: SCTPSocket.h:183
int32 outboundStreams
Definition: SCTPNatPeer.h:51
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 inet::SCTPNatPeer::connectx ( AddressVector  connectAddressList,
int32  connectPort 
)
156 {
157  uint32 outStreams = par("outboundStreams");
158  clientSocket.setOutboundStreams(outStreams);
159  uint32 inStreams = par("inboundStreams");
160  clientSocket.setInboundStreams(inStreams);
161 
162  EV << "issuing OPEN command\n";
163  EV << "Assoc " << clientSocket.getConnectionId() << "::connect to port " << connectPort << "\n";
164  bool streamReset = par("streamReset");
165  clientSocket.connectx(connectAddressList, connectPort, streamReset, (int32)par("prMethod"), (uint32)par("numRequestsPerSession"));
166  numSessions++;
167 
168  if (!streamReset)
169  streamReset = false;
170  else if (streamReset == true) {
171  cMessage *cmsg = new cMessage("StreamReset");
172  cmsg->setKind(MSGKIND_RESET);
173  EV << "StreamReset Timer scheduled at " << simTime() << "\n";
174  scheduleAt(simTime() + (double)par("streamRequestTime"), cmsg);
175  }
176  uint32 streamNum = 0;
177  cStringTokenizer tokenizer(par("streamPriorities").stringValue());
178  while (tokenizer.hasMoreTokens()) {
179  const char *token = tokenizer.nextToken();
180  clientSocket.setStreamPriority(streamNum, (uint32)atoi(token));
181 
182  streamNum++;
183  }
184 }
int32 numSessions
Definition: SCTPNatPeer.h:45
void connectx(AddressVector remoteAddresses, int32 remotePort, bool streamReset=false, int32 prMethod=0, uint32 numRequests=0)
Active OPEN to the given remote socket.
Definition: SCTPSocket.cc:335
#define MSGKIND_RESET
Definition: SCTPNatPeer.cc:36
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
int32_t int32
Definition: Compat.h:31
uint32_t uint32
Definition: Compat.h:30
#define stringValue()
Definition: NedFunctions.cc:24
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 inet::SCTPNatPeer::finish ( )
override
895 {
896  EV << getFullPath() << ": opened " << numSessions << " sessions\n";
897  EV << getFullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n";
898  for (auto & elem : rcvdBytesPerAssoc) {
899  EV << getFullPath() << ": received " << elem.second << " bytes in assoc " << elem.first << "\n";
900  }
901  EV << getFullPath() << "Over all " << packetsRcvd << " packets received\n ";
902  EV << getFullPath() << "Over all " << notifications << " notifications received\n ";
903  for (auto & elem : bytesPerAssoc) {
904  delete elem.second;
905  }
906  bytesPerAssoc.clear();
907  for (auto & elem : endToEndDelay) {
908  delete elem.second;
909  }
910  endToEndDelay.clear();
911  for (auto & elem : histEndToEndDelay) {
912  delete elem.second;
913  }
914  histEndToEndDelay.clear();
915  rcvdPacketsPerAssoc.clear();
916  sentPacketsPerAssoc.clear();
917  rcvdBytesPerAssoc.clear();
918 }
int32 numSessions
Definition: SCTPNatPeer.h:45
SentPacketsPerAssoc sentPacketsPerAssoc
Definition: SCTPNatPeer.h:68
BytesPerAssoc bytesPerAssoc
Definition: SCTPNatPeer.h:72
int32 packetsRcvd
Definition: SCTPNatPeer.h:44
int32 packetsSent
Definition: SCTPNatPeer.h:43
RcvdPacketsPerAssoc rcvdPacketsPerAssoc
Definition: SCTPNatPeer.h:66
HistEndToEndDelay histEndToEndDelay
Definition: SCTPNatPeer.h:74
RcvdBytesPerAssoc rcvdBytesPerAssoc
Definition: SCTPNatPeer.h:70
int32 notifications
Definition: SCTPNatPeer.h:32
int64 bytesSent
Definition: SCTPNatPeer.h:42
EndToEndDelay endToEndDelay
Definition: SCTPNatPeer.h:76
void inet::SCTPNatPeer::generateAndSend ( )
122 {
123  uint32 numBytes;
124  EV << "SCTPNatPeer:generateAndSend \n";
125 
126  cPacket *cmsg = new cPacket("SCTP_C_SEND");
127  SCTPSimpleMessage *msg = new SCTPSimpleMessage("Server");
128  numBytes = (int64)(long)par("requestLength");
129  msg->setDataArraySize(numBytes);
130  for (uint32 i = 0; i < numBytes; i++) {
131  msg->setData(i, 's');
132  }
133  msg->setDataLen(numBytes);
134  msg->setEncaps(false);
135  msg->setBitLength(numBytes * 8);
136  cmsg->encapsulate(msg);
137  SCTPSendInfo *cmd = new SCTPSendInfo();
138  cmd->setAssocId(serverAssocId);
139  if (ordered)
140  cmd->setSendUnordered(COMPLETE_MESG_ORDERED);
141  else
142  cmd->setSendUnordered(COMPLETE_MESG_UNORDERED);
144  cmd->setSid(lastStream);
145  cmd->setPrValue((double)par("prValue"));
146  cmd->setPrMethod((int32)par("prMethod"));
147  cmd->setLast(true);
148  cmsg->setKind(SCTP_C_SEND);
149  cmsg->setControlInfo(cmd);
150  packetsSent++;
151  bytesSent += msg->getBitLength() / 8;
152  sendOrSchedule(cmsg);
153 }
int32 packetsSent
Definition: SCTPNatPeer.h:43
Definition: SCTPCommand.h:33
int32 lastStream
Definition: SCTPNatPeer.h:55
int32_t int32
Definition: Compat.h:31
uint32_t uint32
Definition: Compat.h:30
bool ordered
Definition: SCTPNatPeer.h:47
int64 bytesSent
Definition: SCTPNatPeer.h:42
int32 outboundStreams
Definition: SCTPNatPeer.h:51
Definition: SCTPCommand.h:87
Definition: SCTPCommand.h:88
int64_t int64
Definition: Compat.h:29
void sendOrSchedule(cMessage *msg)
Definition: SCTPNatPeer.cc:111
int32 serverAssocId
Definition: SCTPNatPeer.h:33
void inet::SCTPNatPeer::handleMessage ( cMessage *  msg)
override
216 {
217  int32 id;
218 
219  if (msg->isSelfMessage()) {
220  handleTimer(msg);
221  }
222  else {
223  EV << "SCTPNatPeer::handleMessage kind=" << SCTPAssociation::indicationName(msg->getKind()) << " (" << msg->getKind() << ")\n";
224  switch (msg->getKind()) {
226  if (rendezvous)
228  else
229  delete msg;
230  break;
231 
232  case SCTP_I_PEER_CLOSED:
233  case SCTP_I_ABORT: {
234  if (rendezvous)
236  else {
237  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->getControlInfo()->dup());
238  cMessage *cmsg = new cMessage("Notification");
239  SCTPSendInfo *cmd = new SCTPSendInfo();
240  id = ind->getAssocId();
241  cmd->setAssocId(id);
242  cmd->setSid(ind->getSid());
243  cmd->setNumMsgs(ind->getNumMsgs());
244  cmsg->setControlInfo(cmd);
245  delete ind;
246  delete msg;
247  cmsg->setKind(SCTP_C_ABORT);
248  sendOrSchedule(cmsg);
249  }
250 
251  break;
252  }
253 
254  case SCTP_I_ESTABLISHED: {
257  else {
258  int32 count = 0;
259  SCTPConnectInfo *connectInfo = check_and_cast<SCTPConnectInfo *>(msg->removeControlInfo());
260  numSessions++;
261  serverAssocId = connectInfo->getAssocId();
262  id = serverAssocId;
263  outboundStreams = connectInfo->getOutboundStreams();
264  inboundStreams = connectInfo->getInboundStreams();
265  rcvdPacketsPerAssoc[serverAssocId] = (int64)(long)par("numPacketsToReceivePerClient");
266  sentPacketsPerAssoc[serverAssocId] = (int64)(long)par("numPacketsToSendPerClient");
267  char text[128];
268  sprintf(text, "App: Received Bytes of assoc %d", serverAssocId);
269  bytesPerAssoc[serverAssocId] = new cOutVector(text);
271  sprintf(text, "App: EndToEndDelay of assoc %d", serverAssocId);
272  endToEndDelay[serverAssocId] = new cOutVector(text);
273  sprintf(text, "Hist: EndToEndDelay of assoc %d", serverAssocId);
274  histEndToEndDelay[serverAssocId] = new cDoubleHistogram(text);
275  delete connectInfo;
276  delete msg;
277 
278  if ((int64)(long)par("numPacketsToSendPerClient") > 0) {
279  auto i = sentPacketsPerAssoc.find(serverAssocId);
280  numRequestsToSend = i->second;
281  if ((simtime_t)par("thinkTime") > 0) {
282  generateAndSend();
283  timeoutMsg->setKind(SCTP_C_SEND);
284  scheduleAt(simTime() + (simtime_t)par("thinkTime"), timeoutMsg);
286  i->second = numRequestsToSend;
287  }
288  else {
289  if (queueSize == 0) {
290  while (numRequestsToSend > 0) {
291  generateAndSend();
293  i->second = numRequestsToSend;
294  }
295  }
296  else if (queueSize > 0) {
297  while (numRequestsToSend > 0 && count++ < queueSize * 2) {
298  generateAndSend();
300  i->second = numRequestsToSend;
301  }
302 
303  cMessage *cmsg = new cMessage("SCTP_C_QUEUE_MSGS_LIMIT");
304  SCTPInfo *qinfo = new SCTPInfo();
305  qinfo->setText(queueSize);
306  cmsg->setKind(SCTP_C_QUEUE_MSGS_LIMIT);
307  qinfo->setAssocId(id);
308  cmsg->setControlInfo(qinfo);
309  sendOrSchedule(cmsg);
310  }
311 
312  EV << "!!!!!!!!!!!!!!!All data sent from Peer !!!!!!!!!!\n";
313 
314  auto j = rcvdPacketsPerAssoc.find(serverAssocId);
315  if (j->second == 0 && (simtime_t)par("waitToClose") > 0) {
316  char as[5];
317  sprintf(as, "%d", serverAssocId);
318  cMessage *abortMsg = new cMessage(as);
319  abortMsg->setKind(SCTP_I_ABORT);
320  scheduleAt(simTime() + (simtime_t)par("waitToClose"), abortMsg);
321  }
322  else {
323  EV << "no more packets to send, call shutdown for assoc " << serverAssocId << "\n";
324  cMessage *cmsg = new cMessage("SCTP_C_SHUTDOWN");
325  //SCTPInfo* qinfo = new SCTPInfo();
326  SCTPCommand *cmd = new SCTPCommand();
327  cmsg->setKind(SCTP_C_SHUTDOWN);
328  cmd->setAssocId(serverAssocId);
329  //qinfo->setAssocId(id);
330  //cmsg->setControlInfo(qinfo);
331  cmsg->setControlInfo(cmd);
332  sendOrSchedule(cmsg);
333  }
334  }
335  }
336  }
337  break;
338  }
339 
341  notifications++;
342  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
343  cMessage *cmsg = new cMessage("SCTP_C_RECEIVE");
344  SCTPSendInfo *cmd = new SCTPSendInfo();
345  id = ind->getAssocId();
346  cmd->setAssocId(id);
347  cmd->setSid(ind->getSid());
348  cmd->setNumMsgs(ind->getNumMsgs());
349  cmsg->setKind(SCTP_C_RECEIVE);
350  cmsg->setControlInfo(cmd);
351  delete ind;
352  delete msg;
353  if (!cmsg->isScheduled() && schedule == false) {
354  scheduleAt(simTime() + (simtime_t)par("delayFirstRead"), cmsg);
355  }
356  else if (schedule == true)
357  sendOrSchedule(cmsg);
358  break;
359  }
360 
361  case SCTP_I_DATA: {
362  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->getControlInfo());
363  id = ind->getAssocId();
364  if (rendezvous) {
365  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
366  NatMessage *nat = check_and_cast<NatMessage *>(smsg->decapsulate());
367  peerAddressList.clear();
368  if (nat->getMulti()) {
369  peerAddressList.push_back(nat->getPeer2Addresses(0));
370  EV << "address 0: " << nat->getPeer2Addresses(0) << endl;
371  peerAddressList.push_back(nat->getPeer2Addresses(1));
372  EV << "address 1: " << nat->getPeer2Addresses(1) << endl;
373  }
374  else {
375  peerAddress = nat->getPeer2Addresses(0);
376  }
377  peerPort = nat->getPortPeer2();
378  delete nat;
379  delete smsg;
380  }
381  else {
382  auto j = rcvdBytesPerAssoc.find(id);
385  else if (j != rcvdBytesPerAssoc.end()) {
386  j->second += PK(msg)->getBitLength() / 8;
387  auto k = bytesPerAssoc.find(id);
388  k->second->record(j->second);
389  packetsRcvd++;
390  if (!echo) {
391  if ((int64)(long)par("numPacketsToReceivePerClient") > 0) {
392  auto i = rcvdPacketsPerAssoc.find(id);
393  i->second--;
394  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
395  auto j = endToEndDelay.find(id);
396  j->second->record(simTime() - smsg->getCreationTime());
397  auto k = histEndToEndDelay.find(id);
398  k->second->collect(simTime() - smsg->getCreationTime());
399 
400  if (i->second == 0) {
401  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
402  SCTPInfo *qinfo = new SCTPInfo();
403  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
404  qinfo->setAssocId(id);
405  cmsg->setControlInfo(qinfo);
406  sendOrSchedule(cmsg);
407  }
408  }
409  delete msg;
410  }
411  else {
412  SCTPSendInfo *cmd = new SCTPSendInfo();
413  cmd->setAssocId(id);
414 
415  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg->dup());
416  auto j = endToEndDelay.find(id);
417  j->second->record(simTime() - smsg->getCreationTime());
418  auto k = histEndToEndDelay.find(id);
419  k->second->collect(simTime() - smsg->getCreationTime());
420  cPacket *cmsg = new cPacket("SCTP_C_SEND");
421  bytesSent += smsg->getBitLength() / 8;
422  cmd->setSendUnordered(cmd->getSendUnordered());
424  cmd->setPrValue(0);
425  cmd->setSid(lastStream);
426  cmd->setLast(true);
427  cmsg->encapsulate(smsg);
428  cmsg->setKind(SCTP_C_SEND);
429  cmsg->setControlInfo(cmd);
430  packetsSent++;
431  delete msg;
432  sendOrSchedule(cmsg);
433  }
434  } else {
435  delete msg;
436  }
437  }
438  break;
439  }
440 
442  SCTPCommand *command = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
443  id = command->getAssocId();
444  EV << "peer: SCTP_I_SHUTDOWN_RECEIVED for assoc " << id << "\n";
445  auto i = rcvdPacketsPerAssoc.find(id);
448  else if (i != rcvdPacketsPerAssoc.end()) {
449  if (i->second == 0) {
450  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
451  SCTPInfo *qinfo = new SCTPInfo();
452  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
453  qinfo->setAssocId(id);
454  cmsg->setControlInfo(qinfo);
455  sendOrSchedule(cmsg);
456  }
457 
458  shutdownReceived = true;
459  delete msg;
460  } else {
461  delete msg;
462  }
463  delete command;
464  //delete msg;
465  }
466 
469  EV << "Streams have been resetted\n";
470  break;
471  }
472 
473  case SCTP_I_CLOSED:
474  delete msg;
475  break;
476  }
477  }
478 
479  if (hasGUI()) {
480  char buf[32];
481  auto l = rcvdBytesPerAssoc.find(id);
482  sprintf(buf, "rcvd: %lld bytes\nsent: %lld bytes", (long long int)l->second, (long long int)bytesSent);
483  getDisplayString().setTagArg("t", 0, buf);
484  }
485 }
cMessage * timeoutMsg
Definition: SCTPNatPeer.h:49
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
int32 numSessions
Definition: SCTPNatPeer.h:45
SentPacketsPerAssoc sentPacketsPerAssoc
Definition: SCTPNatPeer.h:68
Definition: SCTPCommand.h:80
BytesPerAssoc bytesPerAssoc
Definition: SCTPNatPeer.h:72
int32 packetsRcvd
Definition: SCTPNatPeer.h:44
void handleTimer(cMessage *msg)
Definition: SCTPNatPeer.cc:487
Definition: SCTPCommand.h:67
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
int32 packetsSent
Definition: SCTPNatPeer.h:43
Definition: SCTPCommand.h:33
Definition: SCTPCommand.h:43
bool shutdownReceived
Definition: SCTPNatPeer.h:40
int32 lastStream
Definition: SCTPNatPeer.h:55
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
static const char * indicationName(const int32 code)
Utility: returns name of SCTP_I_xxx constants.
Definition: SCTPAssociationUtil.cc:206
int32 queueSize
Definition: SCTPNatPeer.h:48
Definition: SCTPCommand.h:79
Definition: SCTPSocket.h:87
L3Address peerAddress
Definition: SCTPNatPeer.h:60
Definition: SCTPCommand.h:63
bool rendezvous
Definition: SCTPNatPeer.h:59
int32 inboundStreams
Definition: SCTPNatPeer.h:52
Definition: SCTPCommand.h:35
Definition: SCTPCommand.h:37
bool echo
Definition: SCTPNatPeer.h:38
RcvdPacketsPerAssoc rcvdPacketsPerAssoc
Definition: SCTPNatPeer.h:66
int getState()
Returns the socket state, one of NOT_BOUND, CLOSED, LISTENING, CONNECTING, CONNECTED, etc.
Definition: SCTPSocket.h:154
Definition: SCTPCommand.h:65
Definition: SCTPCommand.h:42
Definition: SCTPCommand.h:75
bool schedule
Definition: SCTPNatPeer.h:39
Definition: SCTPCommand.h:44
HistEndToEndDelay histEndToEndDelay
Definition: SCTPNatPeer.h:74
RcvdBytesPerAssoc rcvdBytesPerAssoc
Definition: SCTPNatPeer.h:70
Definition: SCTPCommand.h:66
Definition: SCTPCommand.h:64
AddressVector peerAddressList
Definition: SCTPNatPeer.h:62
int32_t int32
Definition: Compat.h:31
Definition: SCTPCommand.h:72
int32 notifications
Definition: SCTPNatPeer.h:32
int64 bytesSent
Definition: SCTPNatPeer.h:42
#define PK(msg)
Definition: INETDefs.h:92
uint16_t id
Definition: TCP_NSC.cc:85
int32 outboundStreams
Definition: SCTPNatPeer.h:51
int64_t int64
Definition: Compat.h:29
const double k
Definition: QAM16Modulation.cc:24
EndToEndDelay endToEndDelay
Definition: SCTPNatPeer.h:76
void generateAndSend()
Definition: SCTPNatPeer.cc:121
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
void sendOrSchedule(cMessage *msg)
Definition: SCTPNatPeer.cc:111
int32 peerPort
Definition: SCTPNatPeer.h:61
Definition: SCTPSocket.h:87
Definition: SCTPCommand.h:82
int32 serverAssocId
Definition: SCTPNatPeer.h:33
void inet::SCTPNatPeer::handleTimer ( cMessage *  msg)
488 {
489  cMessage *cmsg;
490  SCTPCommand *cmd;
491  int32 id;
492 
493  EV << "SCTPNatPeer::handleTimer\n";
494 
495  SCTPConnectInfo *connectInfo = dynamic_cast<SCTPConnectInfo *>(msg->getControlInfo());
496  switch (msg->getKind()) {
497  case MSGKIND_CONNECT:
498  EV << "starting session call connect\n";
499  connect(L3AddressResolver().resolve(par("connectAddress"), 1), par("connectPort"));
500  delete msg;
501  break;
502 
503  case SCTP_C_SEND:
504 
505  EV << "SCTPNatPeer:MSGKIND_SEND\n";
506 
507  if (numRequestsToSend > 0) {
508  generateAndSend();
509  if ((simtime_t)par("thinkTime") > 0)
510  scheduleAt(simTime() + (simtime_t)par("thinkTime"), timeoutMsg);
512  }
513  break;
514 
515  case SCTP_I_ABORT:
516 
517  EV << "SCTPNatPeer:MsgKIND_ABORT for assoc " << atoi(msg->getName()) << "\n";
518 
519  cmsg = new cMessage("CLOSE", SCTP_C_CLOSE);
520  cmd = new SCTPCommand();
521  id = atoi(msg->getName());
522  cmd->setAssocId(id);
523  cmsg->setControlInfo(cmd);
524  sendOrSchedule(cmsg);
525  break;
526 
527  case SCTP_C_RECEIVE:
528 
529  EV << "SCTPNatPeer:SCTP_C_RECEIVE\n";
530  schedule = true;
531  sendOrSchedule(msg);
532  break;
533 
534  default:
535 
536  EV << "MsgKind =" << msg->getKind() << " unknown\n";
537 
538  break;
539  }
540  delete connectInfo;
541 }
cMessage * timeoutMsg
Definition: SCTPNatPeer.h:49
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
Definition: SCTPCommand.h:33
void connect(L3Address connectAddress, int32 connectPort)
Definition: SCTPNatPeer.cc:186
Definition: SCTPCommand.h:37
bool schedule
Definition: SCTPNatPeer.h:39
int32_t int32
Definition: Compat.h:31
Definition: SCTPCommand.h:72
uint16_t id
Definition: TCP_NSC.cc:85
#define MSGKIND_CONNECT
Definition: SCTPNatPeer.cc:32
Definition: SCTPCommand.h:34
void generateAndSend()
Definition: SCTPNatPeer.cc:121
void sendOrSchedule(cMessage *msg)
Definition: SCTPNatPeer.cc:111
void inet::SCTPNatPeer::initialize ( )
override
77 {
78  WATCH(numSessions);
79  WATCH(packetsSent);
80  WATCH(packetsRcvd);
81  WATCH(bytesSent);
82  //WATCH(rcvdBytesPerAssoc);
83  WATCH(numRequestsToSend);
84  // parameters
85  const char *addressesString = par("localAddress");
86  AddressVector addresses = L3AddressResolver().resolve(cStringTokenizer(addressesString).asVector());
87  int32 port = par("localPort");
88  echo = par("echo").boolValue();
89  delay = par("echoDelay");
90  outboundStreams = par("outboundStreams");
91  inboundStreams = par("inboundStreams");
92  ordered = (bool)par("ordered");
93  queueSize = par("queueSize");
94  timeoutMsg = new cMessage("SrvAppTimer");
95  clientSocket.setOutputGate(gate("sctpOut"));
96  if (addresses.size() == 0) {
97  clientSocket.bind(port);
98  }
99  else {
100  clientSocket.bindx(addresses, port);
101  }
103  rendezvous = (bool)par("rendezvous");
104  if ((simtime_t)par("startTime") > 0) {
105  cMessage *msg = new cMessage("ConnectTimer");
106  msg->setKind(MSGKIND_CONNECT);
107  scheduleAt((simtime_t)par("startTime"), msg);
108  }
109 }
cMessage * timeoutMsg
Definition: SCTPNatPeer.h:49
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
int32 numSessions
Definition: SCTPNatPeer.h:45
int32 packetsRcvd
Definition: SCTPNatPeer.h:44
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
int32 packetsSent
Definition: SCTPNatPeer.h:43
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
int32 queueSize
Definition: SCTPNatPeer.h:48
bool rendezvous
Definition: SCTPNatPeer.h:59
int32 inboundStreams
Definition: SCTPNatPeer.h:52
bool echo
Definition: SCTPNatPeer.h:38
std::vector< L3Address > AddressVector
Definition: SCTPCommand_m.h:41
void bind(int localPort)
Bind the socket to a local port number.
Definition: SCTPSocket.cc:136
int32_t int32
Definition: Compat.h:31
bool ordered
Definition: SCTPNatPeer.h:47
int64 bytesSent
Definition: SCTPNatPeer.h:42
#define MSGKIND_CONNECT
Definition: SCTPNatPeer.cc:32
int32 outboundStreams
Definition: SCTPNatPeer.h:51
void setOutputGate(cGate *toSctp)
Sets the gate on which to send to SCTP.
Definition: SCTPSocket.h:177
double delay
Definition: SCTPNatPeer.h:37
void inet::SCTPNatPeer::msgAbandonedArrived ( int32  assocId)
override
848 {
849  chunksAbandoned++;
850 }
int32 chunksAbandoned
Definition: SCTPNatPeer.h:57
void inet::SCTPNatPeer::sendOrSchedule ( cMessage *  msg)
protected
112 {
113  if (delay == 0) {
114  send(msg, "sctpOut");
115  }
116  else {
117  scheduleAt(simTime() + delay, msg);
118  }
119 }
double delay
Definition: SCTPNatPeer.h:37
void inet::SCTPNatPeer::sendqueueFullArrived ( int32  connId)
override
853 {
854  sendAllowed = false;
855 }
bool sendAllowed
Definition: SCTPNatPeer.h:56
void inet::SCTPNatPeer::sendQueueRequest ( )
776 {
777  cMessage *cmsg = new cMessage("SCTP_C_QUEUE_MSGS_LIMIT");
778  SCTPInfo *qinfo = new SCTPInfo();
779  qinfo->setText(queueSize);
780  cmsg->setKind(SCTP_C_QUEUE_MSGS_LIMIT);
781  qinfo->setAssocId(clientSocket.getConnectionId());
782  cmsg->setControlInfo(qinfo);
784 }
void sendRequest(cMessage *msg)
Send request.
Definition: SCTPSocket.cc:405
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
int32 queueSize
Definition: SCTPNatPeer.h:48
Definition: SCTPCommand.h:42
void inet::SCTPNatPeer::sendRequest ( bool  last = true)
protected
657 {
658  EV << "sending request, " << numRequestsToSend - 1 << " more to go\n";
659  uint32 i;
660  int64 numBytes = (int64)(long)par("requestLength");
661  if (numBytes < 1)
662  numBytes = 1;
663 
664  EV << "SCTPNatPeer: sending " << numBytes << " data bytes\n";
665 
666  cPacket *cmsg = new cPacket("SCTP_C_SEND");
667  SCTPSimpleMessage *msg = new SCTPSimpleMessage("data");
668 
669  msg->setDataArraySize(numBytes);
670  for (i = 0; i < numBytes; i++) {
671  msg->setData(i, 'a');
672  }
673  msg->setDataLen(numBytes);
674  msg->setEncaps(false);
675  msg->setBitLength(numBytes * 8);
676  msg->setCreationTime(simTime());
677  cmsg->encapsulate(msg);
678  if (ordered)
679  cmsg->setKind(SCTP_C_SEND_ORDERED);
680  else
681  cmsg->setKind(SCTP_C_SEND_UNORDERED);
682  SCTPSendInfo* sendCommand = new SCTPSendInfo;
683  sendCommand->setLast(true);
684  cmsg->setControlInfo(sendCommand);
685  // send SCTPMessage with SCTPSimpleMessage enclosed
686  clientSocket.sendMsg(cmsg);
687  bytesSent += numBytes;
688 }
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
Definition: SCTPCommand.h:38
uint32_t uint32
Definition: Compat.h:30
bool ordered
Definition: SCTPNatPeer.h:47
int64 bytesSent
Definition: SCTPNatPeer.h:42
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
int64_t int64
Definition: Compat.h:29
Definition: SCTPCommand.h:39
void inet::SCTPNatPeer::sendRequestArrived ( )
overridevirtual

Reimplemented from inet::SCTPSocket::CallbackInterface.

787 {
788  int32 count = 0;
789 
790  EV << "sendRequestArrived numRequestsToSend=" << numRequestsToSend << "\n";
791  while (numRequestsToSend > 0 && count++ < queueSize && sendAllowed) {
792  numRequestsToSend--;
793  if (count == queueSize || numRequestsToSend == 0)
794  sendRequest();
795  else
796  sendRequest(false);
797 
798  if (numRequestsToSend == 0) {
799  EV << "no more packets to send, call shutdown\n";
801  }
802  }
803 }
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
void sendRequest(bool last=true)
Definition: SCTPNatPeer.cc:656
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
int32 queueSize
Definition: SCTPNatPeer.h:48
int32_t int32
Definition: Compat.h:31
bool sendAllowed
Definition: SCTPNatPeer.h:56
void inet::SCTPNatPeer::sendStreamResetNotification ( )
void inet::SCTPNatPeer::setPrimaryPath ( )
void inet::SCTPNatPeer::setStatusString ( const char *  s)
651 {
652  if (hasGUI())
653  getDisplayString().setTagArg("t", 0, s);
654 }
value< double, units::s > s
Definition: Units.h:1049
void inet::SCTPNatPeer::shutdownReceivedArrived ( int32  connId)
override
836 {
837  if (numRequestsToSend == 0 || rendezvous) {
838  cMessage *cmsg = new cMessage("SCTP_C_NO_OUTSTANDING");
839  SCTPInfo *qinfo = new SCTPInfo();
840  cmsg->setKind(SCTP_C_NO_OUTSTANDING);
841  qinfo->setAssocId(connId);
842  cmsg->setControlInfo(qinfo);
844  }
845 }
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
bool rendezvous
Definition: SCTPNatPeer.h:59
Definition: SCTPCommand.h:44
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
void inet::SCTPNatPeer::socketClosed ( int32  connId,
void *  yourPtr 
)
override

Does nothing but update statistics/status.

Redefine if you want to do something else, such as opening a new connection.

590 {
591  // *redefine* to start another session etc.
592 
593  EV << "connection closed\n";
594  setStatusString("closed");
596  if (rendezvous) {
597  const char *addressesString = par("localAddress");
598  AddressVector addresses = L3AddressResolver().resolve(cStringTokenizer(addressesString).asVector());
599  int32 port = par("localPort");
600  rendezvousSocket.setOutputGate(gate("sctpOut"));
603  if (addresses.size() == 0) {
604  rendezvousSocket.bind(port);
605  clientSocket.bind(port);
606  }
607  else {
608  clientSocket.bindx(addresses, port);
609  rendezvousSocket.bindx(addresses, port);
610  }
611  rendezvousSocket.listen(true, (bool)par("streamReset"), par("numPacketsToSendPerClient"));
612  if ((bool)par("multi"))
614  else
616  rendezvous = false;
617  }
618 }
SCTPSocket rendezvousSocket
Definition: SCTPNatPeer.h:36
void bindx(AddressVector localAddr, int localPort)
Definition: SCTPSocket.cc:165
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
void close(int id=-1)
Closes the local end of the connection.
Definition: SCTPSocket.cc:410
L3Address peerAddress
Definition: SCTPNatPeer.h:60
bool rendezvous
Definition: SCTPNatPeer.h:59
int32 inboundStreams
Definition: SCTPNatPeer.h:52
void connect(L3Address connectAddress, int32 connectPort)
Definition: SCTPNatPeer.cc:186
std::vector< L3Address > AddressVector
Definition: SCTPCommand_m.h:41
void bind(int localPort)
Bind the socket to a local port number.
Definition: SCTPSocket.cc:136
void setStatusString(const char *s)
Definition: SCTPNatPeer.cc:650
AddressVector peerAddressList
Definition: SCTPNatPeer.h:62
int32_t int32
Definition: Compat.h:31
void setInboundStreams(int streams)
Definition: SCTPSocket.h:183
int32 outboundStreams
Definition: SCTPNatPeer.h:51
void setOutboundStreams(int streams)
Setter and getter methods for socket and API Parameters.
Definition: SCTPSocket.h:182
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
void connectx(AddressVector connectAddressList, int32 connectPort)
Definition: SCTPNatPeer.cc:155
int32 peerPort
Definition: SCTPNatPeer.h:61
void inet::SCTPNatPeer::socketDataArrived ( int32  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
)
override

Does nothing but update statistics/status.

Redefine to perform or schedule next sending. Beware: this funcion deletes the incoming message, which might not be what you want.

806 {
807  // *redefine* to perform or schedule next sending
808  packetsRcvd++;
809 
810  EV << "Client received packet Nr " << packetsRcvd << " from SCTP\n";
811  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->getControlInfo());
812  bytesRcvd += msg->getBitLength() / 8;
813 
814  if (echo) {
815  SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
816  cPacket *cmsg = new cPacket("SCTP_C_SEND");
817  echoedBytesSent += smsg->getBitLength() / 8;
818  cmsg->encapsulate(smsg);
819  if (ind->getSendUnordered())
820  cmsg->setKind(SCTP_C_SEND_UNORDERED);
821  else
822  cmsg->setKind(SCTP_C_SEND_ORDERED);
823  packetsSent++;
824  clientSocket.sendMsg(cmsg);
825  }
826  if ((int64)(long)par("numPacketsToReceive") > 0) {
828  delete msg;
829  if (numPacketsToReceive == 0) {
830  EV << "Peer: all packets received\n";
831  }
832  }
833 }
int32 packetsRcvd
Definition: SCTPNatPeer.h:44
int32 packetsSent
Definition: SCTPNatPeer.h:43
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
Definition: SCTPCommand.h:38
bool echo
Definition: SCTPNatPeer.h:38
int32 bytesRcvd
Definition: SCTPNatPeer.h:53
int32 numPacketsToReceive
Definition: SCTPNatPeer.h:58
int32 echoedBytesSent
Definition: SCTPNatPeer.h:54
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
int64_t int64
Definition: Compat.h:29
Definition: SCTPCommand.h:39
void inet::SCTPNatPeer::socketDataNotificationArrived ( int32  connId,
void *  yourPtr,
cPacket *  msg 
)
override
544 {
545  SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
546  cMessage *cmsg = new cMessage("SCTP_C_RECEIVE");
547  SCTPSendInfo *cmd = new SCTPSendInfo();
548  cmd->setAssocId(ind->getAssocId());
549  cmd->setSid(ind->getSid());
550  cmd->setNumMsgs(ind->getNumMsgs());
551  cmsg->setKind(SCTP_C_RECEIVE);
552  cmsg->setControlInfo(cmd);
553  delete ind;
555 }
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
Definition: SCTPCommand.h:37
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
void inet::SCTPNatPeer::socketEstablished ( int32  ,
void *  ,
unsigned long int  buffer 
)
override

Does nothing but update statistics/status.

Redefine to perform or schedule first sending.

691 {
692  int32 count = 0;
693  // *redefine* to perform or schedule first sending
694  EV << "SCTPNatPeer: socketEstablished\n";
695  setStatusString("connected");
696  if (rendezvous) {
697  NatMessage *msg = new NatMessage("Rendezvous");
698  msg->setKind(SCTP_C_NAT_INFO);
699  msg->setMulti((bool)par("multi"));
700  msg->setPeer1(par("ownName"));
701  msg->setPeer1AddressesArraySize(1);
702  msg->setPeer1Addresses(0, L3Address());
703  msg->setPortPeer1(par("localPort"));
704  msg->setPeer2(par("peerName"));
705  msg->setPeer2AddressesArraySize(1);
706  msg->setPeer2Addresses(0, L3Address());
707  msg->setPortPeer2(0);
708  cPacket *cmsg = new cPacket(msg->getName());
709  SCTPSimpleMessage *smsg = new SCTPSimpleMessage("nat_data");
710  smsg->setEncaps(true);
711  smsg->encapsulate(msg);
712  smsg->setCreationTime(simTime());
713  smsg->setByteLength(16);
714  smsg->setDataLen(16);
715  cmsg->encapsulate(smsg);
716  clientSocket.sendMsg(cmsg);
717 
718  if ((bool)par("multi")) {
719  cMessage *cmesg = new cMessage("SCTP_C_SEND_ASCONF");
720  SCTPCommand *cmd = new SCTPCommand();
721  cmd->setAssocId(clientSocket.getConnectionId());
722  cmesg->setControlInfo(cmd);
723  cmesg->setKind(SCTP_C_SEND_ASCONF);
725  }
726  }
727  else {
728  EV << " determine number of requests in this session\n";
729  numRequestsToSend = (int64)(long)par("numRequestsPerSession");
730  numPacketsToReceive = (int64)(long)par("numPacketsToReceive");
731  if (numRequestsToSend < 1)
732  numRequestsToSend = 0;
733  // perform first request (next one will be sent when reply arrives)
734  if (numRequestsToSend > 0) {
735  if ((simtime_t)par("thinkTime") > 0) {
736  if (sendAllowed) {
737  sendRequest();
739  }
740  timeMsg->setKind(MSGKIND_SEND);
741  scheduleAt(simTime() + (simtime_t)par("thinkTime"), timeMsg);
742  }
743  else {
744  if (queueSize > 0) {
745  while (numRequestsToSend > 0 && count++ < queueSize * 2 && sendAllowed) {
746  if (count == queueSize * 2)
747  sendRequest();
748  else
749  sendRequest(false);
751  }
752  if (numRequestsToSend > 0 && sendAllowed)
754  }
755  else {
756  while (numRequestsToSend > 0 && sendAllowed) {
757  sendRequest();
759  }
760  }
761 
762  if (numPacketsToReceive == 0 && (simtime_t)par("waitToClose") > 0) {
763  timeMsg->setKind(MSGKIND_ABORT);
764  scheduleAt(simTime() + (simtime_t)par("waitToClose"), timeMsg);
765  }
766  if (numRequestsToSend == 0 && (simtime_t)par("waitToClose") == 0) {
767  EV << "socketEstablished:no more packets to send, call shutdown\n";
769  }
770  }
771  }
772  }
773 }
int32 numRequestsToSend
Definition: SCTPNatPeer.h:46
int count(const std::vector< T > &v, const T &a)
Definition: stlutils.h:58
void sendRequest(bool last=true)
Definition: SCTPNatPeer.cc:656
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
int getConnectionId() const
Returns the internal connection Id.
Definition: SCTPSocket.h:141
void shutdown(int id=-1)
Definition: SCTPSocket.cc:425
int32 queueSize
Definition: SCTPNatPeer.h:48
bool rendezvous
Definition: SCTPNatPeer.h:59
#define MSGKIND_SEND
Definition: SCTPNatPeer.cc:33
void setStatusString(const char *s)
Definition: SCTPNatPeer.cc:650
int32 numPacketsToReceive
Definition: SCTPNatPeer.h:58
cMessage * timeMsg
Definition: SCTPNatPeer.h:50
void sendNotification(cMessage *msg)
Send notification.
Definition: SCTPSocket.cc:393
int32_t int32
Definition: Compat.h:31
bool sendAllowed
Definition: SCTPNatPeer.h:56
#define MSGKIND_ABORT
Definition: SCTPNatPeer.cc:34
Definition: SCTPCommand.h:48
void sendMsg(cMessage *cmsg)
Send data message (provided within control message).
Definition: SCTPSocket.cc:369
int64_t int64
Definition: Compat.h:29
Definition: SCTPCommand.h:49
void sendQueueRequest()
Definition: SCTPNatPeer.cc:775
void inet::SCTPNatPeer::socketFailure ( int32  connId,
void *  yourPtr,
int32  code 
)
override

Does nothing but update statistics/status.

Redefine if you want to try reconnecting after a delay.

621 {
622  // subclasses may override this function, and add code try to reconnect after a delay.
623  EV << "connection broken\n";
624  setStatusString("broken");
625 
626  //numBroken++;
627 
628  // reconnect after a delay
629  timeMsg->setKind(MSGKIND_CONNECT);
630  scheduleAt(simTime() + (simtime_t)par("reconnectInterval"), timeMsg);
631 }
void setStatusString(const char *s)
Definition: SCTPNatPeer.cc:650
cMessage * timeMsg
Definition: SCTPNatPeer.h:50
#define MSGKIND_CONNECT
Definition: SCTPNatPeer.cc:32
void inet::SCTPNatPeer::socketPeerClosed ( int32  connId,
void *  yourPtr 
)
override

Since remote SCTP closed, invokes close().

Redefine if you want to do something else.

558 {
559  // close the connection (if not already closed)
561  EV << "remote SCTP closed, closing here as well\n";
562  setStatusString("closed");
564  if (rendezvous) {
565  const char *addressesString = par("localAddress");
566  AddressVector addresses = L3AddressResolver().resolve(cStringTokenizer(addressesString).asVector());
567  int32 port = par("localPort");
568  rendezvousSocket.setOutputGate(gate("sctpOut"));
571  if (addresses.size() == 0) {
572  rendezvousSocket.bind(port);
573  clientSocket.bind(port);
574  }
575  else {
576  clientSocket.bindx(addresses, port);
577  rendezvousSocket.bindx(addresses, port);
578  }
579  rendezvousSocket.listen(true, (bool)par("streamReset"), par("numPacketsToSendPerClient"));
580  if ((bool)par("multi"))
582  else
584  rendezvous = false;
585  }
586  }
587 }
SCTPSocket rendezvousSocket
Definition: SCTPNatPeer.h:36
void bindx(AddressVector localAddr, int localPort)
Definition: SCTPSocket.cc:165
SCTPSocket clientSocket
Definition: SCTPNatPeer.h:34
void close(int id=-1)
Closes the local end of the connection.
Definition: SCTPSocket.cc:410
L3Address peerAddress
Definition: SCTPNatPeer.h:60
bool rendezvous
Definition: SCTPNatPeer.h:59
int32 inboundStreams
Definition: SCTPNatPeer.h:52
void connect(L3Address connectAddress, int32 connectPort)
Definition: SCTPNatPeer.cc:186
std::vector< L3Address > AddressVector
Definition: SCTPCommand_m.h:41
void bind(int localPort)
Bind the socket to a local port number.
Definition: SCTPSocket.cc:136
void setStatusString(const char *s)
Definition: SCTPNatPeer.cc:650
int getState()
Returns the socket state, one of NOT_BOUND, CLOSED, LISTENING, CONNECTING, CONNECTED, etc.
Definition: SCTPSocket.h:154
Definition: SCTPSocket.h:87
AddressVector peerAddressList
Definition: SCTPNatPeer.h:62
int32_t int32
Definition: Compat.h:31
void setInboundStreams(int streams)
Definition: SCTPSocket.h:183
int32 outboundStreams
Definition: SCTPNatPeer.h:51
void setOutboundStreams(int streams)
Setter and getter methods for socket and API Parameters.
Definition: SCTPSocket.h:182
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
void connectx(AddressVector connectAddressList, int32 connectPort)
Definition: SCTPNatPeer.cc:155
int32 peerPort
Definition: SCTPNatPeer.h:61
void inet::SCTPNatPeer::socketStatusArrived ( int32  connId,
void *  yourPtr,
SCTPStatusInfo status 
)
override

Redefine to handle incoming SCTPStatusInfo.

634 {
635  struct pathStatus ps;
636  auto i = sctpPathStatus.find(status->getPathId());
637  if (i != sctpPathStatus.end()) {
638  ps = i->second;
639  ps.active = status->getActive();
640  }
641  else {
642  ps.active = status->getActive();
643  //ps.pid = status->pathId(); FIXME
644  ps.primaryPath = false;
645  sctpPathStatus[ps.pid] = ps;
646  }
647  delete status;
648 }
SCTPPathStatus sctpPathStatus
Definition: SCTPNatPeer.h:90

Member Data Documentation

BytesPerAssoc inet::SCTPNatPeer::bytesPerAssoc
protected
int32 inet::SCTPNatPeer::bytesRcvd
protected
int64 inet::SCTPNatPeer::bytesSent
protected
int32 inet::SCTPNatPeer::chunksAbandoned
protected
SCTPSocket inet::SCTPNatPeer::clientSocket
protected
double inet::SCTPNatPeer::delay
protected
bool inet::SCTPNatPeer::echo
protected
int32 inet::SCTPNatPeer::echoedBytesSent
protected
EndToEndDelay inet::SCTPNatPeer::endToEndDelay
protected
HistEndToEndDelay inet::SCTPNatPeer::histEndToEndDelay
protected
int32 inet::SCTPNatPeer::inboundStreams
protected
int32 inet::SCTPNatPeer::lastStream
protected
AddressVector inet::SCTPNatPeer::localAddressList
protected
int32 inet::SCTPNatPeer::notifications
protected
int32 inet::SCTPNatPeer::numPacketsToReceive
protected
int32 inet::SCTPNatPeer::numRequestsToSend
protected
int32 inet::SCTPNatPeer::numSessions
protected
bool inet::SCTPNatPeer::ordered
protected
int32 inet::SCTPNatPeer::outboundStreams
protected
int32 inet::SCTPNatPeer::packetsRcvd
protected
int32 inet::SCTPNatPeer::packetsSent
protected
L3Address inet::SCTPNatPeer::peerAddress
protected
AddressVector inet::SCTPNatPeer::peerAddressList
protected
int32 inet::SCTPNatPeer::peerPort
protected
SCTPSocket inet::SCTPNatPeer::peerSocket
protected
int32 inet::SCTPNatPeer::queueSize
protected
RcvdBytesPerAssoc inet::SCTPNatPeer::rcvdBytesPerAssoc
protected
RcvdPacketsPerAssoc inet::SCTPNatPeer::rcvdPacketsPerAssoc
protected
bool inet::SCTPNatPeer::rendezvous
protected
SCTPSocket inet::SCTPNatPeer::rendezvousSocket
protected
bool inet::SCTPNatPeer::schedule
protected
SCTPPathStatus inet::SCTPNatPeer::sctpPathStatus
bool inet::SCTPNatPeer::sendAllowed
protected
SentPacketsPerAssoc inet::SCTPNatPeer::sentPacketsPerAssoc
protected
int32 inet::SCTPNatPeer::serverAssocId
protected
bool inet::SCTPNatPeer::shutdownReceived
protected
cMessage* inet::SCTPNatPeer::timeMsg
protected
cMessage* inet::SCTPNatPeer::timeoutMsg
protected

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