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

(-)a/src/internet/model/nsc-tcp-socket-impl.cc (+13 lines)
 Lines 85-90    Link Here 
85
  : TcpSocket(sock), //copy the base class callbacks
85
  : TcpSocket(sock), //copy the base class callbacks
86
    m_delAckMaxCount (sock.m_delAckMaxCount),
86
    m_delAckMaxCount (sock.m_delAckMaxCount),
87
    m_delAckTimeout (sock.m_delAckTimeout),
87
    m_delAckTimeout (sock.m_delAckTimeout),
88
    m_noDelay (sock.m_noDelay),
88
    m_endPoint (0),
89
    m_endPoint (0),
89
    m_node (sock.m_node),
90
    m_node (sock.m_node),
90
    m_tcp (sock.m_tcp),
91
    m_tcp (sock.m_tcp),
 Lines 794-799    Link Here 
794
  return m_delAckMaxCount;
795
  return m_delAckMaxCount;
795
}
796
}
796
797
798
void
799
NscTcpSocketImpl::SetTcpNoDelay (bool noDelay)
800
{
801
  m_noDelay = noDelay;
802
}
803
804
bool
805
NscTcpSocketImpl::GetTcpNoDelay (void) const
806
{
807
  return m_noDelay;
808
}
809
797
void 
810
void 
798
NscTcpSocketImpl::SetPersistTimeout (Time timeout)
811
NscTcpSocketImpl::SetPersistTimeout (Time timeout)
799
{
812
{
(-)a/src/internet/model/nsc-tcp-socket-impl.h (+3 lines)
 Lines 125-136    Link Here 
125
  virtual Time GetDelAckTimeout (void) const;
125
  virtual Time GetDelAckTimeout (void) const;
126
  virtual void SetDelAckMaxCount (uint32_t count);
126
  virtual void SetDelAckMaxCount (uint32_t count);
127
  virtual uint32_t GetDelAckMaxCount (void) const;
127
  virtual uint32_t GetDelAckMaxCount (void) const;
128
  virtual void SetTcpNoDelay (bool noDelay);
129
  virtual bool GetTcpNoDelay (void) const;
128
  virtual void SetPersistTimeout (Time timeout);
130
  virtual void SetPersistTimeout (Time timeout);
129
  virtual Time GetPersistTimeout (void) const;
131
  virtual Time GetPersistTimeout (void) const;
130
132
131
  enum Socket::SocketErrno GetNativeNs3Errno(int err) const;
133
  enum Socket::SocketErrno GetNativeNs3Errno(int err) const;
132
  uint32_t m_delAckMaxCount;
134
  uint32_t m_delAckMaxCount;
133
  Time m_delAckTimeout;
135
  Time m_delAckTimeout;
136
  bool m_noDelay;
134
137
135
  Ipv4EndPoint *m_endPoint;
138
  Ipv4EndPoint *m_endPoint;
136
  Ptr<Node> m_node;
139
  Ptr<Node> m_node;
(-)a/src/internet/model/rtt-estimator.cc (-1 / +1 lines)
 Lines 53-59    Link Here 
53
                   MakeTimeChecker ())
53
                   MakeTimeChecker ())
54
    .AddAttribute ("MinRTO", 
54
    .AddAttribute ("MinRTO", 
55
                   "Minimum retransmit timeout value",
55
                   "Minimum retransmit timeout value",
56
                   TimeValue (Seconds (0.2)),
56
                   TimeValue (Seconds (1)),
57
                   MakeTimeAccessor (&RttEstimator::minrto),
57
                   MakeTimeAccessor (&RttEstimator::minrto),
58
                   MakeTimeChecker ())
58
                   MakeTimeChecker ())
59
    ;
59
    ;
(-)a/src/internet/model/tcp-socket-base.cc (+27 lines)
 Lines 109-114    Link Here 
109
    m_dupAckCount (sock.m_dupAckCount),
109
    m_dupAckCount (sock.m_dupAckCount),
110
    m_delAckCount (0),
