This documentation is not the Latest Release.
A Discrete-Event Network Simulator
API
tcp-general-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 #include "ns3/test.h"
20 #include "ns3/node-container.h"
21 #include "ns3/tcp-socket-base.h"
22 #include "ns3/simple-net-device-helper.h"
23 #include "ns3/ipv4-address-helper.h"
24 #include "ns3/internet-stack-helper.h"
25 #include "ns3/log.h"
26 #include "ns3/tcp-l4-protocol.h"
27 #include "../model/ipv4-end-point.h"
28 #include "../model/ipv6-end-point.h"
29 #include "tcp-general-test.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("TcpGeneralTest");
34 
35 TcpGeneralTest::TcpGeneralTest (const std::string &desc,
36  uint32_t pktSize, uint32_t pktCount,
37  const Time& pktInterval,
38  const Time& propagationDelay, const Time& startTime,
39  uint32_t initialSlowStartThresh, uint32_t initialCwnd,
40  uint32_t segmentSize,
41  TypeId congestionControl,
42  uint32_t mtu)
43  : TestCase (desc),
44  m_congControlTypeId (congestionControl),
45  m_propagationDelay (propagationDelay),
46  m_startTime (startTime),
47  m_mtu (mtu),
48  m_pktSize (pktSize),
49  m_pktCount (pktCount),
50  m_interPacketInterval (pktInterval),
51  m_initialSlowStartThresh (initialSlowStartThresh),
52  m_initialCwnd (initialCwnd),
53  m_segmentSize (segmentSize),
54  m_remoteAddr (Ipv4Address::GetAny (), 4477)
55 {
56  NS_LOG_FUNCTION (this << desc);
57 }
58 
60 {
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION (this << socket);
68  Ptr<Packet> packet;
69  Address from;
70 
71  while ((packet = socket->RecvFrom (from)))
72  {
73  if (packet->GetSize () == 0)
74  { //EOF
75  break;
76  }
77  }
78 }
79 
80 void
81 TcpGeneralTest::SendPacket (Ptr<Socket> socket, uint32_t pktSize,
82  uint32_t pktCount, Time pktInterval )
83 {
84  NS_LOG_FUNCTION (this << " " << pktSize << " " << pktCount << " " <<
85  pktInterval.GetSeconds ());
86  if (pktCount > 0)
87  {
88  socket->Send (Create<Packet> (pktSize));
90  socket, pktSize, pktCount - 1, pktInterval);
91  }
92  else
93  {
94  socket->Close ();
95  }
96 }
97 
98 void
100 {
101  FinalChecks ();
102 
104  NS_LOG_INFO ("Done.");
105 }
106 
107 void
109 {
110  NS_LOG_INFO ("Create nodes.");
112  nodes.Create (2);
113 
114  InternetStackHelper internet;
115  internet.Install (nodes);
116 
118 
120 
121  SimpleNetDeviceHelper helperChannel;
122  helperChannel.SetNetDevicePointToPointMode (true);
123 
124  NetDeviceContainer net = helperChannel.Install (nodes, channel);
125 
128 
129  Ptr<SimpleNetDevice> senderDev = DynamicCast<SimpleNetDevice> (net.Get (0));
130  Ptr<SimpleNetDevice> receiverDev = DynamicCast<SimpleNetDevice> (net.Get (1));
131 
132  senderDev->SetMtu (m_mtu);
133  senderDev->GetQueue ()->TraceConnect ("Drop", "SENDER",
135  senderDev->TraceConnect ("PhyRxDrop", "sender",
137 
138  receiverDev->SetMtu (m_mtu);
139  receiverDev->GetQueue ()->TraceConnect ("Drop", "RECEIVER",
141  receiverDev->TraceConnect ("PhyRxDrop", "RECEIVER",
143 
144  senderDev->SetReceiveErrorModel (senderEM);
145  receiverDev->SetReceiveErrorModel (receiverEM);
146 
147  Ipv4AddressHelper ipv4;
148  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
149  Ipv4InterfaceContainer i = ipv4.Assign (net);
150  Ipv4Address serverAddress = i.GetAddress (1);
151  //Ipv4Address clientAddress = i.GetAddress (0);
152 
153  NS_LOG_INFO ("Create sockets.");
154  //Receiver socket on n1
156 
157  m_receiverSocket->SetRecvCallback (MakeCallback (&TcpGeneralTest::ReceivePacket, this));
158  m_receiverSocket->SetAcceptCallback (
159  MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
161  m_receiverSocket->SetCloseCallbacks (MakeCallback (&TcpGeneralTest::NormalCloseCb, this),
164  m_receiverSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
165  m_receiverSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
167  m_receiverSocket->TraceConnectWithoutContext ("Tx",
169  m_receiverSocket->TraceConnectWithoutContext ("Rx",
171 
173  m_receiverSocket->Bind (local);
174  m_receiverSocket->Listen ();
175  m_receiverSocket->ShutdownSend ();
176 
177  m_senderSocket = CreateSenderSocket (nodes.Get (0));
178  m_senderSocket->SetCloseCallbacks (MakeCallback (&TcpGeneralTest::NormalCloseCb, this),
180  m_senderSocket->SetRcvAckCb (MakeCallback (&TcpGeneralTest::RcvAckCb, this));
181  m_senderSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
182  m_senderSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
183  m_senderSocket->TraceConnectWithoutContext ("CongestionWindow",
185  m_senderSocket->TraceConnectWithoutContext ("CongState",
187  m_senderSocket->TraceConnectWithoutContext ("Tx",
189  m_senderSocket->TraceConnectWithoutContext ("Rx",
191 
192  m_remoteAddr = InetSocketAddress (serverAddress, 4477);
193 
199 
200  NS_LOG_INFO ("Run Simulation.");
201  Simulator::Run ();
202 }
203 
204 void
206 {
207  NS_LOG_INFO (this);
208  m_senderSocket->Connect (m_remoteAddr);
209 }
210 
211 void
213 {
214  (void) from;
218 
219 }
220 
223 {
224  Ptr<SimpleChannel> ch = CreateObject <SimpleChannel> ();
225 
226  ch->SetAttribute ("Delay", TimeValue (m_propagationDelay));
227 
228  return ch;
229 }
230 
233  TypeId congControl)
234 {
235  ObjectFactory rttFactory;
236  ObjectFactory congestionAlgorithmFactory;
237  ObjectFactory socketFactory;
238 
239  rttFactory.SetTypeId (RttMeanDeviation::GetTypeId ());
240  congestionAlgorithmFactory.SetTypeId (congControl);
241  socketFactory.SetTypeId (socketType);
242 
243  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
244  Ptr<TcpSocketMsgBase> socket = socketFactory.Create <TcpSocketMsgBase> ();
245  Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps> ();
246 
247  socket->SetNode (node);
248  socket->SetTcp (node->GetObject<TcpL4Protocol> ());
249  socket->SetRtt (rtt);
250  socket->SetCongestionControlAlgorithm (algo);
251 
252  socket->SetAttribute ("InitialSlowStartThreshold", UintegerValue (m_initialSlowStartThresh));
253  socket->SetAttribute ("SegmentSize", UintegerValue (m_segmentSize));
254  socket->SetAttribute ("InitialCwnd", UintegerValue (m_initialCwnd));
255 
256  return socket;
257 }
258 
261 {
262  return 0;
263 }
264 
267 {
268  return 0;
269 }
270 
273 {
275 }
276 
279 {
281 }
282 
283 void
285 {
286  if (context.compare ("SENDER") == 0)
287  {
288  QueueDrop (SENDER);
289  }
290  else if (context.compare ("RECEIVER") == 0)
291  {
293  }
294  else
295  {
296  NS_FATAL_ERROR ("Packet dropped in a queue, but queue not recognized");
297  }
298 }
299 
300 void
302 {
303  if (context.compare ("SENDER") == 0)
304  {
305  PhyDrop (SENDER);
306  }
307  else if (context.compare ("RECEIVER") == 0)
308  {
309  PhyDrop (RECEIVER);
310  }
311  else
312  {
313  NS_FATAL_ERROR ("Packet dropped in a queue, but queue not recognized");
314  }
315 }
316 
317 void
319 {
320  if (socket->GetNode () == m_receiverSocket->GetNode ())
321  {
323  }
324  else if (socket->GetNode () == m_senderSocket->GetNode ())
325  {
327  }
328  else
329  {
330  NS_FATAL_ERROR ("Closed socket, but not recognized");
331  }
332 }
333 
334 void
336  const Ptr<const TcpSocketBase> tcp)
337 {
338  if (tcp->GetNode () == m_receiverSocket->GetNode ())
339  {
340  RTOExpired (tcb, RECEIVER);
341  }
342  else if (tcp->GetNode () == m_senderSocket->GetNode ())
343  {
344  RTOExpired (tcb, SENDER);
345  }
346  else
347  {
348  NS_FATAL_ERROR ("Closed socket, but not recognized");
349  }
350 }
351 
352 void
354 {
355  if (socket->GetNode () == m_receiverSocket->GetNode ())
356  {
358  }
359  else if (socket->GetNode () == m_senderSocket->GetNode ())
360  {
361  ErrorClose (SENDER);
362  }
363  else
364  {
365  NS_FATAL_ERROR ("Closed socket, but not recognized");
366  }
367 }
368 
369 void
371 {
372  NS_LOG_FUNCTION (this << p << h << who);
373 }
374 
375 void
377 {
378  NS_LOG_FUNCTION (this << p << h << who);
379 }
380 
381 void
383  const Ptr<const TcpSocketBase> tcp)
384 {
385  if (tcp->GetNode () == m_receiverSocket->GetNode ())
386  {
387  RcvAck (tcp->m_tcb, h, RECEIVER);
388  }
389  else if (tcp->GetNode () == m_senderSocket->GetNode ())
390  {
391  RcvAck (tcp->m_tcb, h, SENDER);
392  }
393  else
394  {
395  NS_FATAL_ERROR ("Received ACK but socket not recognized");
396  }
397 }
398 
399 void
401  const TcpHeader &h, const Ptr<const TcpSocketBase> tcp)
402 {
403  if (tcp->GetNode () == m_receiverSocket->GetNode ())
404  {
405  Tx (p, h, RECEIVER);
406  }
407  else if (tcp->GetNode () == m_senderSocket->GetNode ())
408  {
409  Tx (p, h, SENDER);
410  }
411  else
412  {
413  NS_FATAL_ERROR ("Received ACK but socket not recognized");
414  }
415 }
416 
417 void
419  const Ptr<const TcpSocketBase> tcp)
420 {
421  if (tcp->GetNode () == m_receiverSocket->GetNode ())
422  {
423  Rx (p, h, RECEIVER);
424  }
425  else if (tcp->GetNode () == m_senderSocket->GetNode ())
426  {
427  Rx (p, h, SENDER);
428  }
429  else
430  {
431  NS_FATAL_ERROR ("Received ACK but socket not recognized");
432  }
433 }
434 
435 void
438 {
439  if (tcp->GetNode () == m_receiverSocket->GetNode ())
440  {
441  ProcessedAck (tcp->m_tcb, h, RECEIVER);
442  }
443  else if (tcp->GetNode () == m_senderSocket->GetNode ())
444  {
445  ProcessedAck (tcp->m_tcb, h, SENDER);
446  }
447  else
448  {
449  NS_FATAL_ERROR ("Received ACK but socket not recognized");
450  }
451 }
452 
453 void
455 {
456  NS_LOG_FUNCTION (this << tcp);
457 
458  m_receiverSocket = tcp;
459 }
460 
461 uint32_t
463 {
464  if (who == SENDER)
465  {
466  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_retxThresh;
467  }
468  else if (who == RECEIVER)
469  {
470  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_retxThresh;
471  }
472  else
473  {
474  NS_FATAL_ERROR ("Not defined");
475  }
476 }
477 
478 uint32_t
480 {
481  if (who == SENDER)
482  {
483  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_dupAckCount;
484  }
485  else if (who == RECEIVER)
486  {
487  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_dupAckCount;
488  }
489  else
490  {
491  NS_FATAL_ERROR ("Not defined");
492  }
493 }
494 
495 uint32_t
497 {
498  if (who == SENDER)
499  {
500  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_delAckMaxCount;
501  }
502  else if (who == RECEIVER)
503  {
504  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_delAckMaxCount;
505  }
506  else
507  {
508  NS_FATAL_ERROR ("Not defined");
509  }
510 }
511 
512 Time
514 {
515  if (who == SENDER)
516  {
517  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetDelAckTimeout ();
518  }
519  else if (who == RECEIVER)
520  {
521  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetDelAckTimeout ();
522  }
523  else
524  {
525  NS_FATAL_ERROR ("Not defined");
526  }
527 }
528 
529 uint32_t
531 {
532  if (who == SENDER)
533  {
534  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetSegSize ();
535  }
536  else if (who == RECEIVER)
537  {
538  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetSegSize ();
539  }
540  else
541  {
542  NS_FATAL_ERROR ("Not defined");
543  }
544 }
545 
546 Time
548 {
549  if (who == SENDER)
550  {
551  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rto.Get ();
552  }
553  else if (who == RECEIVER)
554  {
555  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rto.Get ();
556  }
557  else
558  {
559  NS_FATAL_ERROR ("Not defined");
560  }
561 }
562 
563 Time
565 {
566  if (who == SENDER)
567  {
568  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_minRto;
569  }
570  else if (who == RECEIVER)
571  {
572  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_minRto;
573  }
574  else
575  {
576  NS_FATAL_ERROR ("Not defined");
577  }
578 }
579 
580 Time
582 {
583  if (who == SENDER)
584  {
585  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_cnTimeout;
586  }
587  else if (who == RECEIVER)
588  {
589  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_cnTimeout;
590  }
591  else
592  {
593  NS_FATAL_ERROR ("Not defined");
594  }
595 }
596 
599 {
600  if (who == SENDER)
601  {
602  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rtt;
603  }
604  else if (who == RECEIVER)
605  {
606  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rtt;
607  }
608  else
609  {
610  NS_FATAL_ERROR ("Not defined");
611  }
612 }
613 
614 Time
616 {
617  if (who == SENDER)
618  {
619  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_clockGranularity;
620  }
621  else if (who == RECEIVER)
622  {
623  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_clockGranularity;
624  }
625  else
626  {
627  NS_FATAL_ERROR ("Not defined");
628  }
629 }
630 
633 {
634  if (who == SENDER)
635  {
636  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_state.Get ();
637  }
638  else if (who == RECEIVER)
639  {
640 
641  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_state.Get ();
642  }
643  else
644  {
645  NS_FATAL_ERROR ("Not defined");
646  }
647 }
648 
649 uint32_t
651 {
652  if (who == SENDER)
653  {
654  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rWnd.Get ();
655  }
656  else if (who == RECEIVER)
657  {
658 
659  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rWnd.Get ();
660  }
661  else
662  {
663  NS_FATAL_ERROR ("Not defined");
664  }
665 }
666 
667 EventId
669 {
670  if (who == SENDER)
671  {
672  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_persistEvent;
673  }
674  else if (who == RECEIVER)
675  {
676 
677  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_persistEvent;
678  }
679  else
680  {
681  NS_FATAL_ERROR ("Not defined");
682  }
683 }
684 
685 Time
687 {
688  if (who == SENDER)
689  {
690  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_persistTimeout;
691  }
692  else if (who == RECEIVER)
693  {
694 
695  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_persistTimeout;
696  }
697  else
698  {
699  NS_FATAL_ERROR ("Not defined");
700  }
701 }
702 
705 {
706  if (who == SENDER)
707  {
708  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_tcb;
709  }
710  else if (who == RECEIVER)
711  {
712 
713  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_tcb;
714  }
715  else
716  {
717  NS_FATAL_ERROR ("Not defined");
718  }
719 }
720 
721 void
723 {
724  if (who == SENDER)
725  {
726  m_senderSocket->SetRcvBufSize (size);
727  }
728  else if (who == RECEIVER)
729  {
730  m_receiverSocket->SetRcvBufSize (size);
731  }
732  else
733  {
734  NS_FATAL_ERROR ("Not defined");
735  }
736 }
737 
739 
740 TypeId
742 {
743  static TypeId tid = TypeId ("ns3::TcpSocketMsgBase")
745  .SetGroupName ("Internet")
746  .AddConstructor<TcpSocketMsgBase> ()
747  ;
748  return tid;
749 }
750 
753 {
754  return CopyObject<TcpSocketMsgBase> (this);
755 }
756 
757 void
759 {
760  NS_ASSERT (!cb.IsNull ());
761  m_rcvAckCb = cb;
762 }
763 
764 void
766 {
767  NS_ASSERT (!cb.IsNull ());
768  m_processedAckCb = cb;
769 }
770 
771 void
773 {
774  NS_ASSERT (!cb.IsNull ());
775  m_retrCallback = cb;
776 }
777 
778 void
780 {
782  m_rcvAckCb (packet, tcpHeader, this);
783 
784  TcpSocketBase::ReceivedAck (packet, tcpHeader);
785 
786  m_processedAckCb (packet, tcpHeader, this);
787 }
788 
789 void
791 {
793 
794  m_retrCallback (m_tcb, this);
795 }
796 
797 void
799 {
800  NS_ASSERT (!cb.IsNull ());
801  m_forkCb = cb;
802 }
803 
804 void
806  const Address &fromAddress, const Address &toAddress)
807 {
808  TcpSocketBase::CompleteFork (p, tcpHeader, fromAddress, toAddress);
809 
810  if (!m_forkCb.IsNull ())
811  {
812  m_forkCb (this);
813  }
814 }
815 
817 
818 TypeId
820 {
821  static TypeId tid = TypeId ("ns3::TcpSocketSmallAcks")
823  .SetGroupName ("Internet")
824  .AddConstructor<TcpSocketSmallAcks> ()
825  ;
826  return tid;
827 }
828 
836 void
838 {
839  Ptr<Packet> p = Create<Packet> ();
840  TcpHeader header;
842 
843  /*
844  * Add tags for each socket option.
845  * Note that currently the socket adds both IPv4 tag and IPv6 tag
846  * if both options are set. Once the packet got to layer three, only
847  * the corresponding tags will be read.
848  */
849  if (IsManualIpTos ())
850  {
851  SocketIpTosTag ipTosTag;
852  ipTosTag.SetTos (GetIpTos ());
853  p->AddPacketTag (ipTosTag);
854  }
855 
856  if (IsManualIpv6Tclass ())
857  {
858  SocketIpv6TclassTag ipTclassTag;
859  ipTclassTag.SetTclass (GetIpv6Tclass ());
860  p->AddPacketTag (ipTclassTag);
861  }
862 
863  if (IsManualIpTtl ())
864  {
865  SocketIpTtlTag ipTtlTag;
866  ipTtlTag.SetTtl (GetIpTtl ());
867  p->AddPacketTag (ipTtlTag);
868  }
869 
870  if (IsManualIpv6HopLimit ())
871  {
872  SocketIpv6HopLimitTag ipHopLimitTag;
873  ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
874  p->AddPacketTag (ipHopLimitTag);
875  }
876 
877  if (m_endPoint == 0 && m_endPoint6 == 0)
878  {
879  NS_LOG_WARN ("Failed to send empty packet due to null endpoint");
880  return;
881  }
882  if (flags & TcpHeader::FIN)
883  {
884  flags |= TcpHeader::ACK;
885  }
886  else if (m_state == FIN_WAIT_1 || m_state == LAST_ACK || m_state == CLOSING)
887  {
888  ++s;
889  }
890 
891  bool hasSyn = flags & TcpHeader::SYN;
892  bool hasFin = flags & TcpHeader::FIN;
893  bool isAck = flags == TcpHeader::ACK;
894 
895  header.SetFlags (flags);
896  header.SetSequenceNumber (s);
897 
898  // Actual division in small acks.
899  if (hasSyn || hasFin)
900  {
901  header.SetAckNumber (m_rxBuffer->NextRxSequence ());
902  }
903  else
904  {
905  SequenceNumber32 ackSeq;
906 
907  ackSeq = m_lastAckedSeq + m_bytesToAck;
908 
909  if (m_bytesLeftToBeAcked == 0 && m_rxBuffer->NextRxSequence () > m_lastAckedSeq)
910  {
911  m_bytesLeftToBeAcked = m_rxBuffer->NextRxSequence ().GetValue () - 1 - m_bytesToAck;
912  }
913  else if (m_bytesLeftToBeAcked > 0 && m_rxBuffer->NextRxSequence () > m_lastAckedSeq)
914  {
916  }
917 
918  NS_LOG_LOGIC ("Acking up to " << ackSeq << " remaining bytes: " << m_bytesLeftToBeAcked);
919 
920  header.SetAckNumber (ackSeq);
921  m_lastAckedSeq = ackSeq;
922  }
923 
924  // end of division in small acks
925 
926  if (m_endPoint != 0)
927  {
928  header.SetSourcePort (m_endPoint->GetLocalPort ());
929  header.SetDestinationPort (m_endPoint->GetPeerPort ());
930  }
931  else
932  {
933  header.SetSourcePort (m_endPoint6->GetLocalPort ());
934  header.SetDestinationPort (m_endPoint6->GetPeerPort ());
935  }
936  AddOptions (header);
937  header.SetWindowSize (AdvertisedWindowSize ());
938 
939  // RFC 6298, clause 2.4
940  m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation () * 4), m_minRto);
941 
942  if (hasSyn)
943  {
944  if (m_synCount == 0)
945  { // No more connection retries, give up
946  NS_LOG_LOGIC ("Connection failed.");
947  m_rtt->Reset (); //According to recommendation -> RFC 6298
948  CloseAndNotify ();
949  return;
950  }
951  else
952  { // Exponential backoff of connection time out
953  int backoffCount = 0x1 << (m_synRetries - m_synCount);
954  m_rto = m_cnTimeout * backoffCount;
955  m_synCount--;
956  }
957  }
958  if (m_endPoint != 0)
959  {
960  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
962  }
963  else
964  {
965  m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
967  }
968 
969  m_txTrace (p, header, this);
970 
971  if (flags & TcpHeader::ACK)
972  { // If sending an ACK, cancel the delay ACK as well
974  m_delAckCount = 0;
975  }
976  if (m_retxEvent.IsExpired () && (hasSyn || hasFin) && !isAck )
977  { // Retransmit SYN / SYN+ACK / FIN / FIN+ACK to guard against lost
978  NS_LOG_LOGIC ("Schedule retransmission timeout at time "
979  << Simulator::Now ().GetSeconds () << " to expire at time "
980  << (Simulator::Now () + m_rto.Get ()).GetSeconds ());
982  }
983 
984  // send another ACK if bytes remain
985  if (m_bytesLeftToBeAcked > 0 && m_rxBuffer->NextRxSequence () > m_lastAckedSeq)
986  {
987  SendEmptyPacket (flags);
988  }
989 }
990 
993 {
994  return CopyObject<TcpSocketSmallAcks> (this);
995 }
996 
997 } // namespace ns3
virtual void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Processed ack.
Ipv6Address GetLocalAddress()
Get the local address.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:822
tuple channel
Definition: third.py:85
Time GetMinRto(SocketWho who)
Get the minimun RTO attribute.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual void DoTeardown(void)
Teardown the TCP test.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:383
Time GetPersistentTimeout(SocketWho who)
Get the persistent timeout of the selected socket.
an Inet address class
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void SendEmptyPacket(uint8_t flags)
Send empty packet, copied/pasted from TcpSocketBase.
Ptr< TcpSocketMsgBase > m_senderSocket
Pointer to sender socket.
void PhyDropCb(std::string context, Ptr< const Packet > p)
Time m_propagationDelay
Propagation delay of the channel.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:471
uint32_t GetDelAckCount(SocketWho who)
Get the number of delayed ack (if present)
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Class for inserting callbacks special points of the flow of TCP sockets.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:404
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:1047
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
holds a vector of std::pair of Ptr and interface index.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
uint32_t m_synRetries
Number of connection attempts.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void SetForkCb(Callback< void, Ptr< TcpSocketMsgBase > > cb)
Set the callback invoked after the forking.
virtual void DoRun(void)
Execute the tcp test.
void NormalCloseCb(Ptr< Socket > socket)
EventId m_retxEvent
Retransmission event.
virtual void PhyDrop(SocketWho who)
Link drop.
void QueueDropCb(std::string context, Ptr< const Packet > p)
virtual void ErrorClose(SocketWho who)
Socket closed with an error.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:822
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1258
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
static void Run(void)
Run the simulation.
Definition: simulator.cc:200
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Ptr< TcpSocketState > m_tcb
Congestion control informations.
void DoConnect()
Scheduled at 0.0, SENDER starts the connection to RECEIVER.
void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Send packets to other endpoint.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
aggregate IP/TCP/UDP functionality to existing Nodes.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
Definition: socket.cc:371
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
Definition: socket.cc:94
AckManagementCallback m_rcvAckCb
Both sides have shutdown but we still have data we have to finish sending.
Definition: tcp-socket.h:80
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:145
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:496
Time m_cnTimeout
Timeout for connection retry.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Callback< R > MakeNullCallback(void)
Definition: callback.h:1626
static TypeId GetTypeId(void)
Get the type ID.
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:765
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
encapsulates test code
Definition: test.h:1147
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:217
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
Definition: socket.h:999
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
TracedValue< TcpStates_t > m_state
TCP state.
virtual Ptr< ErrorModel > CreateSenderErrorModel()
Create and return the error model to install in the sender node.
uint32_t m_initialCwnd
Initial congestion window.
a polymophic address class
Definition: address.h:90
uint16_t GetPeerPort()
Get the peer port.
Tcp socket creation and multiplexing/demultiplexing.
uint32_t m_delAckCount
Delayed ACK counter.
void SetRcvAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received (at the beginning of the processing) ...
TcpGeneralTest(const std::string &desc, uint32_t pktSize=500, uint32_t pktCount=10, const Time &pktInterval=Seconds(0.01), const Time &propagationDelay=Seconds(0.5), const Time &startTime=Seconds(10), uint32_t initialSlowStartThresh=0xffff, uint32_t initialCwnd=1, uint32_t segmentSize=500, TypeId congestionControl=TcpNewReno::GetTypeId(), uint32_t mtu=1500)
TcpGeneralTest constructor.
tuple nodes
Definition: first.py:25
uint32_t GetRWnd(SocketWho who)
Get the rWnd of the selected socket.
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
Our side has shutdown, waiting to complete transmission of remaining buffered data.
Definition: tcp-socket.h:77
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
virtual void ReceivePacket(Ptr< Socket > socket)
Packet received.
Time GetDelAckTimeout(SocketWho who)
Get the timeout of delayed ack (if present)
void ErrorCloseCb(Ptr< Socket > socket)
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1216
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:533
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:584
AttributeValue implementation for Time.
Definition: nstime.h:957
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
virtual void Retransmit(void)
Halving cwnd and call DoRetransmit()
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
uint16_t GetLocalPort()
Get the local port.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
Hold an unsigned integer type.
Definition: uinteger.h:44
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
double startTime
Base class for all RTT Estimators.
Definition: rtt-estimator.h:43
Ipv4Address GetLocalAddress(void)
Get the local address.
holds a vector of ns3::NetDevice pointers
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
void SetRetransmitCb(RetrCallback cb)
Set the callback invoked after the processing of a retransmit timeout.
uint32_t m_pktCount
Count of the application packet.
Time m_interPacketInterval
Time between sending application packet.
Time GetConnTimeout(SocketWho who)
Get the retransmission time for the SYN segments.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:377
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
A base class for implementation of a stream socket using TCP.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
void ProcessedAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Ptr< TcpL4Protocol > m_tcp
the associated TCP L4 protocol
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:645
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:164
virtual void RcvAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who)
Received ack.
AckManagementCallback m_processedAckCb
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:389
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
virtual void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
Ptr< TcpSocketMsgBase > m_receiverSocket
Pointer to receiver socket.
Time GetRto(SocketWho who)
Get the retransmission time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
virtual void QueueDrop(SocketWho who)
Drop on the queue.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
Congestion control abstract class.
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1192
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:446
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
uint32_t GetReTxThreshold(SocketWho who)
Get the retransmission threshold.
static TypeId GetTypeId(void)
void ForkCb(Ptr< TcpSocketMsgBase > tcp)
Time GetClockGranularity(SocketWho who)
Get the clock granularity attribute.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
void SetProcessedAckCb(AckManagementCallback cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing) ...
Time m_minRto
minimum value of the Retransmit timeout
virtual void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
Instantiate subclasses of ns3::Object.
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1297
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual void NormalClose(SocketWho who)
Socket closed normally.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:914
uint32_t GetId(void) const
Definition: node.cc:107
TracedValue< Time > m_rto
Retransmit timeout.
An identifier for simulation events.
Definition: event-id.h:53
uint16_t GetLocalPort(void)
Get the local port.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Ipv6Address GetPeerAddress()
Get the peer address.
static TypeId GetTypeId(void)
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
virtual Ptr< SimpleChannel > CreateChannel()
Create and return the channel installed between the two socket.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void TxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Ipv4Address GetPeerAddress(void)
Get the peer address.
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
uint32_t m_synCount
Count of remaining connection retries.
void RtoExpiredCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
uint16_t GetPeerPort(void)
Get the peer port.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
uint32_t m_mtu
MTU of the environment.
Callback< void, Ptr< TcpSocketMsgBase > > m_forkCb
A TCP socket which sends ACKs smaller than the segment received.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
uint32_t m_initialSlowStartThresh
Initial slow start threshold.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
void CloseAndNotify(void)
Peacefully close the socket by notifying the upper layer and deallocate end point.
SequenceNumber32 m_lastAckedSeq
InetSocketAddress m_remoteAddr
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
TcpStates_t
Names of the 11 TCP states.
Definition: tcp-socket.h:64
build a set of SimpleNetDevice objects
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
uint32_t m_segmentSize
Segment size.
virtual void RTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who)
Rto has expired.
virtual int Close(void)=0
Close a socket.
Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
indicates whether the socket has IP_TOS set.
Definition: socket.h:1145
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
Our side has shutdown after remote has shutdown.
Definition: tcp-socket.h:74
EventId m_delAckEvent
Delayed ACK timeout event.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void CWndTrace(uint32_t oldValue, uint32_t newValue)
Congestion window changes.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
Time m_clockGranularity
Clock Granularity used in RTO calcs.
uint32_t m_pktSize
Size of the application packet.
virtual uint16_t AdvertisedWindowSize(void) const
The amount of Rx window announced to the peer.
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_txTrace
Trace of transmitted packets.
TcpSocket::TcpStates_t GetTcpState(SocketWho who)
Get the state of the TCP state machine.
Time m_startTime
Data transmission time.
void HandleAccept(Ptr< Socket > socket, const Address &from)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
TypeId m_congControlTypeId
Congestion control.