A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tcp-datasentcb-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 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 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("TcpDatSentCbTest");
27 
33 {
34 public:
35  static TypeId GetTypeId (void);
36 
38  {
39  }
40 
42  {
43  }
44 protected:
45  virtual Ptr<TcpSocketBase> Fork ();
46  virtual void ReceivedData (Ptr<Packet> packet, const TcpHeader& tcpHeader);
47 };
48 
49 NS_OBJECT_ENSURE_REGISTERED (TcpSocketHalfAck);
50 
51 TypeId
53 {
54  static TypeId tid = TypeId ("ns3::TcpSocketHalfAck")
56  .SetGroupName ("Internet")
57  .AddConstructor<TcpSocketHalfAck> ()
58  ;
59  return tid;
60 }
61 
64 {
65  return CopyObject<TcpSocketHalfAck> (this);
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION (this << packet << tcpHeader);
72  static uint32_t times = 1;
73 
74  Ptr<Packet> halved = packet->Copy ();
75 
76  if (times % 2 == 0)
77  halved->RemoveAtEnd (packet->GetSize () / 2);
78 
79  times++;
80 
81  TcpSocketMsgBase::ReceivedData (halved, tcpHeader);
82 }
83 
84 
95 {
96 public:
97  TcpDataSentCbTestCase (const std::string &desc, uint32_t size, uint32_t packets) :
98  TcpGeneralTest (desc),
99  m_pktSize (size),
100  m_pktCount (packets),
101  m_notifiedData (0)
102  { }
103 
104 protected:
106 
107  virtual void DataSent (uint32_t size, SocketWho who);
108  virtual void ConfigureEnvironment ();
109  virtual void FinalChecks ();
110 
111 private:
112  uint32_t m_pktSize;
113  uint32_t m_pktCount;
114  uint32_t m_notifiedData;
115 };
116 
117 void
119 {
123 }
124 
125 void
127 {
128  NS_LOG_FUNCTION (this << who << size);
129 
130  m_notifiedData += size;
131 }
132 
133 void
135 {
137  "Notified more data than application sent");
138 }
139 
142 {
143  NS_LOG_FUNCTION (this);
144 
146 }
147 
148 static class TcpDataSentCbTestSuite : public TestSuite
149 {
150 public:
152  : TestSuite ("tcp-datasentcb", UNIT)
153  {
154  AddTestCase (new TcpDataSentCbTestCase ("Check the data sent callback", 500, 10), TestCase::QUICK);
155  AddTestCase (new TcpDataSentCbTestCase ("Check the data sent callback", 100, 100), TestCase::QUICK);
156  AddTestCase (new TcpDataSentCbTestCase ("Check the data sent callback", 1000, 50), TestCase::QUICK);
157  AddTestCase (new TcpDataSentCbTestCase ("Check the data sent callback", 855, 18), TestCase::QUICK);
158  AddTestCase (new TcpDataSentCbTestCase ("Check the data sent callback", 1243, 59), TestCase::QUICK);
159  }
160 
162 
163 } // namespace ns3
Socket that the 50% of the times saves the entire packet in the buffer, while in the other 50% saves ...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetPktSize() const
Get the application packet size.
Class for inserting callbacks special points of the flow of TCP sockets.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
A suite of tests to run.
Definition: test.h:1333
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
ns3::TcpDataSentCbTestSuite g_tcpDataSentCbTestSuite
TcpDataSentCbTestCase(const std::string &desc, uint32_t size, uint32_t packets)
TcpSocketHalfAck(const TcpSocketHalfAck &other)
Data Sent callback test.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
#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:161
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual void DataSent(uint32_t size, SocketWho who)
Notifying application for sent data.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
virtual void FinalChecks()
Performs the (eventual) final checks through test asserts.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
Definition: packet.cc:333
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
static TypeId GetTypeId(void)
Fast test.
Definition: test.h:1152
SocketWho
Used as parameter of methods, specifies on what node the caller is interested (e.g.
virtual Ptr< TcpSocketBase > Fork()
Call CopyObject<> to clone me.
General infrastructure for TCP testing.
virtual void ConfigureEnvironment(void)
Change the configuration of the evironment.
uint32_t GetPktCount() const
Get the number of application packets.
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
virtual void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Recv of a data, put into buffer, call L7 to get it if necessary.
This test suite implements a Unit Test.
Definition: test.h:1343
virtual void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader)
Recv of a data, put into buffer, call L7 to get it if necessary.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:827
TypeId m_congControlTypeId
Congestion control.