A Discrete-Event Network Simulator
API
onoff-application.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006 Georgia Tech Research Corporation
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License version 2 as
6 // published by the Free Software Foundation;
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // Author: George F. Riley<riley@ece.gatech.edu>
18 //
19 
20 // ns3 - On/Off Data Source Application class
21 // George F. Riley, Georgia Tech, Spring 2007
22 // Adapted from ApplicationOnOff in GTNetS.
23 
24 #ifndef ONOFF_APPLICATION_H
25 #define ONOFF_APPLICATION_H
26 
27 #include "seq-ts-size-header.h"
28 
29 #include "ns3/address.h"
30 #include "ns3/application.h"
31 #include "ns3/data-rate.h"
32 #include "ns3/event-id.h"
33 #include "ns3/ptr.h"
34 #include "ns3/traced-callback.h"
35 
36 namespace ns3
37 {
38 
39 class Address;
40 class RandomVariableStream;
41 class Socket;
42 
97 {
98  public:
103  static TypeId GetTypeId();
104 
106 
107  ~OnOffApplication() override;
108 
117  void SetMaxBytes(uint64_t maxBytes);
118 
123  Ptr<Socket> GetSocket() const;
124 
132  int64_t AssignStreams(int64_t stream);
133 
134  protected:
135  void DoDispose() override;
136 
137  private:
138  // inherited from Application base class.
139  void StartApplication() override; // Called at time specified by Start
140  void StopApplication() override; // Called at time specified by Stop
141 
142  // helpers
146  void CancelEvents();
147 
148  // Event handlers
152  void StartSending();
156  void StopSending();
160  void SendPacket();
161 
165  bool m_connected;
170  uint32_t m_pktSize;
171  uint32_t m_residualBits;
173  uint64_t m_maxBytes;
174  uint64_t m_totBytes;
178  uint32_t m_seq{0};
181 
184 
187 
192 
193  private:
197  void ScheduleNextTx();
201  void ScheduleStartEvent();
205  void ScheduleStopEvent();
210  void ConnectionSucceeded(Ptr<Socket> socket);
215  void ConnectionFailed(Ptr<Socket> socket);
216 };
217 
218 } // namespace ns3
219 
220 #endif /* ONOFF_APPLICATION_H */
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
Class for representing data rates.
Definition: data-rate.h:89
An identifier for simulation events.
Definition: event-id.h:55
Generate traffic to a single destination according to an OnOff pattern.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_residualBits
Number of generated, but not sent, bits.
void ConnectionSucceeded(Ptr< Socket > socket)
Handle a Connection Succeed event.
EventId m_sendEvent
Event id of pending "send packet" event.
void ScheduleStartEvent()
Schedule the next On period start.
bool m_connected
True if connected.
uint32_t m_pktSize
Size of packets.
Ptr< Socket > GetSocket() const
Return a pointer to associated socket.
Ptr< Socket > m_socket
Associated socket.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
void SetMaxBytes(uint64_t maxBytes)
Set the total number of bytes to send.
Ptr< RandomVariableStream > m_offTime
rng for Off Time
void StartApplication() override
Application specific startup code.
Ptr< Packet > m_unsentPacket
Unsent packet cached for future attempt.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
Callbacks for tracing the packet Tx events, includes source and destination addresses.
void DoDispose() override
Destructor implementation.
EventId m_startStopEvent
Event id for next start or stop event.
void ScheduleNextTx()
Schedule the next packet transmission.
DataRate m_cbrRateFailSafe
Rate that data is generated (check copy)
void ConnectionFailed(Ptr< Socket > socket)
Handle a Connection Failed event.
void ScheduleStopEvent()
Schedule the next Off period start.
TracedCallback< Ptr< const Packet >, const Address &, const Address &, const SeqTsSizeHeader & > m_txTraceWithSeqTsSize
Callback for tracing the packet Tx events, includes source, destination, the packet sent,...
uint64_t m_maxBytes
Limit total number of bytes sent.
Time m_lastStartTime
Time last packet sent.
uint64_t m_totBytes
Total bytes sent so far.
void StopSending()
Start an Off period.
void StartSending()
Start an On period.
Address m_local
Local address to bind to.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_onTime
rng for On Time
bool m_enableSeqTsSizeHeader
Enable or disable the use of SeqTsSizeHeader.
TypeId m_tid
Type of the socket used.
uint32_t m_seq
Sequence.
DataRate m_cbrRate
Rate that data is generated.
void StopApplication() override
Application specific shutdown code.
Address m_peer
Peer address.
void CancelEvents()
Cancel all pending events.
void SendPacket()
Send a packet.
Header with a sequence, a timestamp, and a "size" attribute.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.