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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "tcp-general-test.h"
9
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/tcp-header.h"
13
14using namespace ns3;
15
16NS_LOG_COMPONENT_DEFINE("TcpDatSentCbTest");
17
18/**
19 * \ingroup internet-test
20 *
21 * \brief Socket that the 50% of the times saves the entire packet in the buffer,
22 * while in the other 50% saves only half the packet.
23 */
25{
26 public:
27 /**
28 * \brief Get the type ID.
29 * \return the object TypeId
30 */
31 static TypeId GetTypeId();
32
37
38 protected:
39 Ptr<TcpSocketBase> Fork() override;
40 void ReceivedData(Ptr<Packet> packet, const TcpHeader& tcpHeader) override;
41};
42
44
47{
48 static TypeId tid = TypeId("ns3::TcpSocketHalfAck")
50 .SetGroupName("Internet")
51 .AddConstructor<TcpSocketHalfAck>();
52 return tid;
53}
54
60
61void
63{
64 NS_LOG_FUNCTION(this << packet << tcpHeader);
65 static uint32_t times = 1;
66
67 Ptr<Packet> halved = packet->Copy();
68
69 if (times % 2 == 0)
70 {
71 halved->RemoveAtEnd(packet->GetSize() / 2);
72 }
73
74 times++;
75
76 TcpSocketMsgBase::ReceivedData(halved, tcpHeader);
77}
78
79/**
80 * \ingroup internet-test
81 *
82 * \brief Data Sent callback test
83 *
84 * The rationale of this test is to check if the dataSent callback advertises
85 * to the application all the transmitted bytes. We know in advance how many
86 * bytes are being transmitted, and we check if the amount of data notified
87 * equals this value.
88 *
89 */
91{
92 public:
93 /**
94 * Constructor.
95 * \param desc Test description.
96 * \param size Packet size.
97 * \param packets Number of packets.
98 */
99 TcpDataSentCbTestCase(const std::string& desc, uint32_t size, uint32_t packets)
100 : TcpGeneralTest(desc),
101 m_pktSize(size),
102 m_pktCount(packets),
104 {
105 }
106
107 protected:
109
110 void DataSent(uint32_t size, SocketWho who) override;
111 void ConfigureEnvironment() override;
112 void FinalChecks() override;
113
114 private:
115 uint32_t m_pktSize; //!< Packet size.
116 uint32_t m_pktCount; //!< Number of packets sent.
117 uint32_t m_notifiedData; //!< Amount of data notified.
118};
119
120void
127
128void
130{
131 NS_LOG_FUNCTION(this << who << size);
132
133 m_notifiedData += size;
134}
135
136void
138{
141 "Notified more data than application sent");
142}
143
151
152/**
153 * \ingroup internet-test
154 *
155 * \brief TestSuite: Data Sent callback
156 */
158{
159 public:
161 : TestSuite("tcp-datasentcb", Type::UNIT)
162 {
163 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 500, 10),
164 TestCase::Duration::QUICK);
165 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 100, 100),
166 TestCase::Duration::QUICK);
167 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 1000, 50),
168 TestCase::Duration::QUICK);
169 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 855, 18),
170 TestCase::Duration::QUICK);
171 AddTestCase(new TcpDataSentCbTestCase("Check the data sent callback", 1243, 59),
172 TestCase::Duration::QUICK);
173 }
174};
175
176static 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.
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
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:36
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:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
#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:134
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpDataSentCbTestSuite g_tcpDataSentCbTestSuite
Static variable for test initialization.