110
    m_delAckCount (0),
111
    m_delAckMaxCount (sock.m_delAckMaxCount),
111
    m_delAckMaxCount (sock.m_delAckMaxCount),
112
    m_noDelay (sock.m_noDelay),
112
    m_cnCount (sock.m_cnCount),
113
    m_cnCount (sock.m_cnCount),
113
    m_delAckTimeout (sock.m_delAckTimeout),
114
    m_delAckTimeout (sock.m_delAckTimeout),
114
    m_persistTimeout (sock.m_persistTimeout),
115
    m_persistTimeout (sock.m_persistTimeout),
 Lines 1296-1301    Link Here 
1296
        {
1297
        {
1297
          break; // No more
1298
          break; // No more
1298
        }
1299
        }
1300
1301
      // Nagle's algorithm. If enabled, hold off sending if there is unacked 
1302
      // data in the buffer and the amount of data to send is less than a 
1303
      // segment size
1304
      if (!m_noDelay)
1305
        {
1306
          if (UnAckDataCount () > 0 && 
1307
              m_txBuffer.SizeFromSequence (m_nextTxSequence) < m_segmentSize)
1308
            {
1309
              NS_LOG_LOGIC ("Invoking Nagle's algorithm. Wait to send.");
1310
              break;
1311
            }
1312
        }
1313
1299
      uint32_t s = std::min (w, m_segmentSize);  // Send no more than window
1314
      uint32_t s = std::min (w, m_segmentSize);  // Send no more than window
1300
      Ptr<Packet> p = m_txBuffer.CopyFromSequence (s, m_nextTxSequence);
1315
      Ptr<Packet> p = m_txBuffer.CopyFromSequence (s, m_nextTxSequence);
1301
      NS_LOG_LOGIC ("TcpSocketBase " << this << " SendPendingData" <<
1316
      NS_LOG_LOGIC ("TcpSocketBase " << this << " SendPendingData" <<
 Lines 1732-1737    Link Here 
1732
}
1747
}
1733
1748
1734
void
1749
void
1750
TcpSocketBase::SetTcpNoDelay (bool noDelay)
1751
{
1752
  m_noDelay = noDelay;
1753
}
1754
1755
bool
1756
TcpSocketBase::GetTcpNoDelay (void) const
1757
{
1758
  return m_noDelay;
1759
}
1760
1761
void
1735
TcpSocketBase::SetPersistTimeout (Time timeout)
1762
TcpSocketBase::SetPersistTimeout (Time timeout)
1736
{
1763
{
1737
  m_persistTimeout = timeout;
1764
  m_persistTimeout = timeout;
(-)a/src/internet/model/tcp-socket-base.h (+3 lines)
 Lines 115-120    Link Here 
115
  virtual Time     GetDelAckTimeout (void) const;
115
  virtual Time     GetDelAckTimeout (void) const;
116
  virtual void     SetDelAckMaxCount (uint32_t count);
116
  virtual void     SetDelAckMaxCount (uint32_t count);
117
  virtual uint32_t GetDelAckMaxCount (void) const;
117
  virtual uint32_t GetDelAckMaxCount (void) const;
118
  virtual void     SetTcpNoDelay (bool noDelay);
119
  virtual bool     GetTcpNoDelay (void) const;
118
  virtual void     SetPersistTimeout (Time timeout);
120
  virtual void     SetPersistTimeout (Time timeout);
119
  virtual Time     GetPersistTimeout (void) const;
121
  virtual Time     GetPersistTimeout (void) const;
120
  virtual bool     SetAllowBroadcast (bool allowBroadcast);
122
  virtual bool     SetAllowBroadcast (bool allowBroadcast);
 Lines 182-187    Link Here 
182
  uint32_t          m_dupAckCount;     //< Dupack counter
184
  uint32_t          m_dupAckCount;     //< Dupack counter
183
  uint32_t          m_delAckCount;     //< Delayed ACK counter
185
  uint32_t          m_delAckCount;     //< Delayed ACK counter
184
  uint32_t          m_delAckMaxCount;  //< Number of packet to fire an ACK before delay timeout
186
  uint32_t          m_delAckMaxCount;  //< Number of packet to fire an ACK before delay timeout
187
  bool              m_noDelay;         //< Set true to disable Nagle's algorithm
185
  uint32_t          m_cnCount;         //< Count of remaining connection retries
188
  uint32_t          m_cnCount;         //< Count of remaining connection retries
186
  TracedValue<Time> m_rto;             //< Retransmit timeout
189
  TracedValue<Time> m_rto;             //< Retransmit timeout
187
  TracedValue<Time> m_lastRtt;         //< Last RTT sample collected
190
  TracedValue<Time> m_lastRtt;         //< Last RTT sample collected
(-)a/src/internet/model/tcp-socket.cc (+6 lines)
 Lines 22-27    Link Here 
22
#include "ns3/log.h"
22
#include "ns3/log.h"
23
#include "ns3/uinteger.h"
23
#include "ns3/uinteger.h"
24
#include "ns3/double.h"
24
#include "ns3/double.h"
25
#include "ns3/boolean.h"
25
#include "ns3/trace-source-accessor.h"
26
#include "ns3/trace-source-accessor.h"
26
#include "ns3/nstime.h"
27
#include "ns3/nstime.h"
27
#include "tcp-socket.h"
28
#include "tcp-socket.h"
 Lines 93-98    Link Here 
93
                   MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount,
94
                   MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount,
94
                                         &TcpSocket::SetDelAckMaxCount),
95
                                         &TcpSocket::SetDelAckMaxCount),
