View | Details | Raw Unified | Return to bug 2302
Collapse All | Expand All

(-)a/src/internet/test/tcp-general-test.cc (-16 / +55 lines)
 Lines 41-57   TcpGeneralTest::TcpGeneralTest (const std::string &desc, Link Here 
41
                                TypeId congestionControl,
41
                                TypeId congestionControl,
42
                                uint32_t mtu)
42
                                uint32_t mtu)
43
  : TestCase (desc),
43
  : TestCase (desc),
44
  m_congControlTypeId (congestionControl),
44
    m_congControlTypeId (congestionControl),
45
  m_propagationDelay (propagationDelay),
45
    m_propagationDelay (propagationDelay),
46
  m_startTime (startTime),
46
    m_startTime (startTime),
47
  m_mtu (mtu),
47
    m_mtu (mtu),
48
  m_pktSize (pktSize),
48
    m_pktSize (pktSize),
49
  m_pktCount (pktCount),
49
    m_pktCount (pktCount),
50
  m_interPacketInterval (pktInterval),
50
    m_interPacketInterval (pktInterval),
51
  m_initialSlowStartThresh (initialSlowStartThresh),
51
    m_initialSlowStartThresh (initialSlowStartThresh),
52
  m_initialCwnd (initialCwnd),
52
    m_initialCwnd (initialCwnd),
53
  m_segmentSize (segmentSize),
53
    m_segmentSize (segmentSize),
54
  m_remoteAddr (Ipv4Address::GetAny (), 4477)
54
    m_remoteAddr (Ipv4Address::GetAny (), 4477)
55
{
55
{
56
  NS_LOG_FUNCTION (this << desc);
56
  NS_LOG_FUNCTION (this << desc);
57
}
57
}
 Lines 164-169   TcpGeneralTest::DoRun (void) Link Here 
164
  m_receiverSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
164
  m_receiverSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
165
  m_receiverSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
165
  m_receiverSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
166
  m_receiverSocket->SetForkCb (MakeCallback (&TcpGeneralTest::ForkCb, this));
166
  m_receiverSocket->SetForkCb (MakeCallback (&TcpGeneralTest::ForkCb, this));
167
  m_receiverSocket->SetUpdateRttHistoryCb (MakeCallback (&TcpGeneralTest::UpdateRttHistoryCb, this));
167
  m_receiverSocket->TraceConnectWithoutContext ("Tx",
168
  m_receiverSocket->TraceConnectWithoutContext ("Tx",
168
                                                MakeCallback (&TcpGeneralTest::TxPacketCb, this));
169
                                                MakeCallback (&TcpGeneralTest::TxPacketCb, this));
