A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-fack-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018, 2025 NITK Surathkal
3 * SPDX-License-Identifier: GPL-2.0-only
4 *
5 * Authors: Shikha Bakshi <shikhabakshi912@gmail.com>
6 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
7 * Jayesh Akot <akotjayesh@gmail.com>
8 */
9
10/**
11 * @file
12 * @brief Unit test for the TCP Forward Acknowledgment (FACK) implementation.
13 *
14 * This unit test creates a short packet flow and forces four consecutive lost
15 * segments, and verifies that the snd.fack variable is updated to the highest sequence
16 * number present in the incoming SACK blocks, and that its external calculation of
17 * awnd matches the internal state variable.
18 */
19
20#include "tcp-error-model.h"
21#include "tcp-general-test.h"
22
23#include "ns3/assert.h"
24#include "ns3/log.h"
25#include "ns3/node.h"
26#include "ns3/simple-channel.h"
27#include "ns3/tcp-header.h"
28#include "ns3/tcp-tx-buffer.h"
29#include "ns3/test.h"
30
31using namespace ns3;
32
33NS_LOG_COMPONENT_DEFINE("TcpFackTest");
34
35/**
36 * @ingroup internet-test
37 * @brief Test case for Forward Acknowledgment(FACK).
38 *
39 * This test verifies the correctness of FACK-related state variables,
40 * in particular the computation of sndFack and the FACK's inflight(awnd),
41 * ensuring they match the expected behavior of the implementation.
42 */
44{
45 public:
46 /**
47 * @brief Constructor.
48 * @param congControl The TypeId of the congestion control algorithm used.
49 * @param desc Description string for the test case.
50 */
51 TcpFackTest(TypeId congControl, const std::string& desc)
52 : TcpGeneralTest(desc),
53 m_congControlType(congControl)
54
55 {
56 m_congControlTypeId = congControl;
57 }
58
59 private:
61 uint32_t m_pktDropped{0}; //!< The Number of packets has been dropped.
62 uint32_t m_startSeqToKill{4001}; //!< Sequence number of the first packet to drop.
63 uint32_t m_seqToKill{0}; //!< Sequence number to drop.
64 uint32_t m_pkts{4}; //!< Number of packets to drop.
65 uint32_t m_pktSize{1000}; //!< Sender Packet Size
66
67 /**
68 * @brief Count number of packets dropped
69 * @param ipH IPv4 header of the dropped packet.
70 * @param tcpH TCP header of the dropped packet.
71 * @param p The dropped packet.
72 */
73 void PktDropped(const Ipv4Header& ipH, const TcpHeader& tcpH, Ptr<const Packet> p)
74 {
75 NS_LOG_FUNCTION(this << ipH << tcpH);
77 }
78
79 void ConfigureEnvironment() override
80 {
82 SetAppPktSize(1000);
83 SetAppPktCount(10); // send 10 packets
84 }
85
86 void ConfigureProperties() override
87 {
89 SetInitialCwnd(SENDER, 10); // start with 10 segments
92 }
93
95 {
97
98 for (uint32_t i = 0; i < m_pkts; i++)
99 {
102 m_errorModel->SetDropCallback(MakeCallback(&TcpFackTest::PktDropped, this));
103 }
104
105 return m_errorModel;
106 }
107
109 {
111 sock->SetAttribute("Fack", BooleanValue(true));
112 return sock;
113 }
114
115 void RcvAck(const Ptr<const TcpSocketState> tcb, const TcpHeader& h, SocketWho who) override
116 {
117 if (tcb->m_cWnd.Get() >= tcb->m_ssThresh)
118 {
120 uint32_t awnd = tcb->m_highTxMark.Get().GetValue() - sock->GetSndFack() +
121 sock->GetTxBuffer()->GetRetransmitsCount();
122
123 NS_TEST_EXPECT_MSG_EQ(awnd, tcb->m_fackAwnd.Get(), "AWND is not correctly calculated");
124 }
125 }
126
128 const TcpHeader& h,
129 SocketWho who) override
130 {
132 {
133 return;
134 }
135
137 auto sackOpt = DynamicCast<const TcpOptionSack>(opt);
138
139 if (!sackOpt)
140 {
141 return;
142 }
143
144 TcpOptionSack::SackList sacks = sackOpt->GetSackList();
145 SequenceNumber32 highest = h.GetAckNumber();
146
147 for (const auto& s : sacks)
148 {
149 if (s.second > highest)
150 {
151 highest = s.second;
152 }
153 }
155
156 NS_TEST_EXPECT_MSG_EQ(sock->GetSndFack(),
157 highest.GetValue(),
158 "snd_fack did not advance to highest SACKed seq");
159 }
160
161 private:
162 TypeId m_congControlType; //!< Congestion control algorithm type used for this test.
163};
164
165/**
166 * @ingroup internet-test
167 *
168 * @brief Test suite for verifying the behavior of the TCP FACK implementation
169 * under controlled packet loss scenarios.
170 *
171 * Verifies:
172 * - snd.fack correctly tracks the highest SACKed sequence
173 * - awnd calculation matches FACK’s tracking
174 */
175
177{
178 public:
180 : TestSuite("tcp-fack-test", Type::UNIT)
181 {
183
185 new TcpFackTest(cca, " Test snd.fack and awnd values after four packets are dropped."),
187 }
188};
189
190/**
191 * @brief Static variable for test initialization
192 */
Test case for Forward Acknowledgment(FACK).
void ConfigureEnvironment() override
Change the configuration of the environment.
void ProcessedAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who) override
Processed ack.
uint32_t m_seqToKill
Sequence number to drop.
void RcvAck(const Ptr< const TcpSocketState > tcb, const TcpHeader &h, SocketWho who) override
Received ack.
TcpFackTest(TypeId congControl, const std::string &desc)
Constructor.
Ptr< TcpSeqErrorModel > m_errorModel
Error model.
Ptr< ErrorModel > CreateReceiverErrorModel() override
Create and return the error model to install in the receiver node.
uint32_t m_pkts
Number of packets to drop.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
void PktDropped(const Ipv4Header &ipH, const TcpHeader &tcpH, Ptr< const Packet > p)
Count number of packets dropped.
uint32_t m_pktDropped
The Number of packets has been dropped.
TypeId m_congControlType
Congestion control algorithm type used for this test.
uint32_t m_startSeqToKill
Sequence number of the first packet to drop.
void ConfigureProperties() override
Change the configuration of the socket properties.
uint32_t m_pktSize
Sender Packet Size.
Test suite for verifying the behavior of the TCP FACK implementation under controlled packet loss sce...
AttributeValue implementation for Boolean.
Definition boolean.h:26
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
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.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
void SetInitialCwnd(SocketWho who, uint32_t initialCwnd)
Forcefully set the initial cwnd.
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 > GetSenderSocket()
Get the pointer to a previously created sender socket.
void SetSegmentSize(SocketWho who, uint32_t segmentSize)
Forcefully set the segment size.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
Ptr< const TcpOption > GetOption(uint8_t kind) const
Get the option specified.
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
static TypeId GetTypeId()
Get the type ID.
std::list< SackBlock > SackList
SACK list definition.
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:49
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:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
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:605
static TcpFackTestSuite g_tcpFackTestSuite
Static variable for test initialization.