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" |
Peter Barnes
2014/09/23 22:54:26
Mode line and copyright.
mjf.alenazi
2014/11/25 19:51:51
Done.
| |
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/wifi-module.h" | 34 #include "ns3/wifi-module.h" |
6 #include "ns3/internet-module.h" | 35 #include "ns3/internet-module.h" |
7 #include "ns3/epidemic-helper.h" | 36 #include "ns3/epidemic-helper.h" |
37 | |
8 using namespace ns3; | 38 using namespace ns3; |
9 | 39 |
10 /** | 40 /** |
11 This example creates an N-node wireless network, which is set by default to 10 nodes. | 41 \file |
Peter Barnes
2014/09/23 22:54:25
"The wireless channel is configured to use the Ran
mjf.alenazi
2014/11/25 19:51:51
Is there a perfect range model. I would like to us
| |
12 The mobility model can be either static Grid or Randomwaypoint, which by defau lt is selected to be Grid. | 42 \ingroup epidemic |
Peter Barnes
2014/09/23 22:54:25
"…either
RandomDiscPositionAllocator with SteadyS
mjf.alenazi
2014/11/25 19:51:51
Done.
| |
13 The data traffic is generated using OnOff application and received by PacketSi nk. There is one source and | 43 This example creates an N-node wireless network, which is set by default |
14 one sink in this configuration. | 44 to 10 nodes. The mobility model can be either static Grid or Randomwaypoint, |
15 The example runs for 100 seconds, and data is sent from time 10 to 15 seconds, with the extra time in | 45 which by default is selected to be Grid. For the static grid, nodes are |
16 the example allocated to allow the epidemic routing to eventually deliver the | 46 placed in a grid of node with 100 m distance. For the Randomwaypoint, |
17 packets. | 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. | |
18 */ | 53 */ |
19 | 54 |
20 | 55 |
21 NS_LOG_COMPONENT_DEFINE ("EpidemicExample"); | 56 NS_LOG_COMPONENT_DEFINE ("EpidemicExample"); |
22 int main (int argc, char *argv[]) | 57 int main (int argc, char *argv[]) |
23 { | 58 { |
24 // General parameters | 59 // General parameters |
25 std::string mobility_model = "RandomWaypoint"; // Grid or RandomWaypoint | 60 std::string mobility_model = "RandomWaypoint"; // Grid or RandomWaypoint |
26 uint32_t nWifis = 10; | 61 uint32_t nWifis = 10; |
27 double txpDistance = 120.0; | 62 double txpDistance = 120.0; |
28 double nodeSpeed = 50.0; | 63 double nodeSpeed = 50.0; |
29 bool app_logging = true; | 64 bool app_logging = true; |
30 NodeContainer nodeContainer; | 65 NodeContainer nodeContainer; |
31 NetDeviceContainer devices; | 66 NetDeviceContainer devices; |
32 | 67 |
33 | 68 |
34 // Epidemic parameters | 69 // Epidemic parameters |
35 uint32_t epidemicHopCount = 50; | 70 uint32_t epidemicHopCount = 50; |
36 uint32_t epidemicQueueLength = 50; | 71 uint32_t epidemicQueueLength = 50; |
37 uint32_t epidemicQueueEntryExpireTime = 100; | 72 Time epidemicQueueEntryExpireTime = Seconds (100); |
38 uint32_t epidemicBeaconInterval = 1; | 73 Time epidemicBeaconInterval = Seconds (1); |
39 | 74 |
40 // Application parameters | 75 // Application parameters |
41 std::string rate = "0.512kbps"; | 76 std::string rate = "0.512kbps"; |
42 uint32_t packetSize = 64; | 77 uint32_t packetSize = 64; |
43 double appTotalTime = 100.0; | 78 double appTotalTime = 100.0; |
44 double appDataStart = 10.0; | 79 double appDataStart = 10.0; |
45 double appDataEnd = 15; | 80 double appDataEnd = 15; |
46 uint32_t source_num = 0; | 81 uint32_t source_num = 0; |
47 uint32_t sink_num = 9; | 82 uint32_t sink_num = 9; |
48 | 83 |
49 | 84 /* |
50 //Allow users to override the default parameters and set it to new ones from C ommandLine. | 85 Allow users to override the default parameters and set it to |
86 new ones from CommandLine. | |
87 */ | |
51 CommandLine cmd; | 88 CommandLine cmd; |
52 cmd.Usage ("Simple example shows basic epidemic routing scenario.\n"); | 89 cmd.Usage ("Simple example shows basic epidemic routing scenario. " |
Peter Barnes
2014/09/23 22:54:26
Please expand this with the model description from
mjf.alenazi
2014/11/25 19:51:51
Done.
| |
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"); | |
53 cmd.AddValue ("nWifis", "Number of wifi nodes", nWifis); | 101 cmd.AddValue ("nWifis", "Number of wifi nodes", nWifis); |
54 cmd.AddValue ("txpDistance", "Specify node's transmit range", txpDistance); | 102 cmd.AddValue ("txpDistance", "Specify node's transmit range", txpDistance); |
55 cmd.AddValue ("Source", "specifiy Source traffic node", source_num); | 103 cmd.AddValue ("Source", "specify Source traffic node", source_num); |
56 cmd.AddValue ("Sink", "specifiy SINK traffic node", sink_num); | 104 cmd.AddValue ("Sink", "specify SINK traffic node", sink_num); |
57 cmd.AddValue ("rate", "CBR traffic rate(in kbps)", rate); | 105 cmd.AddValue ("rate", "CBR traffic rate(in kbps)", rate); |
58 cmd.AddValue ("packetSize", "The packet size", packetSize); | 106 cmd.AddValue ("packetSize", "The packet size", packetSize); |
59 cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model", nodeSpeed); | 107 cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model", nodeSpeed); |
60 cmd.AddValue ("Hop Count", "number of hops before a packet is dropped", epidem icHopCount); | 108 cmd.AddValue ("Hop Count", "number of hops before a packet is dropped", |
61 cmd.AddValue ("Queue Length", "Length of the epidemic Queue", epidemicQueueLen gth); | 109 epidemicHopCount); |
62 cmd.AddValue ("Queue Entry Expire Time", "Time in seconds before a packet is d ropped in a queue", epidemicQueueEntryExpireTime); | 110 cmd.AddValue ("QueueLength", "Specify queue Length", epidemicQueueLength); |
63 cmd.AddValue ("Beacon Interval", "Time in seconds for the beacon packets inter val", epidemicBeaconInterval); | 111 cmd.AddValue ("QueueEntryExpireTime", "Specify queue Entry Expire Time", |
64 | 112 epidemicQueueEntryExpireTime); |
113 cmd.AddValue ("BeaconInterval", "Specify beaconInterval", | |
114 epidemicBeaconInterval); | |
65 cmd.Parse (argc, argv); | 115 cmd.Parse (argc, argv); |
Peter Barnes
2014/09/23 22:54:25
Validate command args. For example, source_num an
mjf.alenazi
2014/11/25 19:51:51
Done.
| |
66 | 116 |
Peter Barnes
2014/09/23 22:54:26
Write the values of all command line arguments to
mjf.alenazi
2014/11/25 19:51:51
Done.
| |
67 | 117 |
68 | 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; | |
69 | 147 |
70 | 148 |
71 /* | 149 /* |
72 * Enabling OnOffApplication and PacketSink logging | 150 * Enabling OnOffApplication and PacketSink logging |
73 */ | 151 */ |
74 if (app_logging) | 152 if (app_logging) |
75 { | 153 { |
76 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); | 154 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); |
77 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); | 155 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); |
78 LogComponentEnableAll (LOG_PREFIX_TIME); | 156 LogComponentEnableAll (LOG_PREFIX_TIME); |
(...skipping 17 matching lines...) Expand all Loading... | |
96 Ptr<GridPositionAllocator> positionAlloc; | 174 Ptr<GridPositionAllocator> positionAlloc; |
97 positionAlloc = CreateObject<GridPositionAllocator> (); | 175 positionAlloc = CreateObject<GridPositionAllocator> (); |
98 positionAlloc->SetDeltaX (internode_distance); | 176 positionAlloc->SetDeltaX (internode_distance); |
99 mobility.SetPositionAllocator (positionAlloc); | 177 mobility.SetPositionAllocator (positionAlloc); |
100 | 178 |
101 } | 179 } |
102 else if (mobility_model == "RandomWaypoint") | 180 else if (mobility_model == "RandomWaypoint") |
103 { | 181 { |
104 | 182 |
105 /* | 183 /* |
106 * Nodes initial positions and mobility bounds are based on original pape r. | 184 * Nodes initial positions and mobility bounds are based on |
185 * original paper. | |
107 * See Docs for more details. | 186 * See Docs for more details. |
108 */ | 187 */ |
109 ObjectFactory pos; | 188 ObjectFactory pos; |
110 mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", | 189 mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator", |
111 "X", StringValue ("300.0"), | 190 "X", StringValue ("ns3::UniformRandomVariab le[Min=0.0|Max=300.0]"), |
112 "Y", StringValue ("1500.0"), | 191 "Y", StringValue ("ns3::UniformRandomVariab le[Min=0.0|Max=1500.0]")); |
113 "Rho", StringValue ("ns3::UniformRandomVari able[Min=0|Max=30]")); | |
114 | 192 |
115 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", | 193 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", |
116 "MinSpeed", DoubleValue (0.01), | 194 "MinSpeed", DoubleValue (0.01), |
117 "MaxSpeed", DoubleValue (nodeSpeed), | 195 "MaxSpeed", DoubleValue (nodeSpeed), |
118 "MinX", DoubleValue (0.0), | 196 "MinX", DoubleValue (0.0), |
119 "MaxX", DoubleValue (300.0), | 197 "MaxX", DoubleValue (300.0), |
120 "MinPause", DoubleValue (10), | 198 "MinPause", DoubleValue (10), |
121 "MaxPause", DoubleValue (20), | 199 "MaxPause", DoubleValue (20), |
122 "MinY", DoubleValue (0.0), | 200 "MinY", DoubleValue (0.0), |
123 "MaxY", DoubleValue (1500.0) | 201 "MaxY", DoubleValue (1500.0) |
Peter Barnes
2014/09/23 22:54:25
You constrain the mobility to [0, 300] in x, [0, 1
mjf.alenazi
2014/11/25 19:51:51
The paper says "Each node picks a random spot in t
| |
124 ); | 202 ); |
125 } | 203 } |
126 mobility.Install (nodeContainer); | 204 mobility.Install (nodeContainer); |
127 | 205 |
128 | 206 |
129 /* | 207 /* |
130 * Physical and link Layers Setup | 208 * Physical and link Layers Setup |
131 */ | 209 */ |
132 | 210 |
133 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); | 211 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
134 wifiMac.SetType ("ns3::AdhocWifiMac"); | 212 wifiMac.SetType ("ns3::AdhocWifiMac"); |
135 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); | 213 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
136 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); | 214 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
137 | 215 |
138 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", "MaxRange", DoubleValue (txpDistance)); | 216 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", |
217 "MaxRange", DoubleValue (txpDistance)); | |
139 wifiPhy.SetChannel (wifiChannel.Create ()); | 218 wifiPhy.SetChannel (wifiChannel.Create ()); |
140 WifiHelper wifi = WifiHelper::Default (); | 219 WifiHelper wifi = WifiHelper::Default (); |
141 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", Stri ngValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0)); | 220 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
221 "DataMode", StringValue ("OfdmRate6Mbps"), | |
222 "RtsCtsThreshold", UintegerValue (0)); | |
142 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); | 223 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); |
143 | 224 |
144 /* | 225 /* |
145 * Epidemic Routing Setup | 226 * Epidemic Routing Setup |
146 */ | 227 */ |
147 EpidemicHelper epidemic; | 228 EpidemicHelper epidemic; |
148 epidemic.Set ("HopCount", UintegerValue (epidemicHopCount)); | 229 epidemic.Set ("HopCount", UintegerValue (epidemicHopCount)); |
149 epidemic.Set ("QueueLength", UintegerValue (epidemicQueueLength)); | 230 epidemic.Set ("QueueLength", UintegerValue (epidemicQueueLength)); |
150 epidemic.Set ("QueueEntryExpireTime", TimeValue (Seconds (epidemicQueueEntryEx pireTime))); | 231 epidemic.Set ("QueueEntryExpireTime", |
151 epidemic.Set ("BeaconInterval", TimeValue (Seconds (epidemicBeaconInterval))); | 232 TimeValue (epidemicQueueEntryExpireTime)); |
233 epidemic.Set ("BeaconInterval", TimeValue (epidemicBeaconInterval)); | |
152 | 234 |
153 /* | 235 /* |
154 * Internet Stack Setup | 236 * Internet Stack Setup |
155 */ | 237 */ |
156 Ipv4ListRoutingHelper list; | 238 Ipv4ListRoutingHelper list; |
157 InternetStackHelper internet; | 239 InternetStackHelper internet; |
158 internet.SetRoutingHelper (epidemic); | 240 internet.SetRoutingHelper (epidemic); |
159 internet.Install (nodeContainer); | 241 internet.Install (nodeContainer); |
160 Ipv4AddressHelper ipv4; | 242 Ipv4AddressHelper ipv4; |
161 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); | 243 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
162 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); | 244 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
163 | 245 |
164 | 246 |
165 /* | 247 /* |
166 * Application Setup | 248 * Application Setup |
167 */ | 249 */ |
168 | 250 |
169 | 251 |
170 // Sink or server setup | 252 // Sink or server setup |
171 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ::GetAny (), 80)); | 253 PacketSinkHelper sink ("ns3::UdpSocketFactory", |
254 InetSocketAddress (Ipv4Address::GetAny (), 80)); | |
172 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (sink_num)); | 255 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (sink_num)); |
173 apps_sink.Start (Seconds (0.0)); | 256 apps_sink.Start (Seconds (0.0)); |
174 apps_sink.Stop (Seconds (appTotalTime)); | 257 apps_sink.Stop (Seconds (appTotalTime)); |
175 | 258 |
176 | 259 |
177 // Client setup | 260 // Client setup |
178 OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (inter faces.GetAddress (sink_num), 80))); | 261 OnOffHelper onoff1 ("ns3::UdpSocketFactory", |
262 Address (InetSocketAddress (interfaces.GetAddress (sink_nu m), 80))); | |
179 onoff1.SetConstantRate (DataRate (rate)); | 263 onoff1.SetConstantRate (DataRate (rate)); |
180 onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); | 264 onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); |
181 ApplicationContainer apps1 = onoff1.Install (nodeContainer.Get (source_num)); | 265 ApplicationContainer apps1 = onoff1.Install (nodeContainer.Get (source_num)); |
182 apps1.Start (Seconds (appDataStart)); | 266 apps1.Start (Seconds (appDataStart)); |
183 apps1.Stop (Seconds (appDataEnd)); | 267 apps1.Stop (Seconds (appDataEnd)); |
184 | 268 |
185 | 269 |
186 Simulator::Stop (Seconds (appTotalTime)); | 270 Simulator::Stop (Seconds (appTotalTime)); |
187 Simulator::Run (); | 271 Simulator::Run (); |
188 Simulator::Destroy (); | 272 Simulator::Destroy (); |
189 return 0; | 273 return 0; |
190 } | 274 } |
191 | 275 |
LEFT | RIGHT |