A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-pkts-acked-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-general-test.h"
9
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/tcp-header.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpPktsAckedTestSuite");
17
19
20/**
21 * \ingroup internet-test
22 *
23 * \brief Check the number of times that PktsAcked is called
24 *
25 * Set a custom congestion control class, which calls PktsAckedCalled
26 * each time the TCP implementation calls PktsAcked.
27 *
28 * The checks are performed in FinalChecks: the number of bytes acked divided
29 * by segment size should be the same as the number of segments passed through
30 * PktsAcked in the congestion control.
31 *
32 * \see DummyCongControl
33 * \see FinalChecks
34 */
36{
37 public:
38 /**
39 * \brief Constructor.
40 * \param desc Test description.
41 */
42 TcpPktsAckedOpenTest(const std::string& desc);
43
44 /**
45 * \brief Called when an ACK is received.
46 * \param segmentsAcked The segment ACKed.
47 */
48 void PktsAckedCalled(uint32_t segmentsAcked);
49
50 protected:
52 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
53
54 void ConfigureEnvironment() override;
55
56 void FinalChecks() override;
57
58 private:
59 uint32_t m_segmentsAcked; //!< Contains the number of times PktsAcked is called
60 uint32_t m_segmentsReceived; //!< Contains the ack number received
61
62 Ptr<DummyCongControl> m_congCtl; //!< Dummy congestion control.
63};
64
65/**
66 * \ingroup internet-test
67 *
68 * \brief Behaves as NewReno, except that each time PktsAcked is called,
69 * a notification is sent to TcpPktsAckedOpenTest.
70 */
72{
73 public:
74 /**
75 * \brief Get the type ID.
76 * \return the object TypeId
77 */
78 static TypeId GetTypeId();
79
81 {
82 }
83
84 /**
85 * \brief Set the callback to be used when an ACK is received.
86 * \param test The callback.
87 */
92
93 void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt) override
94 {
95 m_test(segmentsAcked);
96 }
97
98 private:
99 Callback<void, uint32_t> m_test; //!< Callback to be used when an ACK is received.
100};
101
102TypeId
104{
105 static TypeId tid = TypeId("ns3::DummyCongControl")
107 .AddConstructor<DummyCongControl>()
108 .SetGroupName("Internet");
109 return tid;
110}
111
113 : TcpGeneralTest(desc),
114 m_segmentsAcked(0),
115 m_segmentsReceived(0)
116{
117}
118
119void
126
137
138void
140{
141 m_segmentsAcked += segmentsAcked;
142}
143
144void
146{
147 if (who == SENDER && (!(h.GetFlags() & TcpHeader::SYN)))
148 {
150 }
151}
152
153void
155{
158 "Not all acked segments have been passed to PktsAcked method");
159}
160
161/**
162 * \ingroup internet-test
163 *
164 * \brief PktsAcked is calls TestSuite.
165 */
167{
168 public:
170 : TestSuite("tcp-pkts-acked-test", Type::UNIT)
171 {
172 AddTestCase(new TcpPktsAckedOpenTest("PktsAcked check while in OPEN state"),
173 TestCase::Duration::QUICK);
174 // Add DISORDER, RECOVERY and LOSS state check
175 }
176};
177
178static TcpPktsAckedTestSuite g_TcpPktsAckedTestSuite; //!< Static variable for test initialization
Behaves as NewReno, except that each time PktsAcked is called, a notification is sent to TcpPktsAcked...
Callback< void, uint32_t > m_test
Callback to be used when an ACK is received.
void SetCallback(Callback< void, uint32_t > test)
Set the callback to be used when an ACK is received.
static TypeId GetTypeId()
Get the type ID.
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Check the number of times that PktsAcked is called.
void PktsAckedCalled(uint32_t segmentsAcked)
Called when an ACK is received.
uint32_t m_segmentsAcked
Contains the number of times PktsAcked is called.
Ptr< DummyCongControl > m_congCtl
Dummy congestion control.
void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who) override
Packet received from IP layer.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
void ConfigureEnvironment() override
Change the configuration of the environment.
Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node) override
Create and install the socket to install on the sender.
uint32_t m_segmentsReceived
Contains the ack number received.
TcpPktsAckedOpenTest(const std::string &desc)
Constructor.
PktsAcked is calls TestSuite.
Callback template class.
Definition callback.h:422
Smart pointer class similar to boost::intrusive_ptr.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
General infrastructure for TCP testing.
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.
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
uint8_t GetFlags() const
Get the flags.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
The NewReno implementation.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
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:684
-ns3 Test suite for the ns3 wrapper script
static TcpPktsAckedTestSuite g_TcpPktsAckedTestSuite
Static variable for test initialization.