169
  m_receiverSocket->TraceConnectWithoutContext ("Rx",
170
  m_receiverSocket->TraceConnectWithoutContext ("Rx",
 Lines 180-186   TcpGeneralTest::DoRun (void) Link Here 
180
  m_senderSocket->SetRcvAckCb (MakeCallback (&TcpGeneralTest::RcvAckCb, this));
181
  m_senderSocket->SetRcvAckCb (MakeCallback (&TcpGeneralTest::RcvAckCb, this));
181
  m_senderSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
182
  m_senderSocket->SetProcessedAckCb (MakeCallback (&TcpGeneralTest::ProcessedAckCb, this));
182
  m_senderSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
183
  m_senderSocket->SetRetransmitCb (MakeCallback (&TcpGeneralTest::RtoExpiredCb, this));
183
  m_senderSocket->SetDataSentCallback(MakeCallback (&TcpGeneralTest::DataSentCb, this));
184
  m_senderSocket->SetUpdateRttHistoryCb (MakeCallback (&TcpGeneralTest::UpdateRttHistoryCb, this));
185
  m_senderSocket->SetDataSentCallback (MakeCallback (&TcpGeneralTest::DataSentCb, this));
184
  m_senderSocket->TraceConnectWithoutContext ("CongestionWindow",
186
  m_senderSocket->TraceConnectWithoutContext ("CongestionWindow",
185
                                              MakeCallback (&TcpGeneralTest::CWndTrace, this));
187
                                              MakeCallback (&TcpGeneralTest::CWndTrace, this));
186
  m_senderSocket->TraceConnectWithoutContext ("CongState",
188
  m_senderSocket->TraceConnectWithoutContext ("CongState",
 Lines 337-342   TcpGeneralTest::NormalCloseCb (Ptr<Socket> socket) Link Here 
337
}
339
}
338
340
339
void
341
void
342
TcpGeneralTest::UpdateRttHistoryCb (Ptr<const TcpSocketBase> tcp,
343
                                    const SequenceNumber32 & seq, uint32_t sz,
344
                                    bool isRetransmission)
345
{
346
  if (tcp->GetNode () == m_receiverSocket->GetNode ())
347
    {
348
      UpdatedRttHistory (seq, sz, isRetransmission, RECEIVER);
349
    }
350
  else if (tcp->GetNode () == m_senderSocket->GetNode ())
351
    {
352
      UpdatedRttHistory (seq, sz, isRetransmission, SENDER);
353
    }
354
  else
355
    {
356
      NS_FATAL_ERROR ("Closed socket, but not recognized");
357
    }
358
}
359
360
void
340
TcpGeneralTest::RtoExpiredCb (const Ptr<const TcpSocketState> tcb,
361
TcpGeneralTest::RtoExpiredCb (const Ptr<const TcpSocketState> tcb,
341
                              const Ptr<const TcpSocketBase> tcp)
362
                              const Ptr<const TcpSocketBase> tcp)
342
{
363
{
 Lines 532-538   TcpGeneralTest::GetDelAckCount (SocketWho who) Link Here 
532
}
553
}
533
554
534
Time
555
Time
535
TcpGeneralTest::GetDelAckTimeout(SocketWho who)
556
TcpGeneralTest::GetDelAckTimeout (SocketWho who)
536
{
557
{
537
  if (who == SENDER)
558
  if (who == SENDER)
538
    {
559
    {
 Lines 777-797   TcpSocketMsgBase::Fork (void) Link Here 
777
}
798
}
778
799
779
void
800
void
780
TcpSocketMsgBase::SetRcvAckCb (AckManagementCallback cb)
801
TcpSocketMsgBase::SetRcvAckCb (AckManagementCb cb)
781
{
802
{
782
  NS_ASSERT (!cb.IsNull ());
803
  NS_ASSERT (!cb.IsNull ());
783
  m_rcvAckCb = cb;
804
  m_rcvAckCb = cb;
784
}
805
}
785
806
786
void
807
void
787
TcpSocketMsgBase::SetProcessedAckCb (AckManagementCallback cb)
808
TcpSocketMsgBase::SetProcessedAckCb (AckManagementCb cb)
788
{
809
{
789
  NS_ASSERT (!cb.IsNull ());
810
  NS_ASSERT (!cb.IsNull ());
790
  m_processedAckCb = cb;
811
  m_processedAckCb = cb;
791
}
812
}
792
813
793
void
814
void
794
TcpSocketMsgBase::SetRetransmitCb (RetrCallback cb)
815
TcpSocketMsgBase::SetRetransmitCb (RetrCb cb)
795
{
816
{
796
  NS_ASSERT (!cb.IsNull ());
817
  NS_ASSERT (!cb.IsNull ());
797
  m_retrCallback = cb;
818
  m_retrCallback = cb;
 Lines 824-829   TcpSocketMsgBase::SetForkCb (Callback<void, Ptr<TcpSocketMsgBase> > cb) Link Here 
824
}
845
}
825
846
826
void
847
void
848
TcpSocketMsgBase::SetUpdateRttHistoryCb (UpdateRttCallback cb)
849
{
850
  NS_ASSERT (!cb.IsNull ());
851
  m_updateRttCb = cb;
852
}
853
854
void
855
TcpSocketMsgBase::UpdateRttHistory (const SequenceNumber32 &seq, uint32_t sz,
856
                                    bool isRetransmission)
857
{
858
  TcpSocketBase::UpdateRttHistory (seq, sz, isRetransmission);
859
  if (!m_updateRttCb.IsNull ())
860
    {
861
      m_updateRttCb (this, seq, sz, isRetransmission);
862
    }
863
}
864
865
void
827
TcpSocketMsgBase::CompleteFork (Ptr<Packet> p, const TcpHeader &tcpHeader,
866
TcpSocketMsgBase::CompleteFork (Ptr<Packet> p, const TcpHeader &tcpHeader,
828
                                const Address &fromAddress, const Address &toAddress)
867
                                const Address &fromAddress, const Address &toAddress)
829
{
868
{
(-)a/src/internet/test/tcp-general-test.h (-15 / +41 lines)
 Lines 60-68   public: Link Here 
60
  }
60
  }
61
61
62
  typedef Callback<void, Ptr<const Packet>, const TcpHeader&,
62
  typedef Callback<void, Ptr<const Packet>, const TcpHeader&,
63
                   Ptr<const TcpSocketBase> > AckManagementCallback;
63
                   Ptr<const TcpSocketBase> > AckManagementCb;
64
  typedef Callback<void, Ptr<const TcpSocketState>,
64
  typedef Callback<void, Ptr<const TcpSocketState>,
65
                   Ptr<const TcpSocketBase> > RetrCallback;
65
                   Ptr<const TcpSocketBase> > RetrCb;
66
  typedef Callback<void, Ptr<const TcpSocketBase>, const SequenceNumber32&,
67
                   uint32_t, bool> UpdateRttCallback;
66
68
67
  /**
69
  /**
68
   * \brief Set the callback invoked when an ACK is received (at the beginning
70
   * \brief Set the callback invoked when an ACK is received (at the beginning
 Lines 70-76   public: Link Here 
70
   *
72
   *
71
   * \param cb callback
73
   * \param cb callback
72
   */
74
   */
73
  void SetRcvAckCb (AckManagementCallback cb);
75
  void SetRcvAckCb (AckManagementCb cb);
74
76
75
  /**
77
  /**
76
   * \brief Set the callback invoked when an ACK is received and processed
78
   * \brief Set the callback invoked when an ACK is received and processed
 Lines 78-91   public: Link Here 
78
   *
80
   *
79
   * \param cb callback
81
   * \param cb callback
80
   */
82
   */
81
  void SetProcessedAckCb (AckManagementCallback cb);
83
  void SetProcessedAckCb (AckManagementCb cb);
82
84
83
  /**
85
  /**
84
   * \brief Set the callback invoked after the processing of a retransmit timeout
86
   * \brief Set the callback invoked after the processing of a retransmit timeout
85
   *
87
   *
86
   * \param cb callback
88
   * \param cb callback
87
   */
89
   */
88
  void SetRetransmitCb (RetrCallback cb);
90
  void SetRetransmitCb (RetrCb cb);
89
91
90
  /**
92
  /**
91
   * \brief Set the callback invoked after the forking
93
   * \brief Set the callback invoked after the forking
 Lines 93-110   public: Link Here 
93
   */
95
   */
94
  void SetForkCb (Callback<void, Ptr<TcpSocketMsgBase> > cb);
96
  void SetForkCb (Callback<void, Ptr<TcpSocketMsgBase> > cb);
95
97
98
  /**
99
   * \brief Set the callback invoked when we update rtt history
100
   *
101
   * \param cb callback
102
   */
103
  void SetUpdateRttHistoryCb (UpdateRttCallback cb);
104
96
protected:
105
protected:
97
  virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
106
  virtual void ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader);
98
  virtual void Retransmit (void);
107
  virtual void Retransmit (void);
99
  virtual Ptr<TcpSocketBase> Fork (void);
108
  virtual Ptr<TcpSocketBase> Fork (void);
100
  virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader,
109
  virtual void CompleteFork (Ptr<Packet> p, const TcpHeader& tcpHeader,
101
                             const Address& fromAddress, const Address& toAddress);
110
                             const Address& fromAddress, const Address& toAddress);
111
  virtual void UpdateRttHistory (const SequenceNumber32 &seq, uint32_t sz,
112
                                 bool isRetransmission);
102
113
103
private:
114
private:
104
  AckManagementCallback m_rcvAckCb;
115
  AckManagementCb m_rcvAckCb;
105
  AckManagementCallback m_processedAckCb;
116
  AckManagementCb m_processedAckCb;
106
  RetrCallback m_retrCallback;
117
  RetrCb m_retrCallback;
107
  Callback<void, Ptr<TcpSocketMsgBase> > m_forkCb;
118
  Callback<void, Ptr<TcpSocketMsgBase> > m_forkCb;
119
  UpdateRttCallback m_updateRttCb;
108
};
120
};
109
121
110
122
 Lines 129-144   public: Link Here 
