A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bulk-send-application-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Tom Henderson (tomh@tomh.org)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#include "ns3/application-container.h"
9#include "ns3/boolean.h"
10#include "ns3/bulk-send-application.h"
11#include "ns3/bulk-send-helper.h"
12#include "ns3/inet-socket-address.h"
13#include "ns3/internet-stack-helper.h"
14#include "ns3/ipv4-address-helper.h"
15#include "ns3/ipv4-address.h"
16#include "ns3/ipv4-interface-container.h"
17#include "ns3/node-container.h"
18#include "ns3/node.h"
19#include "ns3/nstime.h"
20#include "ns3/packet-sink-helper.h"
21#include "ns3/packet-sink.h"
22#include "ns3/simple-net-device-helper.h"
23#include "ns3/string.h"
24#include "ns3/test.h"
25#include "ns3/traced-callback.h"
26#include "ns3/uinteger.h"
27
28using namespace ns3;
29
30/**
31 * @ingroup applications-test
32 * @ingroup tests
33 *
34 * Basic test, checks that the right quantity of packets are sent and received.
35 */
37{
38 public:
40 ~BulkSendBasicTestCase() override;
41
42 private:
43 void DoRun() override;
44 /**
45 * Record a packet successfully sent
46 * @param p the packet
47 */
49 /**
50 * Record a packet successfully received
51 * @param p the packet
52 * @param addr the sender's address
53 */
54 void ReceiveRx(Ptr<const Packet> p, const Address& addr);
55 uint64_t m_sent{0}; //!< number of bytes sent
56 uint64_t m_received{0}; //!< number of bytes received
57};
58
60 : TestCase("Check a basic 300KB transfer")
61{
62}
63
67
68void
73
74void
76{
77 m_received += p->GetSize();
78}
79
80void
82{
84 Ptr<Node> receiver = CreateObject<Node>();
86 nodes.Add(sender);
87 nodes.Add(receiver);
88 SimpleNetDeviceHelper simpleHelper;
89 simpleHelper.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
90 simpleHelper.SetChannelAttribute("Delay", StringValue("10ms"));
91 NetDeviceContainer devices;
92 devices = simpleHelper.Install(nodes);
93 InternetStackHelper internet;
94 internet.Install(nodes);
96 ipv4.SetBase("10.1.1.0", "255.255.255.0");
97 Ipv4InterfaceContainer i = ipv4.Assign(devices);
98 uint16_t port = 9;
99 BulkSendHelper sourceHelper("ns3::TcpSocketFactory", InetSocketAddress(i.GetAddress(1), port));
100 sourceHelper.SetAttribute("MaxBytes", UintegerValue(300000));
101 ApplicationContainer sourceApp = sourceHelper.Install(nodes.Get(0));
102 sourceApp.Start(Seconds(0));
103 sourceApp.Stop(Seconds(10));
104 PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
106 ApplicationContainer sinkApp = sinkHelper.Install(nodes.Get(1));
107 sinkApp.Start(Seconds(0));
108 sinkApp.Stop(Seconds(10));
109
112
113 source->TraceConnectWithoutContext("Tx", MakeCallback(&BulkSendBasicTestCase::SendTx, this));
114 sink->TraceConnectWithoutContext("Rx", MakeCallback(&BulkSendBasicTestCase::ReceiveRx, this));
115
118
119 NS_TEST_ASSERT_MSG_EQ(m_sent, 300000, "Sent the full 300000 bytes");
120 NS_TEST_ASSERT_MSG_EQ(m_received, 300000, "Received the full 300000 bytes");
121}
122
123/**
124 * @ingroup applications-test
125 * @ingroup tests
126 *
127 * This test checks that the sequence number is sent and received in sequence
128 * despite the sending application having to pause and restart its sending
129 * due to a temporarily full transmit buffer.
130 */
132{
133 public:
136
137 private:
138 void DoRun() override;
139 /**
140 * Record a packet successfully sent
141 * @param p the packet
142 * @param from source address
143 * @param to destination address
144 * @param header the SeqTsSizeHeader
145 */
147 const Address& from,
148 const Address& to,
149 const SeqTsSizeHeader& header);
150 /**
151 * Record a packet successfully received
152 * @param p the packet
153 * @param from source address
154 * @param to destination address
155 * @param header the SeqTsSizeHeader
156 */
158 const Address& from,
159 const Address& to,
160 const SeqTsSizeHeader& header);
161 uint64_t m_sent{0}; //!< number of bytes sent
162 uint64_t m_received{0}; //!< number of bytes received
163 uint64_t m_seqTxCounter{0}; //!< Counter for Sequences on Tx
164 uint64_t m_seqRxCounter{0}; //!< Counter for Sequences on Rx
165 Time m_lastTxTs{Seconds(0)}; //!< Last recorded timestamp on Tx
166 Time m_lastRxTs{Seconds(0)}; //!< Last recorded timestamp on Rx
167};
168
170 : TestCase("Check a 300KB transfer with SeqTsSize header enabled")
171{
172}
173
177
178void
180 const Address& from,
181 const Address& to,
182 const SeqTsSizeHeader& header)
183{
184 // The header is not serialized onto the packet in this trace
185 m_sent += p->GetSize() + header.GetSerializedSize();
186 NS_TEST_ASSERT_MSG_EQ(header.GetSeq(), m_seqTxCounter, "Missing sequence number");
188 NS_TEST_ASSERT_MSG_GT_OR_EQ(header.GetTs(), m_lastTxTs, "Timestamp less than last time");
189 m_lastTxTs = header.GetTs();
190}
191
192void
194 const Address& from,
195 const Address& to,
196 const SeqTsSizeHeader& header)
197{
198 // The header is not serialized onto the packet in this trace
199 m_received += p->GetSize() + header.GetSerializedSize();
200 NS_TEST_ASSERT_MSG_EQ(header.GetSeq(), m_seqRxCounter, "Missing sequence number");
202 NS_TEST_ASSERT_MSG_GT_OR_EQ(header.GetTs(), m_lastRxTs, "Timestamp less than last time");
203 m_lastRxTs = header.GetTs();
204}
205
206void
208{
209 Ptr<Node> sender = CreateObject<Node>();
210 Ptr<Node> receiver = CreateObject<Node>();
212 nodes.Add(sender);
213 nodes.Add(receiver);
214 SimpleNetDeviceHelper simpleHelper;
215 simpleHelper.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
216 simpleHelper.SetChannelAttribute("Delay", StringValue("10ms"));
217 NetDeviceContainer devices;
218 devices = simpleHelper.Install(nodes);
219 InternetStackHelper internet;
220 internet.Install(nodes);
222 ipv4.SetBase("10.1.1.0", "255.255.255.0");
223 Ipv4InterfaceContainer i = ipv4.Assign(devices);
224 uint16_t port = 9;
225 BulkSendHelper sourceHelper("ns3::TcpSocketFactory", InetSocketAddress(i.GetAddress(1), port));
226 sourceHelper.SetAttribute("MaxBytes", UintegerValue(300000));
227 sourceHelper.SetAttribute("EnableSeqTsSizeHeader", BooleanValue(true));
228 ApplicationContainer sourceApp = sourceHelper.Install(nodes.Get(0));
229 sourceApp.Start(Seconds(0));
230 sourceApp.Stop(Seconds(10));
231 PacketSinkHelper sinkHelper("ns3::TcpSocketFactory",
233 sinkHelper.SetAttribute("EnableSeqTsSizeHeader", BooleanValue(true));
234 ApplicationContainer sinkApp = sinkHelper.Install(nodes.Get(1));
235 sinkApp.Start(Seconds(0));
236 sinkApp.Stop(Seconds(10));
237
240
241 source->TraceConnectWithoutContext("TxWithSeqTsSize",
243 sink->TraceConnectWithoutContext("RxWithSeqTsSize",
245
248
249 NS_TEST_ASSERT_MSG_EQ(m_sent, 300000, "Sent the full 300000 bytes");
250 NS_TEST_ASSERT_MSG_EQ(m_received, 300000, "Received the full 300000 bytes");
251}
252
253/**
254 * @ingroup applications-test
255 * @ingroup tests
256 *
257 * @brief BulkSend TestSuite
258 */
260{
261 public:
263};
264
266 : TestSuite("applications-bulk-send", Type::UNIT)
267{
268 AddTestCase(new BulkSendBasicTestCase, TestCase::Duration::QUICK);
269 AddTestCase(new BulkSendSeqTsSizeTestCase, TestCase::Duration::QUICK);
270}
271
272static BulkSendTestSuite g_bulkSendTestSuite; //!< Static variable for test initialization
static BulkSendTestSuite g_bulkSendTestSuite
Static variable for test initialization.
Basic test, checks that the right quantity of packets are sent and received.
void DoRun() override
Implementation to actually run this TestCase.
uint64_t m_sent
number of bytes sent
void ReceiveRx(Ptr< const Packet > p, const Address &addr)
Record a packet successfully received.
uint64_t m_received
number of bytes received
void SendTx(Ptr< const Packet > p)
Record a packet successfully sent.
This test checks that the sequence number is sent and received in sequence despite the sending applic...
Time m_lastTxTs
Last recorded timestamp on Tx.
void ReceiveRx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
Record a packet successfully received.
Time m_lastRxTs
Last recorded timestamp on Rx.
uint64_t m_seqRxCounter
Counter for Sequences on Rx.
uint64_t m_seqTxCounter
Counter for Sequences on Tx.
void SendTx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
Record a packet successfully sent.
void DoRun() override
Implementation to actually run this TestCase.
uint64_t m_received
number of bytes received
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
AttributeValue implementation for Boolean.
Definition boolean.h:26
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
Time GetTs() const
uint32_t GetSeq() const
Header with a sequence, a timestamp, and a "size" attribute.
uint32_t GetSerializedSize() const override
build a set of SimpleNetDevice objects
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Hold an unsigned integer type.
Definition uinteger.h:34
uint16_t port
Definition dsdv-manet.cc:33
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Definition test.h:905
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44