36 NS_LOG_COMPONENT_DEFINE (
"wsnconstructor");
42 TypeId (
"ns3::WsnConstructor")
44 .AddConstructor<WsnConstructor> ()
45 .AddAttribute (
"SimulationSeed",
"Seed value of the simulation",
46 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
47 UintegerValue ((uint32_t) 0),
49 MakeUintegerChecker<uint32_t> ())
50 .AddAttribute (
"SimulationName",
"Name of the simulation", StringValue (
"default"),
53 .AddAttribute (
"Topology",
"Network topology (random disc topology OR grid topology)",
57 "IEEE80211n_carrier",
"Carrier frequency of the IEEE 802.11n",
60 .AddAttribute (
"Routing",
"Routing algorithm for wireless multi-hop networks",
64 .AddAttribute (
"NodeNumber",
"Number of sensor nodes in the network",
65 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
66 UintegerValue ((uint16_t) 50),
68 MakeUintegerChecker<uint16_t> ())
69 .AddAttribute (
"Radius",
"Parameter for the setup of the random disc topology",
70 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
71 UintegerValue ((uint16_t) 15),
73 MakeUintegerChecker<uint16_t> ())
74 .AddAttribute (
"CellSide",
75 "The length of a cell side in the grid topology. The length is "
76 "representing the distance between neighbouring nodes on the cardinal "
77 "directions of the reference node.",
78 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
79 UintegerValue ((uint16_t) 20),
81 MakeUintegerChecker<uint16_t> ())
82 .AddAttribute (
"Verbosity",
"Verbosity of the simulation", EnumValue (
Verbosity::Both),
87 .AddAttribute (
"MSS",
"Maximum segment size",
88 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
90 MakeUintegerChecker<uint16_t> ())
92 "CommOverhead",
"Collect statistics about the communication overhead",
97 "String of values delimited by the symbol \",\" each value representing the number "
98 "of hops the onion will travel to return back to the sink node issuer of the onion.",
99 StringValue (
"5,10,20,30,40,50"),
101 .AddAttribute (
"RepeatePaths",
102 "Integer specifying the number of times to generate the onion message for "
103 "each value of the parameter Paths",
104 TypeId::ATTR_CONSTRUCT | TypeId::ATTR_SET | TypeId::ATTR_GET,
105 UintegerValue ((uint16_t) 1),
107 MakeUintegerChecker<uint16_t> ());
149 Config::SetDefault (
"ns3::TcpSocket::SegmentSize", UintegerValue (
m_mss));
150 Config::SetDefault (
"ns3::Wsn_node::MSS", UintegerValue (
m_mss));
157 int run = RngSeedManager::GetRun ();
158 int seed = RngSeedManager::GetRun ();
160 "Simulation randomstream setup, run: " + std::to_string (run) +
161 ", seed:" + std::to_string (seed) +
"\n";
168 LogComponentEnable (
"wsnconstructor", LOG_LEVEL_INFO);
169 LogComponentEnable (
"sink", LOG_LEVEL_INFO);
170 LogComponentEnable (
"sensornode", LOG_LEVEL_INFO);
171 LogComponentEnable (
"outputmanager", LOG_LEVEL_INFO);
172 LogComponentEnable (
"onionrouting", LOG_LEVEL_INFO);
216 time_t givemetime = time (NULL);
222 givemetime = time (NULL);
224 <<
" started at time: " << std::string (ctime (&givemetime)) << std::endl;
228 givemetime = time (NULL);
232 givemetime = time (NULL);
234 <<
" ended at time: " + std::string (ctime (&givemetime)) << std::endl;
239 Ptr<DataOutputInterface> output;
240 output = CreateObject<OmnetDataOutput> ();
241 output->SetFilePrefix (
"./src/onion_routing_wsn/sim_results/comm-overhead-stats-" +
243 output->Output (
data);
246 Simulator::Destroy ();
276 (uint16_t) (
unsigned int) std::stoi (
m_pathsLengths.substr (start, end - start));
282 (uint16_t) (
unsigned int) std::stoi (
m_pathsLengths.substr (start, end - start));
290 data.AddMetadata (
"Captured data:",
291 "Count of packets and statistics about packet size. (sum is in bytes)");
293 Ptr<PacketSizeMinMaxAvgTotalCalculator> macTxPkts =
294 CreateObject<PacketSizeMinMaxAvgTotalCalculator> ();
295 macTxPkts->SetKey (
"total-wsn-communication-overhead-transmitted");
296 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
297 MakeCallback (&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate, macTxPkts));
298 data.AddDataCalculator (macTxPkts);
299 Ptr<PacketSizeMinMaxAvgTotalCalculator> macRxPkts =
300 CreateObject<PacketSizeMinMaxAvgTotalCalculator> ();
301 macRxPkts->SetKey (
"total-wsn-communication-overhead-received");
302 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
303 MakeCallback (&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate, macRxPkts));
304 data.AddDataCalculator (macRxPkts);
305 Ptr<PacketSizeMinMaxAvgTotalCalculator> appRx =
306 CreateObject<PacketSizeMinMaxAvgTotalCalculator> ();
307 appRx->SetKey (
"app-layer-data-received");
308 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::Wsn_node/AppRx",
309 MakeCallback (&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate, appRx));
310 data.AddDataCalculator (appRx);
319 NS_LOG_INFO (
"--------------- Create " <<
m_numNodes <<
" sensor nodes and 1 sink node");
328 "Total sensornodes: " + std::to_string (
sensornodes.GetN ()) +
329 " and 1 sink node \n";
338 NS_LOG_INFO (
"--------------- Creating and configuring devices & setup WiFi channel");
345 wifi.SetStandard (WIFI_STANDARD_80211n_2_4GHZ);
348 wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
352 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager");
355 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper ();
358 YansWifiChannelHelper wifiChannel;
359 wifiChannel.SetPropagationDelay (
"ns3::ConstantSpeedPropagationDelayModel");
363 Ptr<ConstantRateWifiManager> cr = CreateObject<ConstantRateWifiManager> ();
364 cr->GetAttribute (
"DataMode", ptr);
365 std::string mcs_details =
", DataMode: " + ptr.Get ();
366 cr->GetAttribute (
"ControlMode", ptr);
367 mcs_details = mcs_details +
", ControlMode: " + ptr.Get ();
373 wifiChannel.AddPropagationLoss (
"ns3::LogDistancePropagationLossModel",
"Exponent",
374 DoubleValue (3.0),
"ReferenceLoss", DoubleValue (40.0459));
380 wifiChannel.AddPropagationLoss (
"ns3::LogDistancePropagationLossModel",
"Exponent",
387 wifiPhy.SetChannel (wifiChannel.Create ());
390 WifiMacHelper wifiMac;
391 wifiMac.SetType (
"ns3::AdhocWifiMac",
"BE_MaxAmpduSize", UintegerValue (65535));
395 Config::Set (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/"
396 "ShortGuardIntervalSupported",
397 BooleanValue (
false));
403 ", MSS:" + std::to_string (
m_mss) +
"\n";
417 NS_LOG_INFO (
"--------------- Building disc topology");
425 "Network topology: RANDOM DISC, node radius: " + std::to_string (
m_radius) +
426 "m , disc topology radius: " + std::to_string (r_disc) +
427 "m. Sink node located at x:" + std::to_string ((
int) r_disc) +
428 ",y:" + std::to_string ((
int) r_disc) +
" \n";
431 ObjectFactory rndDisc;
432 rndDisc.SetTypeId (
"ns3::RandomDiscPositionAllocator");
433 rndDisc.Set (
"Rho", StringValue (
"ns3::UniformRandomVariable[Min=40|Max=" +
434 std::to_string (r_disc) +
"]"));
435 rndDisc.Set (
"X", DoubleValue (r_disc));
436 rndDisc.Set (
"Y", DoubleValue (r_disc));
437 rndDisc.Set (
"Z", DoubleValue (0));
439 Ptr<PositionAllocator> posAlloc = rndDisc.Create ()->GetObject<PositionAllocator> ();
441 mobility.SetPositionAllocator (posAlloc);
442 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
445 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
446 positionAlloc->Add (Vector (r_disc, r_disc, 0.0));
447 mobility.SetPositionAllocator (positionAlloc);
461 NS_LOG_INFO (
"--------------- Building grid topology");
468 mobility.SetPositionAllocator (
"ns3::GridPositionAllocator",
"MinX", DoubleValue (0),
"MinY",
469 DoubleValue (0),
"DeltaX", DoubleValue (deltaX),
"DeltaY",
470 DoubleValue (deltaY),
"GridWidth", UintegerValue (row_size),
471 "LayoutType", StringValue (
"RowFirst"));
473 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
479 Ptr<MobilityModel> sinkMobility =
m_sink.Get (0)->GetObject<MobilityModel> ();
482 int m = row_size / 2 * row_size + row_size / 2;
484 Ptr<MobilityModel> middleNodeMobility =
sensornodes.Get (m)->GetObject<MobilityModel> ();
485 double middleNode_x = middleNodeMobility->GetPosition ().x;
486 double middleNode_y = middleNodeMobility->GetPosition ().y;
488 middleNodeMobility->SetPosition (
489 Vector (sinkMobility->GetPosition ().x, sinkMobility->GetPosition ().y, 0));
490 sinkMobility->SetPosition (Vector (middleNode_x, middleNode_y, 0));
493 "Network topology: GRID with row size: " + std::to_string (row_size) +
494 ". Distance between nodes on X-axis: " + std::to_string (deltaX) +
495 "m. Distance between nodes on Y-axis: " + std::to_string (deltaY) +
496 "m. Sink node located at x:" + std::to_string ((
int) middleNode_x) +
497 ",y:" + std::to_string ((
int) middleNode_y) +
" \n";
507 NS_LOG_INFO (
"--------------- Install routing & internet stack ");
529 Ipv4AddressHelper address;
531 address.SetBase (
"10.1.0.0",
"255.255.0.0");
542 DsrMainHelper dsrMain;
545 InternetStackHelper stack;
558 Ipv4StaticRoutingHelper staticRouting;
560 Ipv4ListRoutingHelper list;
561 list.Add (staticRouting, 0);
564 InternetStackHelper stack;
565 stack.SetRoutingHelper (list);
577 Ipv4StaticRoutingHelper staticRouting;
579 Ipv4ListRoutingHelper list;
580 list.Add (staticRouting, 0);
583 InternetStackHelper stack;
584 stack.SetRoutingHelper (list);
596 Ipv4StaticRoutingHelper staticRouting;
598 Ipv4ListRoutingHelper list;
599 list.Add (staticRouting, 0);
602 InternetStackHelper stack;
603 stack.SetRoutingHelper (list);
613 NS_LOG_INFO (
"--------------- Configuring Applications ");
617 int routing_setup_time = 20;
621 routing_setup_time = 60;
639 sinkApps.Start (Seconds (1.0 + routing_setup_time));
642 UintegerValue node_delay;
643 sinkApps.Get (0)->GetObject<
Sink> ()->GetAttribute (
"Delay", node_delay);
644 int start_onion = (node_delay.Get () *
m_numNodes) / 1000 +
649 "s, nodes are starting sequentially with " + std::to_string (node_delay.Get ()) +
650 "ms interval, onion starts at: " + std::to_string (start_onion + routing_setup_time) +
"s\n";
664 main (
int argc,
char **argv)
668 Config::SetDefault (
"ns3::ConfigStore::Filename",
669 StringValue (
"src/onion_routing_wsn/configParameters.xml"));
670 Config::SetDefault (
"ns3::ConfigStore::Mode", StringValue (
"Load"));
671 Config::SetDefault (
"ns3::ConfigStore::FileFormat", StringValue (
"Xml"));
672 ConfigStore inputConfig;
673 inputConfig.ConfigureDefaults ();
679 "ns3::WsnConstructor::SimulationSeed");
680 cmd.AddValue (
"a_name",
"ns3::WsnConstructor::SimulationName");
681 cmd.AddValue (
"a_routing",
682 "ns3::WsnConstructor::Routing");
683 cmd.AddValue (
"a_topology",
"ns3::WsnConstructor::Topology");
684 cmd.AddValue (
"a_nodeNumber",
"ns3::WsnConstructor::NodeNumber");
685 cmd.Parse (argc, argv);
687 Ptr<WsnConstructor> bt = CreateObject<WsnConstructor> ();