OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2015 Federico Guerra |
| 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: Federico Guerra <federico@guerra-tlc.com> |
| 19 */ |
| 20 /** |
| 21 * \file woss-aloha-example.cc |
| 22 * \ingroup WOSS |
| 23 * |
| 24 * |
| 25 */ |
| 26 |
| 27 #ifndef NS3_WOSS_SUPPORT |
| 28 int |
| 29 main (int argc, char *argv[]) |
| 30 { |
| 31 return 0; |
| 32 } |
| 33 #else |
| 34 |
| 35 #include "woss-aloha-example.h" |
| 36 #include "ns3/woss-channel.h" |
| 37 #include "ns3/woss-waypoint-mobility-model.h" |
| 38 #include "ns3/woss-position-allocator.h" |
| 39 #include "ns3/core-module.h" |
| 40 #include "ns3/network-module.h" |
| 41 #include "ns3/applications-module.h" |
| 42 #include "ns3/mobility-module.h" |
| 43 #include "ns3/log.h" |
| 44 #include "ns3/config.h" |
| 45 #include "ns3/callback.h" |
| 46 #include "ns3/stats-module.h" |
| 47 |
| 48 |
| 49 #include <fstream> |
| 50 |
| 51 using namespace ns3; |
| 52 |
| 53 NS_LOG_COMPONENT_DEFINE ("WossAlohaExample"); |
| 54 |
| 55 |
| 56 Experiment::Experiment () |
| 57 : m_posAllocSelector (0), |
| 58 m_totalRate (4096), |
| 59 m_maxRange (3000), |
| 60 m_numNodes (2), |
| 61 m_pktSize (1000), |
| 62 m_simTime (Seconds (5000)), |
| 63 m_databasePath (""), |
| 64 m_useMultithread (true), |
| 65 m_useTimeEvolution (false), |
| 66 m_bytesTotal (0), |
| 67 m_dataMode () |
| 68 { |
| 69 } |
| 70 |
| 71 void |
| 72 Experiment::InitWossHelper (Ptr<WossHelper> wossHelper, Ptr<WossPropModel> wossP
rop, woss::CoordZ &txCoordZ) |
| 73 { |
| 74 wossHelper->SetAttribute ("ResDbUseBinary", BooleanValue (false)); |
| 75 wossHelper->SetAttribute ("ResDbUseTimeArr", BooleanValue (true)); |
| 76 wossHelper->SetAttribute ("ResDbFilePath", StringValue ("./woss-aloha-example-
output/res-db/")); |
| 77 wossHelper->SetAttribute ("ResDbFileName", StringValue ("woss-aloha-example-re
sults.dat")); |
| 78 if (m_databasePath != "") |
| 79 { |
| 80 wossHelper->SetAttribute ("SedimDbCoordFilePath", StringValue (m_databaseP
ath + "/sea_floor/DECK41_coordinates.nc")); |
| 81 wossHelper->SetAttribute ("SedimDbMarsdenFilePath", StringValue (m_databas
ePath + "/sea_floor/DECK41_mardsen_square.nc")); |
| 82 wossHelper->SetAttribute ("SedimDbMarsdenOneFilePath", StringValue (m_data
basePath + "/sea_floor/DECK41_mardsen_one_degree.nc")); |
| 83 wossHelper->SetAttribute ("SspDbCoordFilePath", StringValue (m_databasePat
h + "/ssp/standard_depth/2WOA2009_SSP_April.nc")); |
| 84 wossHelper->SetAttribute ("BathyDbCoordFilePath", StringValue (m_databaseP
ath + "/bathymetry/GEBCO_2014_1D.nc")); |
| 85 } |
| 86 wossHelper->SetAttribute ("WossCleanWorkDir", BooleanValue (false)); |
| 87 wossHelper->SetAttribute ("WossWorkDirPath", StringValue ("./woss-aloha-exampl
e-output/work-dir/")); |
| 88 wossHelper->SetAttribute ("WossSimTime", StringValue ("1|10|2012|0|1|1|1|10|20
12|0|1|1")); |
| 89 wossHelper->SetAttribute ("WossManagerTimeEvoActive", BooleanValue (m_useTimeE
volution)); |
| 90 wossHelper->SetAttribute ("WossManagerTotalThreads", IntegerValue (4)); |
| 91 wossHelper->SetAttribute ("WossManagerUseMultithread", BooleanValue (m_useMult
ithread)); |
| 92 |
| 93 wossHelper->Initialize (wossProp); |
| 94 |
| 95 if (m_databasePath == "") |
| 96 { |
| 97 wossHelper->SetCustomBathymetry ("5|0.0|100.0|100.0|200.0|300.0|150.0|400.
0|100.0|700.0|300.0", txCoordZ); |
| 98 wossHelper->SetCustomSediment ("TestSediment|1560.0|200.0|1.5|0.9|0.8|300.
0"); |
| 99 wossHelper->SetCustomSsp ("12|0|1508.42|10|1508.02|20|1507.71|30|1507.53|5
0|1507.03|75|1507.56|100|1508.08|125|1508.49|150|1508.91|200|1509.75|250|1510.58
|300|1511.42"); |
| 100 } |
| 101 |
| 102 } |
| 103 |
| 104 void |
| 105 Experiment::ReceivePacket (Ptr<Socket> socket) |
| 106 { |
| 107 Ptr<Packet> packet; |
| 108 while ((packet = socket->Recv ())) |
| 109 { |
| 110 NS_LOG_DEBUG ("Received a packet of size " << packet->GetSize () << " byte
s"); |
| 111 m_bytesTotal += packet->GetSize (); |
| 112 } |
| 113 } |
| 114 |
| 115 |
| 116 |
| 117 uint32_t |
| 118 Experiment::Run (uint32_t param) |
| 119 { |
| 120 UanHelper uan; |
| 121 |
| 122 |
| 123 uint32_t depth = 70; |
| 124 double sinkLatitude = 42.59; |
| 125 double sinkLongitude = 10.125; |
| 126 |
| 127 woss::CoordZ sinkCoord = woss::CoordZ (sinkLatitude, sinkLongitude, depth); |
| 128 |
| 129 m_bytesTotal = 0; |
| 130 |
| 131 uint32_t nNodes = param; |
| 132 |
| 133 Ptr<WossHelper> wossHelper = CreateObject<WossHelper> (); |
| 134 |
| 135 // Ptr<UanPhyCalcSinrFhFsk> sinr = CreateObject<UanPhyCalcSinrFhFsk> (); |
| 136 Ptr<UanPhyCalcSinrDefault> sinr = CreateObject<UanPhyCalcSinrDefault> (); |
| 137 |
| 138 UanTxMode mode; |
| 139 // mode = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 22000, 4000, 1
3, "FSK"); |
| 140 mode = UanTxModeFactory::CreateMode (UanTxMode::PSK, 200, 200, 22000, 4000, 4,
"QPSK"); |
| 141 |
| 142 UanModesList myModes; |
| 143 myModes.AppendMode (mode); |
| 144 |
| 145 uan.SetPhy ("ns3::UanPhyGen", |
| 146 "SinrModel", PointerValue (sinr), |
| 147 "SupportedModes", UanModesListValue (myModes)); |
| 148 |
| 149 uan.SetMac ("ns3::UanMacAloha"); |
| 150 |
| 151 Ptr<WossPropModel> wossProp = CreateObjectWithAttributes<WossPropModel> (); |
| 152 InitWossHelper (wossHelper, wossProp, sinkCoord); |
| 153 |
| 154 Ptr<WossChannel> wossChannel = CreateObjectWithAttributes<WossChannel> ("Propa
gationModel", PointerValue (wossProp)); |
| 155 wossChannel->SetAttribute ("ChannelEqSnrThresholdDb", DoubleValue (-100.0)); |
| 156 |
| 157 NodeContainer sink; |
| 158 sink.Create (1); |
| 159 NetDeviceContainer sinkDev = uan.Install (sink, wossChannel); |
| 160 |
| 161 NodeContainer nodes; |
| 162 nodes.Create (nNodes); |
| 163 NetDeviceContainer devices = uan.Install (nodes, wossChannel); |
| 164 |
| 165 MobilityHelper mobilitySink, mobility; |
| 166 |
| 167 Ptr<PositionAllocator> pos; |
| 168 |
| 169 Ptr<WossListPositionAllocator> posSink = CreateObject<WossListPositionAllocato
r> (); |
| 170 posSink->Add (sinkCoord); |
| 171 |
| 172 if (m_posAllocSelector == 0) |
| 173 { |
| 174 pos = CreateObject<WossListPositionAllocator> (); |
| 175 Ptr<WossListPositionAllocator> posCast = DynamicCast<WossListPositionAlloc
ator> (pos); |
| 176 |
| 177 for (uint32_t i = 0; i < nNodes; i++) |
| 178 { |
| 179 woss::CoordZ nodeCoord = woss::CoordZ (woss::Coord::getCoordFromBearin
g (sinkCoord, M_PI / 2.0, (i + 1) * 500.0), depth); |
| 180 posCast->Add (nodeCoord); |
| 181 } |
| 182 } |
| 183 else if (m_posAllocSelector == 1) |
| 184 { |
| 185 pos = CreateObject<WossGridPositionAllocator> (); |
| 186 |
| 187 pos->SetAttribute ("MinLatitude", DoubleValue (sinkLatitude)); |
| 188 pos->SetAttribute ("MinLongitude", DoubleValue (sinkLongitude)); |
| 189 pos->SetAttribute ("Depth", DoubleValue (depth)); |
| 190 pos->SetAttribute ("DeltaLatitude", DoubleValue (500.0)); |
| 191 pos->SetAttribute ("DeltaLongitude", DoubleValue (500.0)); |
| 192 pos->SetAttribute ("LayoutType", EnumValue (WossGridPositionAllocator::COL
UMN_FIRST)); |
| 193 pos->SetAttribute ("GridWidth", UintegerValue (2)); |
| 194 } |
| 195 else if (m_posAllocSelector == 2) |
| 196 { |
| 197 pos = CreateObject<WossRandomRectanglePositionAllocator> (); |
| 198 |
| 199 pos->SetAttribute ("Latitude", StringValue ("ns3::UniformRandomVariable[Mi
n=42.59|Max=42.6]")); |
| 200 pos->SetAttribute ("Longitude", StringValue ("ns3::UniformRandomVariable[M
in=10.125|Max=10.127]")); |
| 201 pos->SetAttribute ("Depth", DoubleValue (depth)); |
| 202 } |
| 203 else if (m_posAllocSelector == 3) |
| 204 { |
| 205 pos = CreateObject<WossRandomDiscPositionAllocator> (); |
| 206 |
| 207 pos->SetAttribute ("Latitude", DoubleValue (sinkLatitude)); |
| 208 pos->SetAttribute ("Longitude", DoubleValue (sinkLongitude)); |
| 209 pos->SetAttribute ("Depth", DoubleValue (depth)); |
| 210 } |
| 211 else if (m_posAllocSelector == 4) |
| 212 { |
| 213 Ptr<WossUniformDiscPositionAllocator> pos = CreateObject<WossUniformDiscPo
sitionAllocator> (); |
| 214 |
| 215 pos->SetAttribute ("Latitude", DoubleValue (sinkLatitude)); |
| 216 pos->SetAttribute ("Longitude", DoubleValue (sinkLongitude)); |
| 217 pos->SetAttribute ("Depth", DoubleValue (depth)); |
| 218 } |
| 219 else |
| 220 { |
| 221 NS_FATAL_ERROR ("m_posAllocSelector:" << m_posAllocSelector << " > 4 provi
ded!"); |
| 222 } |
| 223 |
| 224 mobilitySink.SetPositionAllocator (posSink); |
| 225 mobility.SetPositionAllocator (pos); |
| 226 |
| 227 mobilitySink.SetMobilityModel ("ns3::WossWaypointMobilityModel", "InitialPosit
ionIsWaypoint", BooleanValue (true)); |
| 228 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 229 |
| 230 mobilitySink.Install (sink); |
| 231 mobility.Install (nodes); |
| 232 |
| 233 Ptr<Node> nodeSink = sink.Get (0); |
| 234 Ptr<WossWaypointMobilityModel> sinkMob = nodeSink->GetObject<WossWaypointMobil
ityModel> (); |
| 235 NS_ASSERT (sinkMob != NULL); |
| 236 |
| 237 for (int cnt = 0; cnt < 5; ++cnt) |
| 238 { |
| 239 Waypoint wp ( Seconds ((cnt + 1.0) * 10.0), CreateVectorFromCoords (42.59,
10.125 + (cnt + 1.0) * 0.05, depth)); |
| 240 sinkMob->AddWaypoint (wp); |
| 241 } |
| 242 |
| 243 PacketSocketHelper pktskth; |
| 244 pktskth.Install (nodes); |
| 245 pktskth.Install (sink); |
| 246 |
| 247 PacketSocketAddress socket; |
| 248 socket.SetSingleDevice (sinkDev.Get (0)->GetIfIndex ()); |
| 249 socket.SetPhysicalAddress (sinkDev.Get (0)->GetAddress ()); |
| 250 socket.SetProtocol (0); |
| 251 |
| 252 OnOffHelper app ("ns3::PacketSocketFactory", Address (socket)); |
| 253 app.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant
=1]")); |
| 254 app.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constan
t=0]")); |
| 255 app.SetAttribute ("DataRate", DataRateValue (m_totalRate)); |
| 256 app.SetAttribute ("PacketSize", UintegerValue (m_pktSize)); |
| 257 |
| 258 ApplicationContainer apps = app.Install (nodes); |
| 259 |
| 260 apps.Start (Seconds (0.5)); |
| 261 apps.Stop (m_simTime + Seconds (0.5)); |
| 262 |
| 263 Ptr<Node> sinkNode = sink.Get (0); |
| 264 TypeId psfid = TypeId::LookupByName ("ns3::PacketSocketFactory"); |
| 265 |
| 266 Ptr<Socket> sinkSocket = Socket::CreateSocket (sinkNode, psfid); |
| 267 sinkSocket->Bind (socket); |
| 268 sinkSocket->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); |
| 269 |
| 270 Simulator::Stop (m_simTime + Seconds (0.6)); |
| 271 Simulator::Run (); |
| 272 Simulator::Destroy (); |
| 273 |
| 274 return m_bytesTotal; |
| 275 } |
| 276 int |
| 277 main (int argc, char *argv[]) |
| 278 { |
| 279 |
| 280 LogComponentEnable ("WossAlohaExample", LOG_LEVEL_ALL); |
| 281 // LogComponentEnable ("WossHelper", LOG_LEVEL_ALL); |
| 282 // LogComponentEnable ("WossChannel", LOG_LEVEL_ALL); |
| 283 // LogComponentEnable ("WossPropModel", LOG_LEVEL_ALL); |
| 284 // LogComponentEnable ("UanChannel", LOG_LEVEL_ALL); |
| 285 // LogComponentEnable ("UanTransducerHd", LOG_LEVEL_ALL); |
| 286 // LogComponentEnable ("UanPhyGen", LOG_LEVEL_ALL); |
| 287 // LogComponentEnable ("UanPropModelThorp", LOG_LEVEL_ALL); |
| 288 // LogComponentEnable ("WossPositionAllocator", LOG_LEVEL_ALL); |
| 289 // LogComponentEnable ("WossWaypointMobilityModel", LOG_LEVEL_ALL); |
| 290 |
| 291 Experiment exp; |
| 292 |
| 293 CommandLine cmd; |
| 294 cmd.AddValue ("TotalRate", "Total channel capacity", exp.m_totalRate); |
| 295 cmd.AddValue ("PosAllocSelector", "Position Allocator Selector: 0 list, 1 grid
, 2 random rectangle, 3 random disc, 4 uniform disc", exp.m_posAllocSelector); |
| 296 cmd.AddValue ("UseMultithread", "flag to set the WOSS multithread option", exp
.m_useMultithread); |
| 297 cmd.AddValue ("UseTimeEvolution", "flag to set the WOSS time evolution option"
, exp.m_useTimeEvolution); |
| 298 cmd.AddValue ("NumberNodes", "Number of nodes", exp.m_numNodes); |
| 299 cmd.AddValue ("PktSize", "Packet size in bytes", exp.m_pktSize); |
| 300 cmd.AddValue ("SimTime", "Simulation time per trial", exp.m_simTime); |
| 301 cmd.Parse (argc, argv); |
| 302 |
| 303 uint32_t bytesRx = exp.Run (exp.m_numNodes); |
| 304 |
| 305 NS_LOG_DEBUG ("Received a total of " << bytesRx << " bytes at sink"); |
| 306 |
| 307 } |
| 308 |
| 309 #endif // NS3_WOSS_SUPPORT |
| 310 |
OLD | NEW |