129
141
130
  TcpSocketSmallAcks ()
142
  TcpSocketSmallAcks ()
131
    : TcpSocketMsgBase (),
143
    : TcpSocketMsgBase (),
132
    m_bytesToAck (125),
144
      m_bytesToAck (125),
133
    m_bytesLeftToBeAcked (0),
145
      m_bytesLeftToBeAcked (0),
134
    m_lastAckedSeq (1)
146
      m_lastAckedSeq (1)
135
  {
147
  {
136
  }
148
  }
137
149
138
  TcpSocketSmallAcks (const TcpSocketSmallAcks &other) : TcpSocketMsgBase (other),
150
  TcpSocketSmallAcks (const TcpSocketSmallAcks &other) : TcpSocketMsgBase (other),
139
    m_bytesToAck (other.m_bytesToAck),
151
                                                         m_bytesToAck (other.m_bytesToAck),
140
    m_bytesLeftToBeAcked (other.m_bytesLeftToBeAcked),
152
                                                         m_bytesLeftToBeAcked (other.m_bytesLeftToBeAcked),
141
    m_lastAckedSeq (other.m_lastAckedSeq)
153
                                                         m_lastAckedSeq (other.m_lastAckedSeq)
142
  {
154
  {
143
  }
155
  }
144
156
 Lines 464-470   protected: Link Here 
