From fa90164e443855d97470ba430749ce22fb553026 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Wed, 2 Nov 2022 19:35:31 +0000 Subject: [PATCH] examples: Clean wifi-example-apps and wifi-example-sim --- examples/stats/wifi-example-apps.cc | 40 ++++++++---------------- examples/stats/wifi-example-apps.h | 41 +++++++++++++----------- examples/stats/wifi-example-sim.cc | 48 +++++++++++++---------------- 3 files changed, 58 insertions(+), 71 deletions(-) diff --git a/examples/stats/wifi-example-apps.cc b/examples/stats/wifi-example-apps.cc index 4f78f14f0..ff5e1e2e7 100644 --- a/examples/stats/wifi-example-apps.cc +++ b/examples/stats/wifi-example-apps.cc @@ -37,6 +37,10 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE("WiFiDistanceApps"); +// ============================================== +// SENDER +// ============================================== + TypeId Sender::GetTypeId() { @@ -46,7 +50,7 @@ Sender::GetTypeId() .AddAttribute("PacketSize", "The size of packets transmitted.", UintegerValue(64), - MakeUintegerAccessor(&Sender::m_pktSize), + MakeUintegerAccessor(&Sender::m_packetSize), MakeUintegerChecker(1)) .AddAttribute("Destination", "Target host address.", @@ -61,7 +65,7 @@ Sender::GetTypeId() .AddAttribute("NumPackets", "Total number of packets to send.", UintegerValue(30), - MakeUintegerAccessor(&Sender::m_numPkts), + MakeUintegerAccessor(&Sender::m_nPackets), MakeUintegerChecker(1)) .AddAttribute("Interval", "Delay between transmissions.", @@ -79,7 +83,6 @@ Sender::Sender() { NS_LOG_FUNCTION_NOARGS(); m_interval = CreateObject(); - m_socket = nullptr; } Sender::~Sender() @@ -114,8 +117,6 @@ Sender::StartApplication() Simulator::Cancel(m_sendEvent); m_sendEvent = Simulator::ScheduleNow(&Sender::SendPacket, this); - - // end Sender::StartApplication } void @@ -123,16 +124,15 @@ Sender::StopApplication() { NS_LOG_FUNCTION_NOARGS(); Simulator::Cancel(m_sendEvent); - // end Sender::StopApplication } void Sender::SendPacket() { - // NS_LOG_FUNCTION_NOARGS (); + // NS_LOG_FUNCTION_NOARGS(); NS_LOG_INFO("Sending packet at " << Simulator::Now() << " to " << m_destAddr); - Ptr packet = Create(m_pktSize); + Ptr packet = Create(m_packetSize); TimestampTag timestamp; timestamp.SetTimestamp(Simulator::Now()); @@ -145,18 +145,17 @@ Sender::SendPacket() // Report the event to the trace. m_txTrace(packet); - if (++m_count < m_numPkts) + if (++m_count < m_nPackets) { m_sendEvent = Simulator::Schedule(Seconds(m_interval->GetValue()), &Sender::SendPacket, this); } - - // end Sender::SendPacket } -//---------------------------------------------------------------------- -//-- Receiver -//------------------------------------------------------ +// ============================================== +// RECEIVER +// ============================================== + TypeId Receiver::GetTypeId() { @@ -172,11 +171,8 @@ Receiver::GetTypeId() } Receiver::Receiver() - : m_calc(nullptr), - m_delay(nullptr) { NS_LOG_FUNCTION_NOARGS(); - m_socket = nullptr; } Receiver::~Receiver() @@ -209,8 +205,6 @@ Receiver::StartApplication() } m_socket->SetRecvCallback(MakeCallback(&Receiver::Receive, this)); - - // end Receiver::StartApplication } void @@ -222,22 +216,18 @@ Receiver::StopApplication() { m_socket->SetRecvCallback(MakeNullCallback>()); } - - // end Receiver::StopApplication } void Receiver::SetCounter(Ptr> calc) { m_calc = calc; - // end Receiver::SetCounter } void Receiver::SetDelayTracker(Ptr delay) { m_delay = delay; - // end Receiver::SetDelayTracker } void @@ -272,9 +262,5 @@ Receiver::Receive(Ptr socket) { m_calc->Update(); } - - // end receiving packets } - - // end Receiver::Receive } diff --git a/examples/stats/wifi-example-apps.h b/examples/stats/wifi-example-apps.h index 5dc301880..e65a2c2c0 100644 --- a/examples/stats/wifi-example-apps.h +++ b/examples/stats/wifi-example-apps.h @@ -31,6 +31,10 @@ using namespace ns3; +// ============================================== +// SENDER +// ============================================== + /** * Sender application. */ @@ -42,6 +46,7 @@ class Sender : public Application * \return The object TypeId. */ static TypeId GetTypeId(); + Sender(); ~Sender() override; @@ -57,23 +62,24 @@ class Sender : public Application */ void SendPacket(); - uint32_t m_pktSize; //!< The packet size. - Ipv4Address m_destAddr; //!< Destination address. - uint32_t m_destPort; //!< Destination port. - Ptr m_interval; //!< Rng for sending packets. - uint32_t m_numPkts; //!< Number of packets to send. + Ipv4Address m_destAddr; //!< Destination address + uint32_t m_destPort{0}; //!< Destination port + uint32_t m_packetSize{0}; //!< The packet size + Ptr m_interval; //!< Rng for sending packets + uint32_t m_nPackets{0}; //!< Number of packets to send + uint32_t m_count{0}; //!< Number of packets sent - Ptr m_socket; //!< Sending socket. - EventId m_sendEvent; //!< Send packet event. + Ptr m_socket; //!< Sending socket + EventId m_sendEvent; //!< Send packet event - /// Tx TracedCallback. + /// Tx TracedCallback TracedCallback> m_txTrace; - - uint32_t m_count; //!< Number of packets sent. - - // end class Sender }; +// ============================================== +// RECEIVER +// ============================================== + /** * Receiver application. */ @@ -85,6 +91,7 @@ class Receiver : public Application * \return The object TypeId. */ static TypeId GetTypeId(); + Receiver(); ~Receiver() override; @@ -113,11 +120,9 @@ class Receiver : public Application */ void Receive(Ptr socket); - Ptr m_socket; //!< Receiving socket. - uint32_t m_port; //!< Listening port. + Ptr m_socket; //!< Receiving socket + uint32_t m_port{0}; //!< Listening port - Ptr> m_calc; //!< Counter of the number of received packets. - Ptr m_delay; //!< Delay calculator. - - // end class Receiver + Ptr> m_calc; //!< Counter of the number of received packets + Ptr m_delay; //!< Delay calculator }; diff --git a/examples/stats/wifi-example-sim.cc b/examples/stats/wifi-example-sim.cc index 6fbe90632..d2238254b 100644 --- a/examples/stats/wifi-example-sim.cc +++ b/examples/stats/wifi-example-sim.cc @@ -36,7 +36,7 @@ #include "ns3/mobility-module.h" #include "ns3/network-module.h" #include "ns3/stats-module.h" -#include "ns3/yans-wifi-helper.h" +#include "ns3/wifi-module.h" #include #include @@ -49,20 +49,16 @@ NS_LOG_COMPONENT_DEFINE("WiFiDistanceExperiment"); * Function called when a packet is transmitted. * * \param datac The counter of the number of transmitted packets. - * \param path The callback context - * \param packet The transmsiotted packet. + * \param path The callback context. + * \param packet The transmitted packet. */ void TxCallback(Ptr> datac, std::string path, Ptr packet) { NS_LOG_INFO("Sent frame counted in " << datac->GetKey()); datac->Update(); - // end TxCallback } -//---------------------------------------------------------------------- -//-- main -//---------------------------------------------- int main(int argc, char* argv[]) { @@ -109,7 +105,7 @@ main(int argc, char* argv[]) input = sstr.str(); } - //------------------------------------------------------------ + //-------------------------------------------- //-- Create nodes and network stacks //-------------------------------------------- NS_LOG_INFO("Creating nodes."); @@ -131,7 +127,7 @@ main(int argc, char* argv[]) ipAddrs.SetBase("192.168.0.0", "255.255.255.0"); ipAddrs.Assign(nodeDevices); - //------------------------------------------------------------ + //-------------------------------------------- //-- Setup physical layout //-------------------------------------------- NS_LOG_INFO("Installing static mobility; distance " << distance << " ."); @@ -142,7 +138,7 @@ main(int argc, char* argv[]) mobility.SetPositionAllocator(positionAlloc); mobility.Install(nodes); - //------------------------------------------------------------ + //-------------------------------------------- //-- Create a custom traffic source and sink //-------------------------------------------- NS_LOG_INFO("Create traffic source & sink."); @@ -159,7 +155,7 @@ main(int argc, char* argv[]) Config::Set("/NodeList/*/ApplicationList/*/$Sender/Destination", Ipv4AddressValue("192.168.0.2")); - //------------------------------------------------------------ + //-------------------------------------------- //-- Setup stats and data collection //-------------------------------------------- @@ -212,23 +208,24 @@ main(int argc, char* argv[]) receiver->SetCounter(appRx); data.AddDataCalculator(appRx); - /** - * Just to show this is here... - Ptr > test = - CreateObject >(); - test->SetKey("test-dc"); - data.AddDataCalculator(test); + // Just to show this is here... - test->Update(4); - test->Update(8); - test->Update(24); - test->Update(12); - **/ + /* + Ptr> test = + CreateObject>(); + test->SetKey("test-dc"); + data.AddDataCalculator(test); + + test->Update(4); + test->Update(8); + test->Update(24); + test->Update(12); + */ // This DataCalculator connects directly to the transmit trace // provided by our Sender Application. It records some basic // statistics about the sizes of the packets received (min, max, - // avg, total # bytes), although in this scenaro they're fixed. + // avg, total # bytes), although in this scenario they're fixed. Ptr appTxPkts = CreateObject(); appTxPkts->SetKey("tx-pkt-size"); @@ -247,13 +244,13 @@ main(int argc, char* argv[]) receiver->SetDelayTracker(delayStat); data.AddDataCalculator(delayStat); - //------------------------------------------------------------ + //-------------------------------------------- //-- Run the simulation //-------------------------------------------- NS_LOG_INFO("Run Simulation."); Simulator::Run(); - //------------------------------------------------------------ + //-------------------------------------------- //-- Generate statistics output. //-------------------------------------------- @@ -286,6 +283,5 @@ main(int argc, char* argv[]) // Free any memory here at the end of this example. Simulator::Destroy(); - // end main return 0; }