20 #define NS_LOG_APPEND_CONTEXT                                   \ 
   21   if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }  
   24 #include "ns3/inet-socket-address.h" 
   30 #include "ns3/simulation-singleton.h" 
   31 #include "ns3/simulator.h" 
   32 #include "ns3/packet.h" 
   33 #include "ns3/uinteger.h" 
   34 #include "ns3/trace-source-accessor.h" 
   39 #include <arpa/inet.h> 
   40 #include <netinet/in.h> 
   57     .SetGroupName (
"Internet")
 
   58     .AddTraceSource (
"CongestionWindow",
 
   59                      "The TCP connection's congestion window",
 
   61                      "ns3::TracedValueCallback::Uint32")
 
   62     .AddTraceSource (
"SlowStartThreshold",
 
   63                      "TCP slow start threshold (bytes)",
 
   65                      "ns3::TracedValueCallback::Uint32")
 
   66     .AddTraceSource (
"State",
 
   69                      "ns3::TcpStatesTracedValueCallback")
 
   80     m_peerAddress (
"0.0.0.0", 0),
 
   81     m_errno (ERROR_NOTERROR),
 
   82     m_shutdownSend (false),
 
   83     m_shutdownRecv (false),
 
   86     m_closeOnEmpty (false),
 
   88     m_lastMeasuredRtt (
Seconds (0.0))
 
   95     m_delAckMaxCount (sock.m_delAckMaxCount),
 
   96     m_delAckTimeout (sock.m_delAckTimeout),
 
   97     m_noDelay (sock.m_noDelay),
 
  101     m_remoteAddress (sock.m_remoteAddress),
 
  102     m_remotePort (sock.m_remotePort),
 
  103     m_localAddress (sock.m_localAddress),
 
  104     m_localPort (sock.m_localPort),
 
  105     m_peerAddress (sock.m_peerAddress),
 
  106     m_errno (sock.m_errno),
 
  107     m_shutdownSend (sock.m_shutdownSend),
 
  108     m_shutdownRecv (sock.m_shutdownRecv),
 
  109     m_connected (sock.m_connected),
 
  110     m_state (sock.m_state),
 
  111     m_closeOnEmpty (sock.m_closeOnEmpty),
 
  112     m_txBufferSize (sock.m_txBufferSize),
 
  113     m_segmentSize (sock.m_segmentSize),
 
  114     m_rxWindowSize (sock.m_rxWindowSize),
 
  115     m_advertisedWindowSize (sock.m_advertisedWindowSize),
 
  116     m_cWnd (sock.m_cWnd),
 
  117     m_ssThresh (sock.m_ssThresh),
 
  118     m_initialCWnd (sock.m_initialCWnd),
 
  119     m_initialSsThresh (sock.m_initialSsThresh),
 
  120     m_lastMeasuredRtt (
Seconds (0.0)),
 
  121     m_cnTimeout (sock.m_cnTimeout),
 
  122     m_cnCount (sock.m_cnCount),
 
  125     m_sndBufSize (sock.m_sndBufSize)
 
  231   NS_LOG_LOGIC (
"NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported");
 
  299                     " deferring close, state " << 
m_state);
 
  303   NS_LOG_LOGIC (
"NscTcp socket " << 
this << 
" calling disconnect(); moving to CLOSED");
 
  327   std::ostringstream ss;
 
  329   std::string ipstring = ss.str ();
 
  382       return Send (p, flags); 
 
  506   struct sockaddr_in sin;
 
  507   size_t sin_len = 
sizeof(sin);
 
  521   sin_len = 
sizeof(sin);
 
  526   NS_LOG_LOGIC (
"NscTcpSocketImpl " << 
this << 
" accepted connection from "  
  540   struct sockaddr_in sin;
 
  541   size_t sin_len = 
sizeof(sin);
 
  547   NS_LOG_LOGIC (
"NscTcpSocketImpl " << 
this << 
" connected to " 
  580   newSock->m_nscTcpSocket = newsock;
 
  594   uint8_t buffer[8192];
 
  595   len = 
sizeof(buffer);
 
  598   if (err == 0 && len == 0)
 
  611                    "during read_data, ns-3 errno set to" << 
m_errno);
 
  640   size_t size, written = 0;
 
  645       size = p->GetSize ();
 
  650       uint8_t *buf = 
new uint8_t[size];
 
  651       p->CopyData (buf, size);
 
  664       if ((
size_t)ret < size)
 
  666           p->RemoveAtStart (ret);
 
  681     } 
while ((
size_t) ret == size);
 
  693   return CopyObject<NscTcpSocketImpl> (
this);
 
Ipv4EndPoint * m_endPoint
the IPv4 endpoint 
 
virtual Ptr< Node > GetNode(void) const 
Return the node this socket is associated with. 
 
