22 #include "ns3/address.h"
23 #include "ns3/boolean.h"
26 #include "ns3/nstime.h"
27 #include "ns3/packet.h"
28 #include "ns3/simulator.h"
29 #include "ns3/socket-factory.h"
30 #include "ns3/socket.h"
31 #include "ns3/tcp-socket-factory.h"
32 #include "ns3/trace-source-accessor.h"
33 #include "ns3/uinteger.h"
46 TypeId(
"ns3::BulkSendApplication")
48 .SetGroupName(
"Applications")
50 .AddAttribute(
"SendSize",
51 "The amount of data to send each time.",
54 MakeUintegerChecker<uint32_t>(1))
55 .AddAttribute(
"Remote",
56 "The address of the destination",
60 .AddAttribute(
"Local",
61 "The Address on which to bind the socket. If not set, it is generated "
66 .AddAttribute(
"MaxBytes",
67 "The total number of bytes to send. "
68 "Once these bytes are sent, "
69 "no data is sent again. The value zero means "
70 "that there is no limit.",
73 MakeUintegerChecker<uint64_t>())
74 .AddAttribute(
"Protocol",
75 "The type of protocol to use.",
79 .AddAttribute(
"EnableSeqTsSizeHeader",
80 "Add SeqTsSizeHeader to each packet",
85 "A new packet is sent",
87 "ns3::Packet::TracedCallback")
88 .AddTraceSource(
"TxWithSeqTsSize",
89 "A new packet is created with SeqTsSizeHeader",
91 "ns3::PacketSink::SeqTsSizeCallback");
99 m_unsentPacket(nullptr)
151 NS_FATAL_ERROR(
"Using BulkSend with an incompatible socket type. "
152 "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
153 "In other words, use TCP instead of UDP.");
162 "Incompatible peer and local address IP version");
207 NS_LOG_WARN(
"BulkSendApplication found null socket to close in StopApplication");
252 packet = Create<Packet>(toSend);
256 if ((
unsigned)actual == toSend)
262 else if (actual == -1)
267 NS_LOG_DEBUG(
"Unable to send packet; caching for later attempt");
271 else if (actual > 0 && (
unsigned)actual < toSend)
277 <<
"; fragment saved: " << toSend - (
unsigned)actual);
302 NS_LOG_LOGIC(
"BulkSendApplication Connection succeeded");
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.
~BulkSendApplication() override
Ptr< Packet > m_unsentPacket
Variable to cache unsent packet.
Address m_peer
Peer address.
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,...
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
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
virtual int ShutdownRecv()=0
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected 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.
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.
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< 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()
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 AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)