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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: George F. Riley <riley@ece.gatech.edu>
7 */
8
9#ifndef BULK_SEND_APPLICATION_H
10#define BULK_SEND_APPLICATION_H
11
12#include "seq-ts-size-header.h"
13
14#include "ns3/address.h"
15#include "ns3/application.h"
16#include "ns3/event-id.h"
17#include "ns3/ptr.h"
18#include "ns3/traced-callback.h"
19
20namespace ns3
21{
22
23class Address;
24class Socket;
25class TcpHeader;
26class TcpSocketBase;
27
28/**
29 * \ingroup applications
30 * \defgroup bulksend BulkSendApplication
31 *
32 * This traffic generator simply sends data
33 * as fast as possible up to MaxBytes or until
34 * the application is stopped (if MaxBytes is
35 * zero). Once the lower layer send buffer is
36 * filled, it waits until space is free to
37 * send more data, essentially keeping a
38 * constant flow of data. Only SOCK_STREAM
39 * and SOCK_SEQPACKET sockets are supported.
40 * For example, TCP sockets can be used, but
41 * UDP sockets can not be used.
42 */
43
44/**
45 * \ingroup bulksend
46 *
47 * \brief Send as much traffic as possible, trying to fill the bandwidth.
48 *
49 * This traffic generator simply sends data
50 * as fast as possible up to MaxBytes or until
51 * the application is stopped (if MaxBytes is
52 * zero). Once the lower layer send buffer is
53 * filled, it waits until space is free to
54 * send more data, essentially keeping a
55 * constant flow of data. Only SOCK_STREAM
56 * and SOCK_SEQPACKET sockets are supported.
57 * For example, TCP sockets can be used, but
58 * UDP sockets can not be used.
59 *
60 * If the attribute "EnableSeqTsSizeHeader" is enabled, the application will
61 * use some bytes of the payload to store an header with a sequence number,
62 * a timestamp, and the size of the packet sent. Support for extracting
63 * statistics from this header have been added to \c ns3::PacketSink
64 * (enable its "EnableSeqTsSizeHeader" attribute), or users may extract
65 * the header via trace sources.
66 */
68{
69 public:
70 /**
71 * \brief Get the type ID.
72 * \return the object TypeId
73 */
74 static TypeId GetTypeId();
75
77
78 ~BulkSendApplication() override;
79
80 /**
81 * \brief Set the upper bound for the total number of bytes to send.
82 *
83 * Once this bound is reached, no more application bytes are sent. If the
84 * application is stopped during the simulation and restarted, the
85 * total number of bytes sent is not reset; however, the maxBytes
86 * bound is still effective and the application will continue sending
87 * up to maxBytes. The value zero for maxBytes means that
88 * there is no upper bound; i.e. data is sent until the application
89 * or simulation is stopped.
90 *
91 * \param maxBytes the upper bound of bytes to send
92 */
93 void SetMaxBytes(uint64_t maxBytes);
94
95 /**
96 * \brief Get the socket this application is attached to.
97 * \return pointer to associated socket
98 */
99 Ptr<Socket> GetSocket() const;
100
101 protected:
102 void DoDispose() override;
103
104 private:
105 void StartApplication() override;
106 void StopApplication() override;
107
108 /**
109 * \brief Send data until the L4 transmission buffer is full.
110 * \param from From address
111 * \param to To address
112 */
113 void SendData(const Address& from, const Address& to);
114
115 Ptr<Socket> m_socket; //!< Associated socket
116 Address m_peer; //!< Peer address
117 Address m_local; //!< Local address to bind to
118 bool m_connected; //!< True if connected
119 uint8_t m_tos; //!< The packets Type of Service
120 uint32_t m_sendSize; //!< Size of data to send each time
121 uint64_t m_maxBytes; //!< Limit total number of bytes sent
122 uint64_t m_totBytes; //!< Total bytes sent so far
123 TypeId m_tid; //!< The type of protocol to use.
124 uint32_t m_seq{0}; //!< Sequence
125 Ptr<Packet> m_unsentPacket; //!< Variable to cache unsent packet
126 bool m_enableSeqTsSizeHeader{false}; //!< Enable or disable the SeqTsSizeHeader
127
128 /// Traced Callback: sent packets
130
131 /// Traced Callback: retransmitted packets
133 const TcpHeader&,
134 const Address&,
135 const Address&,
138
139 /// Callback for tracing the packet Tx events, includes source, destination, the packet sent,
140 /// and header
143
144 private:
145 /**
146 * \brief Connection Succeeded (called by Socket through a callback)
147 * \param socket the connected socket
148 */
149 void ConnectionSucceeded(Ptr<Socket> socket);
150 /**
151 * \brief Connection Failed (called by Socket through a callback)
152 * \param socket the connected socket
153 */
154 void ConnectionFailed(Ptr<Socket> socket);
155 /**
156 * \brief Send more data as soon as some has been transmitted.
157 *
158 * Used in socket's SetSendCallback - params are forced by it.
159 *
160 * \param socket socket to use
161 * \param unused actually unused
162 */
163 void DataSend(Ptr<Socket> socket, uint32_t unused);
164
165 /**
166 * \brief Packet retransmitted (called by TcpSocketBase sockets via callback)
167 * \param p the retransmitted packet
168 * \param header the TCP header
169 * \param localAddr the local address
170 * \param peerAddr the peer address
171 * \param socket the socket that retransmitted the packet
172 */
174 const TcpHeader& header,
175 const Address& localAddr,
176 const Address& peerAddr,
178};
179
180} // namespace ns3
181
182#endif /* BULK_SEND_APPLICATION_H */
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
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 PacketRetransmitted(Ptr< const Packet > p, const TcpHeader &header, const Address &localAddr, const Address &peerAddr, Ptr< const TcpSocketBase > socket)
Packet retransmitted (called by TcpSocketBase sockets via callback)
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.
TracedCallback< Ptr< const Packet >, const TcpHeader &, const Address &, const Address &, Ptr< const TcpSocketBase > > m_retransmissionTrace
Traced Callback: retransmitted packets.
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.
Header with a sequence, a timestamp, and a "size" attribute.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.