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 |
| 27 * the ITTC at The University of Kansas. |
| 28 */ |
| 29 |
| 30 |
| 31 #include "ns3/core-module.h" |
| 32 #include "ns3/network-module.h" |
| 33 #include "ns3/applications-module.h" |
| 34 #include "ns3/mobility-module.h" |
| 35 #include "ns3/wifi-module.h" |
| 36 #include "ns3/internet-module.h" |
| 37 #include <iostream> |
| 38 #include "ns3/epidemic-helper.h" |
| 39 |
| 40 using namespace ns3; |
| 41 |
| 42 /** |
| 43 \file |
| 44 \ingroup epidemic |
| 45 This example creates the scenarios presented the paper titled 'Epidemic Routing |
| 46 for Partially-Connected Ad Hoc Networks.' |
| 47 |
| 48 We have 50 nodes in an area of 1500 m x 300 m. |
| 49 45 nodes are selected to send a message of size 1KB to the other 44 nodes. |
| 50 The total messages are 45 * 44 = 1980 messages. The buffer size is 2000 which |
| 51 is infinite in these scenarios. The ranges for the transmission are from |
| 52 10 m to 250 m while the default is set to 50 m. The expected results are shown |
| 53 in the paper Mohammed Alenazi, Yufei Cheng, Dongsheng Zhang, and James Sterbenz, |
| 54 "Epidemic Routing Protocol Implementation in ns-3", WNS32015. |
| 55 */ |
| 56 |
| 57 |
| 58 int main (int argc, char *argv[]) |
| 59 { |
| 60 // General parameters |
| 61 uint32_t nWifis = 50; |
| 62 NodeContainer nodeContainer; |
| 63 NetDeviceContainer devices; |
| 64 double txpDistance = 50.0; |
| 65 double nodeSpeed = 10.0; |
| 66 bool appLogging = true; |
| 67 |
| 68 // Application parameters |
| 69 double TotalTime = 200.0; |
| 70 double dataStart = 10.0; |
| 71 double dataEnd = 14.0; |
| 72 uint32_t packetSize = 1024; |
| 73 |
| 74 // Epidemic routing parameters |
| 75 uint32_t hopCount = 50; |
| 76 uint32_t queueLength = 200; |
| 77 Time queueEntryExpireTime = Seconds (1000); |
| 78 Time beaconInterval = Seconds (5); |
| 79 |
| 80 |
| 81 CommandLine cmd; |
| 82 cmd.Usage ("Benchmark example shows epidemic routing scenario presented " |
| 83 "in the original paper. There are 50 nodes in an area of 1500 m x
300 m." |
| 84 " 45 nodes are selected to send a message of size 1KB to the other
" |
| 85 "44 nodes. The total messages are 45 * 44 = 1980 messages. The buf
fer " |
| 86 "size is 2000 which is infinite in these scenarios. The ranges for
" |
| 87 "the transmission are from 10 m to 250 m while the default is set t
o " |
| 88 "50 m.\n"); |
| 89 cmd.AddValue ("nWifis", "Number of \"extra\" Wifi nodes/devices", nWifis); |
| 90 cmd.AddValue ("appLogging", "Tell echo applications to log if true", |
| 91 appLogging); |
| 92 cmd.AddValue ("nodeSpeed", "Node speed in RandomWayPoint model", nodeSpeed); |
| 93 cmd.AddValue ("packetSize", "The packet size", packetSize); |
| 94 cmd.AddValue ("txpDistance", "Specify node's transmit range", txpDistance); |
| 95 cmd.AddValue ("hopCount", "Specify number of hopCount", hopCount); |
| 96 cmd.AddValue ("queueLength", "Specify queue Length", queueLength); |
| 97 cmd.AddValue ("queueEntryExpireTime", "Specify queue Entry Expire Time", |
| 98 queueEntryExpireTime); |
| 99 cmd.AddValue ("beaconInterval", "Specify beaconInterval", beaconInterval); |
| 100 |
| 101 cmd.Parse (argc, argv); |
| 102 |
| 103 |
| 104 std::cout << "Number of wifi nodes: " << nWifis << std::endl; |
| 105 std::cout << "Node speed: " << nodeSpeed << " m/s" << std::endl; |
| 106 std::cout << "Packet size: " << packetSize << " b" << std::endl; |
| 107 std::cout << "Transmission distance: " << txpDistance << " m" << std::endl; |
| 108 std::cout << "Hop count: " << hopCount << std::endl; |
| 109 std::cout << "Queue length: " << queueLength << " packets" << std::endl; |
| 110 std::cout << "Queue entry expire time: " << queueEntryExpireTime.GetSeconds |
| 111 () << " s" << std::endl; |
| 112 std::cout << "Beacon interval: " << beaconInterval.GetSeconds () << " s" << |
| 113 std::endl; |
| 114 |
| 115 |
| 116 |
| 117 /* |
| 118 * Enabling OnOffApplication and PacketSink logging |
| 119 * */ |
| 120 if (appLogging) |
| 121 { |
| 122 LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO); |
| 123 LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); |
| 124 LogComponentEnableAll (LOG_PREFIX_TIME); |
| 125 LogComponentEnableAll (LOG_PREFIX_NODE); |
| 126 LogComponentEnableAll (LOG_PREFIX_FUNC); |
| 127 } |
| 128 |
| 129 |
| 130 |
| 131 |
| 132 nodeContainer.Create (nWifis); |
| 133 |
| 134 |
| 135 /* |
| 136 * Mobility model Setup |
| 137 * The parameters for mobility model matches the epidemic routing paper. |
| 138 */ |
| 139 MobilityHelper mobility; |
| 140 ObjectFactory pos; |
| 141 mobility.SetPositionAllocator ("ns3::RandomRectanglePositionAllocator", |
| 142 "X", StringValue ("ns3::UniformRandomVariable[M
in=0.0|Max=300.0]"), |
| 143 "Y", StringValue ("ns3::UniformRandomVariable[M
in=0.0|Max=1500.0]")); |
| 144 |
| 145 |
| 146 mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel", |
| 147 "MinSpeed", DoubleValue (0.01), |
| 148 "MaxSpeed", DoubleValue (nodeSpeed), |
| 149 "MinX", DoubleValue (0.0), |
| 150 "MaxX", DoubleValue (300.0), |
| 151 "MinPause", DoubleValue (10), |
| 152 "MaxPause", DoubleValue (20), |
| 153 "MinY", DoubleValue (0.0), |
| 154 "MaxY", DoubleValue (1500.0) |
| 155 ); |
| 156 mobility.Install (nodeContainer); |
| 157 |
| 158 |
| 159 /* |
| 160 * Physical and link Layers Setup |
| 161 */ |
| 162 |
| 163 NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
| 164 wifiMac.SetType ("ns3::AdhocWifiMac"); |
| 165 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
| 166 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
| 167 |
| 168 wifiChannel.AddPropagationLoss ("ns3::RangePropagationLossModel", |
| 169 "MaxRange", DoubleValue (txpDistance)); |
| 170 wifiPhy.SetChannel (wifiChannel.Create ()); |
| 171 WifiHelper wifi = WifiHelper::Default (); |
| 172 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
| 173 "DataMode", StringValue ("OfdmRate6Mbps"), |
| 174 "RtsCtsThreshold", UintegerValue (0)); |
| 175 devices = wifi.Install (wifiPhy, wifiMac, nodeContainer); |
| 176 |
| 177 |
| 178 /* |
| 179 * Epidemic Routing Setup |
| 180 * */ |
| 181 EpidemicHelper epidemic; |
| 182 epidemic.Set ("HopCount", UintegerValue (hopCount)); |
| 183 epidemic.Set ("QueueLength", UintegerValue (queueLength)); |
| 184 epidemic.Set ("QueueEntryExpireTime", TimeValue (queueEntryExpireTime)); |
| 185 epidemic.Set ("BeaconInterval", TimeValue (beaconInterval)); |
| 186 |
| 187 /* |
| 188 * Internet Stack Setup |
| 189 * */ |
| 190 Ipv4ListRoutingHelper list; |
| 191 InternetStackHelper internet; |
| 192 internet.SetRoutingHelper (epidemic); |
| 193 internet.Install (nodeContainer); |
| 194 Ipv4AddressHelper ipv4; |
| 195 ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
| 196 Ipv4InterfaceContainer interfaces = ipv4.Assign (devices); |
| 197 |
| 198 |
| 199 /* |
| 200 * Application Setup |
| 201 * */ |
| 202 |
| 203 |
| 204 // Sink or server setup |
| 205 for (uint32_t i = 0; i < 45; ++i) |
| 206 { |
| 207 PacketSinkHelper sink ("ns3::UdpSocketFactory", |
| 208 InetSocketAddress (Ipv4Address::GetAny (), 80)); |
| 209 ApplicationContainer apps_sink = sink.Install (nodeContainer.Get (i)); |
| 210 apps_sink.Start (Seconds (0.0)); |
| 211 apps_sink.Stop (Seconds (TotalTime)); |
| 212 } |
| 213 |
| 214 |
| 215 |
| 216 // Client setup |
| 217 for (uint32_t source = 0; source < 45; ++source) |
| 218 { |
| 219 for (uint32_t sink = 0; sink < 45; ++sink) |
| 220 { |
| 221 if (sink != source) |
| 222 { |
| 223 OnOffHelper onoff1 ("ns3::UdpSocketFactory", |
| 224 Address (InetSocketAddress |
| 225 (interfaces.GetAddress (sink), 80))
); |
| 226 onoff1.SetConstantRate (DataRate ("1024B/s")); |
| 227 onoff1.SetAttribute ("PacketSize", UintegerValue (packetSize)); |
| 228 ApplicationContainer apps1 = onoff1.Install ( |
| 229 nodeContainer.Get (source)); |
| 230 apps1.Start (Seconds (dataStart)); |
| 231 apps1.Stop (Seconds (dataEnd)); |
| 232 } |
| 233 |
| 234 } |
| 235 } |
| 236 |
| 237 |
| 238 |
| 239 Simulator::Stop (Seconds (TotalTime)); |
| 240 Simulator::Run (); |
| 241 Simulator::Destroy (); |
| 242 return 0; |
| 243 } |
| 244 |
OLD | NEW |