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> ();
453 NS_LOG_INFO (
"Socket " <<
this <<
" << unread rx data during close. Sending reset");
519 NS_ABORT_MSG_IF (flags,
"use of flags is not supported in TcpSocketBase::Send()");
552 return Send (p, flags);
561 NS_ABORT_MSG_IF (flags,
"use of flags is not supported in TcpSocketBase::Recv()");
564 return Create<Packet> ();
567 if (outPacket != 0 && outPacket->
GetSize () != 0)
590 if (packet != 0 && packet->
GetSize () != 0)
808 DoForwardUp (packet, header, port, incomingInterface);
819 uint8_t icmpType, uint8_t icmpCode,
822 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
823 (uint32_t)icmpCode << icmpInfo);
826 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
832 uint8_t icmpType, uint8_t icmpCode,
835 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
836 (uint32_t)icmpCode << icmpInfo);
868 if (
m_rWnd.
Get () == 0 && tcpHeader.GetWindowSize () != 0)
870 NS_LOG_LOGIC (
this <<
" Leaving zerowindow persist state");
873 m_rWnd = tcpHeader.GetWindowSize ();
877 &&
OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->
GetSize ()))
880 " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
881 ":" << tcpHeader.GetSequenceNumber () + packet->
GetSize () <<
963 if (
m_rWnd.
Get () == 0 && tcpHeader.GetWindowSize () != 0)
965 NS_LOG_LOGIC (
this <<
" Leaving zerowindow persist state");
968 m_rWnd = tcpHeader.GetWindowSize ();
972 &&
OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->
GetSize ()))
975 " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
976 ":" << tcpHeader.GetSequenceNumber () + packet->
GetSize () <<
1064 else if (tcpflags == 0)
1076 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1147 packet, tcpHeader, fromAddress, toAddress);
1201 NS_LOG_LOGIC (
"Illegal flag " << std::hex << static_cast<uint32_t> (tcpflags) << std::dec <<
" received. Reset packet is sent.");
1281 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1337 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1394 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1431 NS_LOG_LOGIC (
"Illegal flag " << tcpflags <<
" received. Reset packet is sent.");
1492 NS_LOG_LOGIC (
"TCP " <<
this <<
" calling NotifyNormalClose");
1506 NS_LOG_LOGIC (
"TcpSocketBase " <<
this <<
" scheduling LATO1");
1521 std::vector<Ptr<TcpSocketBase> >::iterator it
1528 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
1542 std::vector<Ptr<TcpSocketBase> >::iterator it
1549 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
1599 NS_LOG_WARN (
"Failed to send empty packet due to null endpoint");
1611 header.SetFlags (flags);
1612 header.SetSequenceNumber (s);
1628 bool hasFin = flags & TcpHeader::FIN;
1662 NS_LOG_LOGIC (
"Schedule retransmission timeout at time "
1688 std::vector<Ptr<TcpSocketBase> >::iterator it
1701 std::vector<Ptr<TcpSocketBase> >::iterator it
1748 if (ipv6->GetRoutingProtocol () == 0)
1759 route = ipv6->GetRoutingProtocol ()->RouteOutput (
Ptr<Packet> (), header, oif, errno_);
1901 NS_LOG_LOGIC (
this <<
" SendDataPacket Schedule ReTxTimeout at time " <<
1906 NS_LOG_LOGIC (
"Send packet via TcpL4Protocol with flags 0x" << std::hex << static_cast<uint32_t> (flags) << std::dec);
1945 uint32_t nPacketsSent = 0;
1949 NS_LOG_LOGIC (
"TcpSocketBase " <<
this <<
" SendPendingData" <<
1967 NS_LOG_LOGIC (
"Invoking Nagle's algorithm. Wait to send.");
1975 NS_LOG_LOGIC (
"SendPendingData sent " << nPacketsSent <<
" packets");
1976 return (nPacketsSent > 0);
2005 uint32_t win =
Window ();
2006 NS_LOG_LOGIC (
"UnAckCount=" << unack <<
", Win=" << win);
2007 return (win < unack) ? 0 : (win - unack);
2023 " pkt size " << p->
GetSize () );
2062 NS_LOG_WARN (
"Why TCP " <<
this <<
" got data after close notification?");
2102 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
2107 NS_LOG_LOGIC (
this <<
" Schedule ReTxTimeout at time " <<
2114 NS_LOG_LOGIC (
this <<
"Enter zerowindow persist state");
2115 NS_LOG_LOGIC (
this <<
"Cancelled ReTxTimeout event which was set to expire at " <<
2138 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
2411 return (!allowBroadcast);