A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * This is an example script for AODV manet routing protocol.
18 *
19 * Authors: Pavel Boyko <boyko@iitp.ru>
20 */
21
22#include "ns3/aodv-module.h"
23#include "ns3/core-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/mobility-module.h"
26#include "ns3/network-module.h"
27#include "ns3/ping-helper.h"
28#include "ns3/point-to-point-module.h"
29#include "ns3/yans-wifi-helper.h"
30
31#include <cmath>
32#include <iostream>
33
34using namespace ns3;
35
59{
60 public:
68 bool Configure(int argc, char** argv);
70 void Run();
75 void Report(std::ostream& os);
76
77 private:
78 // parameters
82 double step;
84 double totalTime;
86 bool pcap;
89
90 // network
97
98 private:
100 void CreateNodes();
102 void CreateDevices();
106 void InstallApplications();
107};
108
109int
110main(int argc, char** argv)
111{
113 if (!test.Configure(argc, argv))
114 {
115 NS_FATAL_ERROR("Configuration failed. Aborted.");
116 }
117
118 test.Run();
119 test.Report(std::cout);
120 return 0;
121}
122
123//-----------------------------------------------------------------------------
125 : size(10),
126 step(50),
127 totalTime(100),
128 pcap(true),
129 printRoutes(true)
130{
131}
132
133bool
134AodvExample::Configure(int argc, char** argv)
135{
136 // Enable AODV logs by default. Comment this if too noisy
137 // LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);
138
140 CommandLine cmd(__FILE__);
141
142 cmd.AddValue("pcap", "Write PCAP traces.", pcap);
143 cmd.AddValue("printRoutes", "Print routing table dumps.", printRoutes);
144 cmd.AddValue("size", "Number of nodes.", size);
145 cmd.AddValue("time", "Simulation time, s.", totalTime);
146 cmd.AddValue("step", "Grid step, m", step);
147
148 cmd.Parse(argc, argv);
149 return true;
150}
151
152void
154{
155 // Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1)); //
156 // enable rts cts all the time.
157 CreateNodes();
161
162 std::cout << "Starting simulation for " << totalTime << " s ...\n";
163
167}
168
169void
171{
172}
173
174void
176{
177 std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n";
179 // Name nodes
180 for (uint32_t i = 0; i < size; ++i)
181 {
182 std::ostringstream os;
183 os << "node-" << i;
184 Names::Add(os.str(), nodes.Get(i));
185 }
186 // Create static grid
187 MobilityHelper mobility;
188 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
189 "MinX",
190 DoubleValue(0.0),
191 "MinY",
192 DoubleValue(0.0),
193 "DeltaX",
195 "DeltaY",
196 DoubleValue(0),
197 "GridWidth",
199 "LayoutType",
200 StringValue("RowFirst"));
201 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
202 mobility.Install(nodes);
203}
204
205void
207{
208 WifiMacHelper wifiMac;
209 wifiMac.SetType("ns3::AdhocWifiMac");
210 YansWifiPhyHelper wifiPhy;
212 wifiPhy.SetChannel(wifiChannel.Create());
213 WifiHelper wifi;
214 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
215 "DataMode",
216 StringValue("OfdmRate6Mbps"),
217 "RtsCtsThreshold",
218 UintegerValue(0));
219 devices = wifi.Install(wifiPhy, wifiMac, nodes);
220
221 if (pcap)
222 {
223 wifiPhy.EnablePcapAll(std::string("aodv"));
224 }
225}
226
227void
229{
230 AodvHelper aodv;
231 // you can configure AODV attributes here using aodv.Set(name, value)
233 stack.SetRoutingHelper(aodv); // has effect on the next Install ()
234 stack.Install(nodes);
235 Ipv4AddressHelper address;
236 address.SetBase("10.0.0.0", "255.0.0.0");
237 interfaces = address.Assign(devices);
238
239 if (printRoutes)
240 {
241 Ptr<OutputStreamWrapper> routingStream =
242 Create<OutputStreamWrapper>("aodv.routes", std::ios::out);
244 }
245}
246
247void
249{
251 ping.SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::VERBOSE));
252
254 p.Start(Seconds(0));
255 p.Stop(Seconds(totalTime) - Seconds(0.001));
256
257 // move node away
258 Ptr<Node> node = nodes.Get(size / 2);
259 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
262 mob,
263 Vector(1e5, 1e5, 1e5));
264}
Test script.
Definition: aodv.cc:59
bool Configure(int argc, char **argv)
Configure script parameters.
Definition: aodv.cc:134
void CreateDevices()
Create the devices.
Definition: aodv.cc:206
void InstallApplications()
Create the simulation applications.
Definition: aodv.cc:248
Ipv4InterfaceContainer interfaces
interfaces used in the example
Definition: aodv.cc:96
bool printRoutes
Print routes if true.
Definition: aodv.cc:88
bool pcap
Write per-device PCAP traces if true.
Definition: aodv.cc:86
NodeContainer nodes
nodes used in the example
Definition: aodv.cc:92
double totalTime
Simulation time, seconds.
Definition: aodv.cc:84
void CreateNodes()
Create the nodes.
Definition: aodv.cc:175
void Run()
Run simulation.
Definition: aodv.cc:153
uint32_t size
Number of nodes.
Definition: aodv.cc:80
void Report(std::ostream &os)
Report results.
Definition: aodv.cc:170
void InstallInternetStack()
Create the network.
Definition: aodv.cc:228
NetDeviceContainer devices
devices used in the example
Definition: aodv.cc:94
AodvExample()
Definition: aodv.cc:124
double step
Distance between nodes, meters.
Definition: aodv.cc:82
Helper class that adds AODV routing to nodes.
Definition: aodv-helper.h:36
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:62
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static void PrintRoutingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing tables of all nodes at a particular time.
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)
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:775
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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 ...
Create a ping application and associate it to a node.
Definition: ping-helper.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
Hold an unsigned integer type.
Definition: uinteger.h:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
manage and create wifi channel objects for the YANS model.
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)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
-ns3 Test suite for the ns3 wrapper script