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 .AddTraceSource (
"CongestionWindow",
58 "The TCP connection's congestion window",
70 m_peerAddress (
"0.0.0.0", 0),
71 m_errno (ERROR_NOTERROR),
72 m_shutdownSend (false),
73 m_shutdownRecv (false),
76 m_closeOnEmpty (false),
78 m_lastMeasuredRtt (Seconds (0.0))
85 m_delAckMaxCount (sock.m_delAckMaxCount),
86 m_delAckTimeout (sock.m_delAckTimeout),
87 m_noDelay (sock.m_noDelay),
91 m_remoteAddress (sock.m_remoteAddress),
92 m_remotePort (sock.m_remotePort),
93 m_localAddress (sock.m_localAddress),
94 m_localPort (sock.m_localPort),
95 m_peerAddress (sock.m_peerAddress),
96 m_errno (sock.m_errno),
97 m_shutdownSend (sock.m_shutdownSend),
98 m_shutdownRecv (sock.m_shutdownRecv),
99 m_connected (sock.m_connected),
100 m_state (sock.m_state),
101 m_closeOnEmpty (sock.m_closeOnEmpty),
102 m_txBufferSize (sock.m_txBufferSize),
103 m_segmentSize (sock.m_segmentSize),
104 m_rxWindowSize (sock.m_rxWindowSize),
105 m_advertisedWindowSize (sock.m_advertisedWindowSize),
106 m_cWnd (sock.m_cWnd),
107 m_ssThresh (sock.m_ssThresh),
108 m_initialCWnd (sock.m_initialCWnd),
109 m_lastMeasuredRtt (Seconds (0.0)),
110 m_cnTimeout (sock.m_cnTimeout),
111 m_cnCount (sock.m_cnCount),
114 m_sndBufSize (sock.m_sndBufSize)
219 NS_LOG_LOGIC (
"NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported");
287 " deferring close, state " <<
m_state);
291 NS_LOG_LOGIC (
"NscTcp socket " <<
this <<
" calling disconnect(); moving to CLOSED");
315 std::ostringstream ss;
317 std::string ipstring = ss.str ();
370 return Send (p, flags);
494 struct sockaddr_in sin;
495 size_t sin_len =
sizeof(sin);
509 sin_len =
sizeof(sin);
514 NS_LOG_LOGIC (
"NscTcpSocketImpl " <<
this <<
" accepted connection from "
528 struct sockaddr_in sin;
529 size_t sin_len =
sizeof(sin);
535 NS_LOG_LOGIC (
"NscTcpSocketImpl " <<
this <<
" connected to "
568 newSock->m_nscTcpSocket = newsock;
582 uint8_t buffer[8192];
583 len =
sizeof(buffer);
586 if (err == 0 && len == 0)
599 "during read_data, ns-3 errno set to" <<
m_errno);
628 size_t size, written = 0;
633 size = p->GetSize ();
638 uint8_t *buf =
new uint8_t[size];
639 p->CopyData (buf, size);
652 if ((
size_t)ret < size)
654 p->RemoveAtStart (ret);
669 }
while ((
size_t) ret == size);
681 return CopyObject<NscTcpSocketImpl> (
this);
Ipv4EndPoint * m_endPoint
virtual Ptr< Node > GetNode(void) const
static Ipv4Address Deserialize(const uint8_t buf[4])
keep track of time values and allow control of global simulation resolution
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
virtual int ShutdownSend(void)
std::queue< Ptr< Packet > > m_deliveryQueue
virtual bool is_listening()=0
(abstract) base class of all TcpSockets
virtual int GetSockName(Address &address) const
virtual void SetSndBufSize(uint32_t size)
virtual enum SocketType GetSocketType(void) const
Ipv4Address m_localAddress
void NotifyDataRecv(void)
virtual uint32_t GetAdvWin(void) const
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
virtual void SetAdvWin(uint32_t window)
Ptr< Packet > Recv(void)
Read a single packet from the socket.
void SetDestroyCallback(Callback< void > callback)
enum Socket::SocketErrno GetNativeNs3Errno(int err) const
virtual Time GetConnTimeout(void) const
void AddPacketTag(const Tag &tag) const
void SetAddress(Address addr)
bool SendPendingData(void)
Ipv4Address m_remoteAddress
virtual uint32_t GetConnCount(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
INetStreamSocket * m_nscTcpSocket
uint32_t GetSize(void) const
TracedValue< TcpStates_t > m_state
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
virtual int accept(INetStreamSocket **)=0
static TypeId GetTypeId(void)
virtual void SetConnTimeout(Time timeout)
#define NS_LOG_FUNCTION_NOARGS()
virtual uint32_t GetRcvBufSize(void) const
virtual void SetInitialCwnd(uint32_t cwnd)
virtual void SetPersistTimeout(Time timeout)
InetSocketAddress m_peerAddress
virtual void connect(const char *, int)=0
a polymophic address class
bool ReadPendingData(void)
virtual uint32_t GetSegSize(void) const
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
bool PeekPacketTag(Tag &tag) const
virtual Time GetDelAckTimeout(void) const
void SetNode(Ptr< Node > node)
virtual void SetTcpNoDelay(bool noDelay)
virtual uint32_t GetDelAckMaxCount(void) const
Socket logic for the NSC TCP sockets.
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
Ipv4Address GetLocalAddress(void)
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
virtual int send_data(const void *data, int datalen)=0
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
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void NotifyDataSent(uint32_t size)
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)
virtual bool is_connected()=0
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual uint32_t GetSSThresh(void) const
#define NS_LOG_LOGIC(msg)
virtual void SetRcvBufSize(uint32_t size)
virtual Time GetPersistTimeout(void) const
virtual int Listen(void)
Listen for incoming connections.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void NotifyConnectionSucceeded(void)
Ptr< NscTcpL4Protocol > m_tcp
static InetSocketAddress ConvertFrom(const Address &address)
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual void SetSegSize(uint32_t size)
TracedValue< uint32_t > m_cWnd
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
virtual void SetConnCount(uint32_t count)
#define NS_ASSERT_MSG(condition, message)
void SetTcp(Ptr< NscTcpL4Protocol > tcp)
virtual uint32_t GetRxAvailable(void) const
Ipv4 addresses are stored in host order in this class.
uint32_t m_delAckMaxCount
virtual int getpeername(struct sockaddr *sa, size_t *salen)
virtual int getsockname(struct sockaddr *sa, size_t *salen)
uint16_t GetLocalPort(void)
Address GetAddress(void) const
virtual uint32_t GetSndBufSize(void) const
virtual int Close(void)
Close a socket.
virtual void listen(int)=0
#define NS_LOG_DEBUG(msg)
void ConnectionSucceeded()
virtual enum SocketErrno GetErrno(void) const
virtual void disconnect()=0
uint16_t GetPort(void) const
virtual int read_data(void *buf, int *buflen)=0
Ptr< NscTcpSocketImpl > Copy()
std::queue< Ptr< Packet > > m_txBuffer
virtual void SetDelAckMaxCount(uint32_t count)
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
uint32_t m_advertisedWindowSize
a unique identifier for an interface.
virtual void SetDelAckTimeout(Time timeout)
TypeId SetParent(TypeId tid)
static bool IsMatchingType(const Address &address)
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual ~NscTcpSocketImpl()
virtual void SetSSThresh(uint32_t threshold)
virtual uint32_t GetInitialCwnd(void) const