22 #define NS_LOG_APPEND_CONTEXT \
23 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
25 #include "ns3/abort.h"
27 #include "ns3/inet-socket-address.h"
28 #include "ns3/inet6-socket-address.h"
32 #include "ns3/ipv4-interface-address.h"
33 #include "ns3/ipv4-route.h"
34 #include "ns3/ipv6-route.h"
35 #include "ns3/ipv4-routing-protocol.h"
36 #include "ns3/ipv6-routing-protocol.h"
37 #include "ns3/simulation-singleton.h"
38 #include "ns3/simulator.h"
39 #include "ns3/packet.h"
40 #include "ns3/uinteger.h"
41 #include "ns3/double.h"
42 #include "ns3/trace-source-accessor.h"
69 .AddAttribute (
"MaxSegLifetime",
70 "Maximum segment lifetime in seconds, use for TIME_WAIT state transition to CLOSED state",
73 MakeDoubleChecker<double> (0))
74 .AddAttribute (
"MaxWindowSize",
"Max size of advertised window",
77 MakeUintegerChecker<uint16_t> ())
78 .AddAttribute (
"IcmpCallback",
"Callback invoked whenever an icmp error is received on this socket.",
81 MakeCallbackChecker ())
82 .AddAttribute (
"IcmpCallback6",
"Callback invoked whenever an icmpv6 error is received on this socket.",
85 MakeCallbackChecker ())
86 .AddTraceSource (
"RTO",
87 "Retransmission timeout",
89 .AddTraceSource (
"RTT",
92 .AddTraceSource (
"NextTxSequence",
93 "Next sequence number to send (SND.NXT)",
95 .AddTraceSource (
"HighestSequence",
96 "Highest sequence number ever sent in socket's life time",
98 .AddTraceSource (
"State",
101 .AddTraceSource (
"RWND",
102 "Remote side's flow control window",
116 m_nextTxSequence (0),
122 m_errno (ERROR_NOTERROR),
123 m_closeNotified (false),
124 m_closeOnEmpty (false),
125 m_shutdownSend (false),
126 m_shutdownRecv (false),
138 m_dupAckCount (sock.m_dupAckCount),
140 m_delAckMaxCount (sock.m_delAckMaxCount),
141 m_noDelay (sock.m_noDelay),
142 m_cnRetries (sock.m_cnRetries),
143 m_delAckTimeout (sock.m_delAckTimeout),
144 m_persistTimeout (sock.m_persistTimeout),
145 m_cnTimeout (sock.m_cnTimeout),
148 m_node (sock.m_node),
151 m_nextTxSequence (sock.m_nextTxSequence),
152 m_highTxMark (sock.m_highTxMark),
153 m_rxBuffer (sock.m_rxBuffer),
154 m_txBuffer (sock.m_txBuffer),
155 m_state (sock.m_state),
156 m_errno (sock.m_errno),
157 m_closeNotified (sock.m_closeNotified),
158 m_closeOnEmpty (sock.m_closeOnEmpty),
159 m_shutdownSend (sock.m_shutdownSend),
160 m_shutdownRecv (sock.m_shutdownRecv),
161 m_connected (sock.m_connected),
163 m_segmentSize (sock.m_segmentSize),
164 m_maxWinSize (sock.m_maxWinSize),
177 Callback<void, Ptr<Socket>, uint32_t> vPSUI = MakeNullCallback<void, Ptr<Socket>, uint32_t> ();
267 m_tcp->m_sockets.push_back (
this);
281 m_tcp->m_sockets.push_back (
this);
349 m_tcp->m_sockets.push_back (
this);
454 NS_LOG_INFO (
"Socket " <<
this <<
" << unread rx data during close. Sending reset");
520 NS_ABORT_MSG_IF (flags,
"use of flags is not supported in TcpSocketBase::Send()");
553 return Send (p, flags);
562 NS_ABORT_MSG_IF (flags,
"use of flags is not supported in TcpSocketBase::Recv()");
565 return Create<Packet> ();
568 if (outPacket != 0 && outPacket->
GetSize () != 0)
591 if (packet != 0 && packet->
GetSize () != 0)
809 DoForwardUp (packet, header, port, incomingInterface);
820 uint8_t icmpType, uint8_t icmpCode,
823 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
824 (uint32_t)icmpCode << icmpInfo);
827 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
833 uint8_t icmpType, uint8_t icmpCode,
836 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
837 (uint32_t)icmpCode << icmpInfo);
869 if (
m_rWnd.
Get () == 0 && tcpHeader.GetWindowSize () != 0)
871 NS_LOG_LOGIC (
this <<
" Leaving zerowindow persist state");
874 m_rWnd = tcpHeader.GetWindowSize ();
878 &&
OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->
GetSize ()))
881 " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
882 ":" << tcpHeader.GetSequenceNumber () + packet->
GetSize () <<
964 if (
m_rWnd.
Get () == 0 && tcpHeader.GetWindowSize () != 0)
966 NS_LOG_LOGIC (
this <<
" Leaving zerowindow persist state");
969 m_rWnd = tcpHeader.GetWindowSize ();
973 &&
OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->
GetSize ()))
976 " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
977 ":" << tcpHeader.GetSequenceNumber () + packet->
GetSize () <<
1065 else if (tcpflags == 0)
1077 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1148 packet, tcpHeader, fromAddress, toAddress);
1202 NS_LOG_LOGIC (
"Illegal flag " << std::hex << static_cast<uint32_t> (tcpflags) << std::dec <<
" received. Reset packet is sent.");
1282 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1338 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1395 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1432 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1493 NS_LOG_LOGIC (
"TCP " <<
this <<
" calling NotifyNormalClose");
1507 NS_LOG_LOGIC (
"TcpSocketBase " <<
this <<
" scheduling LATO1");
1522 std::vector<Ptr<TcpSocketBase> >::iterator it
1523 = std::find (
m_tcp->m_sockets.begin (),
m_tcp->m_sockets.end (),
this);
1524 if (it !=
m_tcp->m_sockets.end ())
1526 m_tcp->m_sockets.erase (it);
1529 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
1543 std::vector<Ptr<TcpSocketBase> >::iterator it
1544 = std::find (
m_tcp->m_sockets.begin (),
m_tcp->m_sockets.end (),
this);
1545 if (it !=
m_tcp->m_sockets.end ())
1547 m_tcp->m_sockets.erase (it);
1550 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
1600 NS_LOG_WARN (
"Failed to send empty packet due to null endpoint");
1612 header.SetFlags (flags);
1613 header.SetSequenceNumber (s);
1663 NS_LOG_LOGIC (
"Schedule retransmission timeout at time "
1689 std::vector<Ptr<TcpSocketBase> >::iterator it
1690 = std::find (
m_tcp->m_sockets.begin (),
m_tcp->m_sockets.end (),
this);
1691 if (it !=
m_tcp->m_sockets.end ())
1693 m_tcp->m_sockets.erase (it);
1702 std::vector<Ptr<TcpSocketBase> >::iterator it
1703 = std::find (
m_tcp->m_sockets.begin (),
m_tcp->m_sockets.end (),
this);
1704 if (it !=
m_tcp->m_sockets.end ())
1706 m_tcp->m_sockets.erase (it);
1719 if (ipv4->GetRoutingProtocol () == 0)
1730 route = ipv4->GetRoutingProtocol ()->RouteOutput (
Ptr<Packet> (), header, oif, errno_);
1749 if (ipv6->GetRoutingProtocol () == 0)
1760 route = ipv6->GetRoutingProtocol ()->RouteOutput (
Ptr<Packet> (), header, oif, errno_);
1797 m_tcp->m_sockets.push_back (
this);
1902 NS_LOG_LOGIC (
this <<
" SendDataPacket Schedule ReTxTimeout at time " <<
1907 NS_LOG_LOGIC (
"Send packet via TcpL4Protocol with flags 0x" << std::hex << static_cast<uint32_t> (flags) << std::dec);
1918 m_rtt->SentSeq (seq, sz);
1946 uint32_t nPacketsSent = 0;
1950 NS_LOG_LOGIC (
"TcpSocketBase " <<
this <<
" SendPendingData" <<
1968 NS_LOG_LOGIC (
"Invoking Nagle's algorithm. Wait to send.");
1976 NS_LOG_LOGIC (
"SendPendingData sent " << nPacketsSent <<
" packets");
1977 return (nPacketsSent > 0);
2006 uint32_t win =
Window ();
2007 NS_LOG_LOGIC (
"UnAckCount=" << unack <<
", Win=" << win);
2008 return (win < unack) ? 0 : (win - unack);
2024 " pkt size " << p->
GetSize () );
2063 NS_LOG_WARN (
"Why TCP " <<
this <<
" got data after close notification?");
2103 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
2108 NS_LOG_LOGIC (
this <<
" Schedule ReTxTimeout at time " <<
2115 NS_LOG_LOGIC (
this <<
"Enter zerowindow persist state");
2116 NS_LOG_LOGIC (
this <<
"Cancelled ReTxTimeout event which was set to expire at " <<
2139 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
2235 m_rtt->IncreaseMultiplier ();
2412 return (!allowBroadcast);
static Time GetDelayLeft(const EventId &id)
Ipv6Address GetLocalAddress()
Get the local address.
uint32_t RemoveHeader(Header &header)
void SetTclass(uint8_t tclass)
virtual void DupAck(const TcpHeader &t, uint32_t count)=0
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
keep track of time values and allow control of global simulation resolution
bool IsManualIpTtl(void) const
virtual int GetSockName(Address &address) const
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
uint32_t Size(void) const
virtual void EstimateRtt(const TcpHeader &)
#define NS_LOG_FUNCTION(parameters)
virtual void ReceivedAck(Ptr< Packet >, const TcpHeader &)
virtual uint8_t GetIpTtl(void) const
virtual uint16_t AdvertisedWindowSize(void)
bool Add(Ptr< Packet > p, TcpHeader const &tcph)
virtual uint32_t GetSegSize(void) const
uint8_t GetIpTos(void) const
uint32_t SendDataPacket(SequenceNumber32 seq, uint32_t maxSize, bool withAck)
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
void DiscardUpTo(const SequenceNumber32 &seq)
(abstract) base class of all TcpSockets
Ipv4EndPoint * m_endPoint
virtual ~TcpSocketBase(void)
TracedValue< Time > m_lastRtt
void NotifyDataRecv(void)
virtual int ShutdownRecv(void)
uint32_t SizeFromSequence(const SequenceNumber32 &seq) const
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
void ProcessClosing(Ptr< Packet >, const TcpHeader &)
SequenceNumber32 HeadSequence(void) const
Ptr< Packet > Recv(void)
Read a single packet from the socket.
IPv6 layer implementation.
void SetDestroyCallback(Callback< void > callback)
void PeerClose(Ptr< Packet >, const TcpHeader &)
void AddPacketTag(const Tag &tag) const
void SetAddress(Address addr)
virtual void SetPersistTimeout(Time timeout)
virtual int Send(Ptr< Packet > p, uint32_t flags)
virtual bool GetAllowBroadcast(void) const
Query whether broadcast datagram transmissions are allowed.
void NotifyConnectionFailed(void)
static TypeId GetTypeId(void)
uint32_t Available() const
#define NS_ASSERT(condition)
uint32_t MaxBufferSize(void) const
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void AddOptions(TcpHeader &)
uint32_t GetSize(void) const
bool IsManualIpTos(void) const
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
void CancelAllTimers(void)
virtual void ReceivedData(Ptr< Packet >, const TcpHeader &)
void BindToNetDevice(Ptr< NetDevice > netdevice)
virtual uint8_t GetIpv6HopLimit(void) const
#define NS_LOG_FUNCTION_NOARGS()
void ConnectionSucceeded(void)
void SetFinSequence(const SequenceNumber32 &s)
TracedValue< SequenceNumber32 > m_nextTxSequence
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
void CompleteFork(Ptr< Packet >, const TcpHeader &, const Address &fromAddress, const Address &toAdress)
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
virtual Time GetPersistTimeout(void) const
bool NotifyConnectionRequest(const Address &from)
SequenceNumber32 NextRxSequence(void) const
virtual void PersistTimeout(void)
TracedValue< TcpStates_t > m_state
uint32_t m_delAckMaxCount
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
uint16_t GetPeerPort()
Get the peer port.
virtual uint32_t GetRcvBufSize(void) const
virtual bool GetTcpNoDelay(void) const
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
SequenceNumber< uint32_t, int32_t > SequenceNumber32
SequenceNumber32 MaxRxSequence(void) const
virtual void Retransmit(void)
void SetLocalAddress(Ipv6Address addr)
Set the local address.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
virtual uint32_t UnAckDataCount(void)
void ForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
static const char *const TcpStateName[LAST_STATE]
virtual uint32_t GetSndBufSize(void) const
virtual enum SocketType GetSocketType(void) const
uint16_t GetLocalPort()
Get the local port.
Hold an unsigned integer type.
Ipv6EndPoint * m_endPoint6
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
bool OutOfRange(SequenceNumber32 head, SequenceNumber32 tail) const
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Ipv4Address GetLocalAddress(void)
virtual void SetTcpNoDelay(bool noDelay)
This class implements a tag that carries an address of a packet across the socket interface...
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsManualIpv6Tclass(void) const
void NotifyDataSent(uint32_t size)
virtual uint32_t GetConnCount(void) const
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Ipv4Address GetSource(void) const
void SetNextRxSequence(const SequenceNumber32 &s)
A base class for implementation of a stream socket using TCP.
Ptr< RttEstimator > m_rtt
#define NS_LOG_LOGIC(msg)
virtual void SetTcp(Ptr< TcpL4Protocol > tcp)
Ptr< TcpL4Protocol > m_tcp
void SetHopLimit(uint8_t hopLimit)
void SetMaxBufferSize(uint32_t n)
virtual int ShutdownSend(void)
void NotifyConnectionSucceeded(void)
uint32_t Available(void) const
void ProcessListen(Ptr< Packet >, const TcpHeader &, const Address &, const Address &)
Access to the Ipv4 forwarding table, interfaces, and configuration.
void SetMaxBufferSize(uint32_t s)
bool IsManualIpv6HopLimit(void) const
virtual void SetDelAckMaxCount(uint32_t count)
void NotifyNormalClose(void)
Ptr< Packet > Extract(uint32_t maxSize)
static InetSocketAddress ConvertFrom(const Address &address)
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void ProcessEstablished(Ptr< Packet >, const TcpHeader &)
virtual void SetNode(Ptr< Node > node)
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
virtual uint32_t BytesInFlight(void)
uint8_t GetIpv6Tclass(void) const
bool Add(Ptr< Packet > p)
virtual int Connect(const Address &address)
void ProcessSynRcvd(Ptr< Packet >, const TcpHeader &, const Address &, const Address &)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
static Ipv4Address GetZero(void)
void SetPeer(Ipv4Address address, uint16_t port)
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t > callback)
Set the reception callback.
virtual uint32_t AvailableWindow(void)
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
virtual Ptr< TcpSocketBase > Fork(void)=0
virtual void SetRtt(Ptr< RttEstimator > rtt)
virtual void ReTxTimeout(void)
TracedValue< SequenceNumber32 > m_highTxMark
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SendEmptyPacket(uint8_t flags)
void SetDataSentCallback(Callback< void, Ptr< Socket >, uint32_t > dataSent)
Notify application when a packet has been sent from transport protocol (non-standard socket call) ...
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
void SetLocalAddress(Ipv4Address address)
virtual void SetSndBufSize(uint32_t size)
virtual void SetDelAckTimeout(Time timeout)
virtual void NewAck(SequenceNumber32 const &seq)
void DeallocateEndPoint(void)
Describes an IPv6 address.
uint32_t MaxBufferSize(void) const
Ipv4 addresses are stored in host order in this class.
Ptr< NetDevice > m_boundnetdevice
TracedValue< Time > m_rto
uint16_t GetLocalPort(void)
Ipv6Address GetPeerAddress()
Get the peer address.
virtual void SetConnCount(uint32_t count)
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port)
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Ipv4Address GetPeerAddress(void)
static bool IsMatchingType(const Address &addr)
If the address match.
uint16_t GetPeerPort(void)
uint16_t GetPort(void) const
Get the port.
virtual uint32_t Window(void)
void ProcessSynSent(Ptr< Packet >, const TcpHeader &)
virtual enum SocketErrno GetErrno(void) const
void ProcessWait(Ptr< Packet >, const TcpHeader &)
virtual void ReadOptions(const TcpHeader &)
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
virtual void SetSegSize(uint32_t size)
#define NS_LOG_ERROR(msg)
uint16_t GetPort(void) const
void ProcessLastAck(Ptr< Packet >, const TcpHeader &)
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.
void CloseAndNotify(void)
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
virtual Ptr< Node > GetNode(void) const
virtual void SetRcvBufSize(uint32_t size)
virtual Time GetDelAckTimeout(void) const
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
virtual void DelAckTimeout(void)
virtual void LastAckTimeout(void)
uint32_t Size(void) const
Hold an floating point type.
virtual void DoForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
bool IsExpired(void) const
Ptr< T > GetObject(void) const
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
a unique identifier for an interface.
void NotifySend(uint32_t spaceAvailable)
bool IsIpv4MappedAddress()
If the address is an IPv4-mapped address.
TypeId SetParent(TypeId tid)
bool SendPendingData(bool withAck=false)
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
TracedValue< uint32_t > m_rWnd
static bool IsMatchingType(const Address &address)
void NotifyErrorClose(void)
virtual void DoRetransmit(void)
virtual uint32_t GetDelAckMaxCount(void) const
virtual void SetConnTimeout(Time timeout)
void SetPeer(Ipv6Address addr, uint16_t port)
Set the peer informations (address and port).
virtual Time GetConnTimeout(void) const
void SetHeadSequence(const SequenceNumber32 &seq)
virtual uint32_t GetTxAvailable(void) const
virtual uint32_t GetRxAvailable(void) const
Ptr< Packet > CopyFromSequence(uint32_t numBytes, const SequenceNumber32 &seq)