183 if (msg->isSelfMessage()) {
188 switch (msg->getKind()) {
191 SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->getControlInfo()->dup());
192 cMessage *cmsg =
new cMessage(
"SCTP_C_ABORT");
193 SCTPSendInfo *cmd =
new SCTPSendInfo();
194 id = ind->getAssocId();
196 cmd->setSid(ind->getSid());
197 cmd->setNumMsgs(ind->getNumMsgs());
198 cmsg->setControlInfo(cmd);
202 send(cmsg,
"sctpOut");
207 SCTPConnectInfo *connectInfo = check_and_cast<SCTPConnectInfo *>(msg->removeControlInfo());
209 assocId = connectInfo->getAssocId();
222 SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
223 cMessage *cmsg =
new cMessage(
"SCTP_C_RECEIVE");
224 SCTPSendInfo *cmd =
new SCTPSendInfo();
225 id = ind->getAssocId();
227 cmd->setSid(ind->getSid());
228 cmd->setNumMsgs(ind->getNumMsgs());
230 cmsg->setControlInfo(cmd);
233 send(cmsg,
"sctpOut");
238 EV <<
"\nData arrived at server: assoc=" <<
assocId <<
"\n";
240 SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
241 id = ind->getAssocId();
242 SCTPSimpleMessage *smsg = check_and_cast<SCTPSimpleMessage *>(msg);
243 NatMessage *nat = check_and_cast<NatMessage *>(smsg->decapsulate());
247 if ((elem)->peer1 == nat->getPeer1() || (elem)->peer1Assoc == assocId) {
248 EV <<
"found entry: info: Peer1 = " << nat->getPeer1() <<
" peer1Address1=" << nat->getPeer1Addresses(0) <<
" peer2=" << nat->getPeer2() <<
" peer2Address1=" << nat->getPeer2Addresses(0) <<
"\n";
249 if (nat->getMulti() && nat->getPeer1AddressesArraySize() > 1 && nat->getPeer2AddressesArraySize() > 1) {
250 EV <<
" peer1Address2=" << nat->getPeer1Addresses(1) <<
" peer2Address2=" << nat->getPeer2Addresses(1) << endl;
252 if ((elem)->peer1 == 0 && !(elem)->peer1Address2.isUnspecified()) {
253 (elem)->peer1 = nat->getPeer1();
254 (elem)->peer1Address1 = ind->getRemoteAddr();
255 (elem)->peer1Port = nat->getPortPeer1();
256 if ((elem)->peer2 == 0) {
257 (elem)->peer2 = nat->getPeer2();
260 if (nat->getMulti() && (elem)->peer1Address2.isUnspecified()) {
261 (elem)->peer1Address2 = ind->getRemoteAddr();
263 if (!(elem)->peer2Address1.isUnspecified() && !(elem)->peer1Address1.isUnspecified()) {
264 if (!(elem)->multi || ((elem)->multi && !(elem)->peer2Address2.isUnspecified() && !(elem)->peer1Address2.isUnspecified())) {
265 EV <<
"entry now: Peer1=" << (elem)->peer1 <<
" Peer2=" << (elem)->peer2 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
" peer2Port=" << (elem)->peer2Port <<
"\n";
272 if ((elem)->peer2 == nat->getPeer1() || (elem)->peer2Assoc == assocId) {
273 EV <<
"opposite way: info: Peer1 = " << nat->getPeer1() <<
" peer1Address1=" << nat->getPeer1Addresses(0) <<
" peer2=" << nat->getPeer2() <<
" peer2Address1=" << nat->getPeer2Addresses(0) <<
"\n";
274 if (nat->getMulti() && nat->getPeer1AddressesArraySize() > 1 && nat->getPeer2AddressesArraySize() > 1) {
275 EV <<
" peer1Address2=" << nat->getPeer1Addresses(1) <<
" peer2Address2=" << nat->getPeer2Addresses(1) << endl;
277 if ((elem)->peer2 == 0) {
278 (elem)->peer2 = nat->getPeer1();
280 if ((elem)->peer1 == 0) {
281 (elem)->peer1 = nat->getPeer2();
283 if ((elem)->peer2Address1.isUnspecified()) {
284 (elem)->peer2Address1 = ind->getRemoteAddr();
285 (elem)->peer2Assoc = assocId;
286 (elem)->peer2Port = nat->getPortPeer1();
287 (elem)->peer2Gate = ind->getGate();
288 EV <<
"set peer2Address1=" << ind->getRemoteAddr() <<
" peer2Assoc=" << assocId <<
" peer2Port=" << nat->getPortPeer1() <<
"\n";
290 else if ((elem)->multi && !(elem)->peer2Address2.isUnspecified())
291 (elem)->peer2Address2 = ind->getRemoteAddr();
293 if (!(elem)->multi || ((elem)->multi && !(elem)->peer2Address2.isUnspecified() && !(elem)->peer1Address2.isUnspecified()
294 && !(elem)->peer2Address1.isUnspecified() && !(elem)->peer1Address1.isUnspecified()))
296 EV <<
"entry now: Peer1=" << (elem)->peer1 <<
" Peer2=" << (elem)->peer2 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
" peer1Port=" << (elem)->peer1Port <<
"peer2Port=" << (elem)->peer2Port <<
"\n";
304 if (natVector.size() == 0 || !found) {
305 EV <<
"make new Info for ";
307 info->peer1 = nat->getPeer1();
308 EV << info->peer1 <<
" and assoc " << assocId <<
"\n";
310 info->multi = nat->getMulti();
311 info->peer1Address1 = ind->getRemoteAddr();
313 info->peer1Address2 = L3Address();
314 info->peer2Address2 = L3Address();
316 info->peer1Port = nat->getPortPeer1();
318 info->peer1Gate = ind->getGate();
319 info->peer2 = nat->getPeer2();
320 info->peer2Address1 = L3Address();
322 info->peer2Assoc = 0;
323 info->peer2Gate = -1;
324 natVector.push_back(info);
325 EV <<
"Info: peer1=" << info->peer1 <<
" peer1Address1=" << info->peer1Address1 <<
" peer1Address2=" << info->peer1Address2 <<
" peer1Assoc=" << info->peer1Assoc <<
"\n peer2=" << info->peer2 <<
" peer2Address1=" << info->peer2Address1 <<
" peer2Address2=" << info->peer2Address2 <<
" peer2Assoc=" << info->peer2Assoc <<
"\n";
337 SCTPCommand *command = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
338 id = command->getAssocId();
339 EV <<
"server: SCTP_I_SHUTDOWN_RECEIVED for assoc " <<
id <<
"\n";
340 cMessage *cmsg =
new cMessage(
"SCTP_C_NO_OUTSTANDING");
341 SCTPInfo *qinfo =
new SCTPInfo(
"Info");
343 qinfo->setAssocId(
id);
344 cmsg->setControlInfo(qinfo);
345 send(cmsg,
"sctpOut");
355 EV <<
"Streams have been resetted\n";
365 SCTPCommand *ind = check_and_cast<SCTPCommand *>(msg->removeControlInfo());
368 EV <<
" address added: LOCAL=" << ind->getLocalAddr() <<
", remote=" << ind->getRemoteAddr() <<
" assoc=" << assocId <<
"\n";
369 if (natVector.size() > 0) {
370 for (
auto & elem : natVector) {
371 if ((elem)->peer1Assoc ==
assocId) {
372 EV <<
"found entry for assoc1 = " << assocId <<
" Peer1 = " << (elem)->peer1 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2=" << (elem)->peer2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
"\n";
373 if ((elem)->multi && (elem)->peer1Address2.isUnspecified()) {
374 (elem)->peer1Address2 = ind->getRemoteAddr();
375 EV <<
"added peer1Address2=" << ind->getRemoteAddr() <<
"\n";
377 if (!(elem)->peer2Address1.isUnspecified()) {
378 if (!(elem)->multi || ((elem)->multi && !(elem)->peer2Address2.isUnspecified() && !(elem)->peer1Address2.isUnspecified())) {
379 EV <<
"entry now: Peer1=" << (elem)->peer1 <<
" Peer2=" << (elem)->peer2 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
" peer2Port=" << (elem)->peer2Port <<
"\n";
386 else if ((elem)->peer2Assoc == assocId) {
387 EV <<
"opposite way: found entry for assoc2 = " << assocId <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
"\n";
389 (elem)->peer2Address2 = ind->getRemoteAddr();
391 if (!(elem)->multi || ((elem)->multi && !(elem)->peer2Address2.isUnspecified() && !(elem)->peer1Address2.isUnspecified())) {
392 EV <<
"entry now: Peer1=" << (elem)->peer1 <<
" Peer2=" << (elem)->peer2 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
" peer1Port=" << (elem)->peer1Port <<
"peer2Port=" << (elem)->peer2Port <<
"\n";
398 else if ((elem)->peer2Assoc == 0 && ((elem)->multi)) {
399 (elem)->peer2Address2 = ind->getRemoteAddr();
400 (elem)->peer2Assoc = assocId;
401 (elem)->peer2Port = ind->getRemotePort();
402 (elem)->peer2Gate = ind->getGate();
403 EV <<
"entry now: Peer1=" << (elem)->peer1 <<
" Peer2=" << (elem)->peer2 <<
" peer1Address1=" << (elem)->peer1Address1 <<
" peer1Address2=" << (elem)->peer1Address2 <<
" peer2Address1=" << (elem)->peer2Address1 <<
" peer2Address2=" << (elem)->peer2Address2 <<
" peer1Port=" << (elem)->peer1Port <<
"peer2Port=" << (elem)->peer2Port <<
"\n";
409 else if (natVector.size() == 0 && !found) {
410 EV <<
"make new Info for ";
414 EV << info->peer1 <<
" and assoc " << assocId <<
"\n";
417 info->peer1Address1 = L3Address();
418 info->peer1Address2 = ind->getRemoteAddr();
419 info->peer1Port = ind->getRemotePort();
420 info->peer1Gate = ind->getGate();
422 info->peer2Address1 = L3Address();
423 info->peer2Address2 = L3Address();
425 info->peer2Assoc = 0;
426 info->peer2Gate = -1;
427 natVector.push_back(info);
428 EV <<
"Info: peer1=" << info->peer1 <<
" peer1Address1=" << info->peer1Address1 <<
" peer1Address2=" << info->peer1Address2 <<
" peer1Assoc=" << info->peer1Assoc <<
"\n peer2=" << info->peer1 <<
" peer2Address1=" << info->peer2Address1 <<
" peer2Address2=" << info->peer2Address2 <<
" peer2Assoc=" << info->peer2Assoc <<
"\n";
Definition: SCTPCommand.h:80
int32 inboundStreams
Definition: SCTPNatServer.h:61
void sendInfo(NatInfo *info)
Definition: SCTPNatServer.cc:71
Definition: SCTPCommand.h:67
static const char * indicationName(const int32 code)
Utility: returns name of SCTP_I_xxx constants.
Definition: SCTPAssociationUtil.cc:206
Definition: SCTPCommand.h:79
Definition: SCTPCommand.h:63
uint32 assocId
Definition: SCTPNatServer.h:51
void printNatVector()
Definition: SCTPNatServer.cc:476
Definition: SCTPCommand.h:35
Definition: SCTPCommand.h:37
Definition: SCTPCommand.h:65
Definition: SCTPCommand.h:75
Definition: SCTPCommand.h:44
Definition: SCTPCommand.h:66
Definition: SCTPCommand.h:64
void handleTimer(cMessage *msg)
Definition: SCTPNatServer.cc:442
int32_t int32
Definition: Compat.h:31
Definition: SCTPCommand.h:72
int32 outboundStreams
Definition: SCTPNatServer.h:60
struct inet::natInfo NatInfo
Accepts any number of incoming connections, and sends back whatever arrives on them.
uint16_t id
Definition: TCP_NSC.cc:85
static NatVector natVector
Definition: SCTPNatServer.h:64
bool shutdownReceived
Definition: SCTPNatServer.h:53
int32 notifications
Definition: SCTPNatServer.h:50
int32 numSessions
Definition: SCTPNatServer.h:57
Definition: SCTPCommand.h:82