A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-regression.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 "aodv-regression.h"
10
11#include "bug-772.h"
12
13#include "ns3/abort.h"
14#include "ns3/aodv-helper.h"
15#include "ns3/boolean.h"
16#include "ns3/config.h"
17#include "ns3/double.h"
18#include "ns3/icmpv4.h"
19#include "ns3/internet-stack-helper.h"
20#include "ns3/ipv4-address-helper.h"
21#include "ns3/mobility-helper.h"
22#include "ns3/mobility-model.h"
23#include "ns3/pcap-file.h"
24#include "ns3/pcap-test.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 * @ingroup aodv-test
37 *
38 * @brief AODV regression test suite
39 */
41{
42 public:
44 : TestSuite("routing-aodv-regression", Type::SYSTEM)
45 {
46 SetDataDir(NS_TEST_SOURCEDIR);
47 // General RREQ-RREP-RRER test case
48 AddTestCase(new ChainRegressionTest("aodv-chain-regression-test"),
50 // \bugid{606} test case, should crash if bug is not fixed
51 AddTestCase(new ChainRegressionTest("bug-606-test", Seconds(10), 3, Seconds(1)),
53 // \bugid{772} UDP test case
54 AddTestCase(new Bug772ChainTest("udp-chain-test", "ns3::UdpSocketFactory", Seconds(3), 10),
56 }
57} g_aodvRegressionTestSuite; ///< the test suite
58
59/**
60 * @ingroup aodv-test
61 *
62 * @brief Chain Regression Test
63 */
65 Time t,
66 uint32_t size,
67 Time arpAliveTimeout)
68 : TestCase("AODV chain regression test"),
69 m_nodes(nullptr),
70 m_prefix(prefix),
71 m_time(t),
72 m_size(size),
73 m_step(120),
74 m_arpAliveTimeout(arpAliveTimeout),
75 m_seq(0)
76{
77}
78
83
84void
86{
87 if (Simulator::Now() >= m_time)
88 {
89 return;
90 }
91
93 Icmpv4Echo echo;
95 m_seq++;
96 echo.SetIdentifier(0);
97
98 Ptr<Packet> dataPacket = Create<Packet>(56);
99 echo.SetData(dataPacket);
100 p->AddHeader(echo);
101 Icmpv4Header header;
103 header.SetCode(0);
105 {
106 header.EnableChecksum();
107 }
108 p->AddHeader(header);
109 m_socket->Send(p, 0);
111}
112
113void
115{
118 Config::SetDefault("ns3::ArpCache::AliveTimeout", TimeValue(m_arpAliveTimeout));
119
120 CreateNodes();
122
123 // At m_time / 3 move central node away and see what will happen
124 Ptr<Node> node = m_nodes->Get(m_size / 2);
125 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
126 Simulator::Schedule(Time(m_time / 3), &MobilityModel::SetPosition, mob, Vector(1e5, 1e5, 1e5));
127
131
132 CheckResults();
133
134 delete m_nodes, m_nodes = nullptr;
135}
136
137void
139{
141 m_nodes->Create(m_size);
142 MobilityHelper mobility;
143 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
144 "MinX",
145 DoubleValue(0.0),
146 "MinY",
147 DoubleValue(0.0),
148 "DeltaX",
150 "DeltaY",
151 DoubleValue(0),
152 "GridWidth",
154 "LayoutType",
155 StringValue("RowFirst"));
156 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
157 mobility.Install(*m_nodes);
158}
159
160void
162{
163 // 1. Setup WiFi
164 int64_t streamsUsed = 0;
165 WifiMacHelper wifiMac;
166 wifiMac.SetType("ns3::AdhocWifiMac");
167 YansWifiPhyHelper wifiPhy;
170 Ptr<YansWifiChannel> chan = wifiChannel.Create();
171 wifiPhy.SetChannel(chan);
172
173 // This test suite output was originally based on YansErrorRateModel
174 wifiPhy.SetErrorRateModel("ns3::YansErrorRateModel");
175 WifiHelper wifi;
176 wifi.SetStandard(WIFI_STANDARD_80211a);
177 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
178 "DataMode",
179 StringValue("OfdmRate6Mbps"),
180 "RtsCtsThreshold",
181 StringValue("2200"));
182 NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, *m_nodes);
183
184 // Assign fixed stream numbers to wifi and channel random variables
185 streamsUsed += WifiHelper::AssignStreams(devices, streamsUsed);
186 // Assign 6 streams per device
187 NS_TEST_ASSERT_MSG_EQ(streamsUsed, (devices.GetN() * 2), "Stream assignment mismatch");
188 streamsUsed += wifiChannel.AssignStreams(chan, streamsUsed);
189 // Assign 0 streams per channel for this configuration
190 NS_TEST_ASSERT_MSG_EQ(streamsUsed, (devices.GetN() * 2), "Stream assignment mismatch");
191
192 // 2. Setup TCP/IP & AODV
193 AodvHelper aodv; // Use default parameters here
194 InternetStackHelper internetStack;
195 internetStack.SetRoutingHelper(aodv);
196 internetStack.Install(*m_nodes);
197 streamsUsed += internetStack.AssignStreams(*m_nodes, streamsUsed);
198 // InternetStack uses m_size more streams
199 NS_TEST_ASSERT_MSG_EQ(streamsUsed, (devices.GetN() * 5) + m_size, "Stream assignment mismatch");
200 streamsUsed += aodv.AssignStreams(*m_nodes, streamsUsed);
201 // AODV uses m_size more streams
202 NS_TEST_ASSERT_MSG_EQ(streamsUsed,
203 ((devices.GetN() * 5) + (2 * m_size)),
204 "Stream assignment mismatch");
205
206 Ipv4AddressHelper address;
207 address.SetBase("10.1.1.0", "255.255.255.0");
208 Ipv4InterfaceContainer interfaces = address.Assign(devices);
209
210 // 3. Setup ping
211 m_socket =
212 Socket::CreateSocket(m_nodes->Get(0), TypeId::LookupByName("ns3::Ipv4RawSocketFactory"));
213 m_socket->SetAttribute("Protocol", UintegerValue(1)); // icmp
215 m_socket->Bind(src);
216 InetSocketAddress dst = InetSocketAddress(interfaces.GetAddress(m_size - 1), 0);
217 m_socket->Connect(dst);
218
219 SendPing();
220
221 // 4. write PCAP
223}
224
225void
227{
228 for (uint32_t i = 0; i < m_size; ++i)
229 {
230 NS_PCAP_TEST_EXPECT_EQ(m_prefix << "-" << i << "-0.pcap");
231 }
232}
AODV deferred route lookup test case (see Bug 772)
Definition bug-772.h:29
AODV chain regression test.
const uint32_t m_size
Chain size.
void CreateNodes()
Create test topology.
void DoRun() override
Go.
uint16_t m_seq
Sequence number.
void SendPing()
Send one ping.
const Time m_arpAliveTimeout
ARP alive timeout.
const double m_step
Chain step, meters.
~ChainRegressionTest() override
NodeContainer * m_nodes
void CheckResults()
Compare traces with reference ones.
const Time m_time
Total simulation time.
const std::string m_prefix
PCAP file names prefix.
Ptr< Socket > m_socket
Socket.
void CreateDevices()
Create devices, install TCP/IP stack and applications.
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
ICMP Echo header.
Definition icmpv4.h:99
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition icmpv4.cc:139
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition icmpv4.cc:153
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition icmpv4.cc:146
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
void SetCode(uint8_t code)
Set ICMP code.
Definition icmpv4.cc:112
void SetType(uint8_t type)
Set ICMP type.
Definition icmpv4.cc:105
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition icmpv4.cc:49
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.
Keep track of the current position and velocity of an object.
void SetPosition(const Vector &position)
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
static bool ChecksumEnabled()
Definition node.cc:267
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
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 EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
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
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1055
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1274
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
static constexpr auto SYSTEM
Definition test.h:1293
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 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)
AodvRegressionTestSuite g_aodvRegressionTestSuite
the test suite
ChainRegressionTest(const char *const prefix, Time time=Seconds(10), uint32_t size=5, Time arpAliveTimeout=Seconds(120))
Create test case.
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
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.
#define NS_PCAP_TEST_EXPECT_EQ(filename)
Test that a pair of reference/new pcap files are equal.
Definition pcap-test.h:28