A Discrete-Event Network Simulator
API
bulk-send-application-test-suite.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2020 Tom Henderson (tomh@tomh.org)
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 "ns3/test.h"
21#include "ns3/nstime.h"
22#include "ns3/node.h"
23#include "ns3/traced-callback.h"
24#include "ns3/node-container.h"
25#include "ns3/application-container.h"
26#include "ns3/simple-net-device-helper.h"
27#include "ns3/string.h"
28#include "ns3/uinteger.h"
29#include "ns3/boolean.h"
30#include "ns3/internet-stack-helper.h"
31#include "ns3/ipv4-address.h"
32#include "ns3/inet-socket-address.h"
33#include "ns3/ipv4-address-helper.h"
34#include "ns3/ipv4-interface-container.h"
35#include "ns3/bulk-send-application.h"
36#include "ns3/bulk-send-helper.h"
37#include "ns3/packet-sink.h"
38#include "ns3/packet-sink-helper.h"
39
40using namespace ns3;
41
49{
50public:
52 virtual ~BulkSendBasicTestCase ();
53
54private:
55 virtual void DoRun (void);
66 void ReceiveRx (Ptr<const Packet> p, const Address& addr);
67 uint64_t m_sent {0};
68 uint64_t m_received {0};
69};
70
72 : TestCase ("Check a basic 300KB transfer")
73{
74}
75
77{
78}
79
80void
82{
83 m_sent += p->GetSize ();
84}
85
86void
88{
89 m_received += p->GetSize ();
90}
91
92void
94{
95 Ptr<Node> sender = CreateObject<Node> ();
96 Ptr<Node> receiver = CreateObject<Node> ();
98 nodes.Add (sender);
99 nodes.Add (receiver);
100 SimpleNetDeviceHelper simpleHelper;
101 simpleHelper.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
102 simpleHelper.SetChannelAttribute ("Delay", StringValue ("10ms"));
104 devices = simpleHelper.Install (nodes);
105 InternetStackHelper internet;
106 internet.Install (nodes);
108 ipv4.SetBase ("10.1.1.0", "255.255.255.0");
110 uint16_t port = 9;
111 BulkSendHelper sourceHelper ("ns3::TcpSocketFactory",
113 sourceHelper.SetAttribute ("MaxBytes", UintegerValue (300000));
114 ApplicationContainer sourceApp = sourceHelper.Install (nodes.Get (0));
115 sourceApp.Start (Seconds (0.0));
116 sourceApp.Stop (Seconds (10.0));
117 PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
118 InetSocketAddress (Ipv4Address::GetAny (), port));
119 ApplicationContainer sinkApp = sinkHelper.Install (nodes.Get (1));
120 sinkApp.Start (Seconds (0.0));
121 sinkApp.Stop (Seconds (10.0));
122
123 Ptr<BulkSendApplication> source = DynamicCast<BulkSendApplication> (sourceApp.Get (0));
124 Ptr<PacketSink> sink = DynamicCast<PacketSink> (sinkApp.Get (0));
125
126 source->TraceConnectWithoutContext ("Tx", MakeCallback (&BulkSendBasicTestCase::SendTx, this));
128
129 Simulator::Run ();
130 Simulator::Destroy ();
131
132 NS_TEST_ASSERT_MSG_EQ (m_sent, 300000, "Sent the full 300000 bytes");
133 NS_TEST_ASSERT_MSG_EQ (m_received, 300000, "Received the full 300000 bytes");
134}
135
145{
146public:
149
150private:
151 virtual void DoRun (void);
159 void SendTx (Ptr<const Packet> p, const Address &from, const Address & to, const SeqTsSizeHeader &header);
167 void ReceiveRx (Ptr<const Packet> p, const Address &from, const Address & to, const SeqTsSizeHeader &header);
168 uint64_t m_sent {0};
169 uint64_t m_received {0};
170 uint64_t m_seqTxCounter {0};
171 uint64_t m_seqRxCounter {0};
174};
175
177 : TestCase ("Check a 300KB transfer with SeqTsSize header enabled")
178{
179}
180
182{
183}
184
185void
187{
188 // The header is not serialized onto the packet in this trace
189 m_sent += p->GetSize () + header.GetSerializedSize ();
190 NS_TEST_ASSERT_MSG_EQ (header.GetSeq (), m_seqTxCounter, "Missing sequence number");
192 NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastTxTs, "Timestamp less than last time");
193 m_lastTxTs = header.GetTs ();
194}
195
196void
198{
199 // The header is not serialized onto the packet in this trace
200 m_received += p->GetSize () + header.GetSerializedSize ();
201 NS_TEST_ASSERT_MSG_EQ (header.GetSeq (), m_seqRxCounter, "Missing sequence number");
203 NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastRxTs, "Timestamp less than last time");
204 m_lastRxTs = header.GetTs ();
205}
206
207void
209{
210 Ptr<Node> sender = CreateObject<Node> ();
211 Ptr<Node> receiver = CreateObject<Node> ();
213 nodes.Add (sender);
214 nodes.Add (receiver);
215 SimpleNetDeviceHelper simpleHelper;
216 simpleHelper.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
217 simpleHelper.SetChannelAttribute ("Delay", StringValue ("10ms"));
219 devices = simpleHelper.Install (nodes);
220 InternetStackHelper internet;
221 internet.Install (nodes);
223 ipv4.SetBase ("10.1.1.0", "255.255.255.0");
225 uint16_t port = 9;
226 BulkSendHelper sourceHelper ("ns3::TcpSocketFactory",
228 sourceHelper.SetAttribute ("MaxBytes", UintegerValue (300000));
229 sourceHelper.SetAttribute ("EnableSeqTsSizeHeader", BooleanValue (true));
230 ApplicationContainer sourceApp = sourceHelper.Install (nodes.Get (0));
231 sourceApp.Start (Seconds (0.0));
232 sourceApp.Stop (Seconds (10.0));
233 PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
234 InetSocketAddress (Ipv4Address::GetAny (), port));
235 sinkHelper.SetAttribute ("EnableSeqTsSizeHeader", BooleanValue (true));
236 ApplicationContainer sinkApp = sinkHelper.Install (nodes.Get (1));
237 sinkApp.Start (Seconds (0.0));
238 sinkApp.Stop (Seconds (10.0));
239
240 Ptr<BulkSendApplication> source = DynamicCast<BulkSendApplication> (sourceApp.Get (0));
241 Ptr<PacketSink> sink = DynamicCast<PacketSink> (sinkApp.Get (0));
242
243 source->TraceConnectWithoutContext ("TxWithSeqTsSize", MakeCallback (&BulkSendSeqTsSizeTestCase::SendTx, this));
245
246 Simulator::Run ();
247 Simulator::Destroy ();
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
260{
261public:
263};
264
266 : TestSuite ("bulk-send-application", UNIT)
267{
268 AddTestCase (new BulkSendBasicTestCase, TestCase::QUICK);
269 AddTestCase (new BulkSendSeqTsSizeTestCase, TestCase::QUICK);
270}
271
273
static BulkSendTestSuite g_bulkSendTestSuite
Static variable for test initialization.
Basic test, checks that the right quantity of packets are sent and received.
uint64_t m_sent
number of bytes sent
virtual void DoRun(void)
Implementation to actually run this TestCase.
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...
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time m_lastTxTs
Last recored 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 recored 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.
uint64_t m_received
number of bytes received
a polymophic address class
Definition: address.h:91
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes, not the socket attributes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::BulkSendApplication on each node of the input container configured with all the attri...
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
uint32_t GetSeq(void) const
Time GetTs(void) const
Header with a sequence, a timestamp, and a "size" attribute.
virtual uint32_t GetSerializedSize(void) 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...
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Hold an unsigned integer type.
Definition: uinteger.h:44
uint16_t port
Definition: dsdv-manet.cc:45
#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:141
#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:862
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
devices
Definition: first.py:39
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56