8751
|
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 <iostream>
|
|
33 |
#include <fstream>
|
|
34 |
#include <vector>
|
|
35 |
#include <string>
|
|
36 |
|
|
37 |
#include "ns3/core-module.h"
|
|
38 |
#include "ns3/network-module.h"
|
|
39 |
#include "ns3/applications-module.h"
|
|
40 |
#include "ns3/mobility-module.h"
|
|
41 |
#include "ns3/config-store-module.h"
|
|
42 |
#include "ns3/wifi-module.h"
|
|
43 |
#include "ns3/internet-module.h"
|
|
44 |
#include "ns3/ipv4-list-routing-helper.h"
|
|
45 |
#include "ns3/dsr-module.h"
|
|
46 |
|
|
47 |
NS_LOG_COMPONENT_DEFINE ("DsrExample");
|
|
48 |
|
|
49 |
using namespace ns3;
|
|
50 |
|
|
51 |
int main (int argc, char *argv[])
|
|
52 |
{
|
|
53 |
//
|
|
54 |
// Users may find it convenient to turn on explicit debugging
|
|
55 |
// for selected modules; the below lines suggest how to do this
|
|
56 |
//
|
|
57 |
#if 0
|
|
58 |
LogComponentEnable ("Ipv4L3Protocol", LOG_LEVEL_ALL);
|
|
59 |
LogComponentEnable ("Ipv4L4Protocol", LOG_LEVEL_ALL);
|
|
60 |
LogComponentEnable ("UdpL4Protocol", LOG_LEVEL_ALL);
|
|
61 |
LogComponentEnable ("NetDevice", LOG_LEVEL_ALL);
|
|
62 |
LogComponentEnable ("Ipv4EndPointDemux", LOG_LEVEL_ALL);
|
|
63 |
#endif
|
|
64 |
|
|
65 |
#if 0
|
|
66 |
LogComponentEnable ("DsrOptions", LOG_LEVEL_ALL);
|
|
67 |
LogComponentEnable ("DsrRouting", LOG_LEVEL_ALL);
|
|
68 |
LogComponentEnable ("DsrOptionHeader", LOG_LEVEL_ALL);
|
|
69 |
LogComponentEnable ("DsrFsHeader", LOG_LEVEL_ALL);
|
|
70 |
LogComponentEnable ("DsrGraReplyTable", LOG_LEVEL_ALL);
|
|
71 |
LogComponentEnable ("DsrSendBuffer", LOG_LEVEL_ALL);
|
|
72 |
LogComponentEnable ("RouteCache", LOG_LEVEL_ALL);
|
|
73 |
LogComponentEnable ("DsrMaintainBuffer", LOG_LEVEL_ALL);
|
|
74 |
LogComponentEnable ("RreqTable", LOG_LEVEL_ALL);
|
|
75 |
#endif
|
|
76 |
|
|
77 |
SeedManager::SetSeed (99);
|
|
78 |
SeedManager::SetRun (1);
|
|
79 |
|
|
80 |
double totalTime = 1000.0;
|
|
81 |
double dataStart = 50.0;
|
|
82 |
uint32_t nWifis = 50;
|
|
83 |
uint32_t nSinks = 10;
|
|
84 |
double txp = 8.9048;
|
|
85 |
double pauseTime = 0.0;
|
|
86 |
double nodeSpeed = 20.0;
|
|
87 |
uint32_t packetSize = 64;
|
|
88 |
std::string phyModeControl ("DsssRate11Mbps");
|
|
89 |
std::string phyModeData ("DsssRate11Mbps");
|
|
90 |
std::string rate = "0.512kbps";
|
|
91 |
double ppers = 1.0;
|
|
92 |
/*
|
|
93 |
* Define the DSR parameters
|
|
94 |
*/
|
|
95 |
uint32_t m_maxCacheLen = 64;
|
|
96 |
Time m_maxCacheTime = Seconds (30);
|
|
97 |
Time m_nodeTraversalTime = MicroSeconds (2);
|
|
98 |
Time m_passiveAckTimeout = MicroSeconds (4);
|
|
99 |
uint32_t m_maxSendBuffLen = 64;
|
|
100 |
Time m_sendBufferTimeout = Seconds (30);
|
|
101 |
uint32_t m_maxMaintainLen = 50;
|
|
102 |
Time m_maxMaintainTime = Seconds (30);
|
|
103 |
uint32_t m_maintenanceRetries = 2;
|
|
104 |
std::string cacheType ("PathCache"); // PathCache
|
|
105 |
bool enableSubRoute = false;
|
|
106 |
|
|
107 |
//Allow users to override the default parameters and set it to new ones from CommandLine.
|
|
108 |
CommandLine cmd;
|
|
109 |
cmd.AddValue ("MaxCacheLen", "Max route cache length.", m_maxCacheLen);
|
|
110 |
cmd.AddValue ("RouteCacheTimeout", "Max route cache timeout.", m_maxCacheTime);
|
|
111 |
cmd.AddValue ("NodeTraversalTime", "The time it takes to travel to neighboring nodes.", m_nodeTraversalTime);
|
|
112 |
cmd.AddValue ("PassiveAckTimeout", "The time for ack to traversal the two neighboring nodes.", m_passiveAckTimeout);
|
|
113 |
cmd.AddValue ("MaxSendBuffLen", "Maximum number of packets that can be stored.", m_maxSendBuffLen);
|
|
114 |
cmd.AddValue ("MaxSendBuffTime", "Maximum time packets can be queued.", m_sendBufferTimeout);
|
|
115 |
cmd.AddValue ("MaxMaintLen", "Maximum number of packets that can be stored.", m_maxMaintainLen);
|
|
116 |
cmd.AddValue ("MaxMaintTime", "Maximum time packets can be queued.", m_maxMaintainTime);
|
|
117 |
cmd.AddValue ("MaintenanceRetries", "Maximum retransmission retries for maintenance data packet.", m_maintenanceRetries);
|
|
118 |
cmd.AddValue ("CacheType", "route cache type, Default:PathCache", cacheType);
|
|
119 |
cmd.AddValue ("EnableSubRoute", "whether to enable the sub route mechanism, Default:false", enableSubRoute);
|
|
120 |
cmd.Parse (argc, argv);
|
|
121 |
|
|
122 |
NS_LOG_INFO ("Create nodes.");
|
|
123 |
NodeContainer nodes;
|
|
124 |
nodes.Create (nWifis);
|
|
125 |
NetDeviceContainer devices;
|
|
126 |
|
|
127 |
// Fix non-unicast data rate to be the same as that of unicast
|
|
128 |
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyModeData));
|
|
129 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
|
|
130 |
// disable fragmentation
|
|
131 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
|
|
132 |
|
|
133 |
NS_LOG_INFO ("Create channels.");
|
|
134 |
WifiHelper wifi;
|
|
135 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
|
|
136 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
|
137 |
YansWifiChannelHelper wifiChannel;
|
|
138 |
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
|
|
139 |
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
|
|
140 |
wifiPhy.SetChannel (wifiChannel.Create ());
|
|
141 |
|
|
142 |
// Add a non-QoS upper mac, and disable rate control
|
|
143 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
|
|
144 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue (phyModeData),
|
|
145 |
"ControlMode", StringValue (phyModeControl));
|
|
146 |
wifiPhy.Set ("TxPowerStart", DoubleValue (txp));
|
|
147 |
wifiPhy.Set ("TxPowerEnd", DoubleValue (txp));
|
|
148 |
// Set it to adhoc mode
|
|
149 |
wifiMac.SetType ("ns3::AdhocWifiMac");
|
|
150 |
devices = wifi.Install (wifiPhy, wifiMac, nodes);
|
|
151 |
|
|
152 |
InternetStackHelper internet;
|
|
153 |
DsrMainHelper dsrMain;
|
|
154 |
DsrHelper dsr;
|
|
155 |
dsr.Set ("MaxCacheLen", UintegerValue (m_maxCacheLen));
|
|
156 |
dsr.Set ("RouteCacheTimeout", TimeValue (m_maxCacheTime));
|
|
157 |
dsr.Set ("NodeTraversalTime", TimeValue (m_nodeTraversalTime));
|
|
158 |
dsr.Set ("PassiveAckTimeout", TimeValue (m_passiveAckTimeout));
|
|
159 |
dsr.Set ("MaxSendBuffLen", UintegerValue (m_maxSendBuffLen));
|
|
160 |
dsr.Set ("MaxSendBuffTime", TimeValue (m_sendBufferTimeout));
|
|
161 |
dsr.Set ("MaxMaintLen", UintegerValue (m_maxMaintainLen));
|
|
162 |
dsr.Set ("MaxMaintTime", TimeValue (m_maxMaintainTime));
|
|
163 |
dsr.Set ("MaintenanceRetries", UintegerValue (m_maintenanceRetries));
|
|
164 |
dsr.Set ("EnableSubRoute", BooleanValue (false));
|
|
165 |
dsr.Set ("CacheType", StringValue (cacheType));
|
|
166 |
dsr.Set ("SendBuffInterval", TimeValue (Seconds (50)));
|
|
167 |
internet.Install (nodes);
|
|
168 |
dsrMain.Install (dsr, nodes);
|
|
169 |
|
|
170 |
NS_LOG_INFO ("assigning ip address");
|
|
171 |
Ipv4AddressHelper addressAdhoc;
|
|
172 |
addressAdhoc.SetBase ("10.1.1.0", "255.255.255.0");
|
|
173 |
Ipv4InterfaceContainer adhocInterfaces;
|
|
174 |
adhocInterfaces = addressAdhoc.Assign (devices);
|
|
175 |
|
|
176 |
MobilityHelper mobility;
|
|
177 |
|
|
178 |
ObjectFactory pos;
|
|
179 |
pos.SetTypeId ("ns3::RandomRectanglePositionAllocator");
|
|
180 |
pos.Set ("X", RandomVariableValue (UniformVariable (0.0, 300.0)));
|
|
181 |
pos.Set ("Y", RandomVariableValue (UniformVariable (0.0, 1500.0)));
|
|
182 |
Ptr<PositionAllocator> positionAlloc = pos.Create ()->GetObject<PositionAllocator> ();
|
|
183 |
mobility.SetPositionAllocator (positionAlloc);
|
|
184 |
|
|
185 |
mobility.SetMobilityModel ("ns3::RandomWaypointMobilityModel",
|
|
186 |
"Speed", RandomVariableValue (ConstantVariable (nodeSpeed)),
|
|
187 |
"Pause", RandomVariableValue (ConstantVariable (pauseTime)),
|
|
188 |
"PositionAllocator", PointerValue (positionAlloc));
|
|
189 |
mobility.Install (nodes);
|
|
190 |
|
|
191 |
// many to many application
|
|
192 |
uint16_t port = 9;
|
|
193 |
double randomStartTime = (1 / ppers) / nSinks; //distributed btw 1s evenly as we are sending 1pkt/s
|
|
194 |
|
|
195 |
for (uint32_t i = 0; i < nSinks; i++)
|
|
196 |
{
|
|
197 |
PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
|
|
198 |
ApplicationContainer apps_sink = sink.Install (nodes.Get (i));
|
|
199 |
apps_sink.Start (Seconds (0.0));
|
|
200 |
apps_sink.Stop (Seconds (totalTime));
|
|
201 |
|
|
202 |
OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (adhocInterfaces.GetAddress (i), port)));
|
|
203 |
onoff1.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
|
204 |
onoff1.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
|
205 |
onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize));
|
|
206 |
onoff1.SetAttribute ("DataRate", DataRateValue (DataRate (rate)));
|
|
207 |
|
|
208 |
ApplicationContainer apps1 = onoff1.Install (nodes.Get (i + nSinks));
|
|
209 |
apps1.Start (Seconds (dataStart + i * randomStartTime));
|
|
210 |
apps1.Stop (Seconds (totalTime));
|
|
211 |
}
|
|
212 |
|
|
213 |
AsciiTraceHelper ascii;
|
|
214 |
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("dsrtest.tr");
|
|
215 |
wifiPhy.EnableAsciiAll (stream);
|
|
216 |
|
|
217 |
NS_LOG_INFO ("Run Simulation.");
|
|
218 |
Simulator::Stop (Seconds (totalTime));
|
|
219 |
Simulator::Run ();
|
|
220 |
Simulator::Destroy ();
|
|
221 |
}
|