A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
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 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30
31#include "ns3/applications-module.h"
32#include "ns3/core-module.h"
33#include "ns3/dsr-module.h"
34#include "ns3/internet-module.h"
35#include "ns3/mobility-module.h"
36#include "ns3/network-module.h"
37#include "ns3/yans-wifi-helper.h"
38
39#include <sstream>
40
41using namespace ns3;
42
44
45int
46main(int argc, char* argv[])
47{
48 //
49 // Users may find it convenient to turn on explicit debugging
50 // for selected modules; the below lines suggest how to do this
51 //
52#if 0
53 LogComponentEnable ("Ipv4L3Protocol", LOG_LEVEL_ALL);
54 LogComponentEnable ("UdpL4Protocol", LOG_LEVEL_ALL);
55 LogComponentEnable ("UdpSocketImpl", LOG_LEVEL_ALL);
56 LogComponentEnable ("NetDevice", LOG_LEVEL_ALL);
57 LogComponentEnable ("Ipv4EndPointDemux", LOG_LEVEL_ALL);
58#endif
59
60#if 0
61 LogComponentEnable ("DsrOptions", LOG_LEVEL_ALL);
62 LogComponentEnable ("DsrHelper", LOG_LEVEL_ALL);
63 LogComponentEnable ("DsrRouting", LOG_LEVEL_ALL);
64 LogComponentEnable ("DsrOptionHeader", LOG_LEVEL_ALL);
65 LogComponentEnable ("DsrFsHeader", LOG_LEVEL_ALL);
66 LogComponentEnable ("DsrGraReplyTable", LOG_LEVEL_ALL);
67 LogComponentEnable ("DsrSendBuffer", LOG_LEVEL_ALL);
68 LogComponentEnable ("DsrRouteCache", LOG_LEVEL_ALL);
69 LogComponentEnable ("DsrMaintainBuffer", LOG_LEVEL_ALL);
70 LogComponentEnable ("DsrRreqTable", LOG_LEVEL_ALL);
71 LogComponentEnable ("DsrErrorBuffer", LOG_LEVEL_ALL);
72 LogComponentEnable ("DsrNetworkQueue", LOG_LEVEL_ALL);
73#endif
74
75 NS_LOG_INFO("creating the nodes");
76
77 // General parameters
78 uint32_t nWifis = 50;
79 uint32_t nSinks = 10;
80 double TotalTime = 600.0;
81 double dataTime = 500.0;
82 double ppers = 1;
84 double dataStart = 100.0; // start sending data at 100s
85
86 // mobility parameters
87 double pauseTime = 0.0;
88 double nodeSpeed = 20.0;
89 double txpDistance = 250.0;
90
91 std::string rate = "0.512kbps";
92 std::string dataMode("DsssRate11Mbps");
93 std::string phyMode("DsssRate11Mbps");
94
95 // Allow users to override the default parameters and set it to new ones from CommandLine.
96 CommandLine cmd(__FILE__);
97 cmd.AddValue("nWifis", "Number of wifi nodes", nWifis);
98 cmd.AddValue("nSinks", "Number of SINK traffic nodes", nSinks);
99 cmd.AddValue("rate", "CBR traffic rate(in kbps), Default:8", rate);
100 cmd.AddValue("nodeSpeed", "Node speed in RandomWayPoint model, Default:20", nodeSpeed);
101 cmd.AddValue("packetSize", "The packet size", packetSize);
102 cmd.AddValue("txpDistance", "Specify node's transmit range, Default:300", txpDistance);
103 cmd.AddValue("pauseTime", "pauseTime for mobility model, Default: 0", pauseTime);
104 cmd.Parse(argc, argv);
105
108
109 NodeContainer adhocNodes;
110 adhocNodes.Create(nWifis);
111 NetDeviceContainer allDevices;
112
113 NS_LOG_INFO("setting the default phy and channel parameters");
114 Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
115 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
116 // disable fragmentation for frames below 2200 bytes
117 Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
118 StringValue("2200"));
119
120 NS_LOG_INFO("setting the default phy and channel parameters ");
122 wifi.SetStandard(WIFI_STANDARD_80211b);
123 YansWifiPhyHelper wifiPhy;
124
125 YansWifiChannelHelper wifiChannel;
126 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
127 wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel",
128 "MaxRange",
129 DoubleValue(txpDistance));
130 wifiPhy.SetChannel(wifiChannel.Create());
131
132 // Add a mac and disable rate control
133 WifiMacHelper wifiMac;
134 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
135 "DataMode",
136 StringValue(dataMode),
137 "ControlMode",
138 StringValue(phyMode));
139
140 wifiMac.SetType("ns3::AdhocWifiMac");
141 allDevices = wifi.Install(wifiPhy, wifiMac, adhocNodes);
142
143 NS_LOG_INFO("Configure Tracing.");
144
145 AsciiTraceHelper ascii;
146 Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream("dsrtest.tr");
147 wifiPhy.EnableAsciiAll(stream);
148
149 MobilityHelper adhocMobility;
150 ObjectFactory pos;
151 pos.SetTypeId("ns3::RandomRectanglePositionAllocator");
152 pos.Set("X", StringValue("ns3::UniformRandomVariable[Min=0.0|Max=300.0]"));
153 pos.Set("Y", StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1500.0]"));
154 Ptr<PositionAllocator> taPositionAlloc = pos.Create()->GetObject<PositionAllocator>();
155
156 std::ostringstream speedUniformRandomVariableStream;
157 speedUniformRandomVariableStream << "ns3::UniformRandomVariable[Min=0.0|Max=" << nodeSpeed
158 << "]";
159
160 std::ostringstream pauseConstantRandomVariableStream;
161 pauseConstantRandomVariableStream << "ns3::ConstantRandomVariable[Constant=" << pauseTime
162 << "]";
163
164 adhocMobility.SetMobilityModel(
165 "ns3::RandomWaypointMobilityModel",
166 // "Speed", StringValue
167 // ("ns3::UniformRandomVariable[Min=0.0|Max=nodeSpeed]"),
168 "Speed",
169 StringValue(speedUniformRandomVariableStream.str()),
170 "Pause",
171 StringValue(pauseConstantRandomVariableStream.str()),
172 "PositionAllocator",
173 PointerValue(taPositionAlloc));
174 adhocMobility.Install(adhocNodes);
175
177 DsrMainHelper dsrMain;
178 DsrHelper dsr;
179 internet.Install(adhocNodes);
180 dsrMain.Install(dsr, adhocNodes);
181
182 NS_LOG_INFO("assigning ip address");
184 address.SetBase("10.1.1.0", "255.255.255.0");
185 Ipv4InterfaceContainer allInterfaces;
186 allInterfaces = address.Assign(allDevices);
187
188 uint16_t port = 9;
189 double randomStartTime =
190 (1 / ppers) / nSinks; // distributed btw 1s evenly as we are sending 4pkt/s
191
192 for (uint32_t i = 0; i < nSinks; ++i)
193 {
194 PacketSinkHelper sink("ns3::UdpSocketFactory",
196 ApplicationContainer apps_sink = sink.Install(adhocNodes.Get(i));
197 apps_sink.Start(Seconds(0.0));
198 apps_sink.Stop(Seconds(TotalTime));
199
200 OnOffHelper onoff1("ns3::UdpSocketFactory",
201 Address(InetSocketAddress(allInterfaces.GetAddress(i), port)));
202 onoff1.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1.0]"));
203 onoff1.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0.0]"));
204 onoff1.SetAttribute("PacketSize", UintegerValue(packetSize));
205 onoff1.SetAttribute("DataRate", DataRateValue(DataRate(rate)));
206
207 ApplicationContainer apps1 = onoff1.Install(adhocNodes.Get(i + nWifis - nSinks));
208 apps1.Start(Seconds(dataStart + i * randomStartTime));
209 apps1.Stop(Seconds(dataTime + i * randomStartTime));
210 }
211
212 NS_LOG_INFO("Run Simulation.");
213 Simulator::Stop(Seconds(TotalTime));
216
217 return 0;
218}
a polymophic address class
Definition: address.h:101
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.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Manage ASCII trace files for device models.
Definition: trace-helper.h:174
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
Definition: command-line.h:232
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:296
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
DSR helper class to manage creation of DSR routing instance and to insert it on a node as a sublayer ...
Definition: dsr-helper.h:53
Helper class that adds DSR routing to nodes.
void Install(DsrHelper &dsrHelper, NodeContainer nodes)
Install routing to the nodes.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
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.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
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.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:522
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:37
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Allocate a set of positions.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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: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.
void SetPropagationDelay(std::string name, Ts &&... args)
void AddPropagationLoss(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
uint16_t port
Definition: dsdv-manet.cc:44
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
@ WIFI_STANDARD_80211b
ns address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
@ LOG_LEVEL_ALL
Print everything.
Definition: log.h:116
ns cmd
Definition: second.py:40
ns wifi
Definition: third.py:95
static const uint32_t packetSize
Packet size generated at the AP.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition: wifi-tcp.cc:55