add dox doc and DefaultValue support to OnOffApplication
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 14 May 2007 11:12:29 +0200
changeset 613 9679a238439d
parent 612 ffba29d7bdb2
child 614 fb21d7015386
add dox doc and DefaultValue support to OnOffApplication
examples/simple-p2p.cc
src/applications/onoff-application.cc
src/applications/onoff-application.h
--- a/examples/simple-p2p.cc	Mon May 14 11:11:30 2007 +0200
+++ b/examples/simple-p2p.cc	Mon May 14 11:12:29 2007 +0200
@@ -90,7 +90,9 @@
 
   // 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 @@
     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 @@
     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));
--- a/src/applications/onoff-application.cc	Mon May 14 11:11:30 2007 +0200
+++ b/src/applications/onoff-application.cc	Mon May 14 11:12:29 2007 +0200
@@ -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 @@
 
 // Defaults for rate/size
 DataRate OnOffApplication::g_defaultRate = DataRate(500000);
-uint32_t OnOffApplication::g_defaultSize = 512;
+static IntegerDefaultValue<uint32_t> g_defaultSize ("on-off-app-packet-size", 
+                                                    "The size of packets send by OnOffApplication instances",
+                                                    512, 1);
 
 // Constructors
 
-  OnOffApplication::OnOffApplication(Ptr<INode> 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<INode> 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<INode> 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<INode> 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 @@
   m_maxBytes = maxBytes;
 }
 
+void 
+OnOffApplication::SetDefaultSize (uint32_t size)
+{
+  g_defaultSize.SetValue (size);
+}
+
 void
 OnOffApplication::DoDispose (void)
 {
@@ -97,7 +131,7 @@
       Ptr<IUdp> udp = GetINode ()->QueryInterface<IUdp> (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();
--- a/src/applications/onoff-application.h	Mon May 14 11:11:30 2007 +0200
+++ b/src/applications/onoff-application.h	Mon May 14 11:12:29 2007 +0200
@@ -38,24 +38,52 @@
 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<INode> 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<INode> 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 @@
   virtual void StartApplication (void);    // Called at time specified by Start
   virtual void StopApplication (void);     // Called at time specified by Stop
 
+  void Construct (Ptr<INode> 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<Socket>     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 @@
   
 public:
   static DataRate   g_defaultRate;  // Default sending rate when on
-  static uint32_t g_defaultSize;  // Default packet size
 
 private:
   void ScheduleNextTx();