A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
onoff-application.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation;
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // Author: George F. Riley<riley@ece.gatech.edu>
19 //
20 
21 // ns3 - On/Off Data Source Application class
22 // George F. Riley, Georgia Tech, Spring 2007
23 // Adapted from ApplicationOnOff in GTNetS.
24 
25 #ifndef ONOFF_APPLICATION_H
26 #define ONOFF_APPLICATION_H
27 
28 #include "ns3/address.h"
29 #include "ns3/application.h"
30 #include "ns3/event-id.h"
31 #include "ns3/ptr.h"
32 #include "ns3/data-rate.h"
33 #include "ns3/traced-callback.h"
34 
35 namespace ns3 {
36 
37 class Address;
38 class RandomVariableStream;
39 class Socket;
40 
87 {
88 public:
89  static TypeId GetTypeId (void);
90 
92 
93  virtual ~OnOffApplication();
94 
102  void SetMaxBytes (uint32_t maxBytes);
103 
107  Ptr<Socket> GetSocket (void) const;
108 
117  int64_t AssignStreams (int64_t stream);
118 
119 protected:
120  virtual void DoDispose (void);
121 private:
122  // inherited from Application base class.
123  virtual void StartApplication (void); // Called at time specified by Start
124  virtual void StopApplication (void); // Called at time specified by Stop
125 
126  //helpers
127  void CancelEvents ();
128 
129  void Construct (Ptr<Node> n,
130  const Address &remote,
131  std::string tid,
132  const RandomVariable& ontime,
133  const RandomVariable& offtime,
134  uint32_t size);
135 
136 
137  // Event handlers
138  void StartSending ();
139  void StopSending ();
140  void SendPacket ();
141 
142  Ptr<Socket> m_socket; // Associated socket
143  Address m_peer; // Peer address
144  bool m_connected; // True if connected
145  Ptr<RandomVariableStream> m_onTime; // rng for On Time
146  Ptr<RandomVariableStream> m_offTime; // rng for Off Time
147  DataRate m_cbrRate; // Rate that data is generated
148  uint32_t m_pktSize; // Size of packets
149  uint32_t m_residualBits; // Number of generated, but not sent, bits
150  Time m_lastStartTime; // Time last packet sent
151  uint32_t m_maxBytes; // Limit total number of bytes sent
152  uint32_t m_totBytes; // Total bytes sent so far
153  EventId m_startStopEvent; // Event id for next start or stop event
154  EventId m_sendEvent; // Eventid of pending "send packet" event
155  bool m_sending; // True if currently in sending state
156  TypeId m_tid;
158 
159 private:
160  void ScheduleNextTx ();
161  void ScheduleStartEvent ();
162  void ScheduleStopEvent ();
163  void ConnectionSucceeded (Ptr<Socket> socket);
164  void ConnectionFailed (Ptr<Socket> socket);
165 };
166 
167 } // namespace ns3
168 
169 #endif /* ONOFF_APPLICATION_H */
keep track of time unit.
Definition: nstime.h:149
virtual void StartApplication(void)
Application specific startup code.
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Generate traffic to a single destination according to an OnOff pattern.
a polymophic address class
Definition: address.h:86
Class for representing data rates.
Definition: data-rate.h:71
virtual void DoDispose(void)
The base class for all ns3 applications.
Definition: application.h:61
Ptr< Socket > GetSocket(void) const
int64_t AssignStreams(int64_t stream)
void SetMaxBytes(uint32_t maxBytes)
an identifier for simulation events.
Definition: event-id.h:46
The basic RNG for NS-3.Note: The underlying random number generation method used by NS-3 is the RngSt...
virtual void StopApplication(void)
Application specific shutdown code.
a unique identifier for an interface.
Definition: type-id.h:44