A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-datasentcb-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 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("TcpDatSentCbTest");
28
29/**
30 * \ingroup internet-test
31 *
32 * \brief Socket that the 50% of the times saves the entire packet in the buffer,
33 * while in the other 50% saves only half the packet.
34 */
36{
37 public:
38 /**
39 * \brief Get the type ID.
40 * \return the object TypeId
41 */
42 static TypeId GetTypeId();
43
46 {
47 }
48
49 protected:
50 Ptr<TcpSocketBase> Fork() override;
51 void ReceivedData(Ptr<Packet> packet, const TcpHeader& tcpHeader) override;
52};
53
55
58{
59 static TypeId tid = TypeId("ns3::TcpSocketHalfAck")
61 .SetGroupName("Internet")
62 .AddConstructor<TcpSocketHalfAck>();
63 return tid;
64}
65
68{
69 return CopyObject<TcpSocketHalfAck>(this);
70}
71
72void
74{
75 NS_LOG_FUNCTION(this << packet << tcpHeader);
76 static uint32_t times = 1;
77
78 Ptr<Packet> halved = packet->Copy();
79
80 if (times % 2 == 0)
81 {
82 halved->RemoveAtEnd(packet->GetSize() / 2);
83 }
84
85 times++;
86
87 TcpSocketMsgBase::ReceivedData(halved, tcpHeader);
88}
89
90/**
91 * \ingroup internet-test
92 *
93 * \brief Data Sent callback test
94 *
95 * The rationale of this test is to check if the dataSent callback advertises
96 * to the application all the transmitted bytes. We know in advance how many
97 * bytes are being transmitted, and we check if the amount of data notified
98 * equals this value.
99 *
100 */
102{
103 public:
104 /**
105 * Constructor.
106 * \param desc Test description.
107 * \param size Packet size.
108 * \param packets Number of packets.
109 */
110 TcpDataSentCbTestCase(const std::string& desc, uint32_t size, uint32_t packets)
111 : TcpGeneralTest(desc),
112 m_pktSize(size),
113 m_pktCount(packets),
115 {
116 }
117
118 protected:
120
121 void DataSent(uint32_t size, SocketWho who) override;
122 void ConfigureEnvironment() override;
123 void FinalChecks() override;
124
125 private:
126 uint32_t m_pktSize; //!< Packet size.
127 uint32_t m_pktCount; //!< Number of packets sent.
128 uint32_t m_notifiedData; //!< Amount of data notified.
129};
130
131void
133{
137}
138
139void
141{
142 NS_LOG_FUNCTION(this << who << size);
143
144 m_notifiedData += size;
145}
146
147void
149{
152 "Notified more data than application sent");
153}
154
157{
158 NS_LOG_FUNCTION(this);
159
161}
162
163/**
164 * \ingroup internet-test
165 *
166 * \brief TestSuite: Data Sent callback
167 */
169{
170 public:
172 : TestSuite("tcp-datasentcb", Type::UNIT)
173 {
174 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 500, 10),
175 TestCase::Duration::QUICK);
176 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 100, 100),
177 TestCase::Duration::QUICK);
178 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 1000, 50),
179 TestCase::Duration::QUICK);
180 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 855, 18),
181 TestCase::Duration::QUICK);
182 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 1243, 59),
183 TestCase::Duration::QUICK);
184 }
185};
186
187static TcpDataSentCbTestSuite g_tcpDataSentCbTestSuite; //!< Static variable for test initialization
Data Sent callback test.
Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node) override
Create and install the socket to install on the receiver.
void DataSent(uint32_t size, SocketWho who) override
Notifying application for sent data.
void ConfigureEnvironment() override
Change the configuration of the environment.
uint32_t m_notifiedData
Amount of data notified.
TcpDataSentCbTestCase(const std::string &desc, uint32_t size, uint32_t packets)
Constructor.
uint32_t m_pktCount
Number of packets sent.
uint32_t m_pktSize
Packet size.
void FinalChecks() override
Performs the (eventual) final checks through test asserts.
TestSuite: Data Sent callback.
Socket that the 50% of the times saves the entire packet in the buffer, while in the other 50% saves ...
Ptr< TcpSocketBase > Fork() override
Call CopyObject<> to clone me.
static TypeId GetTypeId()
Get the type ID.
void ReceivedData(Ptr< Packet > packet, const TcpHeader &tcpHeader) override
Recv of a data, put into buffer, call L7 to get it if necessary.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
General infrastructure for TCP testing.
uint32_t GetPktCount() const
Get the number of application packets.
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 SetAppPktSize(uint32_t pktSize)
Set app packet size.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
TypeId m_congControlTypeId
Congestion control.
virtual void ConfigureEnvironment()
Change the configuration of the environment.
uint32_t GetPktSize() const
Get the application packet size.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
Class for inserting callbacks special points of the flow of TCP sockets.
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
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_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
#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.
static TcpDataSentCbTestSuite g_tcpDataSentCbTestSuite
Static variable for test initialization.