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> ();
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
1529 NS_LOG_LOGIC (
this <<
" Cancelled ReTxTimeout event which was set to expire at " <<
1543 std::vector<Ptr<TcpSocketBase> >::iterator 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);
1629 bool hasFin = flags & TcpHeader::FIN;
1663 NS_LOG_LOGIC (
"Schedule retransmission timeout at time "
1689 std::vector<Ptr<TcpSocketBase> >::iterator it
1702 std::vector<Ptr<TcpSocketBase> >::iterator it
1749 if (ipv6->GetRoutingProtocol () == 0)
1760 route = ipv6->GetRoutingProtocol ()->RouteOutput (
Ptr<Packet> (), header, oif, errno_);
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);
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 " <<
2412 return (!allowBroadcast);