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 
43 {
44 public:
46  virtual ~BulkSendBasicTestCase ();
47 
48 private:
49  virtual void DoRun (void);
50  void SendTx (Ptr<const Packet> p);
51  void ReceiveRx (Ptr<const Packet> p, const Address& addr);
52  uint64_t m_sent {0};
53  uint64_t m_received {0};
54 };
55 
57  : TestCase ("Check a basic 300KB transfer")
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68  m_sent += p->GetSize ();
69 }
70 
71 void
73 {
74  m_received += p->GetSize ();
75 }
76 
77 void
79 {
80  Ptr<Node> sender = CreateObject<Node> ();
81  Ptr<Node> receiver = CreateObject<Node> ();
83  nodes.Add (sender);
84  nodes.Add (receiver);
85  SimpleNetDeviceHelper simpleHelper;
86  simpleHelper.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
87  simpleHelper.SetChannelAttribute ("Delay", StringValue ("10ms"));
89  devices = simpleHelper.Install (nodes);
90  InternetStackHelper internet;
91  internet.Install (nodes);
92  Ipv4AddressHelper ipv4;
93  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
95  uint16_t port = 9;
96  BulkSendHelper sourceHelper ("ns3::TcpSocketFactory",
98  sourceHelper.SetAttribute ("MaxBytes", UintegerValue (300000));
99  ApplicationContainer sourceApp = sourceHelper.Install (nodes.Get (0));
100  sourceApp.Start (Seconds (0.0));
101  sourceApp.Stop (Seconds (10.0));
102  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
103  InetSocketAddress (Ipv4Address::GetAny (), port));
104  ApplicationContainer sinkApp = sinkHelper.Install (nodes.Get (1));
105  sinkApp.Start (Seconds (0.0));
106  sinkApp.Stop (Seconds (10.0));
107 
108  Ptr<BulkSendApplication> source = DynamicCast<BulkSendApplication> (sourceApp.Get (0));
109  Ptr<PacketSink> sink = DynamicCast<PacketSink> (sinkApp.Get (0));
110 
113 
114  Simulator::Run ();
115  Simulator::Destroy ();
116 
117  NS_TEST_ASSERT_MSG_EQ (m_sent, 300000, "Sent the full 300000 bytes");
118  NS_TEST_ASSERT_MSG_EQ (m_received, 300000, "Received the full 300000 bytes");
119 }
120 
121 // This test checks that the sequence number is sent and received in sequence
122 // despite the sending application having to pause and restart its sending
123 // due to a temporarily full transmit buffer.
125 {
126 public:
128  virtual ~BulkSendSeqTsSizeTestCase ();
129 
130 private:
131  virtual void DoRun (void);
132  void SendTx (Ptr<const Packet> p, const Address &from, const Address & to, const SeqTsSizeHeader &header);
133  void ReceiveRx (Ptr<const Packet> p, const Address &from, const Address & to, const SeqTsSizeHeader &header);
134  uint64_t m_sent {0};
135  uint64_t m_received {0};
136  uint64_t m_seqTxCounter {0};
137  uint64_t m_seqRxCounter {0};
140 };
141 
143  : TestCase ("Check a 300KB transfer with SeqTsSize header enabled")
144 {
145 }
146 
148 {
149 }
150 
151 void
153 {
154  // The header is not serialized onto the packet in this trace
155  m_sent += p->GetSize () + header.GetSerializedSize ();
156  NS_TEST_ASSERT_MSG_EQ (header.GetSeq (), m_seqTxCounter, "Missing sequence number");
157  m_seqTxCounter++;
158  NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastTxTs, "Timestamp less than last time");
159  m_lastTxTs = header.GetTs ();
160 }
161 
162 void
164 {
165  // The header is not serialized onto the packet in this trace
166  m_received += p->GetSize () + header.GetSerializedSize ();
167  NS_TEST_ASSERT_MSG_EQ (header.GetSeq (), m_seqRxCounter, "Missing sequence number");
168  m_seqRxCounter++;
169  NS_TEST_ASSERT_MSG_GT_OR_EQ (header.GetTs (), m_lastRxTs, "Timestamp less than last time");
170  m_lastRxTs = header.GetTs ();
171 }
172 
173 void
175 {
176  Ptr<Node> sender = CreateObject<Node> ();
177  Ptr<Node> receiver = CreateObject<Node> ();
179  nodes.Add (sender);
180  nodes.Add (receiver);
181  SimpleNetDeviceHelper simpleHelper;
182  simpleHelper.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
183  simpleHelper.SetChannelAttribute ("Delay", StringValue ("10ms"));
185  devices = simpleHelper.Install (nodes);
186  InternetStackHelper internet;
187  internet.Install (nodes);
188  Ipv4AddressHelper ipv4;
189  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
191  uint16_t port = 9;
192  BulkSendHelper sourceHelper ("ns3::TcpSocketFactory",
194  sourceHelper.SetAttribute ("MaxBytes", UintegerValue (300000));
195  sourceHelper.SetAttribute ("EnableSeqTsSizeHeader", BooleanValue (true));
196  ApplicationContainer sourceApp = sourceHelper.Install (nodes.Get (0));
197  sourceApp.Start (Seconds (0.0));
198  sourceApp.Stop (Seconds (10.0));
199  PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
200  InetSocketAddress (Ipv4Address::GetAny (), port));
201  sinkHelper.SetAttribute ("EnableSeqTsSizeHeader", BooleanValue (true));
202  ApplicationContainer sinkApp = sinkHelper.Install (nodes.Get (1));
203  sinkApp.Start (Seconds (0.0));
204  sinkApp.Stop (Seconds (10.0));
205 
206  Ptr<BulkSendApplication> source = DynamicCast<BulkSendApplication> (sourceApp.Get (0));
207  Ptr<PacketSink> sink = DynamicCast<PacketSink> (sinkApp.Get (0));
208 
209  source->TraceConnectWithoutContext ("TxWithSeqTsSize", MakeCallback (&BulkSendSeqTsSizeTestCase::SendTx, this));
211 
212  Simulator::Run ();
213  Simulator::Destroy ();
214 
215  NS_TEST_ASSERT_MSG_EQ (m_sent, 300000, "Sent the full 300000 bytes");
216  NS_TEST_ASSERT_MSG_EQ (m_received, 300000, "Received the full 300000 bytes");
217 }
218 
220 {
221 public:
223 };
224 
226  : TestSuite ("bulk-send-application", UNIT)
227 {
228  AddTestCase (new BulkSendBasicTestCase, TestCase::QUICK);
229  AddTestCase (new BulkSendSeqTsSizeTestCase, TestCase::QUICK);
230 }
231 
233 
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
an Inet address class
virtual void DoRun(void)
Implementation to actually run this TestCase.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Hold variables of type string.
Definition: string.h:41
Header with a sequence, a timestamp, and a "size" attribute.
A suite of tests to run.
Definition: test.h:1343
void ReceiveRx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
aggregate IP/TCP/UDP functionality to existing Nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::BulkSendApplication on each node of the input container configured with all the attri...
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
encapsulates test code
Definition: test.h:1153
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
nodes
Definition: first.py:32
void SendTx(Ptr< const Packet > p, const Address &from, const Address &to, const SeqTsSizeHeader &header)
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
Definition: uinteger.h:44
#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
holds a vector of ns3::NetDevice pointers
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
virtual uint32_t GetSerializedSize(void) const override
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
void SendTx(Ptr< const Packet > p)
uint32_t GetSeq(void) const
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void ReceiveRx(Ptr< const Packet > p, const Address &addr)
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
static BulkSendTestSuite g_bulkSendTestSuite
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes, not the socket attributes...
devices
Definition: first.py:39
build a set of SimpleNetDevice objects
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::SimpleChannel with the attributes configured by SimpleNetDeviceHelper::Se...
#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
Time GetTs(void) const
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
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.