A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bug-772.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Pavel Boyko <boyko@iitp.ru>
7 */
8
9#include "bug-772.h"
10
11#include "ns3/abort.h"
12#include "ns3/aodv-helper.h"
13#include "ns3/boolean.h"
14#include "ns3/config.h"
15#include "ns3/data-rate.h"
16#include "ns3/double.h"
17#include "ns3/inet-socket-address.h"
18#include "ns3/internet-stack-helper.h"
19#include "ns3/ipv4-address-helper.h"
20#include "ns3/mobility-helper.h"
21#include "ns3/mobility-model.h"
22#include "ns3/random-variable-stream.h"
23#include "ns3/rng-seed-manager.h"
24#include "ns3/simulator.h"
25#include "ns3/string.h"
26#include "ns3/uinteger.h"
27#include "ns3/yans-wifi-helper.h"
28
29#include <sstream>
30
31using namespace ns3;
32
33//-----------------------------------------------------------------------------
34// UdpChainTest
35//-----------------------------------------------------------------------------
36Bug772ChainTest::Bug772ChainTest(const char* const prefix,
37 const char* const proto,
38 Time t,
39 uint32_t size)
40 : TestCase("Bug 772 UDP and TCP chain regression test"),
41 m_nodes(nullptr),
42 m_prefix(prefix),
43 m_proto(proto),
44 m_time(t),
45 m_size(size),
46 m_step(120),
47 m_port(9),
49{
50}
51
56
57void
59{
60 if (Simulator::Now() < m_time)
61 {
62 socket->Send(Create<Packet>(1000));
63 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
64 Seconds(0.25),
66 this,
67 socket);
68 }
69}
70
71void
76
77void
79{
82
83 // Default of 3 will cause packet loss
84 Config::SetDefault("ns3::ArpCache::PendingQueueSize", UintegerValue(10));
85
88
89 Simulator::Stop(m_time + Seconds(1)); // Allow buffered packets to clear
92
94
95 delete m_nodes, m_nodes = nullptr;
96}
97
98void
100{
102 m_nodes->Create(m_size);
103 MobilityHelper mobility;
104 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
105 "MinX",
106 DoubleValue(0.0),
107 "MinY",
108 DoubleValue(0.0),
109 "DeltaX",
111 "DeltaY",
112 DoubleValue(0),
113 "GridWidth",
115 "LayoutType",
116 StringValue("RowFirst"));
117 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
118 mobility.Install(*m_nodes);
119}
120
121void
123{
124 int64_t streamsUsed = 0;
125 int64_t totalStreamsUsed = 0;
126 int64_t streamNumber = 0;
127 int64_t streamIncrement = 1000;
128 // 1. Setup WiFi
129 WifiMacHelper wifiMac;
130 wifiMac.SetType("ns3::AdhocWifiMac");
131 YansWifiPhyHelper wifiPhy;
133 // This test suite output was originally based on YansErrorRateModel
134 wifiPhy.SetErrorRateModel("ns3::YansErrorRateModel");
136 Ptr<YansWifiChannel> chan = wifiChannel.Create();
137 wifiPhy.SetChannel(chan);
138 wifiPhy.Set(
139 "TxGain",
140 DoubleValue(1.0)); // this configuration should go away in future revision to the test
141 wifiPhy.Set(
142 "RxGain",
143 DoubleValue(1.0)); // this configuration should go away in future revision to the test
144 WifiHelper wifi;
145 wifi.SetStandard(WIFI_STANDARD_80211a);
146 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
147 "DataMode",
148 StringValue("OfdmRate6Mbps"),
149 "RtsCtsThreshold",
150 StringValue("2200"));
151 NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, *m_nodes);
152
153 // Assign fixed stream numbers to wifi and channel random variables
154 streamsUsed = WifiHelper::AssignStreams(devices, streamNumber);
155 totalStreamsUsed += streamsUsed;
156 streamNumber += streamIncrement;
157 constexpr int expectedWifiStreamsPerDevice = 4;
158 NS_TEST_ASSERT_MSG_EQ(streamsUsed,
159 (devices.GetN() * expectedWifiStreamsPerDevice),
160 "Stream assignment mismatch");
161 streamsUsed = wifiChannel.AssignStreams(chan, streamNumber);
162 totalStreamsUsed += streamsUsed;
163 streamNumber += streamIncrement;
164 // Assign 0 streams per channel for this configuration
165 NS_TEST_ASSERT_MSG_EQ(streamsUsed, 0, "No WifiChannel stream usage expected");
166
167 // 2. Setup TCP/IP & AODV
168 AodvHelper aodv; // Use default parameters here
169 InternetStackHelper internetStack;
170 internetStack.SetIpv6StackInstall(false);
171 internetStack.SetRoutingHelper(aodv);
172 internetStack.Install(*m_nodes);
173 streamsUsed = internetStack.AssignStreams(*m_nodes, streamNumber);
174 totalStreamsUsed += streamsUsed;
175 streamNumber += streamIncrement;
176
177 constexpr int expectedArpL3ProtocolStreams = 1;
178 constexpr int expectedInternetStreamsPerDevice = expectedArpL3ProtocolStreams;
179
180 // Expect number of streams assigned to match random variables streams used by wifi devices plus
181 // internet stack
183 totalStreamsUsed,
184 (devices.GetN() * (expectedWifiStreamsPerDevice + expectedInternetStreamsPerDevice)),
185 "Stream assignment mismatch");
186 streamsUsed = aodv.AssignStreams(*m_nodes, streamsUsed);
187 totalStreamsUsed += streamsUsed;
188 streamNumber += streamIncrement;
189
190 // Expect number of streams assigned to match random variables streams used by wifi devices plus
191 // internet and aodv stack
192 constexpr int expectedAodvStreamsPerDevice = 1;
194 totalStreamsUsed,
195 (devices.GetN() * (expectedWifiStreamsPerDevice + expectedInternetStreamsPerDevice +
196 expectedAodvStreamsPerDevice)),
197 "Stream assignment mismatch");
198 Ipv4AddressHelper address;
199 address.SetBase("10.1.1.0", "255.255.255.0");
200 Ipv4InterfaceContainer interfaces = address.Assign(devices);
201
202 // 3. Setup UDP source and sink
204 m_sendSocket->Bind();
205 m_sendSocket->Connect(InetSocketAddress(interfaces.GetAddress(m_size - 1), m_port));
206 m_sendSocket->SetAllowBroadcast(true);
208 Seconds(1),
210 this,
212
215 m_recvSocket->Listen();
216 m_recvSocket->ShutdownSend();
217 m_recvSocket->SetRecvCallback(MakeCallback(&Bug772ChainTest::HandleRead, this));
218}
219
220void
222{
223 // We should have sent 8 packets (every 0.25 seconds from time 1 to time 3)
224 // Check that the received packet count is 8
225 NS_TEST_EXPECT_MSG_EQ(m_receivedPackets, 8, "Did not receive expected 8 packets");
226}
const std::string m_proto
Socket factory TID.
Definition bug-772.h:49
Bug772ChainTest(const char *const prefix, const char *const proto, Time time, uint32_t size)
Create test case.
Definition bug-772.cc:36
void HandleRead(Ptr< Socket > socket)
Receive data function.
Definition bug-772.cc:72
const uint16_t m_port
port number
Definition bug-772.h:57
void DoRun() override
Go.
Definition bug-772.cc:78
Ptr< Socket > m_recvSocket
Receiving socket.
Definition bug-772.h:74
NodeContainer * m_nodes
Definition bug-772.h:44
const uint32_t m_size
Chain size.
Definition bug-772.h:53
~Bug772ChainTest() override
Definition bug-772.cc:52
const std::string m_prefix
PCAP file names prefix.
Definition bug-772.h:47
void CreateNodes()
Create test topology.
Definition bug-772.cc:99
const double m_step
Chain step, meters.
Definition bug-772.h:55
void CreateDevices()
Create devices, install TCP/IP stack and applications.
Definition bug-772.cc:122
void SendData(Ptr< Socket > socket)
Send data.
Definition bug-772.cc:58
Ptr< Socket > m_sendSocket
Transmitting socket.
Definition bug-772.h:76
const Time m_time
Total simulation time.
Definition bug-772.h:51
void CheckResults()
Compare traces with reference ones.
Definition bug-772.cc:221
uint32_t m_receivedPackets
Received packet count.
Definition bug-772.h:79
Helper class that adds AODV routing to nodes.
Definition aodv-helper.h:25
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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...
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
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.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:597
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
Hold variables of type string.
Definition string.h:45
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:874
Hold an unsigned integer type.
Definition uinteger.h:34
helps to create WifiNetDevice objects
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void Set(std::string name, const AttributeValue &v)
void DisablePreambleDetectionModel()
Disable the preamble detection model on all links.
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
manage and create wifi channel objects for the YANS model.
int64_t AssignStreams(Ptr< YansWifiChannel > c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the channel.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
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:690
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
#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:133
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
@ WIFI_STANDARD_80211a
Every class exported by the ns3 library is enclosed in the ns3 namespace.