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