diff options
| author | Loic Guegan <manzerberdes@gmx.com> | 2019-04-12 10:48:33 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerberdes@gmx.com> | 2019-04-12 10:48:33 +0200 |
| commit | 23e8f7f688da3df8d5b4d47e881865717141325c (patch) | |
| tree | 0146a81697c60a0178440048a4443eb535e1368d | |
| parent | c40644ec64bda1e7e92ffead97da3647b82fd456 (diff) | |
Update code
| -rwxr-xr-x | ns-3_wifi_tests/wifi-test | bin | 236712 -> 264072 bytes | |||
| -rw-r--r-- | ns-3_wifi_tests/wifi-test.cc | 104 |
2 files changed, 74 insertions, 30 deletions
diff --git a/ns-3_wifi_tests/wifi-test b/ns-3_wifi_tests/wifi-test Binary files differindex c0432bb..95ffcdf 100755 --- a/ns-3_wifi_tests/wifi-test +++ b/ns-3_wifi_tests/wifi-test 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 <iostream> #include <utility> // To use std::pair +#include <iomanip> using namespace ns3; NS_LOG_COMPONENT_DEFINE ("wifi-tcp"); - +Ipv4Address cloudIP; +int cloudPort=50; // ---------- Code ---------- @@ -37,22 +40,37 @@ typedef std::pair<NodeContainer,NodeContainer> CellNodes; typedef std::pair<NetDeviceContainer,NetDeviceContainer> CellNetDevices; typedef std::pair<CellNodes,CellNetDevices> Cell; + + +void CloudSwitchRx(Ptr< const Packet > packet, const Address &address){ + NS_LOG_UNCOND(std::setw(7)<<Simulator::Now ().GetSeconds ()<< " Cloud switch receive a packet!"); +} + +void +TotalEnergy (std::string context,double oldValue, double newValue) +{ + NS_LOG_UNCOND ("Energy Value of node " << context << " at time " <<Simulator::Now ().GetSeconds () + << "\t"<< newValue); +} + + + /** - * Create a sensors cell + * Create a sensors cell base on + * nbSensors Number of temperature sensors in the cell + * ap the Access Point (usually linked to the cloud) */ -Cell createCell(uint32_t nbSensors){ +Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> 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<ConstantPositionMobilityModel> ()); } - ap.Get (0)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ()); + ap->AggregateObject (CreateObject<ConstantPositionMobilityModel> ()); // 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 " <<Simulator::Now ().GetSeconds () - << "\t"<< newValue); +Ptr<ns3::Node> buildEdgeAndCloud(int nbOp){ + + NodeContainer OpNodes; + OpNodes.Create(nbOp+1); + + InternetStackHelper stack; + stack.Install(OpNodes); + + for(int i=0;i<nbOp;i++){ // Not nbOp-1 (We add a AP) + NodeContainer curNodes(OpNodes.Get(i),OpNodes.Get(i+1)); + + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); + pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); + + NetDeviceContainer p2pDevices; + p2pDevices = pointToPoint.Install (curNodes); + + Ipv4AddressHelper address; + address.SetBase (("10.1."+std::to_string(i)+".0").c_str(), "255.255.255.0"); + Ipv4InterfaceContainer p2pInterfaces; + p2pInterfaces = address.Assign (p2pDevices); + + // NS_LOG_UNCOND(i); + if(i==nbOp-1){ // If we are on the last Op + cloudIP=p2pInterfaces.GetAddress (1); + + PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), cloudPort)); + ApplicationContainer sinkApp=apSink.Install(curNodes.Get(1)); + sinkApp.Get(0)->TraceConnectWithoutContext("Rx",MakeCallback(&CloudSwitchRx)); + sinkApp.Start (Seconds (0)); + } + } + return(OpNodes.Get(0)); + } @@ -169,9 +213,6 @@ void setupEnergy(Cell cell){ - - - // Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (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 (); |