464
   * \param newValue new value
476
   * \param newValue new value
465
   */
477
   */
466
  virtual void CongStateTrace (const TcpSocketState::TcpCongState_t oldValue,
478
  virtual void CongStateTrace (const TcpSocketState::TcpCongState_t oldValue,
467
                              const TcpSocketState::TcpCongState_t newValue)
479
                               const TcpSocketState::TcpCongState_t newValue)
468
  {
480
  {
469
  }
481
  }
470
482
 Lines 593-598   protected: Link Here 
593
  }
605
  }
594
606
595
  /**
607
  /**
608
   * \brief Updated the Rtt history
609
   * \param seq Sequence inserted
610
   * \param sz size
611
   * \param isRetransmission self-explanatory
612
   * \param who where the rtt history was updated
613
   */
614
  virtual void UpdatedRttHistory (const SequenceNumber32 & seq, uint32_t sz,
615
                                  bool isRetransmission, SocketWho who)
616
  {
617
  }
618
619
  /**
596
   * \brief Notifying application for sent data
620
   * \brief Notifying application for sent data
597
   *
621
   *
598
   * \param size the amount of bytes transmitted
622
   * \param size the amount of bytes transmitted
 Lines 721-726   private: Link Here 
721
                       const Ptr<const TcpSocketBase> tcp);
745
                       const Ptr<const TcpSocketBase> tcp);
722
  void RtoExpiredCb   (const Ptr<const TcpSocketState> tcb,
746
  void RtoExpiredCb   (const Ptr<const TcpSocketState> tcb,
723
                       const Ptr<const TcpSocketBase> tcp);
747
                       const Ptr<const TcpSocketBase> tcp);
748
  void UpdateRttHistoryCb (Ptr<const TcpSocketBase> tcp, const SequenceNumber32&seq,
749
                           uint32_t sz, bool isRetransmission);
724
  void DataSentCb     (Ptr<Socket> socket, uint32_t size);
750
  void DataSentCb     (Ptr<Socket> socket, uint32_t size);
725
  void ForkCb         (Ptr<TcpSocketMsgBase> tcp);
751
  void ForkCb         (Ptr<TcpSocketMsgBase> tcp);
726
  void HandleAccept (Ptr<Socket> socket, const Address& from);
752
  void HandleAccept (Ptr<Socket> socket, const Address& from);
(-)a/src/internet/test/tcp-rtt-estimation.cc (+167 lines)
Line 0    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2016 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
20
#include "tcp-general-test.h"
21
#include "ns3/node.h"
22
#include "ns3/log.h"
23
#include "tcp-error-model.h"
24
25
namespace ns3 {
26
27
NS_LOG_COMPONENT_DEFINE ("TcpRttEstimationTestSuite");
28
29
/**
30
 * \brief Check Rtt calculations
31
 *
32
 * First check is that, for each ACK, we have a valid estimation of the RTT.
33
 * The second check is that, when updating RTT history, we should consider
34
 * retransmission only segments which sequence number is lower than the highest
35
 * already transmitted.
36
 */
