Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | |
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: Mohammed J.F. Alenazi <malenazi@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 by King Saud University and | |
27 * the ITTC at The University of Kansas. | |
28 */ | |
29 | |
1 #include "ns3/core-module.h" | 30 #include "ns3/core-module.h" |
2 #include "ns3/network-module.h" | 31 #include "ns3/network-module.h" |
3 #include "ns3/applications-module.h" | 32 #include "ns3/applications-module.h" |
4 #include "ns3/mobility-module.h" | 33 #include "ns3/mobility-module.h" |
5 #include "ns3/config-store-module.h" | |
6 #include "ns3/wifi-module.h" | 34 #include "ns3/wifi-module.h" |
7 #include "ns3/internet-module.h" | 35 #include "ns3/internet-module.h" |
8 #include <iostream> | |
9 | |
10 #include "ns3/dsdv-module.h" | |
11 #include "ns3/epidemic-helper.h" | 36 #include "ns3/epidemic-helper.h" |
12 #include "ns3/aodv-module.h" | |
13 #include "ns3/dsr-module.h" | |
14 #include "ns3/olsr-module.h" | |
15 #include <cmath> | |
16 #include <time.h> | |
17 | 37 |
Peter Barnes
2013/10/17 22:09:33
Please explain the model used in this example, and
| |
18 using namespace ns3; | 38 using namespace ns3; |
19 | 39 |
20 NS_LOG_COMPONENT_DEFINE ("EpidemicScript"); | 40 /** |
21 | 41 \file |
22 | 42 \ingroup epidemic |
23 | 43 This example creates an N-node wireless network, which is set by default |
24 | 44 to 10 nodes. The mobility model can be either static Grid or Randomwaypoint, |
45 which by default is selected to be Grid. For the static grid, nodes are | |
46 placed in a grid of node with 100 m distance. For the Randomwaypoint, | |
47 the initial positions are randomly uniformly distributed within an area | |
48 of 300x1500 m. The data traffic is generated using OnOff application | |
49 and received by PacketSink. There is one source and one sink in this | |
50 configuration. The example runs for 100 seconds, and data is sent from | |
51 time 10 to 15 seconds, with the extra time in the example allocated to | |
52 allow the epidemic routing to eventually deliver the packets. | |
53 */ | |
54 | |
55 | |
56 NS_LOG_COMPONENT_DEFINE ("EpidemicExample"); | |
25 int main (int argc, char *argv[]) | 57 int main (int argc, char *argv[]) |
26 { | 58 { |
27 // General parameters | 59 // General parameters |
28 std::string mobility_model = "Grid"; // Grid or RandomWaypoint | 60 std::string mobility_model = "RandomWaypoint"; // Grid or RandomWaypoint |
29 uint32_t nWifis = 10; | 61 uint32_t nWifis = 10; |
62 double txpDistance = 120.0; | |
63 double nodeSpeed = 50.0; | |
64 bool app_logging = true; | |
30 NodeContainer nodeContainer; | 65 NodeContainer nodeContainer; |
31 NetDeviceContainer devices; | 66 NetDeviceContainer devices; |
32 double txpDistance = 120.0; | 67 |
33 double nodeSpeed = 50.0; | 68 |
34 | 69 // Epidemic parameters |
35 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); | 70 uint32_t epidemicHopCount = 50; |
36 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); | 71 uint32_t epidemicQueueLength = 50; |
37 LogComponentEnableAll (LOG_PREFIX_TIME); | 72 Time epidemicQueueEntryExpireTime = Seconds (100); |
38 LogComponentEnableAll (LOG_PREFIX_NODE); | 73 Time epidemicBeaconInterval = Seconds (1); |
39 LogComponentEnableAll (LOG_PREFIX_FUNC); | 74 |
40 SeedManager::SetSeed (7); | 75 // Application parameters |
41 | 76 std::string rate = "0.512kbps"; |
42 | 77 uint32_t packetSize = 64; |
43 //» LogComponentEnable("EpidemicRoutingProtocol", LOG_LEVEL_ALL); | 78 double appTotalTime = 100.0; |
Peter Barnes
2013/10/17 22:09:33
Please remove extraneous code, unless it illustrat
| |
44 //» LogComponentEnableAll(LOG_PREFIX_TIME); | 79 double appDataStart = 10.0; |
45 //» LogComponentEnableAll(LOG_PREFIX_NODE); | 80 double appDataEnd = 15; |
46 //» LogComponentEnableAll(LOG_PREFIX_FUNC); | 81 uint32_t source_num = 0; |
47 | 82 uint32_t sink_num = 9; |
48 LogComponentEnable ("EpidemicScript", LOG_LEVEL_ALL); | 83 |
84 /* | |
85 Allow users to override the default parameters and set it to | |
86 new ones from CommandLine. | |
87 */ | |
88 CommandLine cmd; | |
89 cmd.Usage ("Simple example shows basic epidemic routing scenario. " | |
90 "This example creates an N-node wireless network, which is set by " | |
91 "default to 10 nodes. The mobility model can be either static Grid " | |
92 "or Randomwaypoint, which by default is selected to be Grid. For " | |
93 "the static grid, nodes are placed in a grid of node with 100 m dis tance." | |
94 "For the Randomwaypoint, the initial positions are randomly uniform ly " | |
95 "distributed within an area of 300x1500 m.The data traffic is gener ated " | |
96 "using OnOff application and received by PacketSink. There is one s ource " | |
97 "and one sink in this configuration. The example runs for 100 secon ds, " | |
98 "and data is sent from time 10 to 15 seconds, with the extra time i n " | |
99 "the example allocated to allow the epidemic routing to eventually " | |
100 "deliver the packets.\n"); | |
101 cmd.AddValue ("nWifis", "Number of wifi nodes", nWifis); | |
102 cmd.AddValue ("txpDistance", "Specify node's transmit range", txpDistance); | |
103 cmd.AddValue ("Source", "specify Source traffic node", source_num); | |
104 cmd.AddValue ("Sink", "specify SINK traffic node", sink_num); | |
105 cmd.AddValue ("rate", "CBR traffic rate(in kbps)", rate); | |
106 cmd.AddValue ("packetSize", "The packet size", packetSize); | |
107 cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model", nodeSpeed); | |
108 cmd.AddValue ("Hop Count", "number of hops before a packet is dropped", | |
109 epidemicHopCount); | |
110 cmd.AddValue ("QueueLength", "Specify queue Length", epidemicQueueLength); | |
111 cmd.AddValue ("QueueEntryExpireTime", "Specify queue Entry Expire Time", | |
112 epidemicQueueEntryExpireTime); | |
113 cmd.AddValue ("BeaconInterval", "Specify beaconInterval", | |
114 epidemicBeaconInterval); | |
115 cmd.Parse (argc, argv); | |
116 | |
117 | |
118 | |
119 | |
120 if (source_num >= nWifis) | |
121 { | |
122 std::cerr << "Source number can not exceed number of nodes" << std::endl; | |
Peter Barnes
2015/04/28 23:42:31
(from patch-9 comment:)
Add
std::cerr << cmd;
R
mjf.alenazi
2017/05/13 23:57:04
Done.
| |
123 exit (-1); | |
124 } | |
125 | |
126 if (sink_num >= nWifis || source_num >= nWifis) | |
127 { | |
128 std::cerr << "Sink number can not exceed number of nodes" << std::endl; | |
Peter Barnes
2015/04/28 23:42:31
(from patch-9 comment:)
Add
std::cerr << cmd;
R
mjf.alenazi
2017/05/13 23:57:03
Done.
| |
129 exit (-1); | |
130 } | |
131 | |
132 | |
133 | |
134 std::cout << "Number of wifi nodes: " << nWifis << std::endl; | |
135 std::cout << "Source number: " << source_num << std::endl; | |
136 std::cout << "Sink number: " << sink_num << std::endl; | |
137 std::cout << "Node speed: " << nodeSpeed << " m/s" << std::endl; | |
138 std::cout << "Packet size: " << packetSize << " b" << std::endl; | |
139 std::cout << "Transmission distance: " << txpDistance << " m" << std::endl; | |
140 std::cout << "Hop count: " << epidemicHopCount << std::endl; | |
141 std::cout << "Queue length: " << epidemicQueueLength << " packets" | |
142 << std::endl; | |
143 std::cout << "Queue entry expire time: " << | |
144 epidemicQueueEntryExpireTime.GetSeconds () << " s" << std::endl; | |
145 std::cout << "Beacon interval: " << epidemicBeaconInterval.GetSeconds () | |
146 << " s" << std::endl; | |
147 | |
148 | |
149 /* | |
150 * Enabling OnOffApplication and PacketSink logging | |
151 */ | |
152 if (app_logging) | |
153 { | |
154 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); | |
155 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); | |
156 LogComponentEnableAll (LOG_PREFIX_TIME); | |
157 LogComponentEnableAll (LOG_PREFIX_NODE); | |
158 LogComponentEnableAll (LOG_PREFIX_FUNC); | |
159 } | |
160 | |
161 | |
162 | |
163 LogComponentEnable ("EpidemicExample", LOG_LEVEL_ALL); | |
49 nodeContainer.Create (nWifis); | 164 nodeContainer.Create (nWifis); |
50 | 165 |
51 | 166 |
52 /* | 167 /* |
53 * Mobility model Setup | 168 * Mobility model Setup |
54 * */ | 169 */ |
55 MobilityHelper mobility; | 170 MobilityHelper mobility; |
56 if (mobility_model == "Grid") | 171 if (mobility_model == "Grid") |
57 { | 172 { |
58 int internode_distance = 100; | 173 int internode_distance = 100; |
59 Ptr<GridPositionAllocator> positionAlloc; | 174 Ptr<GridPositionAllocator> positionAlloc; |
60 positionAlloc = CreateObject<GridPositionAllocator> (); | 175 positionAlloc = CreateObject<GridPositionAllocator> (); |
61 positionAlloc->SetDeltaX (internode_distance); | 176 positionAlloc->SetDeltaX (internode_distance); |
62 | |
63 mobility.SetPositionAllocator (positionAlloc); | 177 mobility.SetPositionAllocator (positionAlloc); |
64 | 178 |
65 } | 179 } |
66 else if (mobility_model == "RandomWaypoint") | 180 else if (mobility_model == "RandomWaypoint") |
67 { | 181 { |
182 | |
183 /* | |
184 * Nodes initial positions and mobility bounds are based on | |
185 * original paper. | |
186 * See Docs for more details. | |
187 */ | |
68 ObjectFactory pos; | 188 ObjectFactory pos; |
69 mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", | 189 mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator", |
70 "X", StringValue ("100.0"), | 190 "X", StringValue ("ns3::UniformRandomVariab le[Min=0.0|Max=300.0]"), |
71 "Y", StringValue ("100.0"), | 191 "Y", StringValue ("ns3::UniformRandomVariab le[Min=0.0|Max=1500.0]")); |
72 "Rho", StringValue ("ns3::UniformRandomVari able[Min=0|Max=30]")); | |
73 | 192 |
74 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", | 193 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", |
75 "MinSpeed", DoubleValue (0.01), | 194 "MinSpeed", DoubleValue (0.01), |
76 "MaxSpeed", DoubleValue (nodeSpeed), | 195 "MaxSpeed", DoubleValue (nodeSpeed), |
77 "MinX", DoubleValue (0.0), | 196 "MinX", DoubleValue (0.0), |
78 "MaxX", DoubleValue (300.0), | 197 "MaxX", DoubleValue (300.0), |
79 "MinPause", DoubleValue (10), | 198 "MinPause", DoubleValue (10), |
80 "MaxPause", DoubleValue (20), | 199 "MaxPause", DoubleValue (20), |
81 "MinY", DoubleValue (0.0), | 200 "MinY", DoubleValue (0.0), |
82 "MaxY", DoubleValue (1500.0) | 201 "MaxY", DoubleValue (1500.0) |
83 ); | 202 ); |
84 } | 203 } |
85 mobility.Install (nodeContainer); | 204 mobility.Install (nodeContainer); |
86 | 205 |
87 | 206 |
88 /* | 207 /* |
89 * Physical and link Layers Setup | 208 * Physical and link Layers Setup |
90 * */ | 209 */ |
91 | 210 |
92 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); | 211 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
93 wifiMac.SetType ("ns3::AdhocWifiMac"); | 212 wifiMac.SetType ("ns3::AdhocWifiMac"); |
94 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); | 213 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
95 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); | 214 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
96 | 215 |
97 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel","MaxRange",Do ubleValue (txpDistance)); | 216 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", |
217 "MaxRange", DoubleValue (txpDistance)); | |
98 wifiPhy.SetChannel (wifiChannel.Create ()); | 218 wifiPhy.SetChannel (wifiChannel.Create ()); |
99 WifiHelper wifi = WifiHelper::Default (); | 219 WifiHelper wifi = WifiHelper::Default (); |
100 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", Stri ngValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0)); | 220 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
221 "DataMode", StringValue ("OfdmRate6Mbps"), | |
222 "RtsCtsThreshold", UintegerValue (0)); | |
101 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); | 223 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); |
102 | 224 |
103 | |
104 | |
105 | |
106 /* | 225 /* |
107 * Epidemic Routing Setup | 226 * Epidemic Routing Setup |
108 * */ | 227 */ |
109 EpidemicHelper epidemic; | 228 EpidemicHelper epidemic; |
110 epidemic.Set ("FloodCount", UintegerValue (50)); | 229 epidemic.Set ("HopCount", UintegerValue (epidemicHopCount)); |
111 epidemic.Set ("QueueLength", UintegerValue (50)); | 230 epidemic.Set ("QueueLength", UintegerValue (epidemicQueueLength)); |
112 epidemic.Set ("QueueEntryExpireTime", TimeValue (Seconds (100))); | 231 epidemic.Set ("QueueEntryExpireTime", |
113 epidemic.Set ("BeaconInterval", UintegerValue (1)); | 232 TimeValue (epidemicQueueEntryExpireTime)); |
233 epidemic.Set ("BeaconInterval", TimeValue (epidemicBeaconInterval)); | |
114 | 234 |
115 /* | 235 /* |
116 * Internet Stack Setup | 236 * Internet Stack Setup |
117 * */ | 237 */ |
118 Ipv4ListRoutingHelper list; | 238 Ipv4ListRoutingHelper list; |
119 InternetStackHelper internet; | 239 InternetStackHelper internet; |
120 internet.SetRoutingHelper (epidemic); | 240 internet.SetRoutingHelper (epidemic); |
121 | |
122 // | |
Peter Barnes
2013/10/17 22:09:33
More extraneous code.
| |
123 // OlsrHelper olsr; | |
124 // olsr.Set ("HelloInterval", TimeValue (Seconds (1))); | |
125 // list.Add (olsr, 20); | |
126 // internet.SetRoutingHelper (list); | |
127 | |
128 internet.Install (nodeContainer); | 241 internet.Install (nodeContainer); |
129 Ipv4AddressHelper ipv4; | 242 Ipv4AddressHelper ipv4; |
130 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); | 243 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
131 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); | 244 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
132 | 245 |
133 | 246 |
134 /* | 247 /* |
135 * Application Setup | 248 * Application Setup |
136 * */ | 249 */ |
137 | 250 |
138 // Application parameters | |
139 double TotalTime = 100.0; | |
140 double dataStart = 10.0; | |
141 double dataEnd = 15; | |
142 uint32_t source_num = 0; | |
143 uint32_t sink_num = 9; | |
144 | 251 |
145 // Sink or server setup | 252 // Sink or server setup |
146 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ::GetAny (), 80)); | 253 PacketSinkHelper sink ("ns3::UdpSocketFactory", |
254 InetSocketAddress (Ipv4Address::GetAny (), 80)); | |
147 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (sink_num)); | 255 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (sink_num)); |
148 apps_sink.Start (Seconds (0.0)); | 256 apps_sink.Start (Seconds (0.0)); |
149 apps_sink.Stop (Seconds (TotalTime)); | 257 apps_sink.Stop (Seconds (appTotalTime)); |
150 | 258 |
151 | 259 |
152 // Client setup | 260 // Client setup |
153 OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (inter faces.GetAddress (sink_num), 80))); | 261 OnOffHelper onoff1 ("ns3::UdpSocketFactory", |
154 onoff1.SetConstantRate (DataRate ("512B/s")); | 262 Address (InetSocketAddress (interfaces.GetAddress (sink_nu m), 80))); |
155 onoff1.SetAttribute ("PacketSize",UintegerValue (500)); | 263 onoff1.SetConstantRate (DataRate (rate)); |
264 onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); | |
156 ApplicationContainer apps1 = onoff1.Install (nodeContainer.Get (source_num)); | 265 ApplicationContainer apps1 = onoff1.Install (nodeContainer.Get (source_num)); |
157 apps1.Start (Seconds (dataStart)); | 266 apps1.Start (Seconds (appDataStart)); |
158 apps1.Stop (Seconds (dataEnd)); | 267 apps1.Stop (Seconds (appDataEnd)); |
159 | 268 |
160 | 269 |
161 Simulator::Stop (Seconds (TotalTime)); | 270 Simulator::Stop (Seconds (appTotalTime)); |
162 | |
163 | |
164 Simulator::Run (); | 271 Simulator::Run (); |
165 Simulator::Destroy (); | 272 Simulator::Destroy (); |
166 return 0; | 273 return 0; |
167 } | 274 } |
168 | 275 |
LEFT | RIGHT |