From 866c4cd4ec1b45e670d5ba2b06e97e9d7974bc60 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 14 May 2007 11:12:29 +0200 Subject: [PATCH] add dox doc and DefaultValue support to OnOffApplication --- examples/simple-p2p.cc | 12 ++-- src/applications/onoff-application.cc | 80 +++++++++++++++++++-------- src/applications/onoff-application.h | 59 ++++++++++++++++---- 3 files changed, 109 insertions(+), 42 deletions(-) diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 47edad9f4..5eb17cb00 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -90,7 +90,9 @@ int main (int argc, char *argv[]) // The below Bind command tells the queue factory which class to // instantiate, when the queue factory is invoked in the topology code - Bind ("Queue", "DropTailQueue"); + Bind ("Queue", "DropTailQueue"); + + Bind ("on-off-app-packet-size", "210"); //Bind ("DropTailQueue::m_maxPackets", 30); @@ -147,9 +149,7 @@ int main (int argc, char *argv[]) Ipv4Address("10.1.3.2"), 80, ConstantVariable(1), - ConstantVariable(0), - DataRate(448000), - 210); + ConstantVariable(0)); // Start the application ooff->Start(Seconds(1.0)); ooff->Stop (Seconds(10.0)); @@ -160,9 +160,7 @@ int main (int argc, char *argv[]) Ipv4Address("10.1.2.1"), 80, ConstantVariable(1), - ConstantVariable(0), - DataRate(448000), - 210); + ConstantVariable(0)); // Start the application ooff->Start(Seconds(1.1)); ooff->Stop (Seconds(10.0)); diff --git a/src/applications/onoff-application.cc b/src/applications/onoff-application.cc index f47dd5855..182650a20 100644 --- a/src/applications/onoff-application.cc +++ b/src/applications/onoff-application.cc @@ -30,6 +30,7 @@ #include "ns3/socket.h" #include "ns3/simulator.h" #include "ns3/i-udp.h" +#include "ns3/default-value.h" #include "onoff-application.h" using namespace std; @@ -38,31 +39,58 @@ namespace ns3 { // Defaults for rate/size DataRate OnOffApplication::g_defaultRate = DataRate(500000); -uint32_t OnOffApplication::g_defaultSize = 512; +static IntegerDefaultValue g_defaultSize ("on-off-app-packet-size", + "The size of packets send by OnOffApplication instances", + 512, 1); // Constructors - OnOffApplication::OnOffApplication(Ptr n, - const Ipv4Address rip, // Remote IP addr - uint16_t rport, // Remote port - const RandomVariable& ontime, - const RandomVariable& offtime, - DataRate rate, - uint32_t size) - : Application(n), - m_socket(0), // Socket allocated on Start - m_peerIP(rip), - m_peerPort(rport), - m_connected(false), - m_onTime(ontime.Copy()), - m_offTime(offtime.Copy()), - m_cbrRate(rate), - m_pktSize(size), - m_residualBits(0), - m_lastStartTime((HighPrecision)0), - m_maxBytes(0xffffffff), - m_totBytes(0) -{} +OnOffApplication::OnOffApplication(Ptr n, + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& ontime, + const RandomVariable& offtime) + : Application(n), + m_cbrRate (g_defaultRate) +{ + Construct (n, rip, rport, ontime, offtime, + g_defaultSize.GetValue ()); +} + +OnOffApplication::OnOffApplication(Ptr n, + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& ontime, + const RandomVariable& offtime, + DataRate rate, + uint32_t size) + : Application(n), + m_cbrRate (rate) +{ + Construct (n, rip, rport, ontime, offtime, size); +} + +void +OnOffApplication::Construct (Ptr n, + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& onTime, + const RandomVariable& offTime, + uint32_t size) +{ + m_socket = 0; + m_peerIp = rip; + m_peerPort = rport; + m_connected = false; + m_onTime = onTime.Copy (); + m_offTime = offTime.Copy (); + m_pktSize = size; + m_residualBits = 0; + m_lastStartTime = Seconds (0); + m_maxBytes = 0xffffffff; + m_totBytes = 0; +} + OnOffApplication::~OnOffApplication() {} @@ -73,6 +101,12 @@ OnOffApplication::SetMaxBytes(uint32_t maxBytes) m_maxBytes = maxBytes; } +void +OnOffApplication::SetDefaultSize (uint32_t size) +{ + g_defaultSize.SetValue (size); +} + void OnOffApplication::DoDispose (void) { @@ -97,7 +131,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Star Ptr udp = GetINode ()->QueryInterface (IUdp::iid); m_socket = udp->CreateSocket (); m_socket->Bind (); - m_socket->Connect (m_peerIP, m_peerPort); + m_socket->Connect (m_peerIp, m_peerPort); } // Insure no pending event StopApplication(); diff --git a/src/applications/onoff-application.h b/src/applications/onoff-application.h index 0484e6fc0..af7c24914 100644 --- a/src/applications/onoff-application.h +++ b/src/applications/onoff-application.h @@ -38,24 +38,52 @@ class RandomVariable; class Socket; class DataRate; -class OnOffApplication : public Application { - +/** + * \brief Generate traffic to a single destination according to an + * OnOff pattern. + * + * + */ +class OnOffApplication : public Application +{ public: + /** + * \param n node associated to this application + * \param rip remote ip address + * \param rport remove port number + * \param ontime on time random variable + * \param offtime off time random variable + */ OnOffApplication(Ptr n, - const Ipv4Address, // Peer IP address - uint16_t, // Peer port - const RandomVariable&, // Random variable for On time - const RandomVariable&, // Random variable for Off time - DataRate = g_defaultRate, // Data rate when on - uint32_t = g_defaultSize); // Size of packets + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& ontime, + const RandomVariable& offtime); - virtual ~OnOffApplication(); // Destructor + /** + * \param n node associated to this application + * \param rip remote ip address + * \param rport remove port number + * \param ontime on time random variable + * \param offtime off time random variable + * \param rate data rate when on + * \param size size of packets when sending data. + */ + OnOffApplication(Ptr n, + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& ontime, + const RandomVariable& offtime, + DataRate rate, + uint32_t size); + + virtual ~OnOffApplication(); void SetMaxBytes(uint32_t maxBytes); static void DefaultRate(uint64_t r) { g_defaultRate = r;} - static void DefaultSize(uint32_t s) { g_defaultSize = s;} + static void SetDefaultSize (uint32_t size); protected: virtual void DoDispose (void); @@ -64,13 +92,21 @@ private: virtual void StartApplication (void); // Called at time specified by Start virtual void StopApplication (void); // Called at time specified by Stop + void Construct (Ptr n, + const Ipv4Address rip, + uint16_t rport, + const RandomVariable& ontime, + const RandomVariable& offtime, + uint32_t size); + + // Event handlers void StartSending(); void StopSending(); void SendPacket(); Ptr m_socket; // Associated socket - Ipv4Address m_peerIP; // Peer IP address + Ipv4Address m_peerIp; // Peer IP address uint16_t m_peerPort; // Peer port bool m_connected; // True if connected RandomVariable* m_onTime; // rng for On Time @@ -87,7 +123,6 @@ private: public: static DataRate g_defaultRate; // Default sending rate when on - static uint32_t g_defaultSize; // Default packet size private: void ScheduleNextTx();