37
class TcpRttEstimationTest : public TcpGeneralTest
38
{
39
public:
40
  TcpRttEstimationTest (const std::string &desc, bool enableTs, uint32_t dataPkt);
41
42
protected:
43
  virtual Ptr<TcpSocketMsgBase> CreateReceiverSocket (Ptr<Node> node);
44
  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
45
46
  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
47
  virtual void Tx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
48
  virtual void UpdatedRttHistory (const SequenceNumber32 & seq, uint32_t sz,
49
                                  bool isRetransmission, SocketWho who);
50
  virtual void RttTrace (Time oldTime, Time newTime);
51
  void FinalChecks ();
52
53
private:
54
  bool m_enableTs;
55
  bool m_rttChanged;
56
  SequenceNumber32 m_highestTxSeq;
57
};
58
59
TcpRttEstimationTest::TcpRttEstimationTest (const std::string &desc, bool enableTs, uint32_t dataPkt)
60
  : TcpGeneralTest (desc, 500, dataPkt, Seconds (0.01), Seconds (0.05), Seconds (2.0),
61
                    0xffffffff,1, 500),
62
    m_enableTs (enableTs),
63
    m_rttChanged (false),
64
    m_highestTxSeq (0)
65
{
66
}
67
68
Ptr<TcpSocketMsgBase>
69
TcpRttEstimationTest::CreateReceiverSocket (Ptr<Node> node)
70
{
71
  Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateReceiverSocket (node);
72
  if (!m_enableTs)
73
    {
74
      s->SetAttribute ("Timestamp", BooleanValue (false));
75
    }
76
77
  return s;
78
}
79
80
Ptr<TcpSocketMsgBase>
81
TcpRttEstimationTest::CreateSenderSocket (Ptr<Node> node)
82
{
83
  Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateSenderSocket (node);
84
  if (!m_enableTs)
85
    {
86
      s->SetAttribute ("Timestamp", BooleanValue (false));
87
    }
88
89
  return s;
90
}
91
92
void
93
TcpRttEstimationTest::Tx (const Ptr<const Packet> p, const TcpHeader &h, SocketWho who)
94
{
95
  if (who == SENDER && h.GetFlags () != TcpHeader::SYN)
96
    {
97
      if (m_highestTxSeq < h.GetSequenceNumber ())
98
        {
99
          m_highestTxSeq = h.GetSequenceNumber ();
100
        }
101
102
      Ptr<RttEstimator> rttEstimator = GetRttEstimator (SENDER);
103
      NS_ASSERT (rttEstimator != 0);
104
      NS_LOG_DEBUG ("S Rx: seq=" << h.GetSequenceNumber () << " ack=" << h.GetAckNumber ());
105
      NS_TEST_ASSERT_MSG_NE (rttEstimator->GetEstimate (), Seconds (1),
106
                             "Default Estimate for the RTT");
107
    }
108
}
109
110
void
111
TcpRttEstimationTest::Rx (const Ptr<const Packet> p, const TcpHeader &h, SocketWho who)
112
{
113
  if (who == RECEIVER)
114
    {
115
      NS_LOG_DEBUG ("R Rx: seq=" << h.GetSequenceNumber () << " ack=" << h.GetAckNumber ());
116
    }
117
}
118
119
void
120
TcpRttEstimationTest::UpdatedRttHistory (const SequenceNumber32 & seq, uint32_t sz,
121
                                         bool isRetransmission, SocketWho who)
