11#include "ns3/boolean.h"
14#include "ns3/nstime.h"
15#include "ns3/packet.h"
16#include "ns3/simulator.h"
17#include "ns3/socket-factory.h"
18#include "ns3/socket.h"
19#include "ns3/tcp-socket-base.h"
20#include "ns3/tcp-socket-factory.h"
21#include "ns3/trace-source-accessor.h"
22#include "ns3/uinteger.h"
35 TypeId(
"ns3::BulkSendApplication")
37 .SetGroupName(
"Applications")
39 .AddAttribute(
"SendSize",
40 "The amount of data to send each time.",
44 .AddAttribute(
"MaxBytes",
45 "The total number of bytes to send. "
46 "Once these bytes are sent, "
47 "no data is sent again. The value zero means "
48 "that there is no limit.",
52 .AddAttribute(
"Protocol",
53 "The type of protocol to use.",
57 .AddAttribute(
"EnableSeqTsSizeHeader",
58 "Add SeqTsSizeHeader to each packet",
63 "A new packet is sent",
65 "ns3::Packet::TracedCallback")
66 .AddTraceSource(
"TxWithSeqTsSize",
67 "A new packet is created with SeqTsSizeHeader",
69 "ns3::PacketSink::SeqTsSizeCallback")
70 .AddTraceSource(
"TcpRetransmission",
71 "The TCP socket retransmitted a packet",
73 "ns3::TcpSocketBase::RetransmissionCallback");
82 m_unsentPacket(nullptr)
134 NS_FATAL_ERROR(
"Using BulkSend with an incompatible socket type. "
135 "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
136 "In other words, use TCP instead of UDP.");
147 "Incompatible peer and local address IP version");
179 tcpSocket->TraceConnectWithoutContext(
203 NS_LOG_WARN(
"BulkSendApplication found null socket to close in StopApplication");
233 toSend = packet->GetSize();
244 packet->AddHeader(header);
252 if ((
unsigned)actual == toSend)
258 else if (actual == -1)
263 NS_LOG_DEBUG(
"Unable to send packet; caching for later attempt");
267 else if (actual > 0 && (
unsigned)actual < toSend)
272 NS_LOG_DEBUG(
"Packet size: " << packet->GetSize() <<
"; sent: " << actual
273 <<
"; fragment saved: " << toSend - (
unsigned)actual);
274 Ptr<Packet> sent = packet->CreateFragment(0, actual);
275 Ptr<Packet> unsent = packet->CreateFragment(actual, (toSend - (
unsigned)actual));
298 NS_LOG_LOGIC(
"BulkSendApplication Connection succeeded");
302 socket->GetSockName(from);
303 socket->GetPeerName(to);
323 socket->GetSockName(from);
324 socket->GetPeerName(to);
336 NS_LOG_FUNCTION(
this << p << header << localAddr << peerAddr << socket);
a polymophic address class
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
AttributeValue implementation for Boolean.
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.
~BulkSendApplication() override
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,...
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual Socket::SocketType GetSocketType() const =0
void SetConnectCallback(Callback< void, Ptr< Socket > > connectionSucceeded, Callback< void, Ptr< Socket > > connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
virtual int ShutdownRecv()=0
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual int GetSockName(Address &address) const =0
Get socket address.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Base class for source applications.
Address m_local
Local address to bind to.
uint8_t m_tos
The packets Type of Service.
Address m_peer
Peer address.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AttributeValue implementation for TypeId.
Hold an unsigned integer type.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.