24 #include "ns3/abort.h"
25 #include "ns3/config.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/inet-socket-address.h"
29 #include "ns3/internet-stack-helper.h"
30 #include "ns3/ipv4-address-helper.h"
31 #include "ns3/udp-client-server-helper.h"
32 #include "ns3/udp-echo-helper.h"
33 #include "ns3/simple-net-device.h"
34 #include "ns3/simple-channel.h"
36 #include "ns3/simulator.h"
52 virtual void DoRun (
void);
56 UdpClientServerTestCase::UdpClientServerTestCase ()
57 :
TestCase (
"Test that all the udp packets generated by an udpClient application are correctly received by an udpServer application")
61 UdpClientServerTestCase::~UdpClientServerTestCase ()
79 rxDev->SetChannel (channel1);
80 txDev->SetChannel (channel1);
87 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
96 uint32_t MaxPacketSize = 1024;
98 uint32_t maxPacketCount = 10;
101 client.SetAttribute (
"Interval",
TimeValue (interPacketInterval));
102 client.SetAttribute (
"PacketSize",
UintegerValue (MaxPacketSize));
103 apps = client.Install (n.
Get (0));
108 Simulator::Destroy ();
110 NS_TEST_ASSERT_MSG_EQ (server.GetServer ()->GetLost (), 0,
"Packets were lost !");
111 NS_TEST_ASSERT_MSG_EQ (server.GetServer ()->GetReceived (), 8,
"Did not receive expected number of packets !");
126 virtual void DoRun (
void);
130 UdpTraceClientServerTestCase::UdpTraceClientServerTestCase ()
131 :
TestCase (
"Test that all the udp packets generated by an udpTraceClient application are correctly received by an udpServer application")
135 UdpTraceClientServerTestCase::~UdpTraceClientServerTestCase ()
153 rxDev->SetChannel (channel1);
154 txDev->SetChannel (channel1);
160 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
163 uint16_t port = 4000;
169 uint32_t MaxPacketSize = 1400 - 28;
172 apps = client.Install (n.
Get (0));
177 Simulator::Destroy ();
179 NS_TEST_ASSERT_MSG_EQ (server.GetServer ()->GetLost (), 0,
"Packets were lost !");
180 NS_TEST_ASSERT_MSG_EQ (server.GetServer ()->GetReceived (), 247,
"Did not receive expected number of packets !");
195 virtual void DoRun (
void);
199 PacketLossCounterTestCase::PacketLossCounterTestCase ()
200 :
TestCase (
"Test that all the PacketLossCounter class checks loss correctly in different cases")
204 PacketLossCounterTestCase::~PacketLossCounterTestCase ()
211 lossCounter.NotifyReceived (32);
212 for (uint32_t i = 0; i < 64; i++)
214 lossCounter.NotifyReceived (i);
217 NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 0,
"Check that 0 packets are lost");
219 for (uint32_t i = 65; i < 128; i++)
221 lossCounter.NotifyReceived (i);
223 NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 1,
"Check that 1 packet is lost");
225 for (uint32_t i = 134; i < 200; i++)
227 lossCounter.NotifyReceived (i);
229 NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 7,
"Check that 7 (6+1) packets are lost");
232 lossCounter.NotifyReceived (205);
233 lossCounter.NotifyReceived (206);
234 lossCounter.NotifyReceived (207);
235 lossCounter.NotifyReceived (200);
236 lossCounter.NotifyReceived (201);
237 lossCounter.NotifyReceived (202);
238 lossCounter.NotifyReceived (203);
239 lossCounter.NotifyReceived (204);
240 for (uint32_t i = 205; i < 250; i++)
242 lossCounter.NotifyReceived (i);
244 NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 7,
"Check that 7 (6+1) packets are lost even when reordering happens");
247 lossCounter.NotifyReceived (255);
249 lossCounter.NotifyReceived (252);
250 lossCounter.NotifyReceived (253);
251 lossCounter.NotifyReceived (254);
252 for (uint32_t i = 256; i < 300; i++)
254 lossCounter.NotifyReceived (i);
256 NS_TEST_ASSERT_MSG_EQ (lossCounter.GetLost (), 9,
"Check that 9 (6+1+2) packet are lost");
270 virtual void DoRun (
void);
274 UdpEchoClientSetFillTestCase::UdpEchoClientSetFillTestCase ()
275 :
TestCase (
"Test that the UdpEchoClient::SetFill class sets packet size (bug 1378)")
279 UdpEchoClientSetFillTestCase::~UdpEchoClientSetFillTestCase ()
296 rxDev->SetChannel (channel1);
297 txDev->SetChannel (channel1);
304 ipv4.
SetBase (
"10.1.1.0",
"255.255.255.0");
307 uint16_t port = 5000;
315 echoClient.SetAttribute (
"PacketSize",
UintegerValue (1024));
321 for (i = 0; i < 64; i++)
325 echoClient.SetFill (clientApps.
Get (0), &(arry[0]), (uint32_t)64, (uint32_t)64);
331 Simulator::Destroy ();
340 UdpClientServerTestSuite::UdpClientServerTestSuite ()
holds a vector of ns3::Application pointers.
smart pointer class similar to boost::intrusive_ptr
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void SetAttribute(std::string name, const AttributeValue &value)
create an application which sends a udp packet and waits for an echo of this packet ...
virtual void DoRun(void)
Implementation to actually run this test case.
aggregate IP/TCP/UDP functionality to existing Nodes.
virtual void DoRun(void)
Implementation to actually run this test case.
ApplicationContainer Install(Ptr< Node > node) const
Create a server application which waits for input udp packets and sends them back to the original sen...
Create a client application which sends udp packets carrying a 32bit sequence number and a 64 bit tim...
hold objects of type ns3::Time
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
virtual void DoRun(void)
Implementation to actually run this test case.
holds a vector of ns3::NetDevice pointers
Create a server application which waits for input udp packets and uses the information carried into t...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
void SetAttribute(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Install(std::string nodeName) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
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 seconds)
create ns3::Time instances in units of seconds.
ApplicationContainer Install(NodeContainer c)
uint32_t AddDevice(Ptr< NetDevice > device)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
virtual void DoRun(void)
Implementation to actually run this test case.