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 * 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-general-test.h"
20
21#include "ns3/log.h"
22#include "ns3/node.h"
23#include "ns3/tcp-header.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("TcpPktsAckedTestSuite");
28
30
31/**
32 * \ingroup internet-test
33 *
34 * \brief Check the number of times that PktsAcked is called
35 *
36 * Set a custom congestion control class, which calls PktsAckedCalled
37 * each time the TCP implementation calls PktsAcked.
38 *
39 * The checks are performed in FinalChecks: the number of bytes acked divided
40 * by segment size should be the same as the number of segments passed through
41 * PktsAcked in the congestion control.
42 *
43 * \see DummyCongControl
44 * \see FinalChecks
45 */
47{
48 public:
49 /**
50 * \brief Constructor.
51 * \param desc Test description.
52 */
53 TcpPktsAckedOpenTest(const std::string& desc);
54
55 /**
56 * \brief Called when an ACK is received.
57 * \param segmentsAcked The segment ACKed.
58 */
59 void PktsAckedCalled(uint32_t segmentsAcked);
60
61 protected:
63 void Rx(const Ptr<const Packet> p, const TcpHeader& h, SocketWho who) override;
64
65 void ConfigureEnvironment() override;
66
67 void FinalChecks() override;
68
69 private:
70 uint32_t m_segmentsAcked; //!< Contains the number of times PktsAcked is called
71 uint32_t m_segmentsReceived; //!< Contains the ack number received
72
73 Ptr<DummyCongControl> m_congCtl; //!< Dummy congestion control.
74};
75
76/**
77 * \ingroup internet-test
78 *
79 * \brief Behaves as NewReno, except that each time PktsAcked is called,
80 * a notification is sent to TcpPktsAckedOpenTest.
81 */
83{
84 public:
85 /**
86 * \brief Get the type ID.
87 * \return the object TypeId
88 */
89 static TypeId GetTypeId();
90
92 {
93 }
94
95 /**
96 * \brief Set the callback to be used when an ACK is received.
97 * \param test The callback.
98 */
100 {
101 m_test = test;
102 }
103
104 void PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt) override
105 {
106 m_test(segmentsAcked);
107 }
108
109 private:
110 Callback<void, uint32_t> m_test; //!< Callback to be used when an ACK is received.
111};
112
113TypeId
115{
116 static TypeId tid = TypeId("ns3::DummyCongControl")
118 .AddConstructor<DummyCongControl>()
119 .SetGroupName("Internet");
120 return tid;
121}
122
124 : TcpGeneralTest(desc),
125 m_segmentsAcked(0),
126 m_segmentsReceived(0)
127{
128}
129
130void
132{
134 SetAppPktCount(20);
135 SetMTU(500);
136}
137
140{
142 m_congCtl = CreateObject<DummyCongControl>();
144 s->SetCongestionControlAlgorithm(m_congCtl);
145
146 return s;
147}
148
149void
151{
152 m_segmentsAcked += segmentsAcked;
153}
154
155void
157{
158 if (who == SENDER && (!(h.GetFlags() & TcpHeader::SYN)))
159 {
161 }
162}
163
164void
166{
169 "Not all acked segments have been passed to PktsAcked method");
170}
171
172/**
173 * \ingroup internet-test
174 *
175 * \brief PktsAcked is calls TestSuite.
176 */
178{
179 public:
181 : TestSuite("tcp-pkts-acked-test", Type::UNIT)
182 {
183 AddTestCase(new TcpPktsAckedOpenTest("PktsAcked check while in OPEN state"),
184 TestCase::Duration::QUICK);
185 // Add DISORDER, RECOVERY and LOSS state check
186 }
187};
188
189static 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:438
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:47
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:148
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:124
The NewReno implementation.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:145
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:706
-ns3 Test suite for the ns3 wrapper script
static TcpPktsAckedTestSuite g_TcpPktsAckedTestSuite
Static variable for test initialization.