A Discrete-Event Network Simulator
API
tcp-pkts-acked-test.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2016 Natale Patriciello <natale.patriciello@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20#include "tcp-general-test.h"
21#include "ns3/node.h"
22#include "ns3/log.h"
23#include "ns3/tcp-header.h"
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE ("TcpPktsAckedTestSuite");
28
30
48{
49public:
54 TcpPktsAckedOpenTest (const std::string &desc);
55
60 void PktsAckedCalled (uint32_t segmentsAcked);
61
62protected:
64 virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
65
66 virtual void ConfigureEnvironment ();
67
68 void FinalChecks ();
69
70private:
73
75};
76
85{
86public:
91 static TypeId GetTypeId (void);
92
94 {
95 }
96
102 {
103 m_test = test;
104 }
105
106 void PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
107 const Time& rtt)
108 {
109 m_test (segmentsAcked);
110 }
111
112private:
114};
115
116TypeId
118{
119 static TypeId tid = TypeId ("ns3::DummyCongControl")
121 .AddConstructor<DummyCongControl> ()
122 .SetGroupName ("Internet")
123 ;
124 return tid;
125}
126
128 : TcpGeneralTest (desc),
129 m_segmentsAcked (0),
130 m_segmentsReceived (0)
131{
132}
133
134void
136{
137 TcpGeneralTest::ConfigureEnvironment ();
138 SetAppPktCount (20);
139 SetMTU (500);
140}
141
144{
145 Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateSenderSocket (node);
146 m_congCtl = CreateObject<DummyCongControl> ();
148 s->SetCongestionControlAlgorithm (m_congCtl);
149
150 return s;
151}
152
153void
155{
156 m_segmentsAcked += segmentsAcked;
157}
158
159void
161{
162 if (who == SENDER && (!(h.GetFlags () & TcpHeader::SYN)))
163 {
165 }
166}
167
168void
170{
172 "Not all acked segments have been passed to PktsAcked method");
173}
174
175
176
184{
185public:
186 TcpPktsAckedTestSuite () : TestSuite ("tcp-pkts-acked-test", UNIT)
187 {
188 AddTestCase (new TcpPktsAckedOpenTest ("PktsAcked check while in OPEN state"),
189 TestCase::QUICK);
190 // Add DISORDER, RECOVERY and LOSS state check
191 }
192};
193
195
Behaves as NewReno, except that each time PktsAcked is called, a notification is sent to TcpPktsAcked...
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
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(void)
Get the type ID.
Check the number of times that PktsAcked is called.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
void PktsAckedCalled(uint32_t segmentsAcked)
Called when an ACK is received.
uint32_t m_segmentsAcked
Contains the number of times PktsAcked is called.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
Ptr< DummyCongControl > m_congCtl
Dummy congestion control.
void FinalChecks()
Performs the (eventual) final checks through test asserts.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
uint32_t m_segmentsReceived
Contains the ack number received.
TcpPktsAckedOpenTest(const std::string &desc)
Constructor.
PktsAcked is calls TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
General infrastructure for TCP testing.
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.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:45
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
The NewReno implementation.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:141
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
static TcpPktsAckedTestSuite g_TcpPktsAckedTestSuite
Static variable for test initialization.