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/pcap-file.h"
23#include "ns3/pcap-test.h"
24#include "ns3/random-variable-stream.h"
25#include "ns3/rng-seed-manager.h"
26#include "ns3/simulator.h"
27#include "ns3/string.h"
28#include "ns3/uinteger.h"
29#include "ns3/yans-wifi-helper.h"
30
31#include <sstream>
32
33using namespace ns3;
34
35//-----------------------------------------------------------------------------
36// UdpChainTest
37//-----------------------------------------------------------------------------
38Bug772ChainTest::Bug772ChainTest(const char* const prefix,
39 const char* const proto,
40 Time t,
41 uint32_t size)
42 : TestCase("Bug 772 UDP and TCP chain regression test"),
43 m_nodes(nullptr),
44 m_prefix(prefix),
45 m_proto(proto),
46 m_time(t),
47 m_size(size),
48 m_step(120),
49 m_port(9),
51{
52}
53
58
59void
61{
62 if (Simulator::Now() < m_time)
63 {
64 socket->Send(Create<Packet>(1000));
65 Simulator::ScheduleWithContext(socket->GetNode()->GetId(),
66 Seconds(0.25),
68 this,
69 socket);
70 }
71}
72
73void
78
79void
81{
84
85 // Default of 3 will cause packet loss
86 Config::SetDefault("ns3::ArpCache::PendingQueueSize", UintegerValue(10));
87
90
91 Simulator::Stop(m_time + Seconds(1)); // Allow buffered packets to clear
94
96
97 delete m_nodes, m_nodes = nullptr;
98}
99
100void
102{
104 m_nodes->Create(m_size);
105 MobilityHelper mobility;
106 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
107 "MinX",
108 DoubleValue(0.0),
109 "MinY",
110 DoubleValue(0.0),
111 "DeltaX",
113 "DeltaY",
114 DoubleValue(0),
115 "GridWidth",
117 "LayoutType",
118 StringValue("RowFirst"));
119 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
120 mobility.Install(*m_nodes);
121}
122
123void
125{
126 int64_t streamsUsed = 0;
127 // 1. Setup WiFi
128 WifiMacHelper wifiMac;
129 wifiMac.SetType("ns3::AdhocWifiMac");
130 YansWifiPhyHelper wifiPhy;
132 // This test suite output was originally based on YansErrorRateModel
133 wifiPhy.SetErrorRateModel("ns3::YansErrorRateModel");
135 Ptr<YansWifiChannel> chan = wifiChannel.Create();
136 wifiPhy.SetChannel(chan);
137 wifiPhy.Set(
138 "TxGain",
139 DoubleValue(1.0)); // this configuration should go away in future revision to the test
140 wifiPhy.Set(
141 "RxGain",
142 DoubleValue(1.0)); // this configuration should go away in future revision to the test
143 WifiHelper wifi;
144 wifi.SetStandard(WIFI_STANDARD_80211a);
145 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
146 "DataMode",
147 StringValue("OfdmRate6Mbps"),
148 "RtsCtsThreshold",
149 StringValue("2200"));
150 NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, *m_nodes);
151
152 // Assign fixed stream numbers to wifi and channel random variables
153 streamsUsed += WifiHelper::AssignStreams(devices, streamsUsed);
154 // Assign 6 streams per device
155 NS_TEST_ASSERT_MSG_EQ(streamsUsed, (devices.GetN() * 2), "Stream assignment mismatch");
156 streamsUsed += wifiChannel.AssignStreams(chan, streamsUsed);
157 // Assign 0 streams per channel for this configuration
158 NS_TEST_ASSERT_MSG_EQ(streamsUsed, (devices.GetN() * 2), "Stream assignment mismatch");
159
160 // 2. Setup TCP/IP & AODV
161 AodvHelper aodv; // Use default parameters here
162 InternetStackHelper internetStack;
163 internetStack.SetRoutingHelper(aodv);
164 internetStack.Install(*m_nodes);
165 streamsUsed += internetStack.AssignStreams(*m_nodes, streamsUsed);
166 // Expect to use (3*m_size) more streams for internet stack random variables
167 NS_TEST_ASSERT_MSG_EQ(streamsUsed,
168 ((devices.GetN() * 3) + (3 * m_size)),
169 "Stream assignment mismatch");
170 streamsUsed += aodv.AssignStreams(*m_nodes, streamsUsed);
171 // Expect to use m_size more streams for AODV
172 NS_TEST_ASSERT_MSG_EQ(streamsUsed,
173 ((devices.GetN() * 3) + (3 * m_size) + m_size),
174 "Stream assignment mismatch");
175 Ipv4AddressHelper address;
176 address.SetBase("10.1.1.0", "255.255.255.0");
177 Ipv4InterfaceContainer interfaces = address.Assign(devices);
178
179 // 3. Setup UDP source and sink
181 m_sendSocket->Bind();
182 m_sendSocket->Connect(InetSocketAddress(interfaces.GetAddress(m_size - 1), m_port));
183 m_sendSocket->SetAllowBroadcast(true);
185 Seconds(1),
187 this,
189
192 m_recvSocket->Listen();
193 m_recvSocket->ShutdownSend();
194 m_recvSocket->SetRecvCallback(MakeCallback(&Bug772ChainTest::HandleRead, this));
195}
196
197void
199{
200 // We should have sent 8 packets (every 0.25 seconds from time 1 to time 3)
201 // Check that the received packet count is 8
202 NS_TEST_EXPECT_MSG_EQ(m_receivedPackets, 8, "Did not receive expected 8 packets");
203}
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:38
void HandleRead(Ptr< Socket > socket)
Receive data function.
Definition bug-772.cc:74
const uint16_t m_port
port number
Definition bug-772.h:57
void DoRun() override
Go.
Definition bug-772.cc:80
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:54
const std::string m_prefix
PCAP file names prefix.
Definition bug-772.h:47
void CreateNodes()
Create test topology.
Definition bug-772.cc:101
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:124
void SendData(Ptr< Socket > socket)
Send data.
Definition bug-772.cc:60
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:198
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)
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:66
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:131
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:578
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
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
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition type-id.cc:872
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)
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:436
#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:134
#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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
@ WIFI_STANDARD_80211a
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:684