src/applications/onoff/onoff-application.h
changeset 2503 e667dc0f350e
parent 2336 28ce210b91bb
parent 2494 1c69ea12779c
child 2525 50e66705ed7b
equal deleted inserted replaced
2357:d64b1561b1c2 2503:e667dc0f350e
    27 
    27 
    28 #include "ns3/application.h"
    28 #include "ns3/application.h"
    29 #include "ns3/event-id.h"
    29 #include "ns3/event-id.h"
    30 #include "ns3/ptr.h"
    30 #include "ns3/ptr.h"
    31 #include "ns3/data-rate.h"
    31 #include "ns3/data-rate.h"
    32 #include "ns3/callback-trace-source.h"
       
    33 #include "ns3/random-variable.h"
    32 #include "ns3/random-variable.h"
       
    33 #include "ns3/traced-callback.h"
    34 
    34 
    35 namespace ns3 {
    35 namespace ns3 {
    36 
    36 
    37 class Address;
    37 class Address;
    38 class RandomVariable;
    38 class RandomVariable;
    50  * characterized by the specified "data rate" and "packet size".
    50  * characterized by the specified "data rate" and "packet size".
    51  */
    51  */
    52 class OnOffApplication : public Application 
    52 class OnOffApplication : public Application 
    53 {
    53 {
    54 public:
    54 public:
    55   /**
    55   static TypeId GetTypeId (void);
    56    * \param n node associated to this application
       
    57    * \param remote remote ip address
       
    58    * \param tid  TypeId of the socket factory to use. Note this
       
    59    * factory should create sockets compatible with the specified
       
    60    * remote address.
       
    61    * \param ontime on time random variable
       
    62    * \param offtime off time random variable
       
    63    */
       
    64   OnOffApplication(Ptr<Node> n,
       
    65                    const Address &remote,
       
    66                    std::string tid,
       
    67                    const RandomVariable& ontime,
       
    68                    const RandomVariable& offtime);
       
    69 
    56 
    70   /**
    57   OnOffApplication ();
    71    * \param n node associated to this application
       
    72    * \param remote remote ip address
       
    73    * \param tid  TypeId of the socket factory to use. Note this
       
    74    * factory should create sockets compatible with the specified
       
    75    * remote address.
       
    76    * \param ontime on time random variable
       
    77    * \param offtime off time random variable
       
    78    * \param rate data rate when on
       
    79    * \param size size of packets when sending data.
       
    80    */
       
    81   OnOffApplication(Ptr<Node> n,
       
    82                    const Address &remote,
       
    83                    std::string tid,
       
    84                    const RandomVariable& ontime,
       
    85                    const RandomVariable& offtime,
       
    86                    DataRate  rate,
       
    87                    uint32_t size);
       
    88 
    58 
    89   virtual ~OnOffApplication();
    59   virtual ~OnOffApplication();
    90 
    60 
    91   void SetMaxBytes(uint32_t maxBytes);
    61   void SetMaxBytes(uint32_t maxBytes);
    92 
       
    93   /**
       
    94    * \param r the data rate
       
    95    *
       
    96    * Set the data rate to use for every OnOffApplication for which
       
    97    * the user does not specify an explicit data rate.
       
    98    */
       
    99   static void SetDefaultRate(const DataRate & r);
       
   100 
       
   101   /**
       
   102    * \param size the packet size
       
   103    *
       
   104    * Set the packet size to use for every OnOffApplication for
       
   105    * which the user does not specify an explicit packet size.
       
   106    */
       
   107   static void SetDefaultSize (uint32_t size);
       
   108 
    62 
   109 protected:
    63 protected:
   110   virtual void DoDispose (void);
    64   virtual void DoDispose (void);
   111 private:
    65 private:
   112   // inherited from Application base class.
    66   // inherited from Application base class.
   127   void SendPacket();
    81   void SendPacket();
   128 
    82 
   129   Ptr<Socket>     m_socket;       // Associated socket
    83   Ptr<Socket>     m_socket;       // Associated socket
   130   Address         m_peer;         // Peer address
    84   Address         m_peer;         // Peer address
   131   bool            m_connected;    // True if connected
    85   bool            m_connected;    // True if connected
   132   RandomVariable m_onTime;       // rng for On Time
    86   RandomVariable  m_onTime;       // rng for On Time
   133   RandomVariable m_offTime;      // rng for Off Time
    87   RandomVariable  m_offTime;      // rng for Off Time
   134   DataRate        m_cbrRate;      // Rate that data is generated
    88   DataRate        m_cbrRate;      // Rate that data is generated
   135   uint32_t        m_pktSize;      // Size of packets
    89   uint32_t        m_pktSize;      // Size of packets
   136   uint32_t        m_residualBits; // Number of generated, but not sent, bits
    90   uint32_t        m_residualBits; // Number of generated, but not sent, bits
   137   Time            m_lastStartTime;// Time last packet sent
    91   Time            m_lastStartTime;// Time last packet sent
   138   uint32_t        m_maxBytes;     // Limit total number of bytes sent
    92   uint32_t        m_maxBytes;     // Limit total number of bytes sent
   139   uint32_t        m_totBytes;     // Total bytes sent so far
    93   uint32_t        m_totBytes;     // Total bytes sent so far
   140   EventId         m_startStopEvent;     // Event id for next start or stop event
    94   EventId         m_startStopEvent;     // Event id for next start or stop event
   141   EventId         m_sendEvent;    // Eventid of pending "send packet" event
    95   EventId         m_sendEvent;    // Eventid of pending "send packet" event
   142   bool            m_sending;      // True if currently in sending state
    96   bool            m_sending;      // True if currently in sending state
   143   std::string     m_tid;
    97   TypeId          m_tid;
   144   CallbackTraceSource<Ptr<const Packet> > m_txTrace;
    98   TracedCallback<Ptr<const Packet> > m_txTrace;
   145   
    99   
   146 private:
   100 private:
   147   virtual Ptr<TraceResolver> GetTraceResolver (void) const;
       
   148   void ScheduleNextTx();
   101   void ScheduleNextTx();
   149   void ScheduleStartEvent();
   102   void ScheduleStartEvent();
   150   void ScheduleStopEvent();
   103   void ScheduleStopEvent();
   151   void ConnectionSucceeded(Ptr<Socket>);
   104   void ConnectionSucceeded(Ptr<Socket>);
   152   void ConnectionFailed(Ptr<Socket>);
   105   void ConnectionFailed(Ptr<Socket>);