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 
40 using namespace ns3;
41 
49 {
50 public:
52  virtual ~BulkSendBasicTestCase ();
53 
54 private:
55  virtual void DoRun (void);
60  void SendTx (Ptr<const Packet> p);
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 
80 void
82 {
83  m_sent += p->GetSize ();
84 }
85 
86 void
88 {
89  m_received += p->GetSize ();
90 }
91 
92 void
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);
107  Ipv4AddressHelper ipv4;
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 
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 {
146 public:
148  virtual ~BulkSendSeqTsSizeTestCase ();
149 
150 private:
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 
185 void
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");
191  m_seqTxCounter++;
192  NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastTxTs, "Timestamp less than last time");
193  m_lastTxTs = header.GetTs ();
194 }
195 
196 void
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");
202  m_seqRxCounter++;
203  NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastRxTs, "Timestamp less than last time");
204  m_lastRxTs = header.GetTs ();
205 }
206 
207 void
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);
222  Ipv4AddressHelper ipv4;
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 {
261 public:
263 };
264 
266  : TestSuite ("bulk-send-application", UNIT)
267 {
268  AddTestCase (new BulkSendBasicTestCase, TestCase::QUICK);
269  AddTestCase (new BulkSendSeqTsSizeTestCase, TestCase::QUICK);
270 }
271 
273 
BulkSendBasicTestCase::SendTx
void SendTx(Ptr< const Packet > p)
Record a packet successfully sent.
Definition: bulk-send-application-test-suite.cc:81
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::SeqTsSizeHeader::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const override
Definition: seq-ts-size-header.cc:75
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::ApplicationContainer::Get
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Definition: application-container.cc:62
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
BulkSendSeqTsSizeTestCase
This test checks that the sequence number is sent and received in sequence despite the sending applic...
Definition: bulk-send-application-test-suite.cc:145
ns3::SeqTsSizeHeader
Header with a sequence, a timestamp, and a "size" attribute.
Definition: seq-ts-size-header.h:38
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
BulkSendBasicTestCase::m_received
uint64_t m_received
number of bytes received
Definition: bulk-send-application-test-suite.cc:68
NS_TEST_ASSERT_MSG_GT_OR_EQ
#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:1016
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::PacketSinkHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Definition: packet-sink-helper.cc:36
BulkSendSeqTsSizeTestCase::SendTx
void SendTx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
Record a packet successfully sent.
Definition: bulk-send-application-test-suite.cc:186
ns3::BulkSendHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes, not the socket attributes.
Definition: bulk-send-helper.cc:39
ns3::BulkSendHelper
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
Definition: bulk-send-helper.h:43
BulkSendSeqTsSizeTestCase::m_lastRxTs
Time m_lastRxTs
Last recored timestamp on Rx.
Definition: bulk-send-application-test-suite.cc:173
BulkSendSeqTsSizeTestCase::ReceiveRx
void ReceiveRx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
Record a packet successfully received.
Definition: bulk-send-application-test-suite.cc:197
BulkSendSeqTsSizeTestCase::m_lastTxTs
Time m_lastTxTs
Last recored timestamp on Tx.
Definition: bulk-send-application-test-suite.cc:172
first.devices
devices
Definition: first.py:39
BulkSendBasicTestCase::m_sent
uint64_t m_sent
number of bytes sent
Definition: bulk-send-application-test-suite.cc:67
first.nodes
nodes
Definition: first.py:32
ns3::TestCase
encapsulates test code
Definition: test.h:1154
ns3::SimpleNetDeviceHelper::SetChannelAttribute
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: simple-net-device-helper.cc:88
BulkSendBasicTestCase::~BulkSendBasicTestCase
virtual ~BulkSendBasicTestCase()
Definition: bulk-send-application-test-suite.cc:76
ns3::Ipv4AddressHelper::SetBase
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Definition: ipv4-address-helper.cc:64
ns3::Ptr< const Packet >
ns3::SimpleNetDeviceHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Definition: simple-net-device-helper.cc:82
BulkSendBasicTestCase::BulkSendBasicTestCase
BulkSendBasicTestCase()
Definition: bulk-send-application-test-suite.cc:71
BulkSendBasicTestCase
Basic test, checks that the right quantity of packets are sent and received.
Definition: bulk-send-application-test-suite.cc:49
ns3::Address
a polymophic address class
Definition: address.h:91
BulkSendSeqTsSizeTestCase::~BulkSendSeqTsSizeTestCase
virtual ~BulkSendSeqTsSizeTestCase()
Definition: bulk-send-application-test-suite.cc:181
ns3::InternetStackHelper::Install
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Definition: internet-stack-helper.cc:366
BulkSendSeqTsSizeTestCase::m_seqTxCounter
uint64_t m_seqTxCounter
Counter for Sequences on Tx.
Definition: bulk-send-application-test-suite.cc:170
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
BulkSendBasicTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: bulk-send-application-test-suite.cc:93
BulkSendSeqTsSizeTestCase::m_received
uint64_t m_received
number of bytes received
Definition: bulk-send-application-test-suite.cc:169
ns3::SimpleNetDeviceHelper
build a set of SimpleNetDevice objects
Definition: simple-net-device-helper.h:37
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::SeqTsHeader::GetTs
Time GetTs(void) const
Definition: seq-ts-header.cc:54
g_bulkSendTestSuite
static BulkSendTestSuite g_bulkSendTestSuite
Static variable for test initialization.
Definition: bulk-send-application-test-suite.cc:272
ns3::SimpleNetDeviceHelper::Install
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
Definition: simple-net-device-helper.cc:100
BulkSendSeqTsSizeTestCase::m_seqRxCounter
uint64_t m_seqRxCounter
Counter for Sequences on Rx.
Definition: bulk-send-application-test-suite.cc:171
sink
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56
ns3::MakeCallback
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:1642
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition: packet-sink-helper.h:36
ns3::BulkSendHelper::Install
ApplicationContainer Install(NodeContainer c) const
Install an ns3::BulkSendApplication on each node of the input container configured with all the attri...
Definition: bulk-send-helper.cc:58
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
BulkSendTestSuite
BulkSend TestSuite.
Definition: bulk-send-application-test-suite.cc:260
NS_TEST_ASSERT_MSG_EQ
#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:166
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Ipv4AddressHelper::Assign
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Definition: ipv4-address-helper.cc:135
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
BulkSendTestSuite::BulkSendTestSuite
BulkSendTestSuite()
Definition: bulk-send-application-test-suite.cc:265
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
BulkSendSeqTsSizeTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: bulk-send-application-test-suite.cc:208
BulkSendSeqTsSizeTestCase::BulkSendSeqTsSizeTestCase
BulkSendSeqTsSizeTestCase()
Definition: bulk-send-application-test-suite.cc:176
ns3::Ipv4InterfaceContainer::GetAddress
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Definition: ipv4-interface-container.cc:59
ns3::SeqTsHeader::GetSeq
uint32_t GetSeq(void) const
Definition: seq-ts-header.cc:47
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
BulkSendSeqTsSizeTestCase::m_sent
uint64_t m_sent
number of bytes sent
Definition: bulk-send-application-test-suite.cc:168
BulkSendBasicTestCase::ReceiveRx
void ReceiveRx(Ptr< const Packet > p, const Address &addr)
Record a packet successfully received.
Definition: bulk-send-application-test-suite.cc:87
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::PacketSinkHelper::Install
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
Definition: packet-sink-helper.cc:55
port
uint16_t port
Definition: dsdv-manet.cc:45