95
                   MakeUintegerChecker<uint32_t> ())
96
                   MakeUintegerChecker<uint32_t> ())
97
    .AddAttribute ("TcpNoDelay", "Set true to disable Nagle's algorithm",
98
                   BooleanValue (false),
99
                   MakeBooleanAccessor (&TcpSocket::GetTcpNoDelay,
100
                                        &TcpSocket::SetTcpNoDelay),
101
                   MakeBooleanChecker ())
96
    .AddAttribute ("PersistTimeout",
102
    .AddAttribute ("PersistTimeout",
97
                   "Persist timeout to probe for rx window",
103
                   "Persist timeout to probe for rx window",
98
                   TimeValue (Seconds (6)),
104
                   TimeValue (Seconds (6)),
(-)a/src/internet/model/tcp-socket.h (+2 lines)
 Lines 89-94    Link Here 
89
  virtual Time GetDelAckTimeout (void) const = 0;
89
  virtual Time GetDelAckTimeout (void) const = 0;
90
  virtual void SetDelAckMaxCount (uint32_t count) = 0;
90
  virtual void SetDelAckMaxCount (uint32_t count) = 0;
91
  virtual uint32_t GetDelAckMaxCount (void) const = 0;
91
  virtual uint32_t GetDelAckMaxCount (void) const = 0;
92
  virtual void SetTcpNoDelay (bool noDelay) = 0;
93
  virtual bool GetTcpNoDelay (void) const = 0;
92
  virtual void SetPersistTimeout (Time timeout) = 0;
94
  virtual void SetPersistTimeout (Time timeout) = 0;
93
  virtual Time GetPersistTimeout (void) const = 0;
95
  virtual Time GetPersistTimeout (void) const = 0;
94
  
96
  
(-)69da8fae7882 (+206 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 */
16
17
#include "ns3/log.h"
18
#include "ns3/abort.h"
19
#include "ns3/test.h"
20
#include "ns3/pcap-file.h"
21
#include "ns3/config.h"
22
#include "ns3/string.h"
23
#include "ns3/uinteger.h"
24
#include "ns3/boolean.h"
25
#include "ns3/data-rate.h"
26
#include "ns3/inet-socket-address.h"
27
#include "ns3/point-to-point-helper.h"
28
#include "ns3/csma-helper.h"
29
#include "ns3/internet-stack-helper.h"
30
#include "ns3/ipv4-global-routing-helper.h"
31
#include "ns3/ipv4-address-helper.h"
32
#include "ns3/packet-sink-helper.h"
33
#include "ns3/tcp-socket-factory.h"
34
#include "ns3/node-container.h"
35
#include "ns3/simulator.h"
36
#include "ns3tcp-socket-writer.h"
37
38
using namespace ns3;
39
40
NS_LOG_COMPONENT_DEFINE ("Ns3TcpNoDelayTest");
41
42
// ===========================================================================
43
// Tests of Nagle's algorithm and the TCP no delay option
44
// ===========================================================================
45
//
46
//
47
class Ns3TcpNoDelayTestCase : public TestCase
48
{
49
public:
50
  Ns3TcpNoDelayTestCase (bool noDelay);
51
  virtual ~Ns3TcpNoDelayTestCase () {}
52
53
private:
54
  virtual void DoRun (void);
55
  bool m_noDelay;
56
  bool m_writeResults;
57
58
  void SinkRx (std::string path, Ptr<const Packet> p, const Address &address);
59
60
  TestVectors<uint32_t> m_inputs;
61
  TestVectors<uint32_t> m_responses;
62
};
63
64
Ns3TcpNoDelayTestCase::Ns3TcpNoDelayTestCase (bool noDelay)
65
  : TestCase ("Check that ns-3 TCP Nagle's algorithm works correctly and that we can turn it off."),
66
    m_noDelay (noDelay),
67
    m_writeResults (false)
68
{
69
}
70
71
void 
72
Ns3TcpNoDelayTestCase::SinkRx (std::string path, Ptr<const Packet> p, const Address &address)
73
{
74
  m_responses.Add (p->GetSize ());
75
}
76
77
void
78
Ns3TcpNoDelayTestCase::DoRun (void)
79
{
80
  uint16_t sinkPort = 50000;
81
  double sinkStopTime = 8;  // sec; will trigger Socket::Close
82
  double writerStopTime = 5;  // sec; will trigger Socket::Close
83
  double simStopTime = 10;  // sec
84
  Time sinkStopTimeObj = Seconds (sinkStopTime);
85
  Time writerStopTimeObj = Seconds (writerStopTime);
86
  Time simStopTimeObj= Seconds (simStopTime);
87
88
  Ptr<Node> n0 = CreateObject<Node> ();
89
  Ptr<Node> n1 = CreateObject<Node> ();
90
91
  PointToPointHelper pointToPoint;
92
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
93
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
94
95
  NetDeviceContainer devices;
96
  devices = pointToPoint.Install (n0, n1);
97
98
  InternetStackHelper internet;
99
  internet.InstallAll ();
100
101
  Ipv4AddressHelper address;
102
  address.SetBase ("10.1.1.0", "255.255.255.252");
103
  Ipv4InterfaceContainer ifContainer = address.Assign (devices);
104
105
  Ptr<SocketWriter> socketWriter = CreateObject<SocketWriter> ();
106
  Address sinkAddress (InetSocketAddress (ifContainer.GetAddress (1), sinkPort));
107
  socketWriter->Setup (n0, sinkAddress);
108
  n0->AddApplication (socketWriter);
109
  socketWriter->SetStartTime (Seconds (0.));
110
  socketWriter->SetStopTime (writerStopTimeObj);
111
112
  PacketSinkHelper sink ("ns3::TcpSocketFactory",
113
                         InetSocketAddress (Ipv4Address::GetAny (), sinkPort));
114
  ApplicationContainer apps = sink.Install (n1);
115
  // Start the sink application at time zero, and stop it at sinkStopTime
116
  apps.Start (Seconds (0.0));
117
  apps.Stop (sinkStopTimeObj);
118
119
  Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
120
                   MakeCallback (&Ns3TcpNoDelayTestCase::SinkRx, this));
121
122
  // Enable or disable TCP no delay option
123
  Config::SetDefault ("ns3::TcpSocket::TcpNoDelay", BooleanValue (m_noDelay));
124
125
  // Connect the socket writer
126
  Simulator::Schedule (Seconds (1), &SocketWriter::Connect, socketWriter);
127
128
  // Write 5 packets to get some bytes in flight and some acks going
129
  Simulator::Schedule (Seconds (2), &SocketWriter::Write, socketWriter, 2680);
130
  m_inputs.Add (536);
131
  m_inputs.Add (536);
132
  m_inputs.Add (536);
133
  m_inputs.Add (536);
134
  m_inputs.Add (536);
135
136
  // Write one byte after 10 ms to ensure that some data is outstanding 
137
  // and the window is big enough
138
  Simulator::Schedule (Seconds (2.010), &SocketWriter::Write, socketWriter, 1);
139
140
  // If Nagle is not enabled, i.e. no delay is on, add an input for a 1-byte 
141
  // packet to be received
142
  if (m_noDelay)
143
    {
144
      m_inputs.Add (1);
145
    }
146
147
  // One ms later, write 535 bytes, i.e. one segment size - 1
148
  Simulator::Schedule (Seconds (2.012), &SocketWriter::Write, socketWriter, 535);
149
150
  // If Nagle is not enabled, add an input for a 535 byte packet,
151
  // otherwise, we should get a single "full" packet of 536 bytes
152
  if (m_noDelay)
153
    {
154
      m_inputs.Add (535);
155
    }
156
  else
157
    {
158
      m_inputs.Add (536);
159
    }
160
161
  // Close down the socket
162
  Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
163
164
  if (m_writeResults)
165
    {
166
      std::ostringstream oss;
167
      if (m_noDelay)
168
        {
169
          oss << "tcp-no-delay-on-test-case";
170
          pointToPoint.EnablePcapAll (oss.str ());
171
        }
172
      else
173
        {
174
          oss << "tcp-no-delay-off-test-case";
175
          pointToPoint.EnablePcapAll (oss.str ());
176
        }
177
    }
178
179
  Simulator::Stop (simStopTimeObj);
180
  Simulator::Run ();
181
  Simulator::Destroy ();
182
183
  // Compare inputs and outputs
184
  NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (), "Incorrect number of expected receive events");
185
  for (uint32_t i = 0; i < m_responses.GetN (); i++)
186
    {
187
      uint32_t in = m_inputs.Get (i);
188
      uint32_t out = m_responses.Get (i);
189
      NS_TEST_ASSERT_MSG_EQ (in, out, "Mismatch:  expected " << in << " bytes, got " << out << " bytes");
190
    }
191
}
192
193
class Ns3TcpNoDelayTestSuite : public TestSuite
194
{
195
public:
196
  Ns3TcpNoDelayTestSuite ();
197
};
198
199
Ns3TcpNoDelayTestSuite::Ns3TcpNoDelayTestSuite ()
200
  : TestSuite ("ns3-tcp-no-delay", SYSTEM)
201
{
202
  AddTestCase (new Ns3TcpNoDelayTestCase (true));
203
  AddTestCase (new Ns3TcpNoDelayTestCase (false));
204
}
205
206
static Ns3TcpNoDelayTestSuite ns3TcpNoDelayTestSuite;
(-)a/src/test/ns3tcp/wscript (+1 lines)
 Lines 15-20    Link Here 
15
        'ns3tcp-socket-test-suite.cc',
15
        'ns3tcp-socket-test-suite.cc',
16
        'ns3tcp-loss-test-suite.cc',
16
        'ns3tcp-loss-test-suite.cc',
17
        'ns3tcp-state-test-suite.cc',
17
        'ns3tcp-state-test-suite.cc',
18
        'ns3tcp-no-delay-test-suite.cc',
18
        ]
19
        ]
19
    if bld.env['NSC_ENABLED']:
20
    if bld.env['NSC_ENABLED']:
20
        ns3tcp.source.append ('ns3tcp-interop-test-suite.cc')
21
        ns3tcp.source.append ('ns3tcp-interop-test-suite.cc')

Return to bug 1039