Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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 the ITTC at The University of Kans as. | |
27 */ | |
28 | |
29 | |
30 #include "ns3/core-module.h" | |
31 #include "ns3/network-module.h" | |
32 #include "ns3/applications-module.h" | |
33 #include "ns3/mobility-module.h" | |
34 #include "ns3/wifi-module.h" | |
35 #include "ns3/internet-module.h" | |
36 #include "ns3/epidemic-helper.h" | |
37 using namespace ns3; | |
38 | |
39 /** | |
40 This example creates an N-node wireless network, which is set by default to 10 nodes. | |
41 The mobility model can be either static Grid or Randomwaypoint, which by defau lt is selected to be Grid. | |
42 For the static grid, nodes are placed in a grid of node with 100 m distance. | |
43 For the Randomwaypoint, the initial positions are randomly uniformly distribut ed | |
44 within an area of 300x1500 m. | |
45 The data traffic is generated using OnOff application and received by PacketSi nk. There is one source and | |
46 one sink in this configuration. | |
47 The example runs for 100 seconds, and data is sent from time 10 to 15 seconds, with the extra time in | |
48 the example allocated to allow the epidemic routing to eventually deliver the packets. | |
49 */ | |
50 | |
51 | |
52 NS_LOG_COMPONENT_DEFINE ("EpidemicExample"); | |
53 int main (int argc, char *argv[]) | |
54 { | |
55 // General parameters | |
56 std::string mobility_model = "RandomWaypoint"; // Grid or RandomWaypoint | |
57 uint32_t nWifis = 10; | |
58 double txpDistance = 120.0; | |
59 double nodeSpeed = 50.0; | |
60 bool app_logging = true; | |
61 NodeContainer nodeContainer; | |
62 NetDeviceContainer devices; | |
63 | |
64 | |
65 // Epidemic parameters | |
66 uint32_t epidemicHopCount = 50; | |
67 uint32_t epidemicQueueLength = 50; | |
68 Time epidemicQueueEntryExpireTime = Seconds (100); | |
69 Time epidemicBeaconInterval = Seconds (1); | |
70 | |
71 // Application parameters | |
72 std::string rate = "0.512kbps"; | |
73 uint32_t packetSize = 64; | |
74 double appTotalTime = 100.0; | |
75 double appDataStart = 10.0; | |
76 double appDataEnd = 15; | |
77 uint32_t source_num = 0; | |
78 uint32_t sink_num = 9; | |
79 | |
80 | |
81 //Allow users to override the default parameters and set it to new ones from C ommandLine. | |
82 CommandLine cmd; | |
83 cmd.Usage ("Simple example shows basic epidemic routing scenario. This exampl e creates an N-node wireless network, which is set by default to 10 nodes. " | |
84 "The mobility model can be either static Grid or Randomwaypoint, wh ich by default " | |
85 "is selected to be Grid.For the static grid, nodes are placed in a grid of node with 100 m distance." | |
86 "For the Randomwaypoint, the initial positions are randomly uniform ly distributed within an area of 300x1500 m.The data " | |
87 "traffic is generated using OnOff application and received by Packe tSink. There is one source and one sink in this configuration. " | |
88 "The example runs for 100 seconds, and data is sent from time 10 to 15 seconds, with the extra time in the example allocated to allow " | |
89 "the epidemic routing to eventually deliver the packets.\n"); | |
90 cmd.AddValue ("nWifis", "Number of wifi nodes", nWifis); | |
91 cmd.AddValue ("txpDistance", "Specify node's transmit range", txpDistance); | |
92 cmd.AddValue ("Source", "specify Source traffic node", source_num); | |
93 cmd.AddValue ("Sink", "specify SINK traffic node", sink_num); | |
94 cmd.AddValue ("rate", "CBR traffic rate(in kbps)", rate); | |
95 cmd.AddValue ("packetSize", "The packet size", packetSize); | |
96 cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model", nodeSpeed); | |
97 cmd.AddValue ("Hop Count", "number of hops before a packet is dropped", epidem icHopCount); | |
98 cmd.AddValue ("QueueLength", "Specify queue Length", epidemicQueueLength); | |
99 cmd.AddValue ("QueueEntryExpireTime", "Specify queue Entry Expire Time", epide micQueueEntryExpireTime); | |
100 cmd.AddValue ("BeaconInterval", "Specify beaconInterval", epidemicBeaconInterv al); | |
101 cmd.Parse (argc, argv); | |
102 | |
103 std::cout << "Number of wifi nodes: " << nWifis << std::endl; | |
104 std::cout << "Source number: " << source_num << std::endl; | |
105 std::cout << "Sink number: " << sink_num << std::endl; | |
106 std::cout << "Node speed: " << nodeSpeed << " m/s" << std::endl; | |
107 std::cout << "Packet size: " << packetSize << " b" << std::endl; | |
108 std::cout << "Transmission distance: " << txpDistance << " m" << std::endl; | |
109 std::cout << "Hop count: " << epidemicHopCount << std::endl; | |
110 std::cout << "Queue length: " << epidemicQueueLength << " packets" << std::end l; | |
111 std::cout << "Queue entry expire time: " << epidemicQueueEntryExpireTime.GetSe conds () << " s" << std::endl; | |
112 std::cout << "Beacon interval: " << epidemicBeaconInterval.GetSeconds () << " s" << std::endl; | |
113 | |
114 | |
115 | |
116 if (source_num >= nWifis) | |
117 { | |
118 std::cout << "Source number can not excced number of nodes" << std::endl; | |
Peter Barnes
2014/12/17 00:15:46
Errors should be reported to
std::cerr << …
mjf.alenazi
2014/12/19 13:23:59
Done.
| |
119 } | |
120 | |
121 if (sink_num >= nWifis || source_num >= nWifis) | |
122 { | |
123 std::cout << "Sink number can not excced number of nodes" << std::endl; | |
Peter Barnes
2014/12/17 00:15:46
See previous comment.
mjf.alenazi
2014/12/19 13:23:59
Done.
| |
124 } | |
125 | |
126 | |
127 /* | |
128 * Enabling OnOffApplication and PacketSink logging | |
129 */ | |
130 if (app_logging) | |
131 { | |
132 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); | |
133 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); | |
134 LogComponentEnableAll (LOG_PREFIX_TIME); | |
135 LogComponentEnableAll (LOG_PREFIX_NODE); | |
136 LogComponentEnableAll (LOG_PREFIX_FUNC); | |
137 } | |
138 | |
139 | |
140 | |
141 LogComponentEnable ("EpidemicExample", LOG_LEVEL_ALL); | |
142 nodeContainer.Create (nWifis); | |
143 | |
144 | |
145 /* | |
146 * Mobility model Setup | |
147 */ | |
148 MobilityHelper mobility; | |
149 if (mobility_model == "Grid") | |
150 { | |
151 int internode_distance = 100; | |
152 Ptr<GridPositionAllocator> positionAlloc; | |
153 positionAlloc = CreateObject<GridPositionAllocator> (); | |
154 positionAlloc->SetDeltaX (internode_distance); | |
155 mobility.SetPositionAllocator (positionAlloc); | |
156 | |
157 } | |
158 else if (mobility_model == "RandomWaypoint") | |
159 { | |
160 | |
161 /* | |
162 * Nodes initial positions and mobility bounds are based on original pape r. | |
163 * See Docs for more details. | |
164 */ | |
165 ObjectFactory pos; | |
166 mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", | |
167 "X", StringValue ("300.0"), | |
168 "Y", StringValue ("1500.0"), | |
169 "Rho", StringValue ("ns3::UniformRandomVari able[Min=0|Max=30]")); | |
170 | |
171 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", | |
172 "MinSpeed", DoubleValue (0.01), | |
173 "MaxSpeed", DoubleValue (nodeSpeed), | |
174 "MinX", DoubleValue (0.0), | |
175 "MaxX", DoubleValue (300.0), | |
176 "MinPause", DoubleValue (10), | |
177 "MaxPause", DoubleValue (20), | |
178 "MinY", DoubleValue (0.0), | |
179 "MaxY", DoubleValue (1500.0) | |
Peter Barnes
2014/12/17 00:15:46
(See comment on patch 8)
You'll have to read the
mjf.alenazi
2014/12/19 13:23:59
Done.
| |
180 ); | |
181 } | |
182 mobility.Install (nodeContainer); | |
183 | |
184 | |
185 /* | |
186 * Physical and link Layers Setup | |
187 */ | |
188 | |
189 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); | |
190 wifiMac.SetType ("ns3::AdhocWifiMac"); | |
191 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); | |
192 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); | |
193 | |
194 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", "MaxRange", DoubleValue (txpDistance)); | |
195 wifiPhy.SetChannel (wifiChannel.Create ()); | |
196 WifiHelper wifi = WifiHelper::Default (); | |
197 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", Stri ngValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0)); | |
198 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); | |
199 | |
200 /* | |
201 * Epidemic Routing Setup | |
202 */ | |
203 EpidemicHelper epidemic; | |
204 epidemic.Set ("HopCount", UintegerValue (epidemicHopCount)); | |
205 epidemic.Set ("QueueLength", UintegerValue (epidemicQueueLength)); | |
206 epidemic.Set ("QueueEntryExpireTime", TimeValue (epidemicQueueEntryExpireTime) ); | |
207 epidemic.Set ("BeaconInterval", TimeValue (epidemicBeaconInterval)); | |
208 | |
209 /* | |
210 * Internet Stack Setup | |
211 */ | |
212 Ipv4ListRoutingHelper list; | |
213 InternetStackHelper internet; | |
214 internet.SetRoutingHelper (epidemic); | |
215 internet.Install (nodeContainer); | |
216 Ipv4AddressHelper ipv4; | |
217 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); | |
218 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); | |
219 | |
220 | |
221 /* | |
222 * Application Setup | |
223 */ | |
224 | |
225 | |
226 // Sink or server setup | |
227 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ::GetAny (), 80)); | |
228 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (sink_num)); | |
229 apps_sink.Start (Seconds (0.0)); | |
230 apps_sink.Stop (Seconds (appTotalTime)); | |
231 | |
232 | |
233 // Client setup | |
234 OnOffHelper onoff1 ("ns3::UdpSocketFactory", Address (InetSocketAddress (inter faces.GetAddress (sink_num), 80))); | |
235 onoff1.SetConstantRate (DataRate (rate)); | |
236 onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); | |
237 ApplicationContainer apps1 = onoff1.Install (nodeContainer.Get (source_num)); | |
238 apps1.Start (Seconds (appDataStart)); | |
239 apps1.Stop (Seconds (appDataEnd)); | |
240 | |
241 | |
242 Simulator::Stop (Seconds (appTotalTime)); | |
243 Simulator::Run (); | |
244 Simulator::Destroy (); | |
245 return 0; | |
246 } | |
247 | |
OLD | NEW |