From 23e8f7f688da3df8d5b4d47e881865717141325c Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 12 Apr 2019 10:48:33 +0200 Subject: Update code --- ns-3_wifi_tests/wifi-test | Bin 236712 -> 264072 bytes ns-3_wifi_tests/wifi-test.cc | 104 ++++++++++++++++++++++++++++++------------- 2 files changed, 74 insertions(+), 30 deletions(-) (limited to 'ns-3_wifi_tests') diff --git a/ns-3_wifi_tests/wifi-test b/ns-3_wifi_tests/wifi-test index c0432bb..95ffcdf 100755 Binary files a/ns-3_wifi_tests/wifi-test and b/ns-3_wifi_tests/wifi-test differ diff --git a/ns-3_wifi_tests/wifi-test.cc b/ns-3_wifi_tests/wifi-test.cc index 52ccf88..1ba2db8 100644 --- a/ns-3_wifi_tests/wifi-test.cc +++ b/ns-3_wifi_tests/wifi-test.cc @@ -20,15 +20,18 @@ #include "ns3/constant-position-mobility-model.h" #include "ns3/energy-module.h" #include "ns3/wifi-radio-energy-model-helper.h" +#include "ns3/point-to-point-helper.h" // C++ library #include #include // To use std::pair +#include using namespace ns3; NS_LOG_COMPONENT_DEFINE ("wifi-tcp"); - +Ipv4Address cloudIP; +int cloudPort=50; // ---------- Code ---------- @@ -37,22 +40,37 @@ typedef std::pair CellNodes; typedef std::pair CellNetDevices; typedef std::pair Cell; + + +void CloudSwitchRx(Ptr< const Packet > packet, const Address &address){ + NS_LOG_UNCOND(std::setw(7)< ap){ // Create sensors NodeContainer sensors; sensors.Create(nbSensors); - NodeContainer ap; - ap.Create(1); // Place nodes somehow, this is required by every wireless simulation for (uint8_t i = 0; i < nbSensors; ++i) { sensors.Get (i)->AggregateObject (CreateObject ()); } - ap.Get (0)->AggregateObject (CreateObject ()); + ap->AggregateObject (CreateObject ()); // To apply XXWifiPhy and WifiMac on sensors WifiHelper wifiHelper; @@ -92,6 +110,7 @@ Cell createCell(uint32_t nbSensors){ return(std::make_pair(std::make_pair(ap,sensors),std::make_pair(apNetDevice,sensorsNetDevices))); } + /** * Install network stack and applications */ @@ -103,16 +122,15 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval){ // 6. Install TCP/IP stack & assign IP addresses InternetStackHelper internet; - internet.Install (ap); + // internet.Install (ap); internet.Install (sensors); Ipv4AddressHelper ipv4; - ipv4.SetBase ("10.0.0.0", "255.0.0.0"); + ipv4.SetBase ("10.0.0.0", "255.255.255.0"); Ipv4InterfaceContainer apInt,sensorsInt; apInt=ipv4.Assign(apNetDev); sensorsInt=ipv4.Assign(sensorsNetDev); - uint16_t echoPort = 9; - UdpEchoClientHelper echoClientHelper (InetSocketAddress (apInt.GetAddress (0), echoPort)); + UdpEchoClientHelper echoClientHelper (InetSocketAddress (cloudIP, cloudPort)); // echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (10)); echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (sensorsSendInterval))); echoClientHelper.SetAttribute ("PacketSize", UintegerValue (sensorsPktSize)); @@ -121,17 +139,43 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval){ // again using different start times to workaround Bug 388 and Bug 912 echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (1))); // Start at 1 (WIFI seems to not work when t<1) echoClientHelper.Install (sensors); - - PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), echoPort)); - ApplicationContainer sinkApp=apSink.Install(ap); - sinkApp.Start (Seconds (0)); } -void -TotalEnergy (std::string context,double oldValue, double newValue) -{ - NS_LOG_UNCOND ("Energy Value of node " << context << " at time " < buildEdgeAndCloud(int nbOp){ + + NodeContainer OpNodes; + OpNodes.Create(nbOp+1); + + InternetStackHelper stack; + stack.Install(OpNodes); + + for(int i=0;iTraceConnectWithoutContext("Rx",MakeCallback(&CloudSwitchRx)); + sinkApp.Start (Seconds (0)); + } + } + return(OpNodes.Get(0)); + } @@ -169,9 +213,6 @@ void setupEnergy(Cell cell){ - - - // Ptr basicSourcePtr0 = DynamicCast (wifiEdgeNodesSources.Get (0)); // //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy)); @@ -189,24 +230,27 @@ void setupEnergy(Cell cell){ int main(int argc, char* argv[]){ - LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); - LogComponentEnable("PacketSink", LOG_LEVEL_INFO); + //LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO); + // LogComponentEnable("PacketSink", LOG_LEVEL_INFO); uint32_t sensorsFrequency=1; uint32_t sensorsPktSize=150; uint32_t sensorsNumber=2; + uint32_t nbHop=5; CommandLine cmd; - cmd.AddValue ("sensorsSendInterval", "Number of temperature measurement per second (default 1)", sensorsFrequency); - cmd.AddValue ("sensorsPktSize", "Sensor measurements packet size (default 64 bytes)", sensorsPktSize); - cmd.AddValue ("sensorsNumber", "Number of sensors (default 10)", sensorsNumber); + cmd.AddValue ("sensorsSendInterval", "Number of temperature measurement per second", sensorsFrequency); + cmd.AddValue ("sensorsPktSize", "Sensor measurements packet size (bytes)", sensorsPktSize); + cmd.AddValue ("sensorsNumber", "Number of sensors", sensorsNumber); + cmd.AddValue ("nbHop", "Number of hop between AP and Cloud sensors", sensorsNumber); cmd.Parse (argc, argv); - Cell c=createCell(sensorsNumber); + Cell c=createCell(sensorsNumber,buildEdgeAndCloud(nbHop)); + applyScenarios(c,sensorsPktSize,sensorsFrequency); - setupEnergy(c); - + // setupEnergy(c); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); // Run simulators Simulator::Stop (Seconds (20)); Simulator::Run (); -- cgit v1.2.3