A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bulk-send-application.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Georgia Institute of Technology
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#ifndef BULK_SEND_APPLICATION_H
21#define BULK_SEND_APPLICATION_H
22
23#include "seq-ts-size-header.h"
24
25#include "ns3/address.h"
26#include "ns3/application.h"
27#include "ns3/event-id.h"
28#include "ns3/ptr.h"
29#include "ns3/traced-callback.h"
30
31namespace ns3
32{
33
34class Address;
35class Socket;
36
37/**
38 * \ingroup applications
39 * \defgroup bulksend BulkSendApplication
40 *
41 * This traffic generator simply sends data
42 * as fast as possible up to MaxBytes or until
43 * the application is stopped (if MaxBytes is
44 * zero). Once the lower layer send buffer is
45 * filled, it waits until space is free to
46 * send more data, essentially keeping a
47 * constant flow of data. Only SOCK_STREAM
48 * and SOCK_SEQPACKET sockets are supported.
49 * For example, TCP sockets can be used, but
50 * UDP sockets can not be used.
51 */
52
53/**
54 * \ingroup bulksend
55 *
56 * \brief Send as much traffic as possible, trying to fill the bandwidth.
57 *
58 * This traffic generator simply sends data
59 * as fast as possible up to MaxBytes or until
60 * the application is stopped (if MaxBytes is
61 * zero). Once the lower layer send buffer is
62 * filled, it waits until space is free to
63 * send more data, essentially keeping a
64 * constant flow of data. Only SOCK_STREAM
65 * and SOCK_SEQPACKET sockets are supported.
66 * For example, TCP sockets can be used, but
67 * UDP sockets can not be used.
68 *
69 * If the attribute "EnableSeqTsSizeHeader" is enabled, the application will
70 * use some bytes of the payload to store an header with a sequence number,
71 * a timestamp, and the size of the packet sent. Support for extracting
72 * statistics from this header have been added to \c ns3::PacketSink
73 * (enable its "EnableSeqTsSizeHeader" attribute), or users may extract
74 * the header via trace sources.
75 */
77{
78 public:
79 /**
80 * \brief Get the type ID.
81 * \return the object TypeId
82 */
83 static TypeId GetTypeId();
84
86
87 ~BulkSendApplication() override;
88
89 /**
90 * \brief Set the upper bound for the total number of bytes to send.
91 *
92 * Once this bound is reached, no more application bytes are sent. If the
93 * application is stopped during the simulation and restarted, the
94 * total number of bytes sent is not reset; however, the maxBytes
95 * bound is still effective and the application will continue sending
96 * up to maxBytes. The value zero for maxBytes means that
97 * there is no upper bound; i.e. data is sent until the application
98 * or simulation is stopped.
99 *
100 * \param maxBytes the upper bound of bytes to send
101 */
102 void SetMaxBytes(uint64_t maxBytes);
103
104 /**
105 * \brief Get the socket this application is attached to.
106 * \return pointer to associated socket
107 */
108 Ptr<Socket> GetSocket() const;
109
110 protected:
111 void DoDispose() override;
112
113 private:
114 void StartApplication() override;
115 void StopApplication() override;
116
117 /**
118 * \brief Send data until the L4 transmission buffer is full.
119 * \param from From address
120 * \param to To address
121 */
122 void SendData(const Address& from, const Address& to);
123
124 Ptr<Socket> m_socket; //!< Associated socket
125 Address m_peer; //!< Peer address
126 Address m_local; //!< Local address to bind to
127 bool m_connected; //!< True if connected
128 uint8_t m_tos; //!< The packets Type of Service
129 uint32_t m_sendSize; //!< Size of data to send each time
130 uint64_t m_maxBytes; //!< Limit total number of bytes sent
131 uint64_t m_totBytes; //!< Total bytes sent so far
132 TypeId m_tid; //!< The type of protocol to use.
133 uint32_t m_seq{0}; //!< Sequence
134 Ptr<Packet> m_unsentPacket; //!< Variable to cache unsent packet
135 bool m_enableSeqTsSizeHeader{false}; //!< Enable or disable the SeqTsSizeHeader
136
137 /// Traced Callback: sent packets
139
140 /// Callback for tracing the packet Tx events, includes source, destination, the packet sent,
141 /// and header
144
145 private:
146 /**
147 * \brief Connection Succeeded (called by Socket through a callback)
148 * \param socket the connected socket
149 */
150 void ConnectionSucceeded(Ptr<Socket> socket);
151 /**
152 * \brief Connection Failed (called by Socket through a callback)
153 * \param socket the connected socket
154 */
155 void ConnectionFailed(Ptr<Socket> socket);
156 /**
157 * \brief Send more data as soon as some has been transmitted.
158 *
159 * Used in socket's SetSendCallback - params are forced by it.
160 *
161 * \param socket socket to use
162 * \param unused actually unused
163 */
164 void DataSend(Ptr<Socket> socket, uint32_t unused);
165};
166
167} // namespace ns3
168
169#endif /* BULK_SEND_APPLICATION_H */
a polymophic address class
Definition: address.h:101
The base class for all ns3 applications.
Definition: application.h:62
Send as much traffic as possible, trying to fill the bandwidth.
bool m_enableSeqTsSizeHeader
Enable or disable the SeqTsSizeHeader.
void SendData(const Address &from, const Address &to)
Send data until the L4 transmission buffer is full.
uint8_t m_tos
The packets Type of Service.
Ptr< Packet > m_unsentPacket
Variable to cache unsent packet.
void DoDispose() override
Destructor implementation.
void ConnectionSucceeded(Ptr< Socket > socket)
Connection Succeeded (called by Socket through a callback)
static TypeId GetTypeId()
Get the type ID.
bool m_connected
True if connected.
uint32_t m_sendSize
Size of data to send each time.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: sent packets.
Ptr< Socket > GetSocket() const
Get the socket this application is attached to.
void ConnectionFailed(Ptr< Socket > socket)
Connection Failed (called by Socket through a callback)
uint64_t m_maxBytes
Limit total number of bytes sent.
TypeId m_tid
The type of protocol to use.
void StartApplication() override
Application specific startup code.
uint64_t m_totBytes
Total bytes sent so far.
Ptr< Socket > m_socket
Associated socket.
Address m_local
Local address to bind to.
void DataSend(Ptr< Socket > socket, uint32_t unused)
Send more data as soon as some has been transmitted.
void StopApplication() override
Application specific shutdown code.
void SetMaxBytes(uint64_t maxBytes)
Set the upper bound for the total number of bytes to send.
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,...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Header with a sequence, a timestamp, and a "size" attribute.
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.