diff --git a/examples/routing/manet-routing-compare.cc b/examples/routing/manet-routing-compare.cc index 23fc7d4a1..c28b35ae0 100644 --- a/examples/routing/manet-routing-compare.cc +++ b/examples/routing/manet-routing-compare.cc @@ -83,30 +83,60 @@ using namespace dsr; NS_LOG_COMPONENT_DEFINE ("manet-routing-compare"); +/** + * Routing experiment class. + * + * It handles the creation and run of an experiment. + */ class RoutingExperiment { public: RoutingExperiment (); + /** + * Run the experiment. + * \param nSinks The number of Sink Nodes. + * \param txp The Tx power. + * \param CSVfileName The output CSV filename. + */ void Run (int nSinks, double txp, std::string CSVfileName); //static void SetMACParam (ns3::NetDeviceContainer & devices, // int slotDistance); + /** + * Handles the command-line parmeters. + * \param argc The argument count. + * \param argv The argument vector. + * \return the CSV filename. + */ std::string CommandSetup (int argc, char **argv); private: + /** + * Setup the receiving socket in a Sink Node. + * \param addr The address of the node. + * \param node The node pointer. + * \return the socket. + */ Ptr SetupPacketReceive (Ipv4Address addr, Ptr node); + /** + * Receive a packet. + * \param socket The receiving socket. + */ void ReceivePacket (Ptr socket); + /** + * Compute the throughput. + */ void CheckThroughput (); - uint32_t port; - uint32_t bytesTotal; - uint32_t packetsReceived; + uint32_t port; //!< Receiving port number. + uint32_t bytesTotal; //!< Total received bytes. + uint32_t packetsReceived; //!< Total received packets. - std::string m_CSVfileName; - int m_nSinks; - std::string m_protocolName; - double m_txp; - bool m_traceMobility; - uint32_t m_protocol; + std::string m_CSVfileName; //!< CSV filename. + int m_nSinks; //!< Number of sink nodes. + std::string m_protocolName; //!< Protocol name. + double m_txp; //!< Tx power. + bool m_traceMobility; //!< Enavle mobility tracing. + uint32_t m_protocol; //!< Protocol type. }; RoutingExperiment::RoutingExperiment () diff --git a/examples/stats/wifi-example-apps.h b/examples/stats/wifi-example-apps.h index f7e9ae612..06ed64aa9 100644 --- a/examples/stats/wifi-example-apps.h +++ b/examples/stats/wifi-example-apps.h @@ -33,10 +33,15 @@ using namespace ns3; -//---------------------------------------------------------------------- -//------------------------------------------------------ +/** + * Sender application. + */ class Sender : public Application { public: + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); Sender(); virtual ~Sender(); @@ -48,35 +53,52 @@ private: virtual void StartApplication (void); virtual void StopApplication (void); + /** + * Send a packet. + */ void SendPacket (); - uint32_t m_pktSize; - Ipv4Address m_destAddr; - uint32_t m_destPort; - Ptr m_interval; - uint32_t m_numPkts; + 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. - Ptr m_socket; - EventId m_sendEvent; + Ptr m_socket; //!< Sending socket. + EventId m_sendEvent; //!< Send packet event. + /// Tx TracedCallback. TracedCallback > m_txTrace; - uint32_t m_count; + uint32_t m_count; //!< Number of packets sent. // end class Sender }; - - -//------------------------------------------------------ +/** + * Receiver application. + */ class Receiver : public Application { public: + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); Receiver(); virtual ~Receiver(); + /** + * Set the counter calculator for received packets. + * \param calc The CounterCalculator. + */ void SetCounter (Ptr > calc); + + /** + * Set the delay tracker for received packets. + * \param delay The Delay calculator. + */ void SetDelayTracker (Ptr delay); protected: @@ -86,24 +108,35 @@ private: virtual void StartApplication (void); virtual void StopApplication (void); + /** + * Receive a packet. + * \param socket The receiving socket. + */ void Receive (Ptr socket); - Ptr m_socket; + Ptr m_socket; //!< Receiving socket. + uint32_t m_port; //!< Listening port. - uint32_t m_port; - - Ptr > m_calc; - Ptr m_delay; + Ptr > m_calc; //!< Counter of the number of received packets. + Ptr m_delay; //!< Delay calculator. // end class Receiver }; - - -//------------------------------------------------------ +/** + * Timestamp tag - it carries when the packet has been sent. + * + * It would have been more realistic to include this info in + * a header. Here we show how to avoid the extra overhead in + * a simulation. + */ class TimestampTag : public Tag { public: + /** + * \brief Get the type ID. + * \return The object TypeId. + */ static TypeId GetTypeId (void); virtual TypeId GetInstanceTypeId (void) const; @@ -111,14 +144,21 @@ public: virtual void Serialize (TagBuffer i) const; virtual void Deserialize (TagBuffer i); - // these are our accessors to our tag structure + /** + * Set the timestamp. + * \param time The timestamp. + */ void SetTimestamp (Time time); + /** + * Get the timestamp. + * \return the timestamp. + */ Time GetTimestamp (void) const; void Print (std::ostream &os) const; private: - Time m_timestamp; + Time m_timestamp; //!< Timestamp. // end class TimestampTag }; diff --git a/examples/tutorial/CMakeLists.txt b/examples/tutorial/CMakeLists.txt index d78d74415..4ecca4e18 100644 --- a/examples/tutorial/CMakeLists.txt +++ b/examples/tutorial/CMakeLists.txt @@ -45,7 +45,7 @@ build_example( build_example( NAME fifth - SOURCE_FILES fifth.cc + SOURCE_FILES fifth.cc tutorial-app.cc LIBRARIES_TO_LINK ${libcore} ${libpoint-to-point} @@ -55,7 +55,7 @@ build_example( build_example( NAME sixth - SOURCE_FILES sixth.cc + SOURCE_FILES sixth.cc tutorial-app.cc LIBRARIES_TO_LINK ${libcore} ${libpoint-to-point} @@ -65,7 +65,7 @@ build_example( build_example( NAME seventh - SOURCE_FILES seventh.cc + SOURCE_FILES seventh.cc tutorial-app.cc LIBRARIES_TO_LINK ${libcore} ${libstats} diff --git a/examples/tutorial/fifth.cc b/examples/tutorial/fifth.cc index 60272e506..cf660d988 100644 --- a/examples/tutorial/fifth.cc +++ b/examples/tutorial/fifth.cc @@ -18,8 +18,9 @@ #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" -#include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" +#include "ns3/point-to-point-module.h" +#include "tutorial-app.h" using namespace ns3; @@ -59,106 +60,7 @@ NS_LOG_COMPONENT_DEFINE ("FifthScriptExample"); // install in the source node. // =========================================================================== // -class MyApp : public Application -{ -public: - MyApp (); - virtual ~MyApp(); - - void Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate); - -private: - virtual void StartApplication (void); - virtual void StopApplication (void); - - void ScheduleTx (void); - void SendPacket (void); - - Ptr m_socket; - Address m_peer; - uint32_t m_packetSize; - uint32_t m_nPackets; - DataRate m_dataRate; - EventId m_sendEvent; - bool m_running; - uint32_t m_packetsSent; -}; - -MyApp::MyApp () - : m_socket (0), - m_peer (), - m_packetSize (0), - m_nPackets (0), - m_dataRate (0), - m_sendEvent (), - m_running (false), - m_packetsSent (0) -{ -} - -MyApp::~MyApp() -{ - m_socket = 0; -} - -void -MyApp::Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) -{ - m_socket = socket; - m_peer = address; - m_packetSize = packetSize; - m_nPackets = nPackets; - m_dataRate = dataRate; -} - -void -MyApp::StartApplication (void) -{ - m_running = true; - m_packetsSent = 0; - m_socket->Bind (); - m_socket->Connect (m_peer); - SendPacket (); -} - -void -MyApp::StopApplication (void) -{ - m_running = false; - - if (m_sendEvent.IsRunning ()) - { - Simulator::Cancel (m_sendEvent); - } - - if (m_socket) - { - m_socket->Close (); - } -} - -void -MyApp::SendPacket (void) -{ - Ptr packet = Create (m_packetSize); - m_socket->Send (packet); - - if (++m_packetsSent < m_nPackets) - { - ScheduleTx (); - } -} - -void -MyApp::ScheduleTx (void) -{ - if (m_running) - { - Time tNext (Seconds (m_packetSize * 8 / static_cast (m_dataRate.GetBitRate ()))); - m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this); - } -} static void CwndChange (uint32_t oldCwnd, uint32_t newCwnd) @@ -209,7 +111,7 @@ main (int argc, char *argv[]) Ptr ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ()); ns3TcpSocket->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndChange)); - Ptr app = CreateObject (); + Ptr app = CreateObject (); app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps")); nodes.Get (0)->AddApplication (app); app->SetStartTime (Seconds (1.)); diff --git a/examples/tutorial/fourth.cc b/examples/tutorial/fourth.cc index c8893de71..c26aac3b7 100644 --- a/examples/tutorial/fourth.cc +++ b/examples/tutorial/fourth.cc @@ -24,6 +24,9 @@ using namespace ns3; +/** + * Tutorial 4 - a simple Object to show how to hook a trace. + */ class MyObject : public Object { public: @@ -46,7 +49,7 @@ public: } MyObject () {} - TracedValue m_myInt; + TracedValue m_myInt; //!< The traced value. }; void diff --git a/examples/tutorial/seventh.cc b/examples/tutorial/seventh.cc index f56db8c4c..5480c3e6f 100644 --- a/examples/tutorial/seventh.cc +++ b/examples/tutorial/seventh.cc @@ -18,9 +18,10 @@ #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" -#include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" +#include "ns3/point-to-point-module.h" #include "ns3/stats-module.h" +#include "tutorial-app.h" using namespace ns3; @@ -63,128 +64,7 @@ NS_LOG_COMPONENT_DEFINE ("SeventhScriptExample"); // in src/stats/docs/seventh-packet-byte-count.png // =========================================================================== // -class MyApp : public Application -{ -public: - MyApp (); - virtual ~MyApp (); - /** - * Register this type. - * \return The TypeId. - */ - static TypeId GetTypeId (void); - void Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate); - -private: - virtual void StartApplication (void); - virtual void StopApplication (void); - - void ScheduleTx (void); - void SendPacket (void); - - Ptr m_socket; - Address m_peer; - uint32_t m_packetSize; - uint32_t m_nPackets; - DataRate m_dataRate; - EventId m_sendEvent; - bool m_running; - uint32_t m_packetsSent; -}; - -MyApp::MyApp () - : m_socket (0), - m_peer (), - m_packetSize (0), - m_nPackets (0), - m_dataRate (0), - m_sendEvent (), - m_running (false), - m_packetsSent (0) -{ -} - -MyApp::~MyApp () -{ - m_socket = 0; -} - -/* static */ -TypeId MyApp::GetTypeId (void) -{ - static TypeId tid = TypeId ("MyApp") - .SetParent () - .SetGroupName ("Tutorial") - .AddConstructor () - ; - return tid; -} - -void -MyApp::Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) -{ - m_socket = socket; - m_peer = address; - m_packetSize = packetSize; - m_nPackets = nPackets; - m_dataRate = dataRate; -} - -void -MyApp::StartApplication (void) -{ - m_running = true; - m_packetsSent = 0; - if (InetSocketAddress::IsMatchingType (m_peer)) - { - m_socket->Bind (); - } - else - { - m_socket->Bind6 (); - } - m_socket->Connect (m_peer); - SendPacket (); -} - -void -MyApp::StopApplication (void) -{ - m_running = false; - - if (m_sendEvent.IsRunning ()) - { - Simulator::Cancel (m_sendEvent); - } - - if (m_socket) - { - m_socket->Close (); - } -} - -void -MyApp::SendPacket (void) -{ - Ptr packet = Create (m_packetSize); - m_socket->Send (packet); - - if (++m_packetsSent < m_nPackets) - { - ScheduleTx (); - } -} - -void -MyApp::ScheduleTx (void) -{ - if (m_running) - { - Time tNext (Seconds (m_packetSize * 8 / static_cast (m_dataRate.GetBitRate ()))); - m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this); - } -} static void CwndChange (Ptr stream, uint32_t oldCwnd, uint32_t newCwnd) @@ -259,7 +139,7 @@ main (int argc, char *argv[]) Ptr ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ()); - Ptr app = CreateObject (); + Ptr app = CreateObject (); app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps")); nodes.Get (0)->AddApplication (app); app->SetStartTime (Seconds (1.)); diff --git a/examples/tutorial/sixth.cc b/examples/tutorial/sixth.cc index 128377b2d..ab47784ad 100644 --- a/examples/tutorial/sixth.cc +++ b/examples/tutorial/sixth.cc @@ -18,8 +18,9 @@ #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" -#include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" +#include "ns3/point-to-point-module.h" +#include "tutorial-app.h" using namespace ns3; @@ -59,121 +60,7 @@ NS_LOG_COMPONENT_DEFINE ("SixthScriptExample"); // install in the source node. // =========================================================================== // -class MyApp : public Application -{ -public: - MyApp (); - virtual ~MyApp (); - /** - * Register this type. - * \return The TypeId. - */ - static TypeId GetTypeId (void); - void Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate); - -private: - virtual void StartApplication (void); - virtual void StopApplication (void); - - void ScheduleTx (void); - void SendPacket (void); - - Ptr m_socket; - Address m_peer; - uint32_t m_packetSize; - uint32_t m_nPackets; - DataRate m_dataRate; - EventId m_sendEvent; - bool m_running; - uint32_t m_packetsSent; -}; - -MyApp::MyApp () - : m_socket (0), - m_peer (), - m_packetSize (0), - m_nPackets (0), - m_dataRate (0), - m_sendEvent (), - m_running (false), - m_packetsSent (0) -{ -} - -MyApp::~MyApp () -{ - m_socket = 0; -} - -/* static */ -TypeId MyApp::GetTypeId (void) -{ - static TypeId tid = TypeId ("MyApp") - .SetParent () - .SetGroupName ("Tutorial") - .AddConstructor () - ; - return tid; -} - -void -MyApp::Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) -{ - m_socket = socket; - m_peer = address; - m_packetSize = packetSize; - m_nPackets = nPackets; - m_dataRate = dataRate; -} - -void -MyApp::StartApplication (void) -{ - m_running = true; - m_packetsSent = 0; - m_socket->Bind (); - m_socket->Connect (m_peer); - SendPacket (); -} - -void -MyApp::StopApplication (void) -{ - m_running = false; - - if (m_sendEvent.IsRunning ()) - { - Simulator::Cancel (m_sendEvent); - } - - if (m_socket) - { - m_socket->Close (); - } -} - -void -MyApp::SendPacket (void) -{ - Ptr packet = Create (m_packetSize); - m_socket->Send (packet); - - if (++m_packetsSent < m_nPackets) - { - ScheduleTx (); - } -} - -void -MyApp::ScheduleTx (void) -{ - if (m_running) - { - Time tNext (Seconds (m_packetSize * 8 / static_cast (m_dataRate.GetBitRate ()))); - m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this); - } -} static void CwndChange (Ptr stream, uint32_t oldCwnd, uint32_t newCwnd) @@ -225,7 +112,7 @@ main (int argc, char *argv[]) Ptr ns3TcpSocket = Socket::CreateSocket (nodes.Get (0), TcpSocketFactory::GetTypeId ()); - Ptr app = CreateObject (); + Ptr app = CreateObject (); app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, DataRate ("1Mbps")); nodes.Get (0)->AddApplication (app); app->SetStartTime (Seconds (1.)); diff --git a/examples/tutorial/tutorial-app.cc b/examples/tutorial/tutorial-app.cc new file mode 100644 index 000000000..caece9f41 --- /dev/null +++ b/examples/tutorial/tutorial-app.cc @@ -0,0 +1,106 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "tutorial-app.h" +#include "ns3/applications-module.h" + +using namespace ns3; + +TutorialApp::TutorialApp () + : m_socket (0), + m_peer (), + m_packetSize (0), + m_nPackets (0), + m_dataRate (0), + m_sendEvent (), + m_running (false), + m_packetsSent (0) +{ +} + +TutorialApp::~TutorialApp () +{ + m_socket = 0; +} + +/* static */ +TypeId TutorialApp::GetTypeId (void) +{ + static TypeId tid = TypeId ("TutorialApp") + .SetParent () + .SetGroupName ("Tutorial") + .AddConstructor () + ; + return tid; +} + +void +TutorialApp::Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate) +{ + m_socket = socket; + m_peer = address; + m_packetSize = packetSize; + m_nPackets = nPackets; + m_dataRate = dataRate; +} + +void +TutorialApp::StartApplication (void) +{ + m_running = true; + m_packetsSent = 0; + m_socket->Bind (); + m_socket->Connect (m_peer); + SendPacket (); +} + +void +TutorialApp::StopApplication (void) +{ + m_running = false; + + if (m_sendEvent.IsRunning ()) + { + Simulator::Cancel (m_sendEvent); + } + + if (m_socket) + { + m_socket->Close (); + } +} + +void +TutorialApp::SendPacket (void) +{ + Ptr packet = Create (m_packetSize); + m_socket->Send (packet); + + if (++m_packetsSent < m_nPackets) + { + ScheduleTx (); + } +} + +void +TutorialApp::ScheduleTx (void) +{ + if (m_running) + { + Time tNext (Seconds (m_packetSize * 8 / static_cast (m_dataRate.GetBitRate ()))); + m_sendEvent = Simulator::Schedule (tNext, &TutorialApp::SendPacket, this); + } +} diff --git a/examples/tutorial/tutorial-app.h b/examples/tutorial/tutorial-app.h new file mode 100644 index 000000000..15ef30b9e --- /dev/null +++ b/examples/tutorial/tutorial-app.h @@ -0,0 +1,74 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TUTORIAL_APP_H +#define TUTORIAL_APP_H + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" + +namespace ns3 { + +class Application; + +/** + * Tutorial - a simple Application sending packets. + */ +class TutorialApp : public Application +{ +public: + TutorialApp (); + virtual ~TutorialApp (); + + /** + * Register this type. + * \return The TypeId. + */ + static TypeId GetTypeId (void); + + /** + * Setup the socket. + * \param socket The socket. + * \param address The destination address. + * \param packetSize The packet size to transmit. + * \param nPackets The number of packets to transmit. + * \param dataRate the datarate to use. + */ + void Setup (Ptr socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate); + +private: + virtual void StartApplication (void); + virtual void StopApplication (void); + + /// Schedule a new transmission. + void ScheduleTx (void); + /// Send a packet. + void SendPacket (void); + + Ptr m_socket; //!< The tranmission socket. + Address m_peer; //!< The destination address. + uint32_t m_packetSize; //!< The packet size. + uint32_t m_nPackets; //!< The number of pacts to send. + DataRate m_dataRate; //!< The datarate to use. + EventId m_sendEvent; //!< Send event. + bool m_running; //!< True if the application is running. + uint32_t m_packetsSent; //!< The number of pacts sent. +}; + +} // namespace ns3 + +#endif /* TUTORIAL_APP_H */ diff --git a/examples/tutorial/wscript b/examples/tutorial/wscript index 2cd0dfe75..3963d067f 100644 --- a/examples/tutorial/wscript +++ b/examples/tutorial/wscript @@ -23,10 +23,11 @@ def build(bld): obj.source = 'fourth.cc' obj = bld.create_ns3_program('fifth', ['core', 'point-to-point', 'internet', 'applications']) - obj.source = 'fifth.cc' + obj.source = [ 'fifth.cc', 'tutorial-app.cc' ] obj = bld.create_ns3_program('sixth', ['core', 'point-to-point', 'internet', 'applications']) - obj.source = 'sixth.cc' + obj.source = [ 'sixth.cc', 'tutorial-app.cc' ] obj = bld.create_ns3_program('seventh', ['core', 'stats', 'point-to-point', 'internet', 'applications']) - obj.source = 'seventh.cc' + obj.source = [ 'seventh.cc', 'tutorial-app.cc' ] + diff --git a/examples/wireless/wifi-adhoc.cc b/examples/wireless/wifi-adhoc.cc index 3e23304cd..807fffa19 100644 --- a/examples/wireless/wifi-adhoc.cc +++ b/examples/wireless/wifi-adhoc.cc @@ -37,22 +37,63 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("Wifi-Adhoc"); +/** + * WiFi adhoc experiment class. + * + * It handles the creation and run of an experiment. + */ class Experiment { public: Experiment (); + /** + * Constructor. + * \param name The name of the experiment. + */ Experiment (std::string name); + + /** + * Run an experiment. + * \param wifi //!< The WifiHelper class. + * \param wifiPhy //!< The YansWifiPhyHelper class. + * \param wifiMac //!< The WifiMacHelper class. + * \param wifiChannel //!< The YansWifiChannelHelper class. + * \return a 2D dataset of the experiment data. + */ Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel); private: + /** + * Receive a packet. + * \param socket The recieving socket. + */ void ReceivePacket (Ptr socket); + /** + * Set the position of a node. + * \param node The node. + * \param position The position of the node. + */ void SetPosition (Ptr node, Vector position); + /** + * Get the position of a node. + * \param node The node. + * \return the position of the node. + */ Vector GetPosition (Ptr node); + /** + * Move a node by 1m on the x axis, stops at 210m. + * \param node The node. + */ void AdvancePosition (Ptr node); + /** + * Setup the receiving socket. + * \param node The receiving node. + * \return the socket. + */ Ptr SetupPacketReceive (Ptr node); - uint32_t m_bytesTotal; - Gnuplot2dDataset m_output; + uint32_t m_bytesTotal; //!< The number of received bytes. + Gnuplot2dDataset m_output; //!< The output dataset. }; Experiment::Experiment () diff --git a/examples/wireless/wifi-clear-channel-cmu.cc b/examples/wireless/wifi-clear-channel-cmu.cc index 715c77d7f..37fb9c9b2 100644 --- a/examples/wireless/wifi-clear-channel-cmu.cc +++ b/examples/wireless/wifi-clear-channel-cmu.cc @@ -35,23 +35,66 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("ClearChannelCmu"); +/** + * WiFi clear channel cmu experiment class. + * + * It handles the creation and run of an experiment. + */ class Experiment { public: Experiment (); + /** + * Constructor. + * \param name The name of the experiment. + */ Experiment (std::string name); + /** + * Run an experiment. + * \param wifi //!< The WifiHelper class. + * \param wifiPhy //!< The YansWifiPhyHelper class. + * \param wifiMac //!< The WifiMacHelper class. + * \param wifiChannel //!< The YansWifiChannelHelper class. + * \return the number of received packets. + */ uint32_t Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel); private: + /** + * Receive a packet. + * \param socket The recieving socket. + */ void ReceivePacket (Ptr socket); + /** + * Set the position of a node. + * \param node The node. + * \param position The position of the node. + */ void SetPosition (Ptr node, Vector position); + /** + * Get the position of a node. + * \param node The node. + * \return the position of the node. + */ Vector GetPosition (Ptr node); + /** + * Setup the receiving socket. + * \param node The receiving node. + * \return the socket. + */ Ptr SetupPacketReceive (Ptr node); + /** + * Generate the traffic. + * \param socket The sending socket. + * \param pktSize The packet size. + * \param pktCount The number of packets to send. + * \param pktInterval The time between packets. + */ void GenerateTraffic (Ptr socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval ); - uint32_t m_pktsTotal; - Gnuplot2dDataset m_output; + uint32_t m_pktsTotal; //!< Total number of received packets + Gnuplot2dDataset m_output; //!< Output dataset. }; Experiment::Experiment () diff --git a/examples/wireless/wifi-multirate.cc b/examples/wireless/wifi-multirate.cc index 39095b71e..0238391ba 100644 --- a/examples/wireless/wifi-multirate.cc +++ b/examples/wireless/wifi-multirate.cc @@ -16,7 +16,36 @@ * Author: Duy Nguyen */ +#include "ns3/gnuplot.h" +#include "ns3/command-line.h" +#include "ns3/config.h" +#include "ns3/uinteger.h" +#include "ns3/boolean.h" +#include "ns3/double.h" +#include "ns3/string.h" +#include "ns3/log.h" +#include "ns3/yans-wifi-helper.h" +#include "ns3/mobility-helper.h" +#include "ns3/internet-stack-helper.h" +#include "ns3/ipv4-address-helper.h" +#include "ns3/on-off-helper.h" +#include "ns3/yans-wifi-channel.h" +#include "ns3/mobility-model.h" +#include "ns3/olsr-helper.h" +#include "ns3/ipv4-static-routing-helper.h" +#include "ns3/ipv4-list-routing-helper.h" +#include "ns3/rectangle.h" +#include "ns3/flow-monitor-helper.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("multirate"); + /** + * WiFi multirate experiment class. + * + * It handles the creation and run of an experiment. + * * Scenarios: 100 nodes, multiple simultaneous flows, multi-hop ad hoc, routing, * and mobility * @@ -47,100 +76,183 @@ * tail -f filename.pcap * */ - -#include "ns3/gnuplot.h" -#include "ns3/command-line.h" -#include "ns3/config.h" -#include "ns3/uinteger.h" -#include "ns3/boolean.h" -#include "ns3/double.h" -#include "ns3/string.h" -#include "ns3/log.h" -#include "ns3/yans-wifi-helper.h" -#include "ns3/mobility-helper.h" -#include "ns3/internet-stack-helper.h" -#include "ns3/ipv4-address-helper.h" -#include "ns3/on-off-helper.h" -#include "ns3/yans-wifi-channel.h" -#include "ns3/mobility-model.h" -#include "ns3/olsr-helper.h" -#include "ns3/ipv4-static-routing-helper.h" -#include "ns3/ipv4-list-routing-helper.h" -#include "ns3/rectangle.h" -#include "ns3/flow-monitor-helper.h" - -using namespace ns3; - -NS_LOG_COMPONENT_DEFINE ("multirate"); - class Experiment { public: Experiment (); + /** + * \brief Construct a new Experiment object + * + * \param name The name of the experiment. + */ Experiment (std::string name); + /** + * Run an experiment. + * \param wifi The WifiHelper class. + * \param wifiPhy The YansWifiPhyHelper class. + * \param wifiMac The WifiMacHelper class. + * \param wifiChannel The YansWifiChannelHelper class. + * \param mobility The MobilityHelper class. + * \return a 2D dataset of the experiment data. + */ Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility); + /** + * \brief Setup the experiment from the command line arguments. + * + * \param argc The argument count. + * \param argv The argument vector. + * \return true + */ bool CommandSetup (int argc, char **argv); + + /** + * \brief Check if routing is enabled. + * + * \return true if routing is enabled. + */ bool IsRouting () { - return (enableRouting == 1) ? 1 : 0; + return (m_enableRouting == 1) ? 1 : 0; } + /** + * \brief Check if mobility is enabled. + * + * \return true if mobility is enabled. + */ bool IsMobility () { - return (enableMobility == 1) ? 1 : 0; + return (m_enableMobility == 1) ? 1 : 0; } + /** + * \brief Get the Scenario number. + * + * \return the scenario number. + */ uint32_t GetScenario () { - return scenario; + return m_scenario; } - + /** + * \brief Get the RTS Threshold. + * + * \return the RTS Threshold. + */ std::string GetRtsThreshold () { - return rtsThreshold; + return m_rtsThreshold; } + /** + * \brief Get the Output File Name. + * + * \return the Output File Name. + */ std::string GetOutputFileName () { - return outputFileName; + return m_outputFileName; } + /** + * \brief Get the Rate Manager. + * + * \return the Rate Manager. + */ std::string GetRateManager () { - return rateManager; + return m_rateManager; } private: + /** + * \brief Setup the receiving socket. + * + * \param node The receiving node. + * \return the Rx socket. + */ Ptr SetupPacketReceive (Ptr node); + /** + * Generate 1-hop and 2-hop neighbors of a node in grid topology + * \param c The node container. + * \param senderId The sender ID. + * \return the neighbor nodes. + */ NodeContainer GenerateNeighbors (NodeContainer c, uint32_t senderId); + /** + * \brief Setup the application in the nodes. + * + * \param client Client node. + * \param server Server node. + * \param start Start time. + * \param stop Stop time. + */ void ApplicationSetup (Ptr client, Ptr server, double start, double stop); + /** + * Take the grid map, divide it into 4 quadrants + * Assign all nodes from each quadrant to a specific container + * + * \param c The node container. + */ void AssignNeighbors (NodeContainer c); + /** + * Sources and destinations are randomly selected such that a node + * may be the source for multiple destinations and a node maybe a destination + * for multiple sources. + * + * \param c The node container. + */ void SelectSrcDest (NodeContainer c); + /** + * \brief Receive a packet. + * + * \param socket The receiving socket. + */ void ReceivePacket (Ptr socket); + /** + * \brief Calculate the throughput. + */ void CheckThroughput (); + /** + * A sender node will set up a flow to each of the its neighbors + * in its quadrant randomly. All the flows are exponentially distributed. + * + * \param sender The sender node. + * \param c The node neighbors. + */ void SendMultiDestinations (Ptr sender, NodeContainer c); - Gnuplot2dDataset m_output; + Gnuplot2dDataset m_output; //!< Output dataset. - double totalTime; - double expMean; - double samplingPeriod; + double m_totalTime; //!< Total experiment time. + double m_expMean; //!< Exponential parameter for sending packets. + double m_samplingPeriod; //!< Sampling period. - uint32_t bytesTotal; - uint32_t packetSize; - uint32_t gridSize; - uint32_t nodeDistance; - uint32_t port; - uint32_t scenario; + uint32_t m_bytesTotal; //!< Total number of received bytes. + uint32_t m_packetSize; //!< Packet size. + uint32_t m_gridSize; //!< Grid size. + uint32_t m_nodeDistance; //!< Node distance. + uint32_t m_port; //!< Listening port. + uint32_t m_scenario; //!< Scnario number. - bool enablePcap; - bool enableTracing; - bool enableFlowMon; - bool enableRouting; - bool enableMobility; + bool m_enablePcap; //!< True if PCAP output is enabled. + bool m_enableTracing; //!< True if tracing output is enabled. + bool m_enableFlowMon; //!< True if FlowMon is enabled. + bool m_enableRouting; //!< True if routing is enabled. + bool m_enableMobility; //!< True if mobility is enabled. - NodeContainer containerA, containerB, containerC, containerD; - std::string rtsThreshold, rateManager, outputFileName; + /** + * Node containers for each quadrant. + * @{ + */ + NodeContainer m_containerA; + NodeContainer m_containerB; + NodeContainer m_containerC; + NodeContainer m_containerD; + /** @} */ + std::string m_rtsThreshold; //!< Rts threshold. + std::string m_rateManager; //!< Rate manager. + std::string m_outputFileName; //!< Output file name. }; Experiment::Experiment () @@ -149,26 +261,26 @@ Experiment::Experiment () Experiment::Experiment (std::string name) : m_output (name), - totalTime (0.3), - expMean (0.1), + m_totalTime (0.3), + m_expMean (0.1), //flows being exponentially distributed - samplingPeriod (0.1), - bytesTotal (0), - packetSize (2000), - gridSize (10), + m_samplingPeriod (0.1), + m_bytesTotal (0), + m_packetSize (2000), + m_gridSize (10), //10x10 grid for a total of 100 nodes - nodeDistance (30), - port (5000), - scenario (4), - enablePcap (false), - enableTracing (true), - enableFlowMon (false), - enableRouting (false), - enableMobility (false), - rtsThreshold ("2200"), + m_nodeDistance (30), + m_port (5000), + m_scenario (4), + m_enablePcap (false), + m_enableTracing (true), + m_enableFlowMon (false), + m_enableRouting (false), + m_enableMobility (false), + m_rtsThreshold ("2200"), //0 for enabling rts/cts - rateManager ("ns3::MinstrelWifiManager"), - outputFileName ("minstrel") + m_rateManager ("ns3::MinstrelWifiManager"), + m_outputFileName ("minstrel") { m_output.SetStyle (Gnuplot2dDataset::LINES); } @@ -178,7 +290,7 @@ Experiment::SetupPacketReceive (Ptr node) { TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); Ptr sink = Socket::CreateSocket (node, tid); - InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), port); + InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port); sink->Bind (local); sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); @@ -191,68 +303,58 @@ Experiment::ReceivePacket (Ptr socket) Ptr packet; while ((packet = socket->Recv ())) { - bytesTotal += packet->GetSize (); + m_bytesTotal += packet->GetSize (); } } void Experiment::CheckThroughput () { - double mbs = ((bytesTotal * 8.0) / 1000000 / samplingPeriod); - bytesTotal = 0; + double mbs = ((m_bytesTotal * 8.0) / 1000000 / m_samplingPeriod); + m_bytesTotal = 0; m_output.Add ((Simulator::Now ()).GetSeconds (), mbs); //check throughput every samplingPeriod second - Simulator::Schedule (Seconds (samplingPeriod), &Experiment::CheckThroughput, this); + Simulator::Schedule (Seconds (m_samplingPeriod), &Experiment::CheckThroughput, this); } -/** - * - * Take the grid map, divide it into 4 quadrants - * Assign all nodes from each quadrant to a specific container - * - */ void Experiment::AssignNeighbors (NodeContainer c) { uint32_t totalNodes = c.GetN (); for (uint32_t i = 0; i < totalNodes; i++) { - if ( (i % gridSize) <= (gridSize / 2 - 1)) + if ( (i % m_gridSize) <= (m_gridSize / 2 - 1)) { //lower left quadrant if ( i < totalNodes / 2 ) { - containerA.Add (c.Get (i)); + m_containerA.Add (c.Get (i)); } //upper left quadrant if ( i >= (uint32_t)(4 * totalNodes) / 10 ) { - containerC.Add (c.Get (i)); + m_containerC.Add (c.Get (i)); } } - if ( (i % gridSize) >= (gridSize / 2 - 1)) + if ( (i % m_gridSize) >= (m_gridSize / 2 - 1)) { //lower right quadrant if ( i < totalNodes / 2 ) { - containerB.Add (c.Get (i)); + m_containerB.Add (c.Get (i)); } //upper right quadrant if ( i >= (uint32_t)(4 * totalNodes) / 10 ) { - containerD.Add (c.Get (i)); + m_containerD.Add (c.Get (i)); } } } } -/** - * Generate 1-hop and 2-hop neighbors of a node in grid topology - * - */ NodeContainer Experiment::GenerateNeighbors (NodeContainer c, uint32_t senderId) { @@ -270,11 +372,6 @@ Experiment::GenerateNeighbors (NodeContainer c, uint32_t senderId) return nc; } -/** - * Sources and destinations are randomly selected such that a node - * may be the source for multiple destinations and a node maybe a destination - * for multiple sources. - */ void Experiment::SelectSrcDest (NodeContainer c) { @@ -288,16 +385,10 @@ Experiment::SelectSrcDest (NodeContainer c) for (uint32_t i = 0; i < totalNodes / 3; i++) { - ApplicationSetup (c.Get (uvSrc->GetInteger ()), c.Get (uvDest->GetInteger ()), 0, totalTime); + ApplicationSetup (c.Get (uvSrc->GetInteger ()), c.Get (uvDest->GetInteger ()), 0, m_totalTime); } } -/** - * - * A sender node will set up a flow to each of the its neighbors - * in its quadrant randomly. All the flows are exponentially distributed - * - */ void Experiment::SendMultiDestinations (Ptr sender, NodeContainer c) { @@ -309,8 +400,8 @@ Experiment::SendMultiDestinations (Ptr sender, NodeContainer c) // ExponentialRandomVariable params: (mean, upperbound) Ptr ev = CreateObject (); - ev->SetAttribute ("Mean", DoubleValue (expMean)); - ev->SetAttribute ("Bound", DoubleValue (totalTime)); + ev->SetAttribute ("Mean", DoubleValue (m_expMean)); + ev->SetAttribute ("Bound", DoubleValue (m_totalTime)); double start = 0.0, stop; uint32_t destIndex; @@ -330,7 +421,7 @@ Experiment::SendMultiDestinations (Ptr sender, NodeContainer c) start = stop; - if (start > totalTime) + if (start > m_totalTime) { break; } @@ -382,10 +473,10 @@ Experiment::ApplicationSetup (Ptr client, Ptr server, double start, NS_LOG_DEBUG (PrintPosition (client, server)); // Equipping the source node with OnOff Application used for sending - OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.0.0.1"), port))); + OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.0.0.1"), m_port))); onoff.SetConstantRate (DataRate (60000000)); - onoff.SetAttribute ("PacketSize", UintegerValue (packetSize)); - onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (ipv4AddrServer, port))); + onoff.SetAttribute ("PacketSize", UintegerValue (m_packetSize)); + onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (ipv4AddrServer, m_port))); ApplicationContainer apps = onoff.Install (client); apps.Start (Seconds (start)); @@ -401,7 +492,7 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, { - uint32_t nodeSize = gridSize * gridSize; + uint32_t nodeSize = m_gridSize * m_gridSize; NodeContainer c; c.Create (nodeSize); @@ -417,7 +508,7 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, Ipv4ListRoutingHelper list; - if (enableRouting) + if (m_enableRouting) { list.Add (staticRouting, 0); list.Add (olsr, 10); @@ -425,7 +516,7 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, InternetStackHelper internet; - if (enableRouting) + if (m_enableRouting) { internet.SetRoutingHelper (list); // has effect on the next Install () } @@ -442,14 +533,14 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, mobil.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), - "DeltaX", DoubleValue (nodeDistance), - "DeltaY", DoubleValue (nodeDistance), - "GridWidth", UintegerValue (gridSize), + "DeltaX", DoubleValue (m_nodeDistance), + "DeltaY", DoubleValue (m_nodeDistance), + "GridWidth", UintegerValue (m_gridSize), "LayoutType", StringValue ("RowFirst")); mobil.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); - if (enableMobility && enableRouting) + if (m_enableMobility && m_enableRouting) { //Rectangle (xMin, xMax, yMin, yMax) mobil.SetMobilityModel ("ns3::RandomDirection2dMobilityModel", @@ -459,37 +550,37 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, } mobil.Install (c); - if ( scenario == 1 && enableRouting) + if ( m_scenario == 1 && m_enableRouting) { SelectSrcDest (c); } - else if ( scenario == 2) + else if ( m_scenario == 2) { //All flows begin at the same time for (uint32_t i = 0; i < nodeSize - 1; i = i + 2) { - ApplicationSetup (c.Get (i), c.Get (i + 1), 0, totalTime); + ApplicationSetup (c.Get (i), c.Get (i + 1), 0, m_totalTime); } } - else if ( scenario == 3) + else if ( m_scenario == 3) { AssignNeighbors (c); //Note: these senders are hand-picked in order to ensure good coverage //for 10x10 grid, basically one sender for each quadrant //you might have to change these values for other grids NS_LOG_DEBUG (">>>>>>>>>region A<<<<<<<<<"); - SendMultiDestinations (c.Get (22), containerA); + SendMultiDestinations (c.Get (22), m_containerA); NS_LOG_DEBUG (">>>>>>>>>region B<<<<<<<<<"); - SendMultiDestinations (c.Get (26), containerB); + SendMultiDestinations (c.Get (26), m_containerB); NS_LOG_DEBUG (">>>>>>>>>region C<<<<<<<<<"); - SendMultiDestinations (c.Get (72), containerC); + SendMultiDestinations (c.Get (72), m_containerC); NS_LOG_DEBUG (">>>>>>>>>region D<<<<<<<<<"); - SendMultiDestinations (c.Get (76), containerD); + SendMultiDestinations (c.Get (76), m_containerD); } - else if ( scenario == 4) + else if ( m_scenario == 4) { //GenerateNeighbors(NodeContainer, uint32_t sender) //Note: these senders are hand-picked in order to ensure good coverage @@ -519,13 +610,13 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, CheckThroughput (); - if (enablePcap) + if (m_enablePcap) { phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO); phy.EnablePcapAll (GetOutputFileName ()); } - if (enableTracing) + if (m_enableTracing) { AsciiTraceHelper ascii; phy.EnableAsciiAll (ascii.CreateFileStream (GetOutputFileName () + ".tr")); @@ -533,15 +624,15 @@ Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, FlowMonitorHelper flowmonHelper; - if (enableFlowMon) + if (m_enableFlowMon) { flowmonHelper.InstallAll (); } - Simulator::Stop (Seconds (totalTime)); + Simulator::Stop (Seconds (m_totalTime)); Simulator::Run (); - if (enableFlowMon) + if (m_enableFlowMon) { flowmonHelper.SerializeToXmlFile ((GetOutputFileName () + ".flomon"), false, false); } @@ -556,25 +647,25 @@ Experiment::CommandSetup (int argc, char **argv) { // for commandline input CommandLine cmd (__FILE__); - cmd.AddValue ("packetSize", "packet size", packetSize); - cmd.AddValue ("totalTime", "simulation time", totalTime); + cmd.AddValue ("packetSize", "packet size", m_packetSize); + cmd.AddValue ("totalTime", "simulation time", m_totalTime); // according to totalTime, select an appropriate samplingPeriod automatically. - if (totalTime < 1.0) + if (m_totalTime < 1.0) { - samplingPeriod = 0.1; + m_samplingPeriod = 0.1; } else { - samplingPeriod = 1.0; + m_samplingPeriod = 1.0; } // or user selects a samplingPeriod. - cmd.AddValue ("samplingPeriod", "sampling period", samplingPeriod); - cmd.AddValue ("rtsThreshold", "rts threshold", rtsThreshold); - cmd.AddValue ("rateManager", "type of rate", rateManager); - cmd.AddValue ("outputFileName", "output filename", outputFileName); - cmd.AddValue ("enableRouting", "enable Routing", enableRouting); - cmd.AddValue ("enableMobility", "enable Mobility", enableMobility); - cmd.AddValue ("scenario", "scenario ", scenario); + cmd.AddValue ("samplingPeriod", "sampling period", m_samplingPeriod); + cmd.AddValue ("rtsThreshold", "rts threshold", m_rtsThreshold); + cmd.AddValue ("rateManager", "type of rate", m_rateManager); + cmd.AddValue ("outputFileName", "output filename", m_outputFileName); + cmd.AddValue ("enableRouting", "enable Routing", m_enableRouting); + cmd.AddValue ("enableMobility", "enable Mobility", m_enableMobility); + cmd.AddValue ("scenario", "scenario ", m_scenario); cmd.Parse (argc, argv); return true; diff --git a/examples/wireless/wifi-power-adaptation-distance.cc b/examples/wireless/wifi-power-adaptation-distance.cc index dbf2b8c79..da1fb86dd 100644 --- a/examples/wireless/wifi-power-adaptation-distance.cc +++ b/examples/wireless/wifi-power-adaptation-distance.cc @@ -109,40 +109,118 @@ using namespace std; NS_LOG_COMPONENT_DEFINE ("PowerAdaptationDistance"); -//packet size generated at the AP +/// Pcket size generated at the AP static const uint32_t packetSize = 1420; +/** + * \brief Class to collect node statistics. + */ class NodeStatistics { public: + /** + * \brief Constructor. + * + * \param aps Access points + * \param stas WiFi Stations. + */ NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas); + /** + * \brief Callback called by WifiNetDevice/Phy/PhyTxBegin. + * + * \param path The trace path. + * \param packet The sent packet. + * \param powerW The Tx power. + */ void PhyCallback (std::string path, Ptr packet, double powerW); + /** + * \brief Callback called by PacketSink/Rx. + * + * \param path The trace path. + * \param packet The received packet. + * \param from The sender address. + */ void RxCallback (std::string path, Ptr packet, const Address &from); + /** + * \brief Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange. + * + * \param path The trace path. + * \param oldPower Old Tx power. + * \param newPower Actual Tx power. + * \param dest Destination of the transmission. + */ void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest); + /** + * \brief Callback called by WifiNetDevice/RemoteStationManager/x/RateChange. + * + * \param path The trace path. + * \param oldRate Old rate. + * \param newRate Actual rate. + * \param dest Destination of the transmission. + */ void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest); + /** + * \brief Set the Position of a node. + * + * \param node The node. + * \param position The position. + */ void SetPosition (Ptr node, Vector position); + /** + * Move a node. + * \param node The node. + * \param stepsSize The step size. + * \param stepsTime Time on each step. + */ void AdvancePosition (Ptr node, int stepsSize, int stepsTime); + /** + * \brief Get the Position of a node. + * + * \param node The node. + * \return the position of the node. + */ Vector GetPosition (Ptr node); + /** + * \brief Get the Throughput output data + * + * \return the Throughput output data. + */ Gnuplot2dDataset GetDatafile (); + /** + * \brief Get the Power output data. + * + * \return the Power output data. + */ Gnuplot2dDataset GetPowerDatafile (); private: + /// Time, DataRate pair vector. typedef std::vector > TxTime; + /** + * \brief Setup the WifiPhy object. + * + * \param phy The WifiPhy to setup. + */ void SetupPhy (Ptr phy); + /** + * \brief Get the time at which a given datarate has been recorded. + * + * \param rate The datarate to search. + * \return the time. + */ Time GetCalcTxTime (DataRate rate); - std::map currentPower; - std::map currentRate; - uint32_t m_bytesTotal; - double totalEnergy; - double totalTime; - Ptr myPhy; - TxTime timeTable; - Gnuplot2dDataset m_output; - Gnuplot2dDataset m_output_power; + std::map m_currentPower; //!< Current Tx power for each sender. + std::map m_currentRate; //!< Current Tx rate for each sender. + uint32_t m_bytesTotal; //!< Number of received bytes on a given state. + double m_totalEnergy; //!< Energy used on a given state. + double m_totalTime; //!< Time spent on a given state. + TxTime m_timeTable; //!< Time, DataRate table. + Gnuplot2dDataset m_output; //!< Throughput output data. + Gnuplot2dDataset m_output_power; //!< Power output data. }; NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) @@ -150,7 +228,6 @@ NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) Ptr device = aps.Get (0); Ptr wifiDevice = DynamicCast (device); Ptr phy = wifiDevice->GetPhy (); - myPhy = phy; SetupPhy (phy); DataRate dataRate = DataRate (phy->GetDefaultMode ().GetDataRate (phy->GetChannelWidth ())); double power = phy->GetTxPowerEnd (); @@ -159,12 +236,12 @@ NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) Ptr staDevice = stas.Get (j); Ptr wifiStaDevice = DynamicCast (staDevice); Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress (); - currentPower[addr] = power; - currentRate[addr] = dataRate; + m_currentPower[addr] = power; + m_currentRate[addr] = dataRate; } - currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate; - totalEnergy = 0; - totalTime = 0; + m_currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate; + m_totalEnergy = 0; + m_totalTime = 0; m_bytesTotal = 0; m_output.SetTitle ("Throughput Mbits/s"); m_output_power.SetTitle ("Average Transmit Power"); @@ -182,14 +259,14 @@ NodeStatistics::SetupPhy (Ptr phy) DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ())); Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetPhyBand ()); NS_LOG_DEBUG (mode.GetUniqueName () << " " << time.GetSeconds () << " " << dataRate); - timeTable.push_back (std::make_pair (time, dataRate)); + m_timeTable.push_back (std::make_pair (time, dataRate)); } } Time NodeStatistics::GetCalcTxTime (DataRate rate) { - for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++) + for (TxTime::const_iterator i = m_timeTable.begin (); i != m_timeTable.end (); i++) { if (rate == i->second) { @@ -209,21 +286,21 @@ NodeStatistics::PhyCallback (std::string path, Ptr packet, double if (head.GetType () == WIFI_MAC_DATA) { - totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds (); - totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds (); + m_totalEnergy += pow (10.0, m_currentPower[dest] / 10.0) * GetCalcTxTime (m_currentRate[dest]).GetSeconds (); + m_totalTime += GetCalcTxTime (m_currentRate[dest]).GetSeconds (); } } void NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest) { - currentPower[dest] = newPower; + m_currentPower[dest] = newPower; } void NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest) { - currentRate[dest] = newRate; + m_currentRate[dest] = newRate; } void @@ -252,9 +329,9 @@ NodeStatistics::AdvancePosition (Ptr node, int stepsSize, int stepsTime) Vector pos = GetPosition (node); double mbs = ((m_bytesTotal * 8.0) / (1000000 * stepsTime)); m_bytesTotal = 0; - double atp = totalEnergy / stepsTime; - totalEnergy = 0; - totalTime = 0; + double atp = m_totalEnergy / stepsTime; + m_totalEnergy = 0; + m_totalTime = 0; m_output_power.Add (pos.x, atp); m_output.Add (pos.x, mbs); pos.x += stepsSize; diff --git a/examples/wireless/wifi-power-adaptation-interference.cc b/examples/wireless/wifi-power-adaptation-interference.cc index d974e6127..7bf4ec90c 100644 --- a/examples/wireless/wifi-power-adaptation-interference.cc +++ b/examples/wireless/wifi-power-adaptation-interference.cc @@ -80,57 +80,155 @@ using namespace std; NS_LOG_COMPONENT_DEFINE ("PowerAdaptationInterference"); -//Packet size generated at the AP. +/// Packet size generated at the AP. static const uint32_t packetSize = 1420; +/** + * \brief Class to collect node statistics. + */ class NodeStatistics { public: + /** + * \brief Constructor. + * + * \param aps Access points + * \param stas WiFi Stations. + */ NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas); + /** + * \brief Collects the statistics at a given time. + * + * \param time Time at which the statistics are collected. + */ void CheckStatistics (double time); + /** + * \brief Callback called by WifiNetDevice/Phy/PhyTxBegin. + * + * \param path The trace path. + * \param packet The sent packet. + * \param powerW The Tx power. + */ void PhyCallback (std::string path, Ptr packet, double powerW); + /** + * \brief Callback called by PacketSink/Rx. + * + * \param path The trace path. + * \param packet The received packet. + * \param from The sender address. + */ void RxCallback (std::string path, Ptr packet, const Address &from); + /** + * \brief Callback called by WifiNetDevice/RemoteStationManager/x/PowerChange. + * + * \param path The trace path. + * \param oldPower Old Tx power. + * \param newPower Actual Tx power. + * \param dest Destination of the transmission. + */ void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest); + /** + * \brief Callback called by WifiNetDevice/RemoteStationManager/x/RateChange. + * + * \param path The trace path. + * \param oldRate Old rate. + * \param newRate Actual rate. + * \param dest Destination of the transmission. + */ void RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest); + /** + * \brief Callback called by YansWifiPhy/State/State. + * + * \param path The trace path. + * \param init Time when the state started. + * \param duration Amount of time we've been in (or will be in) the state. + * \param state The state. + */ void StateCallback (std::string path, Time init, Time duration, WifiPhyState state); + /** + * \brief Get the Throughput output data + * + * \return the Throughput output data. + */ Gnuplot2dDataset GetDatafile (); + /** + * \brief Get the Power output data. + * + * \return the Power output data. + */ Gnuplot2dDataset GetPowerDatafile (); + /** + * \brief Get the IDLE state output data. + * + * \return the IDLE state output data. + */ Gnuplot2dDataset GetIdleDatafile (); + /** + * \brief Get the BUSY state output data. + * + * \return the BUSY state output data. + */ Gnuplot2dDataset GetBusyDatafile (); + /** + * \brief Get the TX state output data. + * + * \return the TX state output data. + */ Gnuplot2dDataset GetTxDatafile (); + /** + * \brief Get the RX state output data. + * + * \return the RX state output data. + */ Gnuplot2dDataset GetRxDatafile (); + /** + * \brief Get the Busy time. + * + * \return the busy time. + */ double GetBusyTime (); private: + /// Time, DataRate pair vector. typedef std::vector > TxTime; + /** + * \brief Setup the WifiPhy object. + * + * \param phy The WifiPhy to setup. + */ void SetupPhy (Ptr phy); + /** + * \brief Get the time at which a given datarate has been recorded. + * + * \param rate The datarate to search. + * \return the time. + */ Time GetCalcTxTime (DataRate rate); - std::map currentPower; - std::map currentRate; - uint32_t m_bytesTotal; - double totalEnergy; - double totalTime; - double busyTime; - double idleTime; - double txTime; - double rxTime; - double totalBusyTime; - double totalIdleTime; - double totalTxTime; - double totalRxTime; - Ptr myPhy; - TxTime timeTable; - Gnuplot2dDataset m_output; - Gnuplot2dDataset m_output_power; - Gnuplot2dDataset m_output_idle; - Gnuplot2dDataset m_output_busy; - Gnuplot2dDataset m_output_rx; - Gnuplot2dDataset m_output_tx; + std::map m_currentPower; //!< Current Tx power for each sender. + std::map m_currentRate; //!< Current Tx rate for each sender. + uint32_t m_bytesTotal; //!< Number of received bytes. + double m_totalEnergy; //!< Energy used. + double m_totalTime; //!< Time spent. + double busyTime; //!< BUSY time. + double idleTime; //!< IDLE time. + double txTime; //!< TX time. + double rxTime; //!< RX time. + double m_totalBusyTime; //!< Total time in BUSY state. + double m_totalIdleTime; //!< Total time in IDLE state. + double m_totalTxTime; //!< Total time in TX state. + double m_totalRxTime; //!< Total time in RX state. + TxTime m_timeTable; //!< Time, DataRate table. + Gnuplot2dDataset m_output; //!< Throughput output data. + Gnuplot2dDataset m_output_power; //!< Power output data. + Gnuplot2dDataset m_output_idle; //!< IDLE output data. + Gnuplot2dDataset m_output_busy; //!< BUSY output data. + Gnuplot2dDataset m_output_rx; //!< RX output data. + Gnuplot2dDataset m_output_tx; //!< TX output data. }; NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) @@ -138,7 +236,6 @@ NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) Ptr device = aps.Get (0); Ptr wifiDevice = DynamicCast (device); Ptr phy = wifiDevice->GetPhy (); - myPhy = phy; SetupPhy (phy); DataRate dataRate = DataRate (phy->GetDefaultMode ().GetDataRate (phy->GetChannelWidth ())); double power = phy->GetTxPowerEnd (); @@ -147,20 +244,20 @@ NodeStatistics::NodeStatistics (NetDeviceContainer aps, NetDeviceContainer stas) Ptr staDevice = stas.Get (j); Ptr wifiStaDevice = DynamicCast (staDevice); Mac48Address addr = wifiStaDevice->GetMac ()->GetAddress (); - currentPower[addr] = power; - currentRate[addr] = dataRate; + m_currentPower[addr] = power; + m_currentRate[addr] = dataRate; } - currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate; - totalEnergy = 0; - totalTime = 0; + m_currentRate[Mac48Address ("ff:ff:ff:ff:ff:ff")] = dataRate; + m_totalEnergy = 0; + m_totalTime = 0; busyTime = 0; idleTime = 0; txTime = 0; rxTime = 0; - totalBusyTime = 0; - totalIdleTime = 0; - totalTxTime = 0; - totalRxTime = 0; + m_totalBusyTime = 0; + m_totalIdleTime = 0; + m_totalTxTime = 0; + m_totalRxTime = 0; m_bytesTotal = 0; m_output.SetTitle ("Throughput Mbits/s"); m_output_idle.SetTitle ("Idle Time"); @@ -181,14 +278,14 @@ NodeStatistics::SetupPhy (Ptr phy) DataRate dataRate = DataRate (mode.GetDataRate (phy->GetChannelWidth ())); Time time = phy->CalculateTxDuration (packetSize, txVector, phy->GetPhyBand ()); NS_LOG_DEBUG (mode.GetUniqueName () << " " << time.GetSeconds () << " " << dataRate); - timeTable.push_back (std::make_pair (time, dataRate)); + m_timeTable.push_back (std::make_pair (time, dataRate)); } } Time NodeStatistics::GetCalcTxTime (DataRate rate) { - for (TxTime::const_iterator i = timeTable.begin (); i != timeTable.end (); i++) + for (TxTime::const_iterator i = m_timeTable.begin (); i != m_timeTable.end (); i++) { if (rate == i->second) { @@ -208,21 +305,21 @@ NodeStatistics::PhyCallback (std::string path, Ptr packet, double if (head.GetType () == WIFI_MAC_DATA) { - totalEnergy += pow (10.0, currentPower[dest] / 10.0) * GetCalcTxTime (currentRate[dest]).GetSeconds (); - totalTime += GetCalcTxTime (currentRate[dest]).GetSeconds (); + m_totalEnergy += pow (10.0, m_currentPower[dest] / 10.0) * GetCalcTxTime (m_currentRate[dest]).GetSeconds (); + m_totalTime += GetCalcTxTime (m_currentRate[dest]).GetSeconds (); } } void NodeStatistics::PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest) { - currentPower[dest] = newPower; + m_currentPower[dest] = newPower; } void NodeStatistics::RateCallback (std::string path, DataRate oldRate, DataRate newRate, Mac48Address dest) { - currentRate[dest] = newRate; + m_currentRate[dest] = newRate; } void @@ -231,22 +328,22 @@ NodeStatistics::StateCallback (std::string path, Time init, Time duration, WifiP if (state == WifiPhyState::CCA_BUSY) { busyTime += duration.GetSeconds (); - totalBusyTime += duration.GetSeconds (); + m_totalBusyTime += duration.GetSeconds (); } else if (state == WifiPhyState::IDLE) { idleTime += duration.GetSeconds (); - totalIdleTime += duration.GetSeconds (); + m_totalIdleTime += duration.GetSeconds (); } else if (state == WifiPhyState::TX) { txTime += duration.GetSeconds (); - totalTxTime += duration.GetSeconds (); + m_totalTxTime += duration.GetSeconds (); } else if (state == WifiPhyState::RX) { rxTime += duration.GetSeconds (); - totalRxTime += duration.GetSeconds (); + m_totalRxTime += duration.GetSeconds (); } } @@ -261,9 +358,9 @@ NodeStatistics::CheckStatistics (double time) { double mbs = ((m_bytesTotal * 8.0) / (1000000 * time)); m_bytesTotal = 0; - double atp = totalEnergy / time; - totalEnergy = 0; - totalTime = 0; + double atp = m_totalEnergy / time; + m_totalEnergy = 0; + m_totalTime = 0; m_output_power.Add ((Simulator::Now ()).GetSeconds (), atp); m_output.Add ((Simulator::Now ()).GetSeconds (), mbs); @@ -318,7 +415,7 @@ NodeStatistics::GetTxDatafile () double NodeStatistics::GetBusyTime () { - return totalBusyTime + totalRxTime; + return m_totalBusyTime + m_totalRxTime; } void PowerCallback (std::string path, double oldPower, double newPower, Mac48Address dest)