paper-lowrate-iot/ns3-simulations/simulator/main.cc

65 lines
2.5 KiB
C++
Raw Normal View History

2019-04-12 13:52:06 +02:00
#include "modules/modules.hpp"
NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator");
2019-04-12 14:48:47 +02:00
/**
* To get more details about functions please have a look at modules/modules.hpp
*/
2019-04-12 13:52:06 +02:00
int main(int argc, char* argv[]){
uint32_t sensorsFrequency=1;
uint32_t sensorsPktSize=150;
uint32_t sensorsNumber=2;
uint32_t nbHop=5;
2019-04-12 16:05:29 +02:00
uint32_t linksBandwidth=5;
uint32_t linksLatency=2;
2019-04-12 13:52:06 +02:00
CommandLine cmd;
2019-04-12 16:05:29 +02:00
cmd.AddValue ("sensorsSendInterval", "Number of sensors measurement per second", sensorsFrequency);
cmd.AddValue ("sensorsPktSize", "Sensors packet size (bytes)", sensorsPktSize);
cmd.AddValue ("sensorsNumber", "Number of sensors connected to AP", sensorsNumber);
2019-04-25 16:51:15 +02:00
cmd.AddValue ("nbHop", "Number of hop between AP and Cloud", nbHop);
2019-04-12 16:05:29 +02:00
cmd.AddValue ("linksBandwidth", "Links bandwidth between AP and Cloud", linksBandwidth);
cmd.AddValue ("linksLatency", "Links latency between AP and Cloud", linksLatency);
2019-04-12 13:52:06 +02:00
cmd.Parse (argc, argv);
//LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
//LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
2019-04-12 14:48:47 +02:00
// ---------- Setup Simulations ----------
2019-04-12 16:05:29 +02:00
CloudInfos cloud=createCloud(nbHop,linksBandwidth,linksLatency); // Create cloud P2P node chain o--o--o--o--o
setupCloudEnergy(cloud); // DO IT JUST AFTER createCloud !!!!! Otherwise you will be in trouble
2019-04-12 14:48:47 +02:00
Cell cell=createCell(sensorsNumber,cloud.first.Get(0)); // Use first cloud node as Access Point
setupScenario(cell,cloud,sensorsPktSize,sensorsFrequency); // Send data from Sensors to Cloud
setupCellEnergy(cell);
2019-04-12 16:05:29 +02:00
2019-04-12 14:48:47 +02:00
// Don't forget the following
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
2019-04-12 13:52:06 +02:00
2019-04-25 15:51:05 +02:00
// Setup Logs
2019-04-25 09:00:11 +02:00
uint32_t nNode=ns3::NodeList::GetNNodes();
2019-04-25 15:51:05 +02:00
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
// Run Simulations
Simulator::Stop (Seconds (30));
2019-04-12 13:52:06 +02:00
Simulator::Run ();
2019-04-25 15:51:05 +02:00
// Print logs
NS_LOG_UNCOND("NS-3 Version " << NS3_VERSION);
NS_LOG_UNCOND("Simulation used "<< nNode << " nodes");
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map< FlowId, FlowMonitor::FlowStats>::iterator flow=stats.begin(); flow!=stats.end(); flow++)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow->first);
NS_LOG_UNCOND("Flow " <<t.sourceAddress<< " -> "<< t.destinationAddress << " delay = " <<flow->second.delaySum.GetSeconds());
}
// Finish
Simulator::Destroy ();
2019-04-12 13:52:06 +02:00
return(0);
}