22 #include "ns3/address.h"
24 #include "ns3/nstime.h"
25 #include "ns3/socket.h"
26 #include "ns3/simulator.h"
27 #include "ns3/socket-factory.h"
28 #include "ns3/packet.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/tcp-socket-factory.h"
32 #include "ns3/boolean.h"
46 .SetGroupName(
"Applications")
48 .AddAttribute (
"SendSize",
"The amount of data to send each time.",
51 MakeUintegerChecker<uint32_t> (1))
52 .AddAttribute (
"Remote",
"The address of the destination",
56 .AddAttribute (
"Local",
57 "The Address on which to bind the socket. If not set, it is generated automatically.",
61 .AddAttribute (
"MaxBytes",
62 "The total number of bytes to send. "
63 "Once these bytes are sent, "
64 "no data is sent again. The value zero means "
65 "that there is no limit.",
68 MakeUintegerChecker<uint64_t> ())
69 .AddAttribute (
"Protocol",
"The type of protocol to use.",
73 .AddAttribute (
"EnableSeqTsSizeHeader",
74 "Add SeqTsSizeHeader to each packet",
78 .AddTraceSource (
"Tx",
"A new packet is sent",
80 "ns3::Packet::TracedCallback")
81 .AddTraceSource (
"TxWithSeqTsSize",
"A new packet is created with SeqTsSizeHeader",
83 "ns3::PacketSink::SeqTsSizeCallback")
144 NS_FATAL_ERROR (
"Using BulkSend with an incompatible socket type. "
145 "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
146 "In other words, use TCP instead of UDP.");
153 "Incompatible peer and local address IP version");
199 NS_LOG_WARN (
"BulkSendApplication found null socket to close in StopApplication");
244 packet = Create<Packet> (toSend);
248 if ((
unsigned) actual == toSend)
254 else if (actual == -1)
259 NS_LOG_DEBUG (
"Unable to send packet; caching for later attempt");
263 else if (actual > 0 && (
unsigned) actual < toSend)
268 NS_LOG_DEBUG (
"Packet size: " << packet->
GetSize () <<
"; sent: " << actual <<
"; fragment saved: " << toSend - (
unsigned) actual);
278 NS_FATAL_ERROR (
"Unexpected return value from m_socket->Send ()");
292 NS_LOG_LOGIC (
"BulkSendApplication Connection succeeded");
303 NS_LOG_LOGIC (
"BulkSendApplication, Connection Failed");
a polymophic address class
bool IsInvalid(void) const
AttributeValue implementation for Address.
The base class for all ns3 applications.
virtual void DoDispose(void)
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.
Ptr< Packet > m_unsentPacket
Variable to cache unsent packet.
Address m_peer
Peer address.
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,...
void ConnectionSucceeded(Ptr< Socket > socket)
Connection Succeeded (called by Socket through a callback)
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.
virtual void DoDispose(void)
Destructor implementation.
virtual void StartApplication(void)
Application specific startup code.
void ConnectionFailed(Ptr< Socket > socket)
Connection Failed (called by Socket through a callback)
virtual void StopApplication(void)
Application specific shutdown code.
uint64_t m_maxBytes
Limit total number of bytes sent.
TypeId m_tid
The type of protocol to use.
Ptr< Socket > GetSocket(void) const
Get the socket this application is attached to.
virtual ~BulkSendApplication()
uint64_t m_totBytes
Total bytes sent so far.
Ptr< Socket > m_socket
Associated socket.
Address m_local
Local address to bind to.
static TypeId GetTypeId(void)
Get the type ID.
void DataSend(Ptr< Socket > socket, uint32_t unused)
Send more data as soon as some has been transmitted.
void SetMaxBytes(uint64_t maxBytes)
Set the upper bound for the total number of bytes to send.
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.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
static Time Now(void)
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.
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.
virtual int ShutdownRecv(void)=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.
virtual int Close(void)=0
Close a socket.
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 Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual enum Socket::SocketType GetSocketType(void) const =0
static TypeId GetTypeId(void)
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 AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeAddressChecker(void)
Ptr< const AttributeChecker > MakeBooleanChecker(void)
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 AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
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< 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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...