122
{
123
  if (seq < m_highestTxSeq)
124
    {
125
      NS_TEST_ASSERT_MSG_EQ (isRetransmission, true,
126
                             "A retransmission is not flagged as such");
127
    }
128
  else
129
    {
130
      NS_TEST_ASSERT_MSG_EQ (isRetransmission, false,
131
                             "Incorrectly flagging seq as retransmission");
132
    }
133
134
}
135
136
void
137
TcpRttEstimationTest::RttTrace (Time oldTime, Time newTime)
138
{
139
  NS_LOG_DEBUG ("Rtt changed to " << newTime);
140
  m_rttChanged = true;
141
}
142
143
void
144
TcpRttEstimationTest::FinalChecks ()
145
{
146
  NS_TEST_ASSERT_MSG_EQ (m_rttChanged, true, "Rtt was not updated");
147
}
148
149
//-----------------------------------------------------------------------------
150
151
static class TcpRttEstimationTestSuite : public TestSuite
152
{
153
public:
154
  TcpRttEstimationTestSuite () : TestSuite ("tcp-rtt-estimation-test", UNIT)
155
  {
156
    AddTestCase (new TcpRttEstimationTest ("RTT estimation, ts, no data", true, 0),
157
                 TestCase::QUICK);
158
    AddTestCase (new TcpRttEstimationTest ("RTT estimation, no ts, no data", false, 0),
159
                 TestCase::QUICK);
160
    AddTestCase (new TcpRttEstimationTest ("RTT estimation, ts, some data", true, 10),
161
                 TestCase::QUICK);
162
    AddTestCase (new TcpRttEstimationTest ("RTT estimation, no ts, some data", false, 10),
163
                 TestCase::QUICK);
164
  }
165
} g_tcpRttEstimationTestSuite;
166
167
} // namespace ns3
(-)a/src/internet/wscript (+1 lines)
 Lines 244-249   def build(bld): Link Here 
244
        'test/tcp-zero-window-test.cc',
244
        'test/tcp-zero-window-test.cc',
245
        'test/tcp-pkts-acked-test.cc',
245
        'test/tcp-pkts-acked-test.cc',
246
        'test/tcp-bytes-in-flight-test.cc',
246
        'test/tcp-bytes-in-flight-test.cc',
247
        'test/tcp-rtt-estimation.cc',
247
        'test/udp-test.cc',
248
        'test/udp-test.cc',
248
        'test/ipv6-address-generator-test-suite.cc',
249
        'test/ipv6-address-generator-test-suite.cc',
249
        'test/ipv6-dual-stack-test-suite.cc',
250
        'test/ipv6-dual-stack-test-suite.cc',

Return to bug 2302