A Discrete-Event Network Simulator
API
onoff-application.h
Go to the documentation of this file.
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 #include "ns3/seq-ts-size-header.h"
35 
36 namespace ns3 {
37 
38 class Address;
39 class RandomVariableStream;
40 class Socket;
41 
96 {
97 public:
102  static TypeId GetTypeId (void);
103 
104  OnOffApplication ();
105 
106  virtual ~OnOffApplication();
107 
116  void SetMaxBytes (uint64_t maxBytes);
117 
122  Ptr<Socket> GetSocket (void) const;
123 
131  int64_t AssignStreams (int64_t stream);
132 
133 protected:
134  virtual void DoDispose (void);
135 private:
136  // inherited from Application base class.
137  virtual void StartApplication (void); // Called at time specified by Start
138  virtual void StopApplication (void); // Called at time specified by Stop
139 
140  //helpers
144  void CancelEvents ();
145 
146  // Event handlers
150  void StartSending ();
154  void StopSending ();
158  void SendPacket ();
159 
163  bool m_connected;
168  uint32_t m_pktSize;
169  uint32_t m_residualBits;
171  uint64_t m_maxBytes;
172  uint64_t m_totBytes;
176  uint32_t m_seq {0};
178  bool m_enableSeqTsSizeHeader {false};
179 
180 
183 
186 
189 
190 private:
194  void ScheduleNextTx ();
198  void ScheduleStartEvent ();
202  void ScheduleStopEvent ();
207  void ConnectionSucceeded (Ptr<Socket> socket);
212  void ConnectionFailed (Ptr<Socket> socket);
213 };
214 
215 } // namespace ns3
216 
217 #endif /* ONOFF_APPLICATION_H */
void StopSending()
Start an Off period.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Ptr< Packet > m_unsentPacket
Unsent packet cached for future attempt.
virtual void StartApplication(void)
Application specific startup code.
EventId m_sendEvent
Event id of pending "send packet" event.
Ptr< Socket > GetSocket(void) const
Return a pointer to associated socket.
uint32_t m_pktSize
Size of packets.
Header with a sequence, a timestamp, and a "size" attribute.
Forward calls to a chain of Callback.
void ScheduleStartEvent()
Schedule the next On period start.
void CancelEvents()
Cancel all pending events.
Address m_local
Local address to bind to.
Generate traffic to a single destination according to an OnOff pattern.
void ScheduleStopEvent()
Schedule the next Off period start.
a polymophic address class
Definition: address.h:90
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
Callbacks for tracing the packet Tx events, includes source and destination addresses.
DataRate m_cbrRateFailSafe
Rate that data is generated (check copy)
Class for representing data rates.
Definition: data-rate.h:88
virtual void DoDispose(void)
Destructor implementation.
EventId m_startStopEvent
Event id for next start or stop event.
void SendPacket()
Send a packet.
TypeId m_tid
Type of the socket used.
The base class for all ns3 applications.
Definition: application.h:60
Address m_peer
Peer address.
DataRate m_cbrRate
Rate that data is generated.
Ptr< RandomVariableStream > m_onTime
rng for On Time
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_totBytes
Total bytes sent so far.
Ptr< Socket > m_socket
Associated socket.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Ptr< RandomVariableStream > m_offTime
rng for Off Time
void SetMaxBytes(uint64_t maxBytes)
Set the total number of bytes to send.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void ScheduleNextTx()
Schedule the next packet transmission.
void StartSending()
Start an On period.
void ConnectionSucceeded(Ptr< Socket > socket)
Handle a Connection Succeed event.
Time m_lastStartTime
Time last packet sent.
static TypeId GetTypeId(void)
Get the type ID.
An identifier for simulation events.
Definition: event-id.h:53
uint32_t m_seq
Sequence.
void ConnectionFailed(Ptr< Socket > socket)
Handle a Connection Failed event.
bool m_connected
True if connected.
virtual void StopApplication(void)
Application specific shutdown code.
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_residualBits
Number of generated, but not sent, bits.
uint64_t m_maxBytes
Limit total number of bytes sent.
bool m_enableSeqTsSizeHeader
Enable or disable the use of SeqTsSizeHeader.