A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-no-sack-dupack-test.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "tcp-error-model.h"
6#include "tcp-general-test.h"
7
8#include "ns3/config.h"
9#include "ns3/log.h"
10#include "ns3/node.h"
11#include "ns3/simulator.h"
12#include "ns3/tcp-tx-buffer.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpNoSackDupAckTestSuite");
17
18/**
19 * @ingroup internet-test
20 *
21 * @brief A socket that can send an additional (duplicate) ACK on request.
22 */
24{
25 public:
26 /**
27 * @brief Get the type ID.
28 * @return the object TypeId
29 */
30 static TypeId GetTypeId();
31
36
37 /**
38 * @brief Constructor.
39 * @param other The object to copy from.
40 */
42 : TcpSocketMsgBase(other)
43 {
44 }
45
46 /**
47 * @brief Send a pure ACK that repeats the current acknowledgment number.
48 */
49 void SendDupAck();
50
51 protected:
52 Ptr<TcpSocketBase> Fork() override;
53};
54
56
59{
60 static TypeId tid = TypeId("ns3::TcpSocketDupAcker")
62 .SetGroupName("Internet")
63 .AddConstructor<TcpSocketDupAcker>();
64 return tid;
65}
66
67void
72
78
79/**
80 * @ingroup internet-test
81 *
82 * @brief Check that, without SACK, duplicate ACKs below the threshold do not
83 * cause a loss to be inferred (see @issueid{1107}).
84 *
85 * Without SACK, the sender accounts for each duplicate ACK by guessing that
86 * a segment has been SACKed. The receiver of this test sends some additional
87 * duplicate ACKs, so that the sender holds more guesses than the segments
88 * actually received out of order. The test checks that those guesses are
89 * dropped when the cumulative ACK advances outside of fast recovery, or
90 * ends it, instead of being turned into a lost segment.
91 *
92 * Two scenarios are supported. With no segment dropped, the receiver
93 * duplicates two consecutive ACKs, each of which acknowledges one segment:
94 * the sender must never enter fast recovery nor retransmit. With one segment
95 * dropped, the receiver sends one additional duplicate ACK during fast
96 * recovery: the sender must enter fast recovery once and retransmit only
97 * the dropped segment.
98 */
100{
101 public:
102 /**
103 * @brief Constructor.
104 * @param desc Description.
105 * @param toDrop Sequence number of the segment to drop (0 to drop none).
106 */
107 TcpNoSackDupAckTest(const std::string& desc, uint32_t toDrop);
108
109 protected:
110 void ConfigureEnvironment() override;
111 void ConfigureProperties() override;
114 void Tx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
116 const TcpSocketState::TcpCongState_t newValue) override;
117 void FinalChecks() override;
118
119 private:
120 /**
121 * @brief Make the receiver send an additional duplicate ACK.
122 */
123 void InjectDupAck();
124
125 uint32_t m_toDrop; //!< Sequence number to drop (0 to drop none)
126 SequenceNumber32 m_highestSeqTx; //!< Highest sequence number sent by the sender
127 SequenceNumber32 m_lastAckTx; //!< Last ACK number sent by the receiver
128 uint32_t m_advancingAcks{0}; //!< ACKs sent by the receiver that advance the ACK number
129 uint32_t m_receiverDupAcks{0}; //!< Duplicate ACKs generated by the receiver itself
130 uint32_t m_injectedDupAcks{0}; //!< Additional duplicate ACKs injected by the test
131 bool m_injecting{false}; //!< True while an additional duplicate ACK is being sent
132 uint32_t m_retransmissions{0}; //!< Data segments retransmitted by the sender
133 uint32_t m_disorderEntries{0}; //!< Number of times the sender entered CA_DISORDER
134 uint32_t m_recoveryEntries{0}; //!< Number of times the sender entered CA_RECOVERY
135 uint32_t m_lossEntries{0}; //!< Number of times the sender entered CA_LOSS
136};
137
139 : TcpGeneralTest(desc),
140 m_toDrop(toDrop),
142 m_lastAckTx(1)
143{
144}
145
146void
156
157void
159{
162 // Every data segment is acknowledged by its own ACK
164}
165
171
174{
176 if (m_toDrop != 0)
177 {
178 errorModel->AddSeqToKill(SequenceNumber32(m_toDrop));
179 }
180 return errorModel;
181}
182
183void
185{
187 NS_TEST_ASSERT_MSG_NE(receiver, nullptr, "The receiver is not a TcpSocketDupAcker");
188
189 m_injecting = true;
190 receiver->SendDupAck();
191 m_injecting = false;
192}
193
194void
196{
197 if (who == SENDER)
198 {
199 if (p->GetSize() == 0)
200 {
201 return;
202 }
203
205 {
206 NS_LOG_DEBUG("Retransmission of seq=" << h.GetSequenceNumber());
208 if (m_toDrop != 0)
209 {
212 "Retransmitted a segment that was not dropped");
213 }
214 }
215 else
216 {
218 }
219 return;
220 }
221
222 if (p->GetSize() != 0 || h.GetFlags() != TcpHeader::ACK)
223 {
224 return;
225 }
226
227 if (m_injecting)
228 {
229 NS_LOG_DEBUG("Additional dupack sent, ack=" << h.GetAckNumber());
231 return;
232 }
233
234 bool inject = false;
235 if (h.GetAckNumber() > m_lastAckTx)
236 {
239 // With no drop, duplicate two consecutive ACKs
240 inject = (m_toDrop == 0 && (m_advancingAcks == 3 || m_advancingAcks == 4));
241 }
242 else
243 {
245 // With a drop, add a dupack once the sender is in fast recovery
246 inject = (m_toDrop != 0 && m_receiverDupAcks == 5);
247 }
248
249 if (inject)
250 {
251 // The ACK that is being traced has to leave the socket first
253 }
254}
255
256void
258 const TcpSocketState::TcpCongState_t newValue)
259{
261 << " -> " << TcpSocketState::TcpCongStateName[newValue]);
262
263 switch (newValue)
264 {
267 break;
270 break;
273 break;
276 0,
277 "A segment is marked as lost when going back to CA_OPEN from "
280 0,
281 "A guessed SACK is left when going back to CA_OPEN from "
283 break;
284 default:
285 break;
286 }
287}
288
289void
291{
292 NS_TEST_ASSERT_MSG_EQ(m_lossEntries, 0, "The sender experienced a retransmission timeout");
293
294 if (m_toDrop == 0)
295 {
296 NS_TEST_ASSERT_MSG_EQ(m_injectedDupAcks, 2, "Additional dupacks not sent");
297 NS_TEST_ASSERT_MSG_EQ(m_disorderEntries, 2, "The dupacks did not reach the sender");
298 NS_TEST_ASSERT_MSG_EQ(m_recoveryEntries, 0, "Fast recovery entered without a loss");
299 NS_TEST_ASSERT_MSG_EQ(m_retransmissions, 0, "Segment retransmitted without a loss");
300 }
301 else
302 {
303 NS_TEST_ASSERT_MSG_EQ(m_injectedDupAcks, 1, "Additional dupack not sent");
304 NS_TEST_ASSERT_MSG_EQ(m_recoveryEntries, 1, "Fast recovery not entered exactly once");
305 NS_TEST_ASSERT_MSG_EQ(m_retransmissions, 1, "Not exactly one segment retransmitted");
306 }
307}
308
309/**
310 * @ingroup internet-test
311 *
312 * @brief TestSuite: duplicate ACK handling when SACK is disabled
313 */
315{
316 public:
318 : TestSuite("tcp-no-sack-dupack-test", Type::UNIT)
319 {
320 AddTestCase(new TcpNoSackDupAckTest("Additional dupack in fast recovery, one drop", 1001),
322 AddTestCase(new TcpNoSackDupAckTest("Dupacks below the threshold, no drop", 0),
324 }
325};
326
328 g_tcpNoSackDupAckTestSuite; //!< Static variable for test initialization
Check that, without SACK, duplicate ACKs below the threshold do not cause a loss to be inferred (see ...
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
uint32_t m_recoveryEntries
Number of times the sender entered CA_RECOVERY.
void ConfigureProperties() override
Change the configuration of the socket properties.
uint32_t m_retransmissions
Data segments retransmitted by the sender.
void ConfigureEnvironment() override
Change the configuration of the environment.
uint32_t m_lossEntries
Number of times the sender entered CA_LOSS.
bool m_injecting
True while an additional duplicate ACK is being sent.
void Tx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet transmitted down to IP layer.
uint32_t m_disorderEntries
Number of times the sender entered CA_DISORDER.
SequenceNumber32 m_highestSeqTx
Highest sequence number sent by the sender.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
Ptr< ErrorModel > CreateReceiverErrorModel() override
Create and return the error model to install in the receiver node.
void InjectDupAck()
Make the receiver send an additional duplicate ACK.
uint32_t m_advancingAcks
ACKs sent by the receiver that advance the ACK number.
TcpNoSackDupAckTest(const std::string &desc, uint32_t toDrop)
Constructor.
void CongStateTrace(const TcpSocketState::TcpCongState_t oldValue, const TcpSocketState::TcpCongState_t newValue) override
State on Ack state machine changes.
uint32_t m_receiverDupAcks
Duplicate ACKs generated by the receiver itself.
uint32_t m_injectedDupAcks
Additional duplicate ACKs injected by the test.
uint32_t m_toDrop
Sequence number to drop (0 to drop none).
SequenceNumber32 m_lastAckTx
Last ACK number sent by the receiver.
TestSuite: duplicate ACK handling when SACK is disabled.
A socket that can send an additional (duplicate) ACK on request.
TcpSocketDupAcker(const TcpSocketDupAcker &other)
Constructor.
Ptr< TcpSocketBase > Fork() override
Call CopyObject<> to clone me.
static TypeId GetTypeId()
Get the type ID.
void SendDupAck()
Send a pure ACK that repeats the current acknowledgment number.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:614
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
void SetDelAckMaxCount(SocketWho who, uint32_t count)
Forcefully set the delayed acknowledgement count.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
@ RECEIVER
Receiver node.
Ptr< TcpTxBuffer > GetTxBuffer(SocketWho who)
Get the Tx buffer from selected socket.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual void ConfigureProperties()
Change the configuration of the socket properties.
TypeId m_congControlTypeId
Congestion control.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
TcpGeneralTest(const std::string &desc)
TcpGeneralTest constructor.
Ptr< TcpSocketMsgBase > GetReceiverSocket()
Get the pointer to a previously created receiver 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:36
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
uint8_t GetFlags() const
Get the flags.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
virtual void SendEmptyPacket(uint8_t flags)
Send a empty packet that carries a flag, e.g., ACK.
static INTERNET_EXPORT const char *const TcpCongStateName[TcpSocketState::CA_LAST_STATE]
Literal names of TCP states for use in log messages.
TcpCongState_t
Definition of the Congestion state machine.
@ CA_RECOVERY
CWND was reduced, we are fast-retransmitting.
@ CA_DISORDER
In all the respects it is "Open", but requires a bit more attention.
@ CA_LOSS
CWND was reduced due to RTO timeout or SACK reneging.
@ CA_OPEN
Normal state, no dubious events.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
SequenceNumber< uint32_t > SequenceNumber32
32 bit Sequence number.
#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:133
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition test.h:553
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
Ptr< T > CopyObject(Ptr< const T > object)
Definition object.h:597
static TcpNoSackDupAckTestSuite g_tcpNoSackDupAckTestSuite
Static variable for test initialization.