11#include "ns3/address.h"
12#include "ns3/boolean.h"
15#include "ns3/nstime.h"
16#include "ns3/packet.h"
17#include "ns3/simulator.h"
18#include "ns3/socket-factory.h"
19#include "ns3/socket.h"
20#include "ns3/tcp-socket-base.h"
21#include "ns3/tcp-socket-factory.h"
22#include "ns3/trace-source-accessor.h"
23#include "ns3/uinteger.h"
36 TypeId(
"ns3::BulkSendApplication")
38 .SetGroupName(
"Applications")
40 .AddAttribute(
"SendSize",
41 "The amount of data to send each time.",
45 .AddAttribute(
"Remote",
46 "The address of the destination",
50 .AddAttribute(
"Local",
51 "The Address on which to bind the socket. If not set, it is generated "
57 "The Type of Service used to send IPv4 packets. "
58 "All 8 bits of the TOS byte are set (including ECN bits).",
62 .AddAttribute(
"MaxBytes",
63 "The total number of bytes to send. "
64 "Once these bytes are sent, "
65 "no data is sent again. The value zero means "
66 "that there is no limit.",
70 .AddAttribute(
"Protocol",
71 "The type of protocol to use.",
75 .AddAttribute(
"EnableSeqTsSizeHeader",
76 "Add SeqTsSizeHeader to each packet",
81 "A new packet is sent",
83 "ns3::Packet::TracedCallback")
84 .AddTraceSource(
"TxWithSeqTsSize",
85 "A new packet is created with SeqTsSizeHeader",
87 "ns3::PacketSink::SeqTsSizeCallback")
88 .AddTraceSource(
"TcpRetransmission",
89 "The TCP socket retransmitted a packet",
91 "ns3::TcpSocketBase::RetransmissionCallback");
100 m_unsentPacket(nullptr)
152 NS_FATAL_ERROR(
"Using BulkSend with an incompatible socket type. "
153 "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
154 "In other words, use TCP instead of UDP.");
165 "Incompatible peer and local address IP version");
197 tcpSocket->TraceConnectWithoutContext(
221 NS_LOG_WARN(
"BulkSendApplication found null socket to close in StopApplication");
251 toSend = packet->GetSize();
262 packet->AddHeader(header);
270 if ((
unsigned)actual == toSend)
276 else if (actual == -1)
281 NS_LOG_DEBUG(
"Unable to send packet; caching for later attempt");
285 else if (actual > 0 && (
unsigned)actual < toSend)
290 NS_LOG_DEBUG(
"Packet size: " << packet->GetSize() <<
"; sent: " << actual
291 <<
"; fragment saved: " << toSend - (
unsigned)actual);
292 Ptr<Packet> sent = packet->CreateFragment(0, actual);
293 Ptr<Packet> unsent = packet->CreateFragment(actual, (toSend - (
unsigned)actual));
316 NS_LOG_LOGIC(
"BulkSendApplication Connection succeeded");
320 socket->GetSockName(from);
321 socket->GetPeerName(to);
341 socket->GetSockName(from);
342 socket->GetPeerName(to);
354 NS_LOG_FUNCTION(
this << p << header << localAddr << peerAddr << socket);
a polymophic address class
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
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.
~BulkSendApplication() override
Ptr< Packet > m_unsentPacket
Variable to cache unsent packet.
Address m_peer
Peer address.
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,...
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.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#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.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
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< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeAddressChecker()
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Ptr< const AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)