A Discrete-Event Network Simulator
API
tcp-bytes-in-flight-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include "tcp-error-model.h"
20#include "tcp-general-test.h"
21
22#include "ns3/config.h"
23#include "ns3/log.h"
24#include "ns3/node.h"
25
26using namespace ns3;
27
28NS_LOG_COMPONENT_DEFINE("TcpBytesInFlightTestSuite");
29
44{
45 public:
51 TcpBytesInFlightTest(const std::string& desc, std::vector<uint32_t>& toDrop);
52
53 protected:
65 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
72 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
78 void BytesInFlightTrace(uint32_t oldValue, uint32_t newValue) override;
79
86 void PktDropped(const Ipv4Header& ipH, const TcpHeader& tcpH, Ptr<const Packet> p);
87
91 void ConfigureEnvironment() override;
92
98 void BeforeRTOExpired(const Ptr<const TcpSocketState> tcb, SocketWho who) override;
99
105 void RTOExpired(Time oldVal, Time newVal);
106
110 void FinalChecks() override;
111
112 private:
117 std::vector<uint32_t> m_toDrop;
118};
119
120TcpBytesInFlightTest::TcpBytesInFlightTest(const std::string& desc, std::vector<uint32_t>& toDrop)
121 : TcpGeneralTest(desc),
122 m_guessedBytesInFlight(0),
123 m_dupAckRecv(0),
124 m_lastAckRecv(1),
125 m_greatestSeqSent(0),
126 m_toDrop(toDrop)
127{
128}
129
130void
132{
133 TcpGeneralTest::ConfigureEnvironment();
134 SetAppPktCount(30);
137
138 Config::SetDefault("ns3::TcpSocketBase::Sack", BooleanValue(false));
139}
140
143{
144 Ptr<TcpSeqErrorModel> m_errorModel = CreateObject<TcpSeqErrorModel>();
145 for (std::vector<uint32_t>::iterator it = m_toDrop.begin(); it != m_toDrop.end(); ++it)
146 {
147 m_errorModel->AddSeqToKill(SequenceNumber32(*it));
148 }
149
151
152 return m_errorModel;
153}
154
155void
157{
158 NS_LOG_DEBUG("Before RTO for " << who);
159 GetSenderSocket()->TraceConnectWithoutContext(
160 "RTO",
162}
163
164void
166{
167 NS_LOG_DEBUG("RTO expired at " << newVal.GetSeconds());
169}
170
171void
173{
174 NS_LOG_DEBUG("Drop seq= " << tcpH.GetSequenceNumber() << " size " << p->GetSize());
175}
176
177void
179{
180 if (who == RECEIVER)
181 {
182 }
183 else if (who == SENDER)
184 {
185 if (h.GetAckNumber() > m_lastAckRecv)
186 { // New ack
188 NS_LOG_DEBUG("Recv ACK=" << h.GetAckNumber());
189
190 if (m_dupAckRecv > 0)
191 { // Previously we got some ACKs
193 { // This an ACK which acknowledge all the window
194 m_guessedBytesInFlight = 0; // All outstanding data acked
195 diff = 0;
196 m_dupAckRecv = 0;
197 }
198 else
199 {
200 // Partial ACK: Update the dupAck received count
201 m_dupAckRecv -= diff / GetSegSize(SENDER);
202 // During fast recovery the TCP data sender respond to a partial acknowledgment
203 // by inferring that the next in-sequence packet has been lost (RFC5681)
205 }
206 }
207
208 if ((h.GetFlags() & TcpHeader::FIN) != 0 || m_guessedBytesInFlight + 1 == diff)
209 { // received the ACK for the FIN (which includes 1 spurious byte)
210 diff -= 1;
211 }
214 NS_LOG_DEBUG("Update m_guessedBytesInFlight to " << m_guessedBytesInFlight);
215 }
216 else if (h.GetAckNumber() == m_lastAckRecv && m_lastAckRecv != SequenceNumber32(1) &&
217 (h.GetFlags() & TcpHeader::FIN) == 0)
218 {
219 // For each dupack I should guess that a segment has been received
220 // Please do not count FIN and SYN/ACK as dupacks
222 m_dupAckRecv++;
223 // RFC 6675 says after two dupacks, the segment is considered lost
224 if (m_dupAckRecv == 3)
225 {
226 NS_LOG_DEBUG("Loss of a segment detected");
228 }
229 NS_LOG_DEBUG("Dupack received, Update m_guessedBytesInFlight to "
231 }
232 }
233}
234
235void
237{
238 if (who == SENDER)
239 {
240 static SequenceNumber32 retr = SequenceNumber32(0);
241 static uint32_t times = 0;
242
244 { // This is not a retransmission
246 times = 0;
247 }
248
249 if (retr == h.GetSequenceNumber())
250 {
251 ++times;
252 }
253
254 if (times < 2)
255 {
256 // count retransmission only one time
258 }
259 retr = h.GetSequenceNumber();
260
261 NS_LOG_DEBUG("TX size=" << p->GetSize() << " seq=" << h.GetSequenceNumber()
262 << " m_guessedBytesInFlight=" << m_guessedBytesInFlight);
263 }
264}
265
266void
268{
269 NS_LOG_DEBUG("Socket BytesInFlight=" << newValue << " mine is=" << m_guessedBytesInFlight);
271 newValue,
272 "At time " << Simulator::Now().GetSeconds()
273 << "; guessed and measured bytes in flight differs");
274}
275
276void
278{
280 0,
281 "Still present bytes in flight at the end of the transmission");
282}
283
291{
292 public:
294 : TestSuite("tcp-bytes-in-flight-test", UNIT)
295 {
296 std::vector<uint32_t> toDrop;
297 AddTestCase(new TcpBytesInFlightTest("BytesInFlight value, no drop", toDrop),
298 TestCase::QUICK);
299 toDrop.push_back(4001);
300 AddTestCase(new TcpBytesInFlightTest("BytesInFlight value, one drop", toDrop),
301 TestCase::QUICK);
302 toDrop.push_back(4001);
304 new TcpBytesInFlightTest("BytesInFlight value, two drop of same segment", toDrop),
305 TestCase::QUICK);
306 toDrop.pop_back();
307 toDrop.push_back(4501);
309 new TcpBytesInFlightTest("BytesInFlight value, two drop of consecutive segments",
310 toDrop),
311 TestCase::QUICK);
312 }
313};
314
Check the value of BytesInFlight against a home-made guess.
void ConfigureEnvironment() override
Configure the test.
std::vector< uint32_t > m_toDrop
List of SequenceNumber to drop.
void BytesInFlightTrace(uint32_t oldValue, uint32_t newValue) override
Track the bytes in flight.
void FinalChecks() override
Do the final checks.
void BeforeRTOExpired(const Ptr< const TcpSocketState > tcb, SocketWho who) override
Do the checks before the RTO expires.
SequenceNumber32 m_lastAckRecv
Last ACK received.
uint32_t m_guessedBytesInFlight
Guessed bytes in flight.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Transmit a packet.
void PktDropped(const Ipv4Header &ipH, const TcpHeader &tcpH, Ptr< const Packet > p)
Called when a packet is dropped.
TcpBytesInFlightTest(const std::string &desc, std::vector< uint32_t > &toDrop)
Constructor.
void RTOExpired(Time oldVal, Time newVal)
Update when RTO expires.
uint32_t m_dupAckRecv
Number of DupACKs received.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Receive a packet.
Ptr< ErrorModel > CreateReceiverErrorModel() override
Create a receiver error model.
SequenceNumber32 m_greatestSeqSent
greatest sequence number sent.
TestSuite: Check the value of BytesInFlight against a home-made guess.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Packet header for IPv4.
Definition: ipv4-header.h:34
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > cb)
Set the drop callback.
General infrastructure for TCP testing.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Ptr< TcpSocketMsgBase > GetSenderSocket()
Get the pointer to a previously created sender socket.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:137
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:167
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:143
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
static TcpBytesInFlightTestSuite g_tcpBytesInFlightTestSuite
Static variable for test initialization.