static Ipv4Address Deserialize(const uint8_t buf[4])
 
Simulation virtual time values and global simulation resolution. 
 
Ipv4Address GetIpv4(void) const 
 
static Ipv4Address GetAny(void)
 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
 
SocketErrno
Enumeration of the possible errors returned by a socket. 
 
virtual int ShutdownSend(void)
 
std::queue< Ptr< Packet > > m_deliveryQueue
receive buffer 
 
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4) 
 
virtual bool is_listening()=0
Check the listening state. 
 
(abstract) base class of all TcpSockets 
 
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system. 
 
virtual int GetSockName(Address &address) const 
Get socket address. 
 
virtual void SetSndBufSize(uint32_t size)
Set the send buffer size. 
 
uint32_t m_txBufferSize
transmission buffer size 
 
virtual enum SocketType GetSocketType(void) const 
 
Ipv4Address m_localAddress
local address 
 
Sent a connection request, waiting for ack. 
 
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received. 
 
NscTcpSocketImpl()
Create an unbound tcp socket. 
 
Ptr< Node > m_node
the associated node 
 
virtual uint32_t GetAdvWin(void) const 
Get the Advertised Window size. 
 
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback. 
 
virtual void SetAdvWin(uint32_t window)
Set the Advertised Window size. 
 
Ptr< Packet > Recv(void)
Read a single packet from the socket. 
 
uint32_t m_rxAvailable
receive buffer available size 
 
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback. 
 
enum Socket::SocketErrno GetNativeNs3Errno(int err) const 
Translate between a NSC error and a ns-3 error code. 
 
virtual Time GetConnTimeout(void) const 
Get the connection timeout. 
 
void AddPacketTag(const Tag &tag) const 
Add a packet tag. 
 
void SetAddress(Address addr)
Set the tag's address. 
 
bool SendPendingData(void)
Send all the pending data. 
 
uint32_t m_rcvBufSize
maximum receive socket buffer size 
 
Ipv4Address m_remoteAddress
peer IP address 
 
virtual uint32_t GetConnCount(void) const 
Get the number of connection retries before giving up. 
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
INetStreamSocket * m_nscTcpSocket
the real NSC TCP socket 
 
uint32_t GetSize(void) const 
Returns the the size in bytes of the packet (including the zero-filled initial payload). 
 
TracedValue< TcpStates_t > m_state
state information 
 
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket. 
 
uint32_t m_sndBufSize
buffer limit for the outgoing queue 
 
virtual int accept(INetStreamSocket **)=0
Accept an incoming connection. 
 
static TypeId GetTypeId(void)
Get the type ID. 
 
virtual void SetConnTimeout(Time timeout)
Set the connection timeout. 
 
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function. 
 
SocketType
Enumeration of the possible socket types. 
 
virtual uint32_t GetRcvBufSize(void) const 
Get the receive buffer size. 
 
bool m_shutdownSend
Send no longer allowed. 
 
virtual void SetInitialCwnd(uint32_t cwnd)
Set the initial Congestion Window. 
 
virtual void SetPersistTimeout(Time timeout)
Set the timout for persistent connection. 
 
InetSocketAddress m_peerAddress
peer IP and port 
 
bool m_closeOnEmpty
true if socket will close when buffer is empty 
 
virtual void connect(const char *, int)=0
Connect to a remote peer. 
 
a polymophic address class 
 
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source. 
 
bool ReadPendingData(void)
Read all the pending data. 
 
virtual uint32_t GetSegSize(void) const 
Get the segment size. 
 
virtual uint32_t GetTxAvailable(void) const 
Returns the number of bytes which can be sent in a single call to Send. 
 
Time m_cnTimeout
Timeout for connection retry. 
 
bool PeekPacketTag(Tag &tag) const 
Search a matching tag and call Tag::Deserialize if it is found. 
 
virtual Time GetDelAckTimeout(void) const 
Get the time to delay an ACK. 
 
uint32_t m_initialCWnd
Initial cWnd value. 
 
void SetNode(Ptr< Node > node)
Set the associated node. 
 
enum SocketErrno m_errno
last error number 
 
uint32_t m_initialSsThresh
Initial Slow Start Threshold. 
 
virtual void SetTcpNoDelay(bool noDelay)
Enable/Disable Nagle's algorithm. 
 
bool m_connected
Connection established. 
 
virtual uint32_t GetDelAckMaxCount(void) const 
Get the number of packet to fire an ACK before delay timeout. 
 
Socket logic for the NSC TCP sockets. 
 
Ipv4Address GetLocalAddress(void)
Get the local address. 
 
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed. 
 
Time m_persistTimeout
Time between sending 1-byte probes. 
 
virtual int send_data(const void *data, int datalen)=0
Send some data. 
 
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host. 
 
This class implements a tag that carries an address of a packet across the socket interface...
 
virtual bool GetTcpNoDelay(void) const 
Check if Nagle's algorithm is enabled or not. 
 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
 
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent. 
 
virtual int ShutdownRecv(void)
 
virtual bool GetAllowBroadcast() const 
Query whether broadcast datagram transmissions are allowed. 
 
void Print(std::ostream &os) const 
Print this address to the given output stream. 
 
void ForwardUp(Ptr< Packet > p, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP. 
 
virtual bool is_connected()=0
Check the connection state. 
 
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address. 
 
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC. 
 
virtual void SetRcvBufSize(uint32_t size)
Set the receive buffer size. 
 
uint32_t m_cnCount
Count of remaining connection retries. 
 
virtual Time GetPersistTimeout(void) const 
Get the timout for persistent connection. 
 
virtual int Listen(void)
Listen for incoming connections. 
 
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket. 
 
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established. 
 
void CompleteFork(void)
Complete the Fork operations (after a connection has been accepted) 
 
uint16_t m_remotePort
peer port 
 
Ptr< NscTcpL4Protocol > m_tcp
the associated TCP L4 protocol 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address. 
 
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created. 
 
virtual void SetSegSize(uint32_t size)
Set the segment size. 
 
TracedValue< uint32_t > m_cWnd
Congestion window. 
 
bool m_noDelay
Disable ACk delay. 
 
virtual uint32_t GetInitialSSThresh(void) const 
Get the initial Slow Start Threshold. 
 
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now. 
 
virtual void SetConnCount(uint32_t count)
Set the number of connection retries before giving up. 
 
bool m_shutdownRecv
Receive no longer allowed. 
 
Time m_delAckTimeout
Time to delay an ACK. 
 
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
 
uint32_t m_rxWindowSize
Receive window size. 
 
void SetTcp(Ptr< NscTcpL4Protocol > tcp)
Set the associated TCP L4 protocol. 
 
virtual uint32_t GetRxAvailable(void) const 
Return number of bytes which can be returned from one or multiple calls to Recv. 
 
Ipv4 addresses are stored in host order in this class. 
 
int FinishBind(void)
Finish the binding process. 
 
uint32_t m_delAckMaxCount
Number of packet to fire an ACK before delay timeout. 
 
virtual int getpeername(struct sockaddr *sa, size_t *salen)
Get the peer name. 
 
virtual int getsockname(struct sockaddr *sa, size_t *salen)
Get the socket local name. 
 
uint16_t GetLocalPort(void)
Get the local port. 
 
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN. 
 
Address GetAddress(void) const 
Get the tag's address. 
 
virtual uint32_t GetSndBufSize(void) const 
Get the send buffer size. 
 
bool Accept(void)
Accept an incoming connection. 
 
virtual int Close(void)
Close a socket. 
 
virtual void listen(int)=0
Put the socket in Listening state on a port. 
 
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG. 
 
Time Seconds(double value)
Construct a Time in the indicated unit. 
 
void ConnectionSucceeded()
Called when a connection is in Established state. 
 
virtual enum SocketErrno GetErrno(void) const 
Get last error number. 
 
Struct interface to NSC Stream (i.e., TCP) Sockets. 
 
Remote side has shutdown and is waiting for us to finish writing our data and to shutdown (we have to...
 
virtual void disconnect()=0
Disconnect from a remote peer. 
 
Listening for a connection. 
 
uint16_t GetPort(void) const 
 
virtual int read_data(void *buf, int *buflen)=0
Read some data. 
 
uint16_t m_localPort
local port 
 
Ptr< NscTcpSocketImpl > Copy()
Copy self. 
 
std::queue< Ptr< Packet > > m_txBuffer
transmission buffer 
 
virtual void SetDelAckMaxCount(uint32_t count)
Set the number of packet to fire an ACK before delay timeout. 
 
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer. 
 
virtual void SetInitialSSThresh(uint32_t threshold)
Set the initial Slow Start Threshold. 
 
uint32_t m_advertisedWindowSize
Window to advertise. 
 
TracedValue< uint32_t > m_ssThresh
Slow Start Threshold. 
 
a unique identifier for an interface. 
 
virtual void SetDelAckTimeout(Time timeout)
Set the time to delay an ACK. 
 
uint32_t m_segmentSize
SegmentSize. 
 
TypeId SetParent(TypeId tid)
Set the parent TypeId. 
 
static bool IsMatchingType(const Address &address)
 
virtual int Connect(const Address &address)
Initiate a connection to a remote host. 
 
virtual ~NscTcpSocketImpl()
 
virtual uint32_t GetInitialCwnd(void) const 
Get the initial Congestion Window. 
 
void NSCWakeup(void)
Called by NscTcpSocketImpl::ForwardUp()