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 
24 using namespace ns3;
25 
26 NS_LOG_COMPONENT_DEFINE ("TcpPktsAckedTestSuite");
27 
28 class DummyCongControl;
29 
47 {
48 public:
53  TcpPktsAckedOpenTest (const std::string &desc);
54 
59  void PktsAckedCalled (uint32_t segmentsAcked);
60 
61 protected:
62  virtual Ptr<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> node);
63  virtual void Rx (const Ptr<const Packet> p, const TcpHeader&h, SocketWho who);
64 
65  virtual void ConfigureEnvironment ();
66 
67  void FinalChecks ();
68 
69 private:
70  uint32_t m_segmentsAcked;
71  uint32_t m_segmentsReceived;
72 
74 };
75 
84 {
85 public:
90  static TypeId GetTypeId (void);
91 
93  {
94  }
95 
101  {
102  m_test = test;
103  }
104 
105  void PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
106  const Time& rtt)
107  {
108  m_test (segmentsAcked);
109  }
110 
111 private:
113 };
114 
115 TypeId
117 {
118  static TypeId tid = TypeId ("ns3::DummyCongControl")
119  .SetParent<TcpNewReno> ()
120  .AddConstructor<DummyCongControl> ()
121  .SetGroupName ("Internet")
122  ;
123  return tid;
124 }
125 
127  : TcpGeneralTest (desc),
128  m_segmentsAcked (0),
129  m_segmentsReceived (0)
130 {
131 }
132 
133 void
135 {
136  TcpGeneralTest::ConfigureEnvironment ();
137  SetAppPktCount (20);
138  SetMTU (500);
139 }
140 
143 {
144  Ptr<TcpSocketMsgBase> s = TcpGeneralTest::CreateSenderSocket (node);
145  m_congCtl = CreateObject<DummyCongControl> ();
148 
149  return s;
150 }
151 
152 void
154 {
155  m_segmentsAcked += segmentsAcked;
156 }
157 
158 void
160 {
161  if (who == SENDER && (!(h.GetFlags () & TcpHeader::SYN)))
162  {
164  }
165 }
166 
167 void
169 {
171  "Not all acked segments have been passed to PktsAcked method");
172 }
173 
174 
175 
183 {
184 public:
185  TcpPktsAckedTestSuite () : TestSuite ("tcp-pkts-acked-test", UNIT)
186  {
187  AddTestCase (new TcpPktsAckedOpenTest ("PktsAcked check while in OPEN state"),
188  TestCase::QUICK);
189  // Add DISORDER, RECOVERY and LOSS state check
190  }
191 };
192 
194 
void SetCongestionControlAlgorithm(Ptr< TcpCongestionOps > algo)
Install a congestion control algorithm on this socket.
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Check the number of times that PktsAcked is called.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
A suite of tests to run.
Definition: test.h:1342
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
TcpPktsAckedOpenTest(const std::string &desc)
Constructor.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Callback< void, uint32_t > m_test
Callback to be used when an ACK is received.
The NewReno implementation.
This test suite implements a Unit Test.
Definition: test.h:1352
uint32_t m_segmentsAcked
Contains the number of times PktsAcked is called.
static TcpPktsAckedTestSuite g_TcpPktsAckedTestSuite
Static variable for test initialization.
virtual void Rx(const Ptr< const Packet > p, const TcpHeader &h, SocketWho who)
Packet received from IP layer.
PktsAcked is calls TestSuite.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void SetMTU(uint32_t mtu)
MTU of the bottleneck link.
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
#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:168
Ptr< DummyCongControl > m_congCtl
Dummy congestion control.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Behaves as NewReno, except that each time PktsAcked is called, a notification is sent to TcpPktsAcked...
void FinalChecks()
Performs the (eventual) final checks through test asserts.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSegSize(SocketWho who)
Get the segment size of the node specified.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
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.
General infrastructure for TCP testing.
uint32_t m_segmentsReceived
Contains the ack number received.
a unique identifier for an interface.
Definition: type-id.h:58
void SetCallback(Callback< void, uint32_t > test)
Set the callback to be used when an ACK is received.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
static TypeId GetTypeId(void)
Get the type ID.