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 #define __STDC_LIMIT_MACROS
20 #include "ns3/test.h"
21 #include "ns3/node-container.h"
22 #include "ns3/tcp-socket-base.h"
23 #include "ns3/simple-net-device-helper.h"
24 #include "ns3/ipv4-address-helper.h"
25 #include "ns3/internet-stack-helper.h"
26 #include "ns3/log.h"
27 #include "ns3/queue.h"
28 #include "ns3/tcp-l4-protocol.h"
29 #include "ns3/ipv4-end-point.h"
30 #include "ns3/ipv6-end-point.h"
31 #include "ns3/tcp-header.h"
32 #include "ns3/tcp-tx-buffer.h"
33 #include "ns3/tcp-rx-buffer.h"
34 #include "ns3/rtt-estimator.h"
35 
36 #include "tcp-general-test.h"
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("TcpGeneralTest");
41 
42 TcpGeneralTest::TcpGeneralTest (const std::string &desc)
43  : TestCase (desc),
44  m_congControlTypeId (TcpNewReno::GetTypeId ()),
45  m_recoveryTypeId (TcpClassicRecovery::GetTypeId ()),
46  m_remoteAddr (Ipv4Address::GetAny (), 4477)
47 {
48  NS_LOG_FUNCTION (this << desc);
49 }
50 
52 {
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION (this << socket);
60  Ptr<Packet> packet;
61  Address from;
62 
63  while ((packet = socket->RecvFrom (from)))
64  {
65  if (packet->GetSize () == 0)
66  { //EOF
67  break;
68  }
69  }
70 }
71 
72 void
74  uint32_t pktCount, Time pktInterval )
75 {
76  NS_LOG_FUNCTION (this << " " << pktSize << " " << pktCount << " " <<
77  pktInterval.GetSeconds ());
78  if (pktCount > 0)
79  {
80  socket->Send (Create<Packet> (pktSize));
82  socket, pktSize, pktCount - 1, pktInterval);
83  }
84  else
85  {
86  socket->Close ();
87  }
88 }
89 
90 void
92 {
93  FinalChecks ();
94 
96  NS_LOG_INFO ("Done.");
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION (this);
103 
107  SetTransmitStart (Seconds (10));
108  SetAppPktSize (500);
109  SetAppPktCount (10);
111  SetMTU (1500);
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION (this);
118  SetInitialCwnd (SENDER, 1);
120  SetSegmentSize (SENDER, 500);
121  SetSegmentSize (RECEIVER, 500);
122 }
123 
124 void
126 {
128 
129  NS_LOG_INFO ("Create nodes.");
131  nodes.Create (2);
132 
133  InternetStackHelper internet;
134  internet.Install (nodes);
135 
137 
139 
140  SimpleNetDeviceHelper helperChannel;
141  helperChannel.SetNetDevicePointToPointMode (true);
142 
143  NetDeviceContainer net = helperChannel.Install (nodes, channel);
144 
147 
148  Ptr<SimpleNetDevice> senderDev = DynamicCast<SimpleNetDevice> (net.Get (0));
149  Ptr<SimpleNetDevice> receiverDev = DynamicCast<SimpleNetDevice> (net.Get (1));
150 
151  senderDev->SetMtu (m_mtu);
152  senderDev->GetQueue ()->TraceConnect ("Drop", "SENDER",
154  senderDev->TraceConnect ("PhyRxDrop", "sender",
156 
157  receiverDev->SetMtu (m_mtu);
158  receiverDev->GetQueue ()->TraceConnect ("Drop", "RECEIVER",
160  receiverDev->TraceConnect ("PhyRxDrop", "RECEIVER",
162 
163  senderDev->SetReceiveErrorModel (senderEM);
164  receiverDev->SetReceiveErrorModel (receiverEM);
165 
166  Ipv4AddressHelper ipv4;
167  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
168  Ipv4InterfaceContainer i = ipv4.Assign (net);
169  Ipv4Address serverAddress = i.GetAddress (1);
170  //Ipv4Address clientAddress = i.GetAddress (0);
171 
172  NS_LOG_INFO ("Create sockets.");
173  //Receiver socket on n1
175 
176  m_receiverSocket->SetRecvCallback (MakeCallback (&TcpGeneralTest::ReceivePacket, this));
177  m_receiverSocket->SetAcceptCallback (
178  MakeNullCallback<bool, Ptr<Socket>, const Address &> (),
180  m_receiverSocket->SetCloseCallbacks (MakeCallback (&TcpGeneralTest::NormalCloseCb, this),
183  m_receiverSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
184  m_receiverSocket->SetAfterRetransmitCb (MakeCallback (&TcpGeneralTest::AfterRetransmitCb, this));
185  m_receiverSocket->SetBeforeRetransmitCb (MakeCallback (&TcpGeneralTest::BeforeRetransmitCb, this));
187  m_receiverSocket->SetUpdateRttHistoryCb (MakeCallback (&TcpGeneralTest::UpdateRttHistoryCb, this));
188  m_receiverSocket->TraceConnectWithoutContext ("Tx",
190  m_receiverSocket->TraceConnectWithoutContext ("Rx",
192 
194  m_receiverSocket->Bind (local);
195 
197  m_senderSocket->SetCloseCallbacks (MakeCallback (&TcpGeneralTest::NormalCloseCb, this),
199  m_senderSocket->SetRcvAckCb (MakeCallback (&TcpGeneralTest::RcvAckCb, this));
200  m_senderSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
201  m_senderSocket->SetAfterRetransmitCb (MakeCallback (&TcpGeneralTest::AfterRetransmitCb, this));
202  m_senderSocket->SetBeforeRetransmitCb (MakeCallback (&TcpGeneralTest::BeforeRetransmitCb, this));
203  m_senderSocket->SetDataSentCallback (MakeCallback (&TcpGeneralTest::DataSentCb, this));
204  m_senderSocket->SetUpdateRttHistoryCb (MakeCallback (&TcpGeneralTest::UpdateRttHistoryCb, this));
205  m_senderSocket->TraceConnectWithoutContext ("CongestionWindow",
207  m_senderSocket->TraceConnectWithoutContext ("CongestionWindowInflated",
209  m_senderSocket->TraceConnectWithoutContext ("SlowStartThreshold",
211  m_senderSocket->TraceConnectWithoutContext ("CongState",
213  m_senderSocket->TraceConnectWithoutContext ("Tx",
215  m_senderSocket->TraceConnectWithoutContext ("Rx",
217  m_senderSocket->TraceConnectWithoutContext ("RTT",
219  m_senderSocket->TraceConnectWithoutContext ("BytesInFlight",
221  m_senderSocket->TraceConnectWithoutContext ("RTO",
223  m_senderSocket->TraceConnectWithoutContext ("NextTxSequence",
225  m_senderSocket->TraceConnectWithoutContext ("HighestSequence",
227  m_senderSocket->m_rateOps->TraceConnectWithoutContext ("TcpRateUpdated",
229  m_senderSocket->m_rateOps->TraceConnectWithoutContext ("TcpRateSampleUpdated",
231 
232 
233  m_remoteAddr = InetSocketAddress (serverAddress, 4477);
234 
236 
237  m_receiverSocket->Listen ();
238  m_receiverSocket->ShutdownSend ();
239 
242  Simulator::ScheduleWithContext (nodes.Get (0)->GetId (),
245 
246  NS_LOG_INFO ("Run Simulation.");
247  Simulator::Run ();
248 }
249 
250 void
252 {
253  NS_LOG_INFO (this);
254  m_senderSocket->Connect (m_remoteAddr);
255 }
256 
257 void
259 {
260  (void) from;
264 
265 }
266 
269 {
270  Ptr<SimpleChannel> ch = CreateObject <SimpleChannel> ();
271 
272  ch->SetAttribute ("Delay", TimeValue (m_propagationDelay));
273 
274  return ch;
275 }
276 
279  TypeId congControl)
280 {
281  return CreateSocket (node, socketType, congControl, m_recoveryTypeId);
282 }
283 
286  TypeId congControl, TypeId recoveryAlgorithm)
287 {
288  ObjectFactory rttFactory;
289  ObjectFactory congestionAlgorithmFactory;
290  ObjectFactory recoveryAlgorithmFactory;
291  ObjectFactory socketFactory;
292 
293  rttFactory.SetTypeId (RttMeanDeviation::GetTypeId ());
294  congestionAlgorithmFactory.SetTypeId (congControl);
295  recoveryAlgorithmFactory.SetTypeId (recoveryAlgorithm);
296  socketFactory.SetTypeId (socketType);
297 
298  Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator> ();
299  Ptr<TcpSocketMsgBase> socket = DynamicCast<TcpSocketMsgBase> (socketFactory.Create ());
300  Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps> ();
301  Ptr<TcpRecoveryOps> recovery = recoveryAlgorithmFactory.Create<TcpRecoveryOps> ();
302 
303  socket->SetNode (node);
304  socket->SetTcp (node->GetObject<TcpL4Protocol> ());
305  socket->SetRtt (rtt);
306  socket->SetCongestionControlAlgorithm (algo);
307  socket->SetRecoveryAlgorithm (recovery);
308  return socket;
309 }
310 
313 {
314  return nullptr;
315 }
316 
319 {
320  return nullptr;
321 }
322 
325 {
327 }
328 
331 {
333 }
334 
335 void
337 {
338  if (context.compare ("SENDER") == 0)
339  {
340  QueueDrop (SENDER);
341  }
342  else if (context.compare ("RECEIVER") == 0)
343  {
345  }
346  else
347  {
348  NS_FATAL_ERROR ("Packet dropped in a queue, but queue not recognized");
349  }
350 }
351 
352 void
353 TcpGeneralTest::PhyDropCb (std::string context, [[maybe_unused]] Ptr<const Packet> p)
354 {
355  if (context.compare ("SENDER") == 0)
356  {
357  PhyDrop (SENDER);
358  }
359  else if (context.compare ("RECEIVER") == 0)
360  {
361  PhyDrop (RECEIVER);
362  }
363  else
364  {
365  NS_FATAL_ERROR ("Packet dropped in a queue, but queue not recognized");
366  }
367 }
368 
369 void
371 {
372  if (socket->GetNode () == m_receiverSocket->GetNode ())
373  {
375  }
376  else if (socket->GetNode () == m_senderSocket->GetNode ())
377  {
379  }
380  else
381  {
382  NS_FATAL_ERROR ("Closed socket, but not recognized");
383  }
384 }
385 
386 void
388  const SequenceNumber32 & seq, uint32_t sz,
389  bool isRetransmission)
390 {
391  if (tcp->GetNode () == m_receiverSocket->GetNode ())
392  {
393  UpdatedRttHistory (seq, sz, isRetransmission, RECEIVER);
394  }
395  else if (tcp->GetNode () == m_senderSocket->GetNode ())
396  {
397  UpdatedRttHistory (seq, sz, isRetransmission, SENDER);
398  }
399  else
400  {
401  NS_FATAL_ERROR ("Closed socket, but not recognized");
402  }
403 }
404 
405 void
407  const Ptr<const TcpSocketBase> tcp)
408 {
409  if (tcp->GetNode () == m_receiverSocket->GetNode ())
410  {
411  AfterRTOExpired (tcb, RECEIVER);
412  }
413  else if (tcp->GetNode () == m_senderSocket->GetNode ())
414  {
415  AfterRTOExpired (tcb, SENDER);
416  }
417  else
418  {
419  NS_FATAL_ERROR ("Closed socket, but not recognized");
420  }
421 }
422 
423 void
425  const Ptr<const TcpSocketBase> tcp)
426 {
427  if (tcp->GetNode () == m_receiverSocket->GetNode ())
428  {
429  BeforeRTOExpired (tcb, RECEIVER);
430  }
431  else if (tcp->GetNode () == m_senderSocket->GetNode ())
432  {
433  BeforeRTOExpired (tcb, SENDER);
434  }
435  else
436  {
437  NS_FATAL_ERROR ("Closed socket, but not recognized");
438  }
439 }
440 
441 void
443 {
444  if (socket->GetNode () == m_receiverSocket->GetNode ())
445  {
446  DataSent (size, RECEIVER);
447  }
448  else if (socket->GetNode () == m_senderSocket->GetNode ())
449  {
450  DataSent (size, SENDER);
451  }
452  else
453  {
454  NS_FATAL_ERROR ("Closed socket, but not recognized");
455  }
456 }
457 
458 void
460 {
461  if (socket->GetNode () == m_receiverSocket->GetNode ())
462  {
464  }
465  else if (socket->GetNode () == m_senderSocket->GetNode ())
466  {
467  ErrorClose (SENDER);
468  }
469  else
470  {
471  NS_FATAL_ERROR ("Closed socket, but not recognized");
472  }
473 }
474 
475 void
477 {
478  NS_LOG_FUNCTION (this << p << h << who);
479 }
480 
481 void
483 {
484  NS_LOG_FUNCTION (this << p << h << who);
485 }
486 
487 void
489  const Ptr<const TcpSocketBase> tcp)
490 {
491  if (tcp->GetNode () == m_receiverSocket->GetNode ())
492  {
493  RcvAck (tcp->m_tcb, h, RECEIVER);
494  }
495  else if (tcp->GetNode () == m_senderSocket->GetNode ())
496  {
497  RcvAck (tcp->m_tcb, h, SENDER);
498  }
499  else
500  {
501  NS_FATAL_ERROR ("Received ACK but socket not recognized");
502  }
503 }
504 
505 void
507  const TcpHeader &h, const Ptr<const TcpSocketBase> tcp)
508 {
509  if (tcp->GetNode () == m_receiverSocket->GetNode ())
510  {
511  Tx (p, h, RECEIVER);
512  }
513  else if (tcp->GetNode () == m_senderSocket->GetNode ())
514  {
515  Tx (p, h, SENDER);
516  }
517  else
518  {
519  NS_FATAL_ERROR ("Received ACK but socket not recognized");
520  }
521 }
522 
523 void
525  const Ptr<const TcpSocketBase> tcp)
526 {
527  if (tcp->GetNode () == m_receiverSocket->GetNode ())
528  {
529  Rx (p, h, RECEIVER);
530  }
531  else if (tcp->GetNode () == m_senderSocket->GetNode ())
532  {
533  Rx (p, h, SENDER);
534  }
535  else
536  {
537  NS_FATAL_ERROR ("Received ACK but socket not recognized");
538  }
539 }
540 
541 void
544 {
545  if (tcp->GetNode () == m_receiverSocket->GetNode ())
546  {
547  ProcessedAck (tcp->m_tcb, h, RECEIVER);
548  }
549  else if (tcp->GetNode () == m_senderSocket->GetNode ())
550  {
551  ProcessedAck (tcp->m_tcb, h, SENDER);
552  }
553  else
554  {
555  NS_FATAL_ERROR ("Received ACK but socket not recognized");
556  }
557 }
558 
559 void
561 {
562  NS_LOG_FUNCTION (this << tcp);
563 
564  m_receiverSocket = tcp;
565 }
566 
567 uint32_t
569 {
570  if (who == SENDER)
571  {
572  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_retxThresh;
573  }
574  else if (who == RECEIVER)
575  {
576  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_retxThresh;
577  }
578  else
579  {
580  NS_FATAL_ERROR ("Not defined");
581  }
582 }
583 
584 uint32_t
586 {
587  if (who == SENDER)
588  {
589  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_dupAckCount;
590  }
591  else if (who == RECEIVER)
592  {
593  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_dupAckCount;
594  }
595  else
596  {
597  NS_FATAL_ERROR ("Not defined");
598  }
599 }
600 
601 uint32_t
603 {
604  if (who == SENDER)
605  {
606  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_delAckMaxCount;
607  }
608  else if (who == RECEIVER)
609  {
610  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_delAckMaxCount;
611  }
612  else
613  {
614  NS_FATAL_ERROR ("Not defined");
615  }
616 }
617 
618 Time
620 {
621  if (who == SENDER)
622  {
623  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetDelAckTimeout ();
624  }
625  else if (who == RECEIVER)
626  {
627  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetDelAckTimeout ();
628  }
629  else
630  {
631  NS_FATAL_ERROR ("Not defined");
632  }
633 }
634 
635 uint32_t
637 {
638  if (who == SENDER)
639  {
640  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetSegSize ();
641  }
642  else if (who == RECEIVER)
643  {
644  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetSegSize ();
645  }
646  else
647  {
648  NS_FATAL_ERROR ("Not defined");
649  }
650 }
651 
654 {
655  return GetTcb (who)->m_highTxMark;
656 }
657 
658 uint32_t
660 {
661  if (who == SENDER)
662  {
663  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetInitialCwnd ();
664  }
665  else if (who == RECEIVER)
666  {
667  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetInitialCwnd ();
668  }
669  else
670  {
671  NS_FATAL_ERROR ("Not defined");
672  }
673 }
674 
675 uint32_t
677 {
678  if (who == SENDER)
679  {
680  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->GetInitialSSThresh ();
681  }
682  else if (who == RECEIVER)
683  {
684  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->GetInitialSSThresh ();
685  }
686  else
687  {
688  NS_FATAL_ERROR ("Not defined");
689  }
690 }
691 
692 Time
694 {
695  if (who == SENDER)
696  {
697  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rto.Get ();
698  }
699  else if (who == RECEIVER)
700  {
701  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rto.Get ();
702  }
703  else
704  {
705  NS_FATAL_ERROR ("Not defined");
706  }
707 }
708 
709 Time
711 {
712  if (who == SENDER)
713  {
714  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_minRto;
715  }
716  else if (who == RECEIVER)
717  {
718  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_minRto;
719  }
720  else
721  {
722  NS_FATAL_ERROR ("Not defined");
723  }
724 }
725 
726 Time
728 {
729  if (who == SENDER)
730  {
731  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_cnTimeout;
732  }
733  else if (who == RECEIVER)
734  {
735  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_cnTimeout;
736  }
737  else
738  {
739  NS_FATAL_ERROR ("Not defined");
740  }
741 }
742 
745 {
746  if (who == SENDER)
747  {
748  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rtt;
749  }
750  else if (who == RECEIVER)
751  {
752  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rtt;
753  }
754  else
755  {
756  NS_FATAL_ERROR ("Not defined");
757  }
758 }
759 
760 Time
762 {
763  if (who == SENDER)
764  {
765  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_clockGranularity;
766  }
767  else if (who == RECEIVER)
768  {
769  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_clockGranularity;
770  }
771  else
772  {
773  NS_FATAL_ERROR ("Not defined");
774  }
775 }
776 
779 {
780  if (who == SENDER)
781  {
782  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_state.Get ();
783  }
784  else if (who == RECEIVER)
785  {
786 
787  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_state.Get ();
788  }
789  else
790  {
791  NS_FATAL_ERROR ("Not defined");
792  }
793 }
794 
795 uint32_t
797 {
798  if (who == SENDER)
799  {
800  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_rWnd.Get ();
801  }
802  else if (who == RECEIVER)
803  {
804 
805  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_rWnd.Get ();
806  }
807  else
808  {
809  NS_FATAL_ERROR ("Not defined");
810  }
811 }
812 
813 EventId
815 {
816  if (who == SENDER)
817  {
818  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_persistEvent;
819  }
820  else if (who == RECEIVER)
821  {
822 
823  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_persistEvent;
824  }
825  else
826  {
827  NS_FATAL_ERROR ("Not defined");
828  }
829 }
830 
831 Time
833 {
834  if (who == SENDER)
835  {
836  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_persistTimeout;
837  }
838  else if (who == RECEIVER)
839  {
840 
841  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_persistTimeout;
842  }
843  else
844  {
845  NS_FATAL_ERROR ("Not defined");
846  }
847 }
848 
851 {
852  if (who == SENDER)
853  {
854  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_tcb;
855  }
856  else if (who == RECEIVER)
857  {
858 
859  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_tcb;
860  }
861  else
862  {
863  NS_FATAL_ERROR ("Not defined");
864  }
865 }
866 
869 {
870  if (who == SENDER)
871  {
872  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_tcb->m_rxBuffer;
873  }
874  else if (who == RECEIVER)
875  {
876 
877  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_tcb->m_rxBuffer;
878  }
879  else
880  {
881  NS_FATAL_ERROR ("Not defined");
882  }
883 }
884 
887  {
888  if (who == SENDER)
889  {
890  return DynamicCast<TcpSocketMsgBase> (m_senderSocket)->m_txBuffer;
891  }
892  else if (who == RECEIVER)
893  {
894  return DynamicCast<TcpSocketMsgBase> (m_receiverSocket)->m_txBuffer;
895  }
896  else
897  {
898  NS_FATAL_ERROR ("Not defined");
899  }
900  }
901 
902 
903 void
905 {
906  if (who == SENDER)
907  {
908  m_senderSocket->SetRcvBufSize (size);
909  }
910  else if (who == RECEIVER)
911  {
912  m_receiverSocket->SetRcvBufSize (size);
913  }
914  else
915  {
916  NS_FATAL_ERROR ("Not defined");
917  }
918 }
919 
920 void
922 {
923  if (who == SENDER)
924  {
925  m_senderSocket->SetSegSize (segmentSize);
926  }
927  else if (who == RECEIVER)
928  {
929  m_receiverSocket->SetSegSize (segmentSize);
930  }
931  else
932  {
933  NS_FATAL_ERROR ("Not defined");
934  }
935 }
936 
937 void
938 TcpGeneralTest::SetInitialCwnd (SocketWho who, uint32_t initialCwnd)
939 {
940  if (who == SENDER)
941  {
942  m_senderSocket->SetInitialCwnd (initialCwnd);
943  }
944  else if (who == RECEIVER)
945  {
946  m_receiverSocket->SetInitialCwnd (initialCwnd);
947  }
948  else
949  {
950  NS_FATAL_ERROR ("Not defined");
951  }
952 }
953 void
955 {
956  if (who == SENDER)
957  {
958  m_senderSocket->SetDelAckMaxCount (count);
959  }
960  else if (who == RECEIVER)
961  {
962  m_receiverSocket->SetDelAckMaxCount (count);
963  }
964  else
965  {
966  NS_FATAL_ERROR ("Not defined");
967  }
968 }
969 void
971 {
972  if (who == SENDER)
973  {
974  m_senderSocket->SetUseEcn (useEcn);
975  }
976  else if (who == RECEIVER)
977  {
978  m_receiverSocket->SetUseEcn (useEcn);
979  }
980  else
981  {
982  NS_FATAL_ERROR ("Not defined");
983  }
984 }
985 
986 void
988 {
989  if (who == SENDER)
990  {
991  m_senderSocket->SetPacingStatus (pacing);
992  }
993  else if (who == RECEIVER)
994  {
995  m_receiverSocket->SetPacingStatus (pacing);
996  }
997  else
998  {
999  NS_FATAL_ERROR ("Not defined");
1000  }
1001 }
1002 
1003 void
1005 {
1006  if (who == SENDER)
1007  {
1008  m_senderSocket->SetPaceInitialWindow (paceWindow);
1009  }
1010  else if (who == RECEIVER)
1011  {
1012  m_receiverSocket->SetPaceInitialWindow (paceWindow);
1013  }
1014  else
1015  {
1016  NS_FATAL_ERROR ("Not defined");
1017  }
1018 }
1019 
1020 void
1021 TcpGeneralTest::SetInitialSsThresh (SocketWho who, uint32_t initialSsThresh)
1022 {
1023  if (who == SENDER)
1024  {
1025  m_senderSocket->SetInitialSSThresh (initialSsThresh);
1026  }
1027  else if (who == RECEIVER)
1028  {
1029  m_receiverSocket->SetInitialSSThresh (initialSsThresh);
1030  }
1031  else
1032  {
1033  NS_FATAL_ERROR ("Not defined");
1034  }
1035 }
1036 
1038 
1039 TypeId
1041 {
1042  static TypeId tid = TypeId ("ns3::TcpSocketMsgBase")
1044  .SetGroupName ("Internet")
1045  .AddConstructor<TcpSocketMsgBase> ()
1046  ;
1047  return tid;
1048 }
1049 
1052 {
1053  return CopyObject<TcpSocketMsgBase> (this);
1054 }
1055 
1056 void
1058 {
1059  NS_ASSERT (!cb.IsNull ());
1060  m_rcvAckCb = cb;
1061 }
1062 
1063 void
1065 {
1066  NS_ASSERT (!cb.IsNull ());
1067  m_processedAckCb = cb;
1068 }
1069 
1070 void
1072 {
1073  NS_ASSERT (!cb.IsNull ());
1074  m_afterRetrCallback = cb;
1075 }
1076 
1077 void
1079 {
1080  NS_ASSERT (!cb.IsNull ());
1081  m_beforeRetrCallback = cb;
1082 }
1083 
1084 void
1086 {
1088  m_rcvAckCb (packet, tcpHeader, this);
1089 
1090  TcpSocketBase::ReceivedAck (packet, tcpHeader);
1091 
1092  m_processedAckCb (packet, tcpHeader, this);
1093 }
1094 
1095 void
1097 {
1098  m_beforeRetrCallback (m_tcb, this);
1100  m_afterRetrCallback (m_tcb, this);
1101 }
1102 
1103 void
1105 {
1106  NS_ASSERT (!cb.IsNull ());
1107  m_forkCb = cb;
1108 }
1109 
1110 void
1112 {
1113  NS_ASSERT (!cb.IsNull ());
1114  m_updateRttCb = cb;
1115 }
1116 
1117 void
1119  bool isRetransmission)
1120 {
1121  TcpSocketBase::UpdateRttHistory (seq, sz, isRetransmission);
1122  if (!m_updateRttCb.IsNull ())
1123  {
1124  m_updateRttCb (this, seq, sz, isRetransmission);
1125  }
1126 }
1127 
1128 void
1130  const Address &fromAddress, const Address &toAddress)
1131 {
1132  TcpSocketBase::CompleteFork (p, tcpHeader, fromAddress, toAddress);
1133 
1134  if (!m_forkCb.IsNull ())
1135  {
1136  m_forkCb (this);
1137  }
1138 }
1139 
1141 
1142 TypeId
1144 {
1145  static TypeId tid = TypeId ("ns3::TcpSocketSmallAcks")
1147  .SetGroupName ("Internet")
1148  .AddConstructor<TcpSocketSmallAcks> ()
1149  ;
1150  return tid;
1151 }
1152 
1153 /*
1154  * Send empty packet, copied/pasted from TcpSocketBase
1155  *
1156  * The rationale for copying/pasting is that we need to edit a little the
1157  * code inside. Since there isn't a well-defined division of duties,
1158  * we are forced to do this.
1159  */
1160 void
1162 {
1163  Ptr<Packet> p = Create<Packet> ();
1164  TcpHeader header;
1166 
1167  /*
1168  * Add tags for each socket option.
1169  * Note that currently the socket adds both IPv4 tag and IPv6 tag
1170  * if both options are set. Once the packet got to layer three, only
1171  * the corresponding tags will be read.
1172  */
1173  if (GetIpTos ())
1174  {
1175  SocketIpTosTag ipTosTag;
1176  ipTosTag.SetTos (GetIpTos ());
1177  p->AddPacketTag (ipTosTag);
1178  }
1179 
1180  if (IsManualIpv6Tclass ())
1181  {
1182  SocketIpv6TclassTag ipTclassTag;
1183  ipTclassTag.SetTclass (GetIpv6Tclass ());
1184  p->AddPacketTag (ipTclassTag);
1185  }
1186 
1187  if (IsManualIpTtl ())
1188  {
1189  SocketIpTtlTag ipTtlTag;
1190  ipTtlTag.SetTtl (GetIpTtl ());
1191  p->AddPacketTag (ipTtlTag);
1192  }
1193 
1194  if (IsManualIpv6HopLimit ())
1195  {
1196  SocketIpv6HopLimitTag ipHopLimitTag;
1197  ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
1198  p->AddPacketTag (ipHopLimitTag);
1199  }
1200 
1201  if (m_endPoint == nullptr && m_endPoint6 == nullptr)
1202  {
1203  NS_LOG_WARN ("Failed to send empty packet due to null endpoint");
1204  return;
1205  }
1206  if (flags & TcpHeader::FIN)
1207  {
1208  flags |= TcpHeader::ACK;
1209  }
1210  else if (m_state == FIN_WAIT_1 || m_state == LAST_ACK || m_state == CLOSING)
1211  {
1212  ++s;
1213  }
1214 
1215  bool hasSyn = flags & TcpHeader::SYN;
1216  bool hasFin = flags & TcpHeader::FIN;
1217  bool isAck = flags == TcpHeader::ACK;
1218 
1219  header.SetFlags (flags);
1220  header.SetSequenceNumber (s);
1221 
1222  // Actual division in small acks.
1223  if (hasSyn || hasFin)
1224  {
1225  header.SetAckNumber (m_tcb->m_rxBuffer->NextRxSequence ());
1226  }
1227  else
1228  {
1229  SequenceNumber32 ackSeq;
1230 
1231  ackSeq = m_lastAckedSeq + m_bytesToAck;
1232 
1233  if (m_bytesLeftToBeAcked == 0 && m_tcb->m_rxBuffer->NextRxSequence () > m_lastAckedSeq)
1234  {
1235  m_bytesLeftToBeAcked = m_tcb->m_rxBuffer->NextRxSequence ().GetValue () - m_lastAckedSeq.GetValue ();
1237  NS_LOG_DEBUG ("Setting m_bytesLeftToBeAcked to " << m_bytesLeftToBeAcked);
1238  }
1239  else if (m_bytesLeftToBeAcked > 0 && m_tcb->m_rxBuffer->NextRxSequence () > m_lastAckedSeq)
1240  {
1242  NS_LOG_DEBUG ("Decrementing m_bytesLeftToBeAcked to " << m_bytesLeftToBeAcked);
1243  }
1244 
1245  NS_LOG_LOGIC ("Acking up to " << ackSeq << " remaining bytes: " << m_bytesLeftToBeAcked);
1246 
1247  header.SetAckNumber (ackSeq);
1248  m_lastAckedSeq = ackSeq;
1249  }
1250 
1251  // end of division in small acks
1252 
1253  if (m_endPoint != nullptr)
1254  {
1255  header.SetSourcePort (m_endPoint->GetLocalPort ());
1257  }
1258  else
1259  {
1260  header.SetSourcePort (m_endPoint6->GetLocalPort ());
1262  }
1263  AddOptions (header);
1264  header.SetWindowSize (AdvertisedWindowSize ());
1265 
1266  // RFC 6298, clause 2.4
1267  m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation () * 4), m_minRto);
1268 
1269  if (hasSyn)
1270  {
1271  if (m_synCount == 0)
1272  { // No more connection retries, give up
1273  NS_LOG_LOGIC ("Connection failed.");
1274  m_rtt->Reset (); //According to recommendation -> RFC 6298
1275  CloseAndNotify ();
1276  return;
1277  }
1278  else
1279  { // Exponential backoff of connection time out
1280  int backoffCount = 0x1 << (m_synRetries - m_synCount);
1281  m_rto = m_cnTimeout * backoffCount;
1282  m_synCount--;
1283  }
1284  }
1285  if (m_endPoint != nullptr)
1286  {
1287  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
1289  }
1290  else
1291  {
1292  m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
1294  }
1295 
1296  m_txTrace (p, header, this);
1297 
1298  if (flags & TcpHeader::ACK)
1299  { // If sending an ACK, cancel the delay ACK as well
1300  m_delAckEvent.Cancel ();
1301  m_delAckCount = 0;
1302  }
1303  if (m_retxEvent.IsExpired () && (hasSyn || hasFin) && !isAck )
1304  { // Retransmit SYN / SYN+ACK / FIN / FIN+ACK to guard against lost
1305  NS_LOG_LOGIC ("Schedule retransmission timeout at time "
1306  << Simulator::Now ().GetSeconds () << " to expire at time "
1307  << (Simulator::Now () + m_rto.Get ()).GetSeconds ());
1309  }
1310 
1311  // send another ACK if bytes remain
1312  if (m_bytesLeftToBeAcked > m_bytesToAck && m_tcb->m_rxBuffer->NextRxSequence () > m_lastAckedSeq && !hasFin)
1313  {
1314  NS_LOG_DEBUG ("Recursing to call SendEmptyPacket() again with m_bytesLeftToBeAcked = " << m_bytesLeftToBeAcked);
1315  SendEmptyPacket (flags);
1316  }
1317 }
1318 
1321 {
1322  return CopyObject<TcpSocketSmallAcks> (this);
1323 }
1324 
a polymophic address class
Definition: address.h:91
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
An identifier for simulation events.
Definition: event-id.h:54
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
static Ipv4Address GetAny(void)
uint16_t GetPeerPort(void)
Get the peer port.
Ipv4Address GetPeerAddress(void)
Get the peer address.
uint16_t GetLocalPort(void)
Get the local port.
Ipv4Address GetLocalAddress(void)
Get the local address.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Ipv6Address GetLocalAddress()
Get the local address.
uint16_t GetLocalPort()
Get the local port.
Ipv6Address GetPeerAddress()
Get the peer address.
uint16_t GetPeerPort()
Get the peer port.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
static void EnablePrinting(void)
Enable printing packets metadata.
Definition: packet.cc:572
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Base class for all RTT Estimators.
Definition: rtt-estimator.h:43
static TypeId GetTypeId(void)
Get the type ID.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
build a set of SimpleNetDevice objects
void SetNetDevicePointToPointMode(bool pointToPointMode)
SimpleNetDevice is Broadcast capable and ARP needing.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:383
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:495
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:377
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:1077
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:520
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:545
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
virtual int Close(void)=0
Close a socket.
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
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:371
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:453
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.
indicates whether the socket has IP_TOS set.
Definition: socket.h:1263
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:785
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition: socket.h:1117
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:604
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition: socket.h:1165
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:665
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1356
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:900
The Classic recovery implementation.
Congestion control abstract class.
Ptr< RttEstimator > GetRttEstimator(SocketWho who)
Get the Rtt estimator of the socket.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
void ErrorCloseCb(Ptr< Socket > socket)
Error Close Callback.
virtual void ErrorClose([[maybe_unused]] SocketWho who)
Socket closed with an error.
virtual void RcvAck([[maybe_unused]] const Ptr< const TcpSocketState > tcb, [[maybe_unused]] const TcpHeader &h, [[maybe_unused]] SocketWho who)
Received ack.
virtual void QueueDrop([[maybe_unused]] SocketWho who)
Drop on the queue.
virtual void CWndTrace([[maybe_unused]] uint32_t oldValue, [[maybe_unused]] uint32_t newValue)
Tracks the congestion window changes.
TypeId m_recoveryTypeId
Recovery.
uint32_t GetDelAckCount(SocketWho who)
Get the number of delayed ack (if present)
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
virtual void ProcessedAck([[maybe_unused]] const Ptr< const TcpSocketState > tcb, [[maybe_unused]] const TcpHeader &h, [[maybe_unused]] SocketWho who)
Processed ack.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
void SetDelAckMaxCount(SocketWho who, uint32_t count)
Forcefully set the delayed acknowledgement count.
virtual void RateSampleUpdatedTrace([[maybe_unused]] const TcpRateLinux::TcpRateSample &sample)
Track the rate sample value of TcpRateLinux.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
void BeforeRetransmitCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
Invoked before a retransmit event.
Ptr< TcpTxBuffer > GetTxBuffer(SocketWho who)
Get the Tx buffer from selected socket.
virtual void HighestTxSeqTrace([[maybe_unused]] SequenceNumber32 oldValue, [[maybe_unused]] SequenceNumber32 newValue)
Highest tx seq changes.
virtual void UpdatedRttHistory([[maybe_unused]] const SequenceNumber32 &seq, [[maybe_unused]] uint32_t sz, [[maybe_unused]] bool isRetransmission, [[maybe_unused]] SocketWho who)
Updated the Rtt history.
void TxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Tx packet Callback.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
void SetCongestionControl(TypeId congControl)
Congestion control of the sender socket.
uint32_t m_mtu
MTU of the environment.
virtual void RttTrace([[maybe_unused]] Time oldTime, [[maybe_unused]] Time newTime)
Rtt changes.
Time GetMinRto(SocketWho who)
Get the minimum RTO attribute.
Ptr< TcpSocketState > GetTcb(SocketWho who)
Get the TCB from selected socket.
void SetRcvBufSize(SocketWho who, uint32_t size)
Forcefully set a defined size for rx buffer.
virtual void ConfigureProperties(void)
Change the configuration of the socket properties.
Time m_interPacketInterval
Time between sending application packet down to tcp socket.
uint32_t m_pktSize
Size of the application packet.
EventId GetPersistentEvent(SocketWho who)
Get the persistent event of the selected socket.
uint32_t m_pktCount
Count of the application packet.
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an accept connection.
void QueueDropCb(std::string context, Ptr< const Packet > p)
Queue Drop Callback.
void ForkCb(Ptr< TcpSocketMsgBase > tcp)
Fork Callback.
uint32_t GetReTxThreshold(SocketWho who)
Get the retransmission threshold.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
void RxPacketCb(const Ptr< const Packet > p, const TcpHeader &h, const Ptr< const TcpSocketBase > tcp)
Rx packet Callback.
virtual void BytesInFlightTrace([[maybe_unused]] uint32_t oldValue, [[maybe_unused]] uint32_t newValue)
Bytes in flight changes.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
uint32_t GetDupAckCount(SocketWho who)
Get the number of dupack received.
void SetPaceInitialWindow(SocketWho who, bool paceWindow)
Enable or disable pacing of the initial window.
uint32_t GetInitialSsThresh(SocketWho who)
Get the initial slow start threshold.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual void NextTxSeqTrace([[maybe_unused]] SequenceNumber32 oldValue, [[maybe_unused]] SequenceNumber32 newValue)
Next tx seq changes.
virtual void DoRun(void)
Execute the tcp test.
virtual Ptr< SimpleChannel > CreateChannel()
Create and return the channel installed between the two socket.
virtual void DataSent([[maybe_unused]] uint32_t size, [[maybe_unused]] SocketWho who)
Notifying application for sent data.
Time GetDelAckTimeout(SocketWho who)
Get the timeout of delayed ack (if present)
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
Time GetClockGranularity(SocketWho who)
Get the clock granularity attribute.
void SetUseEcn(SocketWho who, TcpSocketState::UseEcn_t useEcn)
Forcefully set the ECN mode of use.
Time m_startTime
Data transmission time.
Ptr< TcpSocketMsgBase > m_senderSocket
Pointer to sender socket.
void DoConnect()
Scheduled at 0.0, SENDER starts the connection to RECEIVER.
Time GetRto(SocketWho who)
Get the retransmission time.
Ptr< TcpRxBuffer > GetRxBuffer(SocketWho who)
Get the Rx buffer from selected socket.
Time GetConnTimeout(SocketWho who)
Get the retransmission time for the SYN segments.
void AfterRetransmitCb(const Ptr< const TcpSocketState > tcb, const Ptr< const TcpSocketBase > tcp)
Invoked after a retransmit event.
void SetAppPktInterval(Time pktInterval)
Interval between app-generated packet.
uint32_t GetRWnd(SocketWho who)
Get the rWnd of the selected socket.
void PhyDropCb(std::string context, Ptr< const Packet > p)
Drop at Phy layer Callback.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
TypeId m_congControlTypeId
Congestion control.
virtual void ReceivePacket(Ptr< Socket > socket)
Packet received.
void DataSentCb(Ptr< Socket > socket, uint32_t size)
Data sent Callback.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
virtual void PhyDrop([[maybe_unused]] SocketWho who)
Link drop.
void SendPacket(Ptr< Socket > socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
Send packets to other endpoint.
virtual void NormalClose([[maybe_unused]] SocketWho who)
Socket closed normally.
virtual void SsThreshTrace([[maybe_unused]] uint32_t oldValue, [[maybe_unused]] uint32_t newValue)
Slow start threshold changes.
void NormalCloseCb(Ptr< Socket > socket)
Normal Close Callback.
virtual void ConfigureEnvironment(void)
Change the configuration of the environment.
Time m_propagationDelay
Propagation delay of the channel.
void RcvAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
Receive ACK Callback.
TcpSocket::TcpStates_t GetTcpState(SocketWho who)
Get the state of the TCP state machine.
void SetInitialSsThresh(SocketWho who, uint32_t initialSsThresh)
Forcefully set the initial ssthresh.
SequenceNumber32 GetHighestTxMark(SocketWho who)
Get the highest tx mark of the node specified.
virtual void CongStateTrace([[maybe_unused]] const TcpSocketState::TcpCongState_t oldValue, [[maybe_unused]] const TcpSocketState::TcpCongState_t newValue)
State on Ack state machine changes.
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
Time GetPersistentTimeout(SocketWho who)
Get the persistent timeout of the selected socket.
void SetRecoveryAlgorithm(TypeId recovery)
recovery algorithm of the sender socket
virtual void BeforeRTOExpired([[maybe_unused]] const Ptr< const TcpSocketState > tcb, [[maybe_unused]] SocketWho who)
Rto has expired.
virtual void DoTeardown(void)
Teardown the TCP test.
virtual void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet transmitted down to IP layer.
virtual void RateUpdatedTrace([[maybe_unused]] const TcpRateLinux::TcpRateConnection &rate)
Track the rate value of TcpRateLinux.
void SetPacingStatus(SocketWho who, bool pacing)
Enable or disable pacing in the TCP socket.
Ptr< TcpSocketMsgBase > m_receiverSocket
Pointer to receiver socket.
virtual Ptr< ErrorModel > CreateSenderErrorModel()
Create and return the error model to install in the sender node.
uint32_t GetInitialCwnd(SocketWho who)
Get the initial congestion window.
TcpGeneralTest(const std::string &desc)
TcpGeneralTest constructor.
void UpdateRttHistoryCb(Ptr< const TcpSocketBase > tcp, const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update RTT with new data.
virtual void RtoTrace([[maybe_unused]] Time oldValue, [[maybe_unused]] Time newValue)
RTO changes.
void ProcessedAckCb(Ptr< const Packet > p, const TcpHeader &h, Ptr< const TcpSocketBase > tcp)
ACK processed Callback.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
virtual void CWndInflTrace([[maybe_unused]] uint32_t oldValue, [[maybe_unused]] uint32_t newValue)
Tracks the inflated congestion window changes.
InetSocketAddress m_remoteAddr
Remote peer address.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
virtual void AfterRTOExpired([[maybe_unused]] const Ptr< const TcpSocketState > tcb, [[maybe_unused]] SocketWho who)
Rto has expired.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:45
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition: tcp-header.cc:95
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition: tcp-header.cc:101
void SetFlags(uint8_t flags)
Set flags of the header.
Definition: tcp-header.cc:113
void SetWindowSize(uint16_t windowSize)
Set the window size.
Definition: tcp-header.cc:119
void SetSourcePort(uint16_t port)
Set the source port.
Definition: tcp-header.cc:89
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition: tcp-header.cc:107
TCP socket creation and multiplexing/demultiplexing.
The NewReno implementation.
recovery abstract class
A base class for implementation of a stream socket using TCP.
void CloseAndNotify(void)
Peacefully close the socket by notifying the upper layer and deallocate end point.
Time m_minRto
minimum value of the Retransmit timeout
TracedCallback< Ptr< const Packet >, const TcpHeader &, Ptr< const TcpSocketBase > > m_txTrace
Trace of transmitted packets.
Ptr< TcpL4Protocol > m_tcp
the associated TCP L4 protocol
Ptr< TcpSocketState > m_tcb
Congestion control information.
TracedValue< Time > m_rto
Retransmit timeout.
EventId m_delAckEvent
Delayed ACK timeout event.
void AddOptions(TcpHeader &tcpHeader)
Add options to TcpHeader.
TracedValue< TcpStates_t > m_state
TCP state.
Ptr< RttEstimator > m_rtt
Round trip time estimator.
virtual void ReTxTimeout(void)
An RTO event happened.
EventId m_retxEvent
Retransmission event.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
uint32_t m_delAckCount
Delayed ACK counter.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
Time m_cnTimeout
Timeout for connection retry.
Time m_clockGranularity
Clock Granularity used in RTO calcs.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
uint32_t m_synRetries
Number of connection attempts.
uint32_t m_synCount
Count of remaining connection retries.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
Class for inserting callbacks special points of the flow of TCP sockets.
UpdateRttCallback m_updateRttCb
Update RTT callback.
virtual void UpdateRttHistory(const SequenceNumber32 &seq, uint32_t sz, bool isRetransmission)
Update the RTT history, when we send TCP segments.
AckManagementCb m_processedAckCb
Processed ACK callback.
virtual void CompleteFork(Ptr< Packet > p, const TcpHeader &tcpHeader, const Address &fromAddress, const Address &toAddress)
Complete a connection by forking the socket.
void SetAfterRetransmitCb(RetrCb cb)
Set the callback invoked after the processing of a retransmit timeout.
void SetForkCb(Callback< void, Ptr< TcpSocketMsgBase > > cb)
Set the callback invoked after the forking.
void SetRcvAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received (at the beginning of the processing)
AckManagementCb m_rcvAckCb
Receive ACK callback.
virtual Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
void SetProcessedAckCb(AckManagementCb cb)
Set the callback invoked when an ACK is received and processed (at the end of the processing)
void SetBeforeRetransmitCb(RetrCb cb)
Set the callback invoked before the processing of a retransmit timeout.
virtual void ReceivedAck(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Received an ACK packet.
RetrCb m_beforeRetrCallback
Before retransmission callback.
Callback< void, Ptr< TcpSocketMsgBase > > m_forkCb
Fork callback.
RetrCb m_afterRetrCallback
After retransmission callback.
static TypeId GetTypeId(void)
Get the type ID.
virtual void ReTxTimeout(void)
An RTO event happened.
void SetUpdateRttHistoryCb(UpdateRttCallback cb)
Set the callback invoked when we update rtt history.
A TCP socket which sends ACKs smaller than the segment received.
static TypeId GetTypeId(void)
Get the type ID.
SequenceNumber32 m_lastAckedSeq
Last sequence number ACKed.
uint32_t m_bytesToAck
Number of bytes to be ACKed.
Ptr< TcpSocketBase > Fork(void)
Call CopyObject<> to clone me.
virtual void SendEmptyPacket(uint8_t flags)
Send a empty packet that carries a flag, e.g., ACK.
uint32_t m_bytesLeftToBeAcked
Number of bytes to be ACKed left.
TracedValue< SequenceNumber32 > m_highTxMark
Highest seqno ever sent, regardless of ReTx.
UseEcn_t
Parameter value related to ECN enable/disable functionality similar to sysctl for tcp_ecn.
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
encapsulates test code
Definition: test.h:994
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
AttributeValue implementation for Time.
Definition: nstime.h:1308
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
uint32_t segmentSize
#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
Callback< R, Ts... > MakeNullCallback(void)
Definition: callback.h:1688
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:230
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
TcpStates_t
Names of the 11 TCP states.
Definition: tcp-socket.h:65
@ FIN_WAIT_1
Our side has shutdown, waiting to complete transmission of remaining buffered data
Definition: tcp-socket.h:78
@ LAST_ACK
Our side has shutdown after remote has shutdown.
Definition: tcp-socket.h:75
@ CLOSING
Both sides have shutdown but we still have data we have to finish sending
Definition: tcp-socket.h:81
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
channel
Definition: third.py:92
uint32_t pktSize
packet size used for the simulation (in bytes)
Definition: wifi-bianchi.cc:89