A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
dsr.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 Yufei Cheng
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19
*
20
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22
* Information and Telecommunication Technology Center (ITTC)
23
* and Department of Electrical Engineering and Computer Science
24
* The University of Kansas Lawrence, KS USA.
25
*
26
* Work supported in part by NSF FIND (Future Internet Design) Program
27
* under grant CNS-0626918 (Postmodern Internet Architecture),
28
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
* US Department of Defense (DoD), and ITTC at The University of Kansas.
30
*/
31
32
#include "ns3/core-module.h"
33
#include "ns3/network-module.h"
34
#include "ns3/applications-module.h"
35
#include "ns3/mobility-module.h"
36
#include "ns3/config-store-module.h"
37
#include "ns3/wifi-module.h"
38
#include "ns3/internet-module.h"
39
#include "ns3/dsr-module.h"
40
#include <sstream>
41
42
using namespace
ns3;
43
NS_LOG_COMPONENT_DEFINE
(
"DsrTest"
);
44
45
int
46
main
(
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
(
"RouteCache"
,
LOG_LEVEL_ALL
);
69
LogComponentEnable
(
"DsrMaintainBuffer"
,
LOG_LEVEL_ALL
);
70
LogComponentEnable
(
"RreqTable"
,
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;
83
uint32_t packetSize = 64;
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;
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
106
SeedManager::SetSeed
(10);
107
SeedManager::SetRun
(1);
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"
,
StringValue
(
"2200"
));
118
119
NS_LOG_INFO
(
"setting the default phy and channel parameters "
);
120
WifiHelper
wifi;
121
wifi.
SetStandard
(
WIFI_PHY_STANDARD_80211b
);
122
YansWifiPhyHelper
wifiPhy =
YansWifiPhyHelper::Default
();
123
124
YansWifiChannelHelper
wifiChannel;
125
wifiChannel.
SetPropagationDelay
(
"ns3::ConstantSpeedPropagationDelayModel"
);
126
wifiChannel.
AddPropagationLoss
(
"ns3::RangePropagationLossModel"
,
"MaxRange"
,
DoubleValue
(txpDistance));
127
wifiPhy.
SetChannel
(wifiChannel.
Create
());
128
129
// Add a non-QoS upper mac, and disable rate control
130
NqosWifiMacHelper
wifiMac =
NqosWifiMacHelper::Default
();
131
wifi.
SetRemoteStationManager
(
"ns3::ConstantRateWifiManager"
,
"DataMode"
,
StringValue
(dataMode),
"ControlMode"
,
132
StringValue
(phyMode));
133
134
wifiMac.
SetType
(
"ns3::AdhocWifiMac"
);
135
allDevices = wifi.
Install
(wifiPhy, wifiMac, adhocNodes);
136
137
NS_LOG_INFO
(
"Configure Tracing."
);
138
139
AsciiTraceHelper
ascii;
140
Ptr<OutputStreamWrapper>
stream = ascii.
CreateFileStream
(
"dsrtest.tr"
);
141
wifiPhy.
EnableAsciiAll
(stream);
142
143
MobilityHelper
adhocMobility;
144
ObjectFactory
pos;
145
pos.
SetTypeId
(
"ns3::RandomRectanglePositionAllocator"
);
146
pos.
Set
(
"X"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=300.0]"
));
147
pos.
Set
(
"Y"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1500.0]"
));
148
Ptr<PositionAllocator>
taPositionAlloc = pos.
Create
()->
GetObject
<
PositionAllocator
> ();
149
150
ostringstream speedUniformRandomVariableStream;
151
speedUniformRandomVariableStream <<
"ns3::UniformRandomVariable[Min=0.0|Max="
152
<< nodeSpeed
153
<<
"]"
;
154
155
ostringstream pauseConstantRandomVariableStream;
156
pauseConstantRandomVariableStream <<
"ns3::ConstantRandomVariable[Constant="
157
<< pauseTime
158
<<
"]"
;
159
160
adhocMobility.
SetMobilityModel
(
"ns3::RandomWaypointMobilityModel"
,
161
// "Speed", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=nodeSpeed]"),
162
"Speed"
,
StringValue
(speedUniformRandomVariableStream.str ()),
163
"Pause"
,
StringValue
(pauseConstantRandomVariableStream.str ()),
164
"PositionAllocator"
,
PointerValue
(taPositionAlloc)
165
);
166
adhocMobility.
Install
(adhocNodes);
167
168
InternetStackHelper
internet;
169
DsrMainHelper
dsrMain;
170
DsrHelper
dsr;
171
internet.
Install
(adhocNodes);
172
dsrMain.
Install
(dsr, adhocNodes);
173
174
NS_LOG_INFO
(
"assigning ip address"
);
175
Ipv4AddressHelper
address;
176
address.
SetBase
(
"10.1.1.0"
,
"255.255.255.0"
);
177
Ipv4InterfaceContainer
allInterfaces;
178
allInterfaces = address.
Assign
(allDevices);
179
180
uint16_t
port
= 9;
181
double
randomStartTime = (1 / ppers) / nSinks;
//distributed btw 1s evenly as we are sending 4pkt/s
182
183
for
(uint32_t i = 0; i < nSinks; ++i)
184
{
185
PacketSinkHelper
sink (
"ns3::UdpSocketFactory"
,
InetSocketAddress
(
Ipv4Address::GetAny
(), port));
186
ApplicationContainer
apps_sink = sink.
Install
(adhocNodes.
Get
(i));
187
apps_sink.
Start
(
Seconds
(0.0));
188
apps_sink.
Stop
(
Seconds
(TotalTime));
189
190
OnOffHelper
onoff1 (
"ns3::UdpSocketFactory"
,
Address
(
InetSocketAddress
(allInterfaces.
GetAddress
(i),
port
)));
191
onoff1.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1.0]"
));
192
onoff1.SetAttribute (
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0.0]"
));
193
onoff1.SetAttribute (
"PacketSize"
,
UintegerValue
(packetSize));
194
onoff1.SetAttribute (
"DataRate"
,
DataRateValue
(
DataRate
(rate)));
195
196
ApplicationContainer
apps1 = onoff1.Install (adhocNodes.
Get
(i + nWifis - nSinks));
197
apps1.
Start
(
Seconds
(dataStart + i * randomStartTime));
198
apps1.
Stop
(
Seconds
(dataTime + i * randomStartTime));
199
}
200
201
NS_LOG_INFO
(
"Run Simulation."
);
202
Simulator::Stop
(
Seconds
(TotalTime));
203
Simulator::Run
();
204
Simulator::Destroy
();
205
}
206
src
dsr
examples
dsr.cc
Generated on Tue Nov 13 2012 10:32:12 for ns-3 by
1.8.1.2