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 "bulk-send-application.h"
38 NS_OBJECT_ENSURE_REGISTERED (BulkSendApplication);
41 BulkSendApplication::GetTypeId (
void)
43 static TypeId tid = TypeId (
"ns3::BulkSendApplication")
44 .SetParent<Application> ()
45 .AddConstructor<BulkSendApplication> ()
46 .AddAttribute (
"SendSize",
"The amount of data to send each time.",
48 MakeUintegerAccessor (&BulkSendApplication::m_sendSize),
49 MakeUintegerChecker<uint32_t> (1))
50 .AddAttribute (
"Remote",
"The address of the destination",
52 MakeAddressAccessor (&BulkSendApplication::m_peer),
53 MakeAddressChecker ())
54 .AddAttribute (
"MaxBytes",
55 "The total number of bytes to send. "
56 "Once these bytes are sent, "
57 "no data is sent again. The value zero means "
58 "that there is no limit.",
60 MakeUintegerAccessor (&BulkSendApplication::m_maxBytes),
61 MakeUintegerChecker<uint32_t> ())
62 .AddAttribute (
"Protocol",
"The type of protocol to use.",
63 TypeIdValue (TcpSocketFactory::GetTypeId ()),
64 MakeTypeIdAccessor (&BulkSendApplication::m_tid),
66 .AddTraceSource (
"Tx",
"A new packet is created and is sent",
73 BulkSendApplication::BulkSendApplication ()
81 BulkSendApplication::~BulkSendApplication ()
90 m_maxBytes = maxBytes;
124 NS_FATAL_ERROR (
"Using BulkSend with an incompatible socket type. "
125 "BulkSend requires SOCK_STREAM or SOCK_SEQPACKET. "
126 "In other words, use TCP instead of UDP.");
141 MakeCallback (&BulkSendApplication::ConnectionSucceeded,
this),
142 MakeCallback (&BulkSendApplication::ConnectionFailed,
this));
163 NS_LOG_WARN (
"BulkSendApplication found null socket to close in StopApplication");
170 void BulkSendApplication::SendData (
void)
174 while (m_maxBytes == 0 || m_totBytes < m_maxBytes)
176 uint32_t toSend = m_sendSize;
180 toSend = std::min (m_sendSize, m_maxBytes - m_totBytes);
183 Ptr<Packet> packet = Create<Packet> (toSend);
185 int actual = m_socket->
Send (packet);
188 m_totBytes += actual;
193 if ((
unsigned)actual != toSend)
199 if (m_totBytes == m_maxBytes && m_connected)
206 void BulkSendApplication::ConnectionSucceeded (Ptr<Socket> socket)
209 NS_LOG_LOGIC (
"BulkSendApplication Connection succeeded");
214 void BulkSendApplication::ConnectionFailed (Ptr<Socket> socket)
217 NS_LOG_LOGIC (
"BulkSendApplication, Connection Failed");
220 void BulkSendApplication::DataSend (Ptr<Socket>, uint32_t)
#define NS_LOG_FUNCTION(parameters)
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
#define NS_LOG_COMPONENT_DEFINE(name)
virtual int ShutdownRecv(void)=0
virtual void DoDispose(void)
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual void StopApplication(void)
Application specific shutdown code.
virtual void StartApplication(void)
Application specific startup code.
Ptr< Node > GetNode() const
void SetMaxBytes(uint32_t maxBytes)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
virtual enum Socket::SocketType GetSocketType(void) const =0
#define NS_LOG_LOGIC(msg)
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual void DoDispose(void)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
static bool IsMatchingType(const Address &addr)
If the address match.
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 Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Close(void)=0
Close a socket.
Ptr< Socket > GetSocket(void) const
static bool IsMatchingType(const Address &address)