|
|
| 39 |
#include "ns3/packet.h" |
39 |
#include "ns3/packet.h" |
| 40 |
#include "ns3/uinteger.h" |
40 |
#include "ns3/uinteger.h" |
| 41 |
#include "ns3/double.h" |
41 |
#include "ns3/double.h" |
|
|
42 |
#include "ns3/pointer.h" |
| 42 |
#include "ns3/trace-source-accessor.h" |
43 |
#include "ns3/trace-source-accessor.h" |
| 43 |
#include "tcp-socket-base.h" |
44 |
#include "tcp-socket-base.h" |
| 44 |
#include "tcp-l4-protocol.h" |
45 |
#include "tcp-l4-protocol.h" |
|
|
| 106 |
MakeTimeAccessor (&TcpSocketBase::SetClockGranularity, |
107 |
MakeTimeAccessor (&TcpSocketBase::SetClockGranularity, |
| 107 |
&TcpSocketBase::GetClockGranularity), |
108 |
&TcpSocketBase::GetClockGranularity), |
| 108 |
MakeTimeChecker ()) |
109 |
MakeTimeChecker ()) |
|
|
110 |
.AddAttribute ("TxBuffer", |
| 111 |
"TCP Tx buffer", |
| 112 |
PointerValue (), |
| 113 |
MakePointerAccessor (&TcpSocketBase::GetTxBuffer), |
| 114 |
MakePointerChecker<TcpTxBuffer> ()) |
| 115 |
.AddAttribute ("RxBuffer", |
| 116 |
"TCP Rx buffer", |
| 117 |
PointerValue (), |
| 118 |
MakePointerAccessor (&TcpSocketBase::GetRxBuffer), |
| 119 |
MakePointerChecker<TcpRxBuffer> ()) |
| 109 |
.AddTraceSource ("RTO", |
120 |
.AddTraceSource ("RTO", |
| 110 |
"Retransmission timeout", |
121 |
"Retransmission timeout", |
| 111 |
MakeTraceSourceAccessor (&TcpSocketBase::m_rto), |
122 |
MakeTraceSourceAccessor (&TcpSocketBase::m_rto), |
|
|
| 164 |
|
175 |
|
| 165 |
{ |
176 |
{ |
| 166 |
NS_LOG_FUNCTION (this); |
177 |
NS_LOG_FUNCTION (this); |
|
|
178 |
m_rxBuffer = CreateObject<TcpRxBuffer> (); |
| 179 |
m_txBuffer = CreateObject<TcpTxBuffer> (); |
| 167 |
} |
180 |
} |
| 168 |
|
181 |
|
| 169 |
TcpSocketBase::TcpSocketBase (const TcpSocketBase& sock) |
182 |
TcpSocketBase::TcpSocketBase (const TcpSocketBase& sock) |
|
|
| 184 |
m_rtt (0), |
197 |
m_rtt (0), |
| 185 |
m_nextTxSequence (sock.m_nextTxSequence), |
198 |
m_nextTxSequence (sock.m_nextTxSequence), |
| 186 |
m_highTxMark (sock.m_highTxMark), |
199 |
m_highTxMark (sock.m_highTxMark), |
| 187 |
m_rxBuffer (sock.m_rxBuffer), |
|
|
| 188 |
m_txBuffer (sock.m_txBuffer), |
| 189 |
m_state (sock.m_state), |
200 |
m_state (sock.m_state), |
| 190 |
m_errno (sock.m_errno), |
201 |
m_errno (sock.m_errno), |
| 191 |
m_closeNotified (sock.m_closeNotified), |
202 |
m_closeNotified (sock.m_closeNotified), |
|
|
| 219 |
SetDataSentCallback (vPSUI); |
230 |
SetDataSentCallback (vPSUI); |
| 220 |
SetSendCallback (vPSUI); |
231 |
SetSendCallback (vPSUI); |
| 221 |
SetRecvCallback (vPS); |
232 |
SetRecvCallback (vPS); |
|
|
233 |
m_txBuffer = CopyObject (sock.m_txBuffer); |
| 234 |
m_rxBuffer = CopyObject (sock.m_rxBuffer); |
| 222 |
} |
235 |
} |
| 223 |
|
236 |
|
| 224 |
TcpSocketBase::~TcpSocketBase (void) |
237 |
TcpSocketBase::~TcpSocketBase (void) |
|
|
| 501 |
/// \internal |
514 |
/// \internal |
| 502 |
/// First we check to see if there is any unread rx data. |
515 |
/// First we check to see if there is any unread rx data. |
| 503 |
/// \bugid{426} claims we should send reset in this case. |
516 |
/// \bugid{426} claims we should send reset in this case. |
| 504 |
if (m_rxBuffer.Size () != 0) |
517 |
if (m_rxBuffer->Size () != 0) |
| 505 |
{ |
518 |
{ |
| 506 |
NS_LOG_INFO ("Socket " << this << " << unread rx data during close. Sending reset"); |
519 |
NS_LOG_INFO ("Socket " << this << " << unread rx data during close. Sending reset"); |
| 507 |
SendRST (); |
520 |
SendRST (); |
| 508 |
return 0; |
521 |
return 0; |
| 509 |
} |
522 |
} |
| 510 |
|
523 |
|
| 511 |
if (m_txBuffer.SizeFromSequence (m_nextTxSequence) > 0) |
524 |
if (m_txBuffer->SizeFromSequence (m_nextTxSequence) > 0) |
| 512 |
{ // App close with pending data must wait until all data transmitted |
525 |
{ // App close with pending data must wait until all data transmitted |
| 513 |
if (m_closeOnEmpty == false) |
526 |
if (m_closeOnEmpty == false) |
| 514 |
{ |
527 |
{ |
|
|
| 531 |
m_closeOnEmpty = true; |
544 |
m_closeOnEmpty = true; |
| 532 |
//if buffer is already empty, send a fin now |
545 |
//if buffer is already empty, send a fin now |
| 533 |
//otherwise fin will go when buffer empties. |
546 |
//otherwise fin will go when buffer empties. |
| 534 |
if (m_txBuffer.Size () == 0) |
547 |
if (m_txBuffer->Size () == 0) |
| 535 |
{ |
548 |
{ |
| 536 |
if (m_state == ESTABLISHED || m_state == CLOSE_WAIT) |
549 |
if (m_state == ESTABLISHED || m_state == CLOSE_WAIT) |
| 537 |
{ |
550 |
{ |
|
|
| 573 |
if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) |
586 |
if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) |
| 574 |
{ |
587 |
{ |
| 575 |
// Store the packet into Tx buffer |
588 |
// Store the packet into Tx buffer |
| 576 |
if (!m_txBuffer.Add (p)) |
589 |
if (!m_txBuffer->Add (p)) |
| 577 |
{ // TxBuffer overflow, send failed |
590 |
{ // TxBuffer overflow, send failed |
| 578 |
m_errno = ERROR_MSGSIZE; |
591 |
m_errno = ERROR_MSGSIZE; |
| 579 |
return -1; |
592 |
return -1; |
|
|
| 584 |
return -1; |
597 |
return -1; |
| 585 |
} |
598 |
} |
| 586 |
// Submit the data to lower layers |
599 |
// Submit the data to lower layers |
| 587 |
NS_LOG_LOGIC ("txBufSize=" << m_txBuffer.Size () << " state " << TcpStateName[m_state]); |
600 |
NS_LOG_LOGIC ("txBufSize=" << m_txBuffer->Size () << " state " << TcpStateName[m_state]); |
| 588 |
if (m_state == ESTABLISHED || m_state == CLOSE_WAIT) |
601 |
if (m_state == ESTABLISHED || m_state == CLOSE_WAIT) |
| 589 |
{ // Try to send the data out |
602 |
{ // Try to send the data out |
| 590 |
SendPendingData (m_connected); |
603 |
SendPendingData (m_connected); |
|
|
| 612 |
{ |
625 |
{ |
| 613 |
NS_LOG_FUNCTION (this); |
626 |
NS_LOG_FUNCTION (this); |
| 614 |
NS_ABORT_MSG_IF (flags, "use of flags is not supported in TcpSocketBase::Recv()"); |
627 |
NS_ABORT_MSG_IF (flags, "use of flags is not supported in TcpSocketBase::Recv()"); |
| 615 |
if (m_rxBuffer.Size () == 0 && m_state == CLOSE_WAIT) |
628 |
if (m_rxBuffer->Size () == 0 && m_state == CLOSE_WAIT) |
| 616 |
{ |
629 |
{ |
| 617 |
return Create<Packet> (); // Send EOF on connection close |
630 |
return Create<Packet> (); // Send EOF on connection close |
| 618 |
} |
631 |
} |
| 619 |
Ptr<Packet> outPacket = m_rxBuffer.Extract (maxSize); |
632 |
Ptr<Packet> outPacket = m_rxBuffer->Extract (maxSize); |
| 620 |
if (outPacket != 0 && outPacket->GetSize () != 0) |
633 |
if (outPacket != 0 && outPacket->GetSize () != 0) |
| 621 |
{ |
634 |
{ |
| 622 |
SocketAddressTag tag; |
635 |
SocketAddressTag tag; |
|
|
| 663 |
TcpSocketBase::GetTxAvailable (void) const |
676 |
TcpSocketBase::GetTxAvailable (void) const |
| 664 |
{ |
677 |
{ |
| 665 |
NS_LOG_FUNCTION (this); |
678 |
NS_LOG_FUNCTION (this); |
| 666 |
return m_txBuffer.Available (); |
679 |
return m_txBuffer->Available (); |
| 667 |
} |
680 |
} |
| 668 |
|
681 |
|
| 669 |
/* Inherit from Socket class: Get the max number of bytes an app can read */ |
682 |
/* Inherit from Socket class: Get the max number of bytes an app can read */ |
|
|
| 671 |
TcpSocketBase::GetRxAvailable (void) const |
684 |
TcpSocketBase::GetRxAvailable (void) const |
| 672 |
{ |
685 |
{ |
| 673 |
NS_LOG_FUNCTION (this); |
686 |
NS_LOG_FUNCTION (this); |
| 674 |
return m_rxBuffer.Available (); |
687 |
return m_rxBuffer->Available (); |
| 675 |
} |
688 |
} |
| 676 |
|
689 |
|
| 677 |
/* Inherit from Socket class: Return local address:port */ |
690 |
/* Inherit from Socket class: Return local address:port */ |
|
|
| 847 |
} |
860 |
} |
| 848 |
if (m_state == LAST_ACK || m_state == CLOSING || m_state == CLOSE_WAIT) |
861 |
if (m_state == LAST_ACK || m_state == CLOSING || m_state == CLOSE_WAIT) |
| 849 |
{ // In LAST_ACK and CLOSING states, it only wait for an ACK and the |
862 |
{ // In LAST_ACK and CLOSING states, it only wait for an ACK and the |
| 850 |
// sequence number must equals to m_rxBuffer.NextRxSequence () |
863 |
// sequence number must equals to m_rxBuffer->NextRxSequence () |
| 851 |
return (m_rxBuffer.NextRxSequence () != head); |
864 |
return (m_rxBuffer->NextRxSequence () != head); |
| 852 |
} |
865 |
} |
| 853 |
|
866 |
|
| 854 |
// In all other cases, check if the sequence number is in range |
867 |
// In all other cases, check if the sequence number is in range |
| 855 |
return (tail < m_rxBuffer.NextRxSequence () || m_rxBuffer.MaxRxSequence () <= head); |
868 |
return (tail < m_rxBuffer->NextRxSequence () || m_rxBuffer->MaxRxSequence () <= head); |
| 856 |
} |
869 |
} |
| 857 |
|
870 |
|
| 858 |
/* Function called by the L3 protocol when it received a packet to pass on to |
871 |
/* Function called by the L3 protocol when it received a packet to pass on to |
|
|
| 944 |
NS_LOG_LOGIC ("At state " << TcpStateName[m_state] << |
957 |
NS_LOG_LOGIC ("At state " << TcpStateName[m_state] << |
| 945 |
" received packet of seq [" << tcpHeader.GetSequenceNumber () << |
958 |
" received packet of seq [" << tcpHeader.GetSequenceNumber () << |
| 946 |
":" << tcpHeader.GetSequenceNumber () + packet->GetSize () << |
959 |
":" << tcpHeader.GetSequenceNumber () + packet->GetSize () << |
| 947 |
") out of range [" << m_rxBuffer.NextRxSequence () << ":" << |
960 |
") out of range [" << m_rxBuffer->NextRxSequence () << ":" << |
| 948 |
m_rxBuffer.MaxRxSequence () << ")"); |
961 |
m_rxBuffer->MaxRxSequence () << ")"); |
| 949 |
// Acknowledgement should be sent for all unacceptable packets (RFC793, p.69) |
962 |
// Acknowledgement should be sent for all unacceptable packets (RFC793, p.69) |
| 950 |
if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST)) |
963 |
if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST)) |
| 951 |
{ |
964 |
{ |
|
|
| 974 |
TcpHeader h; |
987 |
TcpHeader h; |
| 975 |
h.SetFlags (TcpHeader::RST); |
988 |
h.SetFlags (TcpHeader::RST); |
| 976 |
h.SetSequenceNumber (m_nextTxSequence); |
989 |
h.SetSequenceNumber (m_nextTxSequence); |
| 977 |
h.SetAckNumber (m_rxBuffer.NextRxSequence ()); |
990 |
h.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 978 |
h.SetSourcePort (tcpHeader.GetDestinationPort ()); |
991 |
h.SetSourcePort (tcpHeader.GetDestinationPort ()); |
| 979 |
h.SetDestinationPort (tcpHeader.GetSourcePort ()); |
992 |
h.SetDestinationPort (tcpHeader.GetSourcePort ()); |
| 980 |
h.SetWindowSize (AdvertisedWindowSize ()); |
993 |
h.SetWindowSize (AdvertisedWindowSize ()); |
|
|
| 1048 |
NS_LOG_LOGIC ("At state " << TcpStateName[m_state] << |
1061 |
NS_LOG_LOGIC ("At state " << TcpStateName[m_state] << |
| 1049 |
" received packet of seq [" << tcpHeader.GetSequenceNumber () << |
1062 |
" received packet of seq [" << tcpHeader.GetSequenceNumber () << |
| 1050 |
":" << tcpHeader.GetSequenceNumber () + packet->GetSize () << |
1063 |
":" << tcpHeader.GetSequenceNumber () + packet->GetSize () << |
| 1051 |
") out of range [" << m_rxBuffer.NextRxSequence () << ":" << |
1064 |
") out of range [" << m_rxBuffer->NextRxSequence () << ":" << |
| 1052 |
m_rxBuffer.MaxRxSequence () << ")"); |
1065 |
m_rxBuffer->MaxRxSequence () << ")"); |
| 1053 |
// Acknowledgement should be sent for all unacceptable packets (RFC793, p.69) |
1066 |
// Acknowledgement should be sent for all unacceptable packets (RFC793, p.69) |
| 1054 |
if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST)) |
1067 |
if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST)) |
| 1055 |
{ |
1068 |
{ |
|
|
| 1078 |
TcpHeader h; |
1091 |
TcpHeader h; |
| 1079 |
h.SetFlags (TcpHeader::RST); |
1092 |
h.SetFlags (TcpHeader::RST); |
| 1080 |
h.SetSequenceNumber (m_nextTxSequence); |
1093 |
h.SetSequenceNumber (m_nextTxSequence); |
| 1081 |
h.SetAckNumber (m_rxBuffer.NextRxSequence ()); |
1094 |
h.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 1082 |
h.SetSourcePort (tcpHeader.GetDestinationPort ()); |
1095 |
h.SetSourcePort (tcpHeader.GetDestinationPort ()); |
| 1083 |
h.SetDestinationPort (tcpHeader.GetSourcePort ()); |
1096 |
h.SetDestinationPort (tcpHeader.GetSourcePort ()); |
| 1084 |
h.SetWindowSize (AdvertisedWindowSize ()); |
1097 |
h.SetWindowSize (AdvertisedWindowSize ()); |
|
|
| 1138 |
else if (tcpflags == 0) |
1151 |
else if (tcpflags == 0) |
| 1139 |
{ // No flags means there is only data |
1152 |
{ // No flags means there is only data |
| 1140 |
ReceivedData (packet, tcpHeader); |
1153 |
ReceivedData (packet, tcpHeader); |
| 1141 |
if (m_rxBuffer.Finished ()) |
1154 |
if (m_rxBuffer->Finished ()) |
| 1142 |
{ |
1155 |
{ |
| 1143 |
PeerClose (packet, tcpHeader); |
1156 |
PeerClose (packet, tcpHeader); |
| 1144 |
} |
1157 |
} |
|
|
| 1164 |
if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK)) |
1177 |
if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK)) |
| 1165 |
{ // Ignore if no ACK flag |
1178 |
{ // Ignore if no ACK flag |
| 1166 |
} |
1179 |
} |
| 1167 |
else if (tcpHeader.GetAckNumber () < m_txBuffer.HeadSequence ()) |
1180 |
else if (tcpHeader.GetAckNumber () < m_txBuffer->HeadSequence ()) |
| 1168 |
{ // Case 1: Old ACK, ignored. |
1181 |
{ // Case 1: Old ACK, ignored. |
| 1169 |
NS_LOG_LOGIC ("Ignored ack of " << tcpHeader.GetAckNumber ()); |
1182 |
NS_LOG_LOGIC ("Ignored ack of " << tcpHeader.GetAckNumber ()); |
| 1170 |
} |
1183 |
} |
| 1171 |
else if (tcpHeader.GetAckNumber () == m_txBuffer.HeadSequence ()) |
1184 |
else if (tcpHeader.GetAckNumber () == m_txBuffer->HeadSequence ()) |
| 1172 |
{ // Case 2: Potentially a duplicated ACK |
1185 |
{ // Case 2: Potentially a duplicated ACK |
| 1173 |
if (tcpHeader.GetAckNumber () < m_nextTxSequence && packet->GetSize() == 0) |
1186 |
if (tcpHeader.GetAckNumber () < m_nextTxSequence && packet->GetSize() == 0) |
| 1174 |
{ |
1187 |
{ |
|
|
| 1178 |
// otherwise, the ACK is precisely equal to the nextTxSequence |
1191 |
// otherwise, the ACK is precisely equal to the nextTxSequence |
| 1179 |
NS_ASSERT (tcpHeader.GetAckNumber () <= m_nextTxSequence); |
1192 |
NS_ASSERT (tcpHeader.GetAckNumber () <= m_nextTxSequence); |
| 1180 |
} |
1193 |
} |
| 1181 |
else if (tcpHeader.GetAckNumber () > m_txBuffer.HeadSequence ()) |
1194 |
else if (tcpHeader.GetAckNumber () > m_txBuffer->HeadSequence ()) |
| 1182 |
{ // Case 3: New ACK, reset m_dupAckCount and update m_txBuffer |
1195 |
{ // Case 3: New ACK, reset m_dupAckCount and update m_txBuffer |
| 1183 |
NS_LOG_LOGIC ("New ack of " << tcpHeader.GetAckNumber ()); |
1196 |
NS_LOG_LOGIC ("New ack of " << tcpHeader.GetAckNumber ()); |
| 1184 |
NewAck (tcpHeader.GetAckNumber ()); |
1197 |
NewAck (tcpHeader.GetAckNumber ()); |
|
|
| 1248 |
NS_LOG_INFO ("SYN_SENT -> SYN_RCVD"); |
1261 |
NS_LOG_INFO ("SYN_SENT -> SYN_RCVD"); |
| 1249 |
m_state = SYN_RCVD; |
1262 |
m_state = SYN_RCVD; |
| 1250 |
m_cnCount = m_cnRetries; |
1263 |
m_cnCount = m_cnRetries; |
| 1251 |
m_rxBuffer.SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
1264 |
m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
| 1252 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
1265 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
| 1253 |
} |
1266 |
} |
| 1254 |
else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK) |
1267 |
else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK) |
|
|
| 1258 |
m_state = ESTABLISHED; |
1271 |
m_state = ESTABLISHED; |
| 1259 |
m_connected = true; |
1272 |
m_connected = true; |
| 1260 |
m_retxEvent.Cancel (); |
1273 |
m_retxEvent.Cancel (); |
| 1261 |
m_rxBuffer.SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
1274 |
m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
| 1262 |
m_highTxMark = ++m_nextTxSequence; |
1275 |
m_highTxMark = ++m_nextTxSequence; |
| 1263 |
m_txBuffer.SetHeadSequence (m_nextTxSequence); |
1276 |
m_txBuffer->SetHeadSequence (m_nextTxSequence); |
| 1264 |
SendEmptyPacket (TcpHeader::ACK); |
1277 |
SendEmptyPacket (TcpHeader::ACK); |
| 1265 |
SendPendingData (m_connected); |
1278 |
SendPendingData (m_connected); |
| 1266 |
Simulator::ScheduleNow (&TcpSocketBase::ConnectionSucceeded, this); |
1279 |
Simulator::ScheduleNow (&TcpSocketBase::ConnectionSucceeded, this); |
|
|
| 1300 |
m_connected = true; |
1313 |
m_connected = true; |
| 1301 |
m_retxEvent.Cancel (); |
1314 |
m_retxEvent.Cancel (); |
| 1302 |
m_highTxMark = ++m_nextTxSequence; |
1315 |
m_highTxMark = ++m_nextTxSequence; |
| 1303 |
m_txBuffer.SetHeadSequence (m_nextTxSequence); |
1316 |
m_txBuffer->SetHeadSequence (m_nextTxSequence); |
| 1304 |
if (m_endPoint) |
1317 |
if (m_endPoint) |
| 1305 |
{ |
1318 |
{ |
| 1306 |
m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), |
1319 |
m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), |
|
|
| 1324 |
} |
1337 |
} |
| 1325 |
else if (tcpflags == TcpHeader::SYN) |
1338 |
else if (tcpflags == TcpHeader::SYN) |
| 1326 |
{ // Probably the peer lost my SYN+ACK |
1339 |
{ // Probably the peer lost my SYN+ACK |
| 1327 |
m_rxBuffer.SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
1340 |
m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1)); |
| 1328 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
1341 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
| 1329 |
} |
1342 |
} |
| 1330 |
else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK)) |
1343 |
else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK)) |
| 1331 |
{ |
1344 |
{ |
| 1332 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer.NextRxSequence ()) |
1345 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ()) |
| 1333 |
{ // In-sequence FIN before connection complete. Set up connection and close. |
1346 |
{ // In-sequence FIN before connection complete. Set up connection and close. |
| 1334 |
m_connected = true; |
1347 |
m_connected = true; |
| 1335 |
m_retxEvent.Cancel (); |
1348 |
m_retxEvent.Cancel (); |
| 1336 |
m_highTxMark = ++m_nextTxSequence; |
1349 |
m_highTxMark = ++m_nextTxSequence; |
| 1337 |
m_txBuffer.SetHeadSequence (m_nextTxSequence); |
1350 |
m_txBuffer->SetHeadSequence (m_nextTxSequence); |
| 1338 |
if (m_endPoint) |
1351 |
if (m_endPoint) |
| 1339 |
{ |
1352 |
{ |
| 1340 |
m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), |
1353 |
m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (), |
|
|
| 1385 |
else if (tcpflags == TcpHeader::ACK) |
1398 |
else if (tcpflags == TcpHeader::ACK) |
| 1386 |
{ // Process the ACK, and if in FIN_WAIT_1, conditionally move to FIN_WAIT_2 |
1399 |
{ // Process the ACK, and if in FIN_WAIT_1, conditionally move to FIN_WAIT_2 |
| 1387 |
ReceivedAck (packet, tcpHeader); |
1400 |
ReceivedAck (packet, tcpHeader); |
| 1388 |
if (m_state == FIN_WAIT_1 && m_txBuffer.Size () == 0 |
1401 |
if (m_state == FIN_WAIT_1 && m_txBuffer->Size () == 0 |
| 1389 |
&& tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1)) |
1402 |
&& tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1)) |
| 1390 |
{ // This ACK corresponds to the FIN sent |
1403 |
{ // This ACK corresponds to the FIN sent |
| 1391 |
NS_LOG_INFO ("FIN_WAIT_1 -> FIN_WAIT_2"); |
1404 |
NS_LOG_INFO ("FIN_WAIT_1 -> FIN_WAIT_2"); |
|
|
| 1398 |
{ // Process the ACK first |
1411 |
{ // Process the ACK first |
| 1399 |
ReceivedAck (packet, tcpHeader); |
1412 |
ReceivedAck (packet, tcpHeader); |
| 1400 |
} |
1413 |
} |
| 1401 |
m_rxBuffer.SetFinSequence (tcpHeader.GetSequenceNumber ()); |
1414 |
m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber ()); |
| 1402 |
} |
1415 |
} |
| 1403 |
else if (tcpflags == TcpHeader::SYN || tcpflags == (TcpHeader::SYN | TcpHeader::ACK)) |
1416 |
else if (tcpflags == TcpHeader::SYN || tcpflags == (TcpHeader::SYN | TcpHeader::ACK)) |
| 1404 |
{ // Duplicated SYN or SYN+ACK, possibly due to spurious retransmission |
1417 |
{ // Duplicated SYN or SYN+ACK, possibly due to spurious retransmission |
|
|
| 1416 |
} |
1429 |
} |
| 1417 |
|
1430 |
|
| 1418 |
// Check if the close responder sent an in-sequence FIN, if so, respond ACK |
1431 |
// Check if the close responder sent an in-sequence FIN, if so, respond ACK |
| 1419 |
if ((m_state == FIN_WAIT_1 || m_state == FIN_WAIT_2) && m_rxBuffer.Finished ()) |
1432 |
if ((m_state == FIN_WAIT_1 || m_state == FIN_WAIT_2) && m_rxBuffer->Finished ()) |
| 1420 |
{ |
1433 |
{ |
| 1421 |
if (m_state == FIN_WAIT_1) |
1434 |
if (m_state == FIN_WAIT_1) |
| 1422 |
{ |
1435 |
{ |
| 1423 |
NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING"); |
1436 |
NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING"); |
| 1424 |
m_state = CLOSING; |
1437 |
m_state = CLOSING; |
| 1425 |
if (m_txBuffer.Size () == 0 |
1438 |
if (m_txBuffer->Size () == 0 |
| 1426 |
&& tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1)) |
1439 |
&& tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1)) |
| 1427 |
{ // This ACK corresponds to the FIN sent |
1440 |
{ // This ACK corresponds to the FIN sent |
| 1428 |
TimeWait (); |
1441 |
TimeWait (); |
|
|
| 1451 |
|
1464 |
|
| 1452 |
if (tcpflags == TcpHeader::ACK) |
1465 |
if (tcpflags == TcpHeader::ACK) |
| 1453 |
{ |
1466 |
{ |
| 1454 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer.NextRxSequence ()) |
1467 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ()) |
| 1455 |
{ // This ACK corresponds to the FIN sent |
1468 |
{ // This ACK corresponds to the FIN sent |
| 1456 |
TimeWait (); |
1469 |
TimeWait (); |
| 1457 |
} |
1470 |
} |
|
|
| 1487 |
} |
1500 |
} |
| 1488 |
else if (tcpflags == TcpHeader::ACK) |
1501 |
else if (tcpflags == TcpHeader::ACK) |
| 1489 |
{ |
1502 |
{ |
| 1490 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer.NextRxSequence ()) |
1503 |
if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ()) |
| 1491 |
{ // This ACK corresponds to the FIN sent. This socket closed peacefully. |
1504 |
{ // This ACK corresponds to the FIN sent. This socket closed peacefully. |
| 1492 |
CloseAndNotify (); |
1505 |
CloseAndNotify (); |
| 1493 |
} |
1506 |
} |
|
|
| 1515 |
NS_LOG_FUNCTION (this << tcpHeader); |
1528 |
NS_LOG_FUNCTION (this << tcpHeader); |
| 1516 |
|
1529 |
|
| 1517 |
// Ignore all out of range packets |
1530 |
// Ignore all out of range packets |
| 1518 |
if (tcpHeader.GetSequenceNumber () < m_rxBuffer.NextRxSequence () |
1531 |
if (tcpHeader.GetSequenceNumber () < m_rxBuffer->NextRxSequence () |
| 1519 |
|| tcpHeader.GetSequenceNumber () > m_rxBuffer.MaxRxSequence ()) |
1532 |
|| tcpHeader.GetSequenceNumber () > m_rxBuffer->MaxRxSequence ()) |
| 1520 |
{ |
1533 |
{ |
| 1521 |
return; |
1534 |
return; |
| 1522 |
} |
1535 |
} |
| 1523 |
// For any case, remember the FIN position in rx buffer first |
1536 |
// For any case, remember the FIN position in rx buffer first |
| 1524 |
m_rxBuffer.SetFinSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ())); |
1537 |
m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ())); |
| 1525 |
NS_LOG_LOGIC ("Accepted FIN at seq " << tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ())); |
1538 |
NS_LOG_LOGIC ("Accepted FIN at seq " << tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ())); |
| 1526 |
// If there is any piggybacked data, process it |
1539 |
// If there is any piggybacked data, process it |
| 1527 |
if (p->GetSize ()) |
1540 |
if (p->GetSize ()) |
|
|
| 1529 |
ReceivedData (p, tcpHeader); |
1542 |
ReceivedData (p, tcpHeader); |
| 1530 |
} |
1543 |
} |
| 1531 |
// Return if FIN is out of sequence, otherwise move to CLOSE_WAIT state by DoPeerClose |
1544 |
// Return if FIN is out of sequence, otherwise move to CLOSE_WAIT state by DoPeerClose |
| 1532 |
if (!m_rxBuffer.Finished ()) |
1545 |
if (!m_rxBuffer->Finished ()) |
| 1533 |
{ |
1546 |
{ |
| 1534 |
return; |
1547 |
return; |
| 1535 |
} |
1548 |
} |
|
|
| 1684 |
|
1697 |
|
| 1685 |
header.SetFlags (flags); |
1698 |
header.SetFlags (flags); |
| 1686 |
header.SetSequenceNumber (s); |
1699 |
header.SetSequenceNumber (s); |
| 1687 |
header.SetAckNumber (m_rxBuffer.NextRxSequence ()); |
1700 |
header.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 1688 |
if (m_endPoint != 0) |
1701 |
if (m_endPoint != 0) |
| 1689 |
{ |
1702 |
{ |
| 1690 |
header.SetSourcePort (m_endPoint->GetLocalPort ()); |
1703 |
header.SetSourcePort (m_endPoint->GetLocalPort ()); |
|
|
| 1879 |
m_cnCount = m_cnRetries; |
1892 |
m_cnCount = m_cnRetries; |
| 1880 |
SetupCallback (); |
1893 |
SetupCallback (); |
| 1881 |
// Set the sequence number and send SYN+ACK |
1894 |
// Set the sequence number and send SYN+ACK |
| 1882 |
m_rxBuffer.SetNextRxSequence (h.GetSequenceNumber () + SequenceNumber32 (1)); |
1895 |
m_rxBuffer->SetNextRxSequence (h.GetSequenceNumber () + SequenceNumber32 (1)); |
| 1883 |
|
1896 |
|
| 1884 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
1897 |
SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK); |
| 1885 |
} |
1898 |
} |
|
|
| 1906 |
NS_LOG_FUNCTION (this << seq << maxSize << withAck); |
1919 |
NS_LOG_FUNCTION (this << seq << maxSize << withAck); |
| 1907 |
|
1920 |
|
| 1908 |
bool isRetransmission = false; |
1921 |
bool isRetransmission = false; |
| 1909 |
if ( seq == m_txBuffer.HeadSequence () ) |
1922 |
if ( seq == m_txBuffer->HeadSequence () ) |
| 1910 |
{ |
1923 |
{ |
| 1911 |
isRetransmission = true; |
1924 |
isRetransmission = true; |
| 1912 |
} |
1925 |
} |
| 1913 |
|
1926 |
|
| 1914 |
Ptr<Packet> p = m_txBuffer.CopyFromSequence (maxSize, seq); |
1927 |
Ptr<Packet> p = m_txBuffer->CopyFromSequence (maxSize, seq); |
| 1915 |
uint32_t sz = p->GetSize (); // Size of packet |
1928 |
uint32_t sz = p->GetSize (); // Size of packet |
| 1916 |
uint8_t flags = withAck ? TcpHeader::ACK : 0; |
1929 |
uint8_t flags = withAck ? TcpHeader::ACK : 0; |
| 1917 |
uint32_t remainingData = m_txBuffer.SizeFromSequence (seq + SequenceNumber32 (sz)); |
1930 |
uint32_t remainingData = m_txBuffer->SizeFromSequence (seq + SequenceNumber32 (sz)); |
| 1918 |
|
1931 |
|
| 1919 |
/* |
1932 |
/* |
| 1920 |
* Add tags for each socket option. |
1933 |
* Add tags for each socket option. |
|
|
| 1967 |
TcpHeader header; |
1980 |
TcpHeader header; |
| 1968 |
header.SetFlags (flags); |
1981 |
header.SetFlags (flags); |
| 1969 |
header.SetSequenceNumber (seq); |
1982 |
header.SetSequenceNumber (seq); |
| 1970 |
header.SetAckNumber (m_rxBuffer.NextRxSequence ()); |
1983 |
header.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 1971 |
if (m_endPoint) |
1984 |
if (m_endPoint) |
| 1972 |
{ |
1985 |
{ |
| 1973 |
header.SetSourcePort (m_endPoint->GetLocalPort ()); |
1986 |
header.SetSourcePort (m_endPoint->GetLocalPort ()); |
|
|
| 2041 |
TcpSocketBase::SendPendingData (bool withAck) |
2054 |
TcpSocketBase::SendPendingData (bool withAck) |
| 2042 |
{ |
2055 |
{ |
| 2043 |
NS_LOG_FUNCTION (this << withAck); |
2056 |
NS_LOG_FUNCTION (this << withAck); |
| 2044 |
if (m_txBuffer.Size () == 0) |
2057 |
if (m_txBuffer->Size () == 0) |
| 2045 |
{ |
2058 |
{ |
| 2046 |
return false; // Nothing to send |
2059 |
return false; // Nothing to send |
| 2047 |
|
2060 |
|
|
|
| 2052 |
return false; // Is this the right way to handle this condition? |
2065 |
return false; // Is this the right way to handle this condition? |
| 2053 |
} |
2066 |
} |
| 2054 |
uint32_t nPacketsSent = 0; |
2067 |
uint32_t nPacketsSent = 0; |
| 2055 |
while (m_txBuffer.SizeFromSequence (m_nextTxSequence)) |
2068 |
while (m_txBuffer->SizeFromSequence (m_nextTxSequence)) |
| 2056 |
{ |
2069 |
{ |
| 2057 |
uint32_t w = AvailableWindow (); // Get available window size |
2070 |
uint32_t w = AvailableWindow (); // Get available window size |
| 2058 |
NS_LOG_LOGIC ("TcpSocketBase " << this << " SendPendingData" << |
2071 |
NS_LOG_LOGIC ("TcpSocketBase " << this << " SendPendingData" << |
|
|
| 2060 |
" rxwin " << m_rWnd << |
2073 |
" rxwin " << m_rWnd << |
| 2061 |
" segsize " << m_segmentSize << |
2074 |
" segsize " << m_segmentSize << |
| 2062 |
" nextTxSeq " << m_nextTxSequence << |
2075 |
" nextTxSeq " << m_nextTxSequence << |
| 2063 |
" highestRxAck " << m_txBuffer.HeadSequence () << |
2076 |
" highestRxAck " << m_txBuffer->HeadSequence () << |
| 2064 |
" pd->Size " << m_txBuffer.Size () << |
2077 |
" pd->Size " << m_txBuffer->Size () << |
| 2065 |
" pd->SFS " << m_txBuffer.SizeFromSequence (m_nextTxSequence)); |
2078 |
" pd->SFS " << m_txBuffer->SizeFromSequence (m_nextTxSequence)); |
| 2066 |
// Stop sending if we need to wait for a larger Tx window (prevent silly window syndrome) |
2079 |
// Stop sending if we need to wait for a larger Tx window (prevent silly window syndrome) |
| 2067 |
if (w < m_segmentSize && m_txBuffer.SizeFromSequence (m_nextTxSequence) > w) |
2080 |
if (w < m_segmentSize && m_txBuffer->SizeFromSequence (m_nextTxSequence) > w) |
| 2068 |
{ |
2081 |
{ |
| 2069 |
break; // No more |
2082 |
break; // No more |
| 2070 |
} |
2083 |
} |
| 2071 |
// Nagle's algorithm (RFC896): Hold off sending if there is unacked data |
2084 |
// Nagle's algorithm (RFC896): Hold off sending if there is unacked data |
| 2072 |
// in the buffer and the amount of data to send is less than one segment |
2085 |
// in the buffer and the amount of data to send is less than one segment |
| 2073 |
if (!m_noDelay && UnAckDataCount () > 0 |
2086 |
if (!m_noDelay && UnAckDataCount () > 0 |
| 2074 |
&& m_txBuffer.SizeFromSequence (m_nextTxSequence) < m_segmentSize) |
2087 |
&& m_txBuffer->SizeFromSequence (m_nextTxSequence) < m_segmentSize) |
| 2075 |
{ |
2088 |
{ |
| 2076 |
NS_LOG_LOGIC ("Invoking Nagle's algorithm. Wait to send."); |
2089 |
NS_LOG_LOGIC ("Invoking Nagle's algorithm. Wait to send."); |
| 2077 |
break; |
2090 |
break; |
|
|
| 2089 |
TcpSocketBase::UnAckDataCount () |
2102 |
TcpSocketBase::UnAckDataCount () |
| 2090 |
{ |
2103 |
{ |
| 2091 |
NS_LOG_FUNCTION (this); |
2104 |
NS_LOG_FUNCTION (this); |
| 2092 |
return m_nextTxSequence.Get () - m_txBuffer.HeadSequence (); |
2105 |
return m_nextTxSequence.Get () - m_txBuffer->HeadSequence (); |
| 2093 |
} |
2106 |
} |
| 2094 |
|
2107 |
|
| 2095 |
uint32_t |
2108 |
uint32_t |
| 2096 |
TcpSocketBase::BytesInFlight () |
2109 |
TcpSocketBase::BytesInFlight () |
| 2097 |
{ |
2110 |
{ |
| 2098 |
NS_LOG_FUNCTION (this); |
2111 |
NS_LOG_FUNCTION (this); |
| 2099 |
return m_highTxMark.Get () - m_txBuffer.HeadSequence (); |
2112 |
return m_highTxMark.Get () - m_txBuffer->HeadSequence (); |
| 2100 |
} |
2113 |
} |
| 2101 |
|
2114 |
|
| 2102 |
uint32_t |
2115 |
uint32_t |
|
|
| 2119 |
uint16_t |
2132 |
uint16_t |
| 2120 |
TcpSocketBase::AdvertisedWindowSize () |
2133 |
TcpSocketBase::AdvertisedWindowSize () |
| 2121 |
{ |
2134 |
{ |
| 2122 |
uint32_t w = m_rxBuffer.MaxBufferSize () - m_rxBuffer.Size (); |
2135 |
uint32_t w = m_rxBuffer->MaxBufferSize () - m_rxBuffer->Size (); |
| 2123 |
|
2136 |
|
| 2124 |
w >>= m_sndScaleFactor; |
2137 |
w >>= m_sndScaleFactor; |
| 2125 |
|
2138 |
|
|
|
| 2142 |
" pkt size " << p->GetSize () ); |
2155 |
" pkt size " << p->GetSize () ); |
| 2143 |
|
2156 |
|
| 2144 |
// Put into Rx buffer |
2157 |
// Put into Rx buffer |
| 2145 |
SequenceNumber32 expectedSeq = m_rxBuffer.NextRxSequence (); |
2158 |
SequenceNumber32 expectedSeq = m_rxBuffer->NextRxSequence (); |
| 2146 |
if (!m_rxBuffer.Add (p, tcpHeader)) |
2159 |
if (!m_rxBuffer->Add (p, tcpHeader)) |
| 2147 |
{ // Insert failed: No data or RX buffer full |
2160 |
{ // Insert failed: No data or RX buffer full |
| 2148 |
SendEmptyPacket (TcpHeader::ACK); |
2161 |
SendEmptyPacket (TcpHeader::ACK); |
| 2149 |
return; |
2162 |
return; |
| 2150 |
} |
2163 |
} |
| 2151 |
// Now send a new ACK packet acknowledging all received and delivered data |
2164 |
// Now send a new ACK packet acknowledging all received and delivered data |
| 2152 |
if (m_rxBuffer.Size () > m_rxBuffer.Available () || m_rxBuffer.NextRxSequence () > expectedSeq + p->GetSize ()) |
2165 |
if (m_rxBuffer->Size () > m_rxBuffer->Available () || m_rxBuffer->NextRxSequence () > expectedSeq + p->GetSize ()) |
| 2153 |
{ // A gap exists in the buffer, or we filled a gap: Always ACK |
2166 |
{ // A gap exists in the buffer, or we filled a gap: Always ACK |
| 2154 |
SendEmptyPacket (TcpHeader::ACK); |
2167 |
SendEmptyPacket (TcpHeader::ACK); |
| 2155 |
} |
2168 |
} |
|
|
| 2169 |
} |
2182 |
} |
| 2170 |
} |
2183 |
} |
| 2171 |
// Notify app to receive if necessary |
2184 |
// Notify app to receive if necessary |
| 2172 |
if (expectedSeq < m_rxBuffer.NextRxSequence ()) |
2185 |
if (expectedSeq < m_rxBuffer->NextRxSequence ()) |
| 2173 |
{ // NextRxSeq advanced, we have something to send to the app |
2186 |
{ // NextRxSeq advanced, we have something to send to the app |
| 2174 |
if (!m_shutdownRecv) |
2187 |
if (!m_shutdownRecv) |
| 2175 |
{ |
2188 |
{ |
|
|
| 2182 |
} |
2195 |
} |
| 2183 |
// If we received FIN before and now completed all "holes" in rx buffer, |
2196 |
// If we received FIN before and now completed all "holes" in rx buffer, |
| 2184 |
// invoke peer close procedure |
2197 |
// invoke peer close procedure |
| 2185 |
if (m_rxBuffer.Finished () && (tcpHeader.GetFlags () & TcpHeader::FIN) == 0) |
2198 |
if (m_rxBuffer->Finished () && (tcpHeader.GetFlags () & TcpHeader::FIN) == 0) |
| 2186 |
{ |
2199 |
{ |
| 2187 |
DoPeerClose (); |
2200 |
DoPeerClose (); |
| 2188 |
} |
2201 |
} |
|
|
| 2277 |
} |
2290 |
} |
| 2278 |
// Note the highest ACK and tell app to send more |
2291 |
// Note the highest ACK and tell app to send more |
| 2279 |
NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack << |
2292 |
NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack << |
| 2280 |
" numberAck " << (ack - m_txBuffer.HeadSequence ())); // Number bytes ack'ed |
2293 |
" numberAck " << (ack - m_txBuffer->HeadSequence ())); // Number bytes ack'ed |
| 2281 |
m_txBuffer.DiscardUpTo (ack); |
2294 |
m_txBuffer->DiscardUpTo (ack); |
| 2282 |
if (GetTxAvailable () > 0) |
2295 |
if (GetTxAvailable () > 0) |
| 2283 |
{ |
2296 |
{ |
| 2284 |
NotifySend (GetTxAvailable ()); |
2297 |
NotifySend (GetTxAvailable ()); |
|
|
| 2287 |
{ |
2300 |
{ |
| 2288 |
m_nextTxSequence = ack; // If advanced |
2301 |
m_nextTxSequence = ack; // If advanced |
| 2289 |
} |
2302 |
} |
| 2290 |
if (m_txBuffer.Size () == 0 && m_state != FIN_WAIT_1 && m_state != CLOSING) |
2303 |
if (m_txBuffer->Size () == 0 && m_state != FIN_WAIT_1 && m_state != CLOSING) |
| 2291 |
{ // No retransmit timer if no data to retransmit |
2304 |
{ // No retransmit timer if no data to retransmit |
| 2292 |
NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " << |
2305 |
NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " << |
| 2293 |
(Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ()); |
2306 |
(Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ()); |
|
|
| 2309 |
return; |
2322 |
return; |
| 2310 |
} |
2323 |
} |
| 2311 |
// If all data are received (non-closing socket and nothing to send), just return |
2324 |
// If all data are received (non-closing socket and nothing to send), just return |
| 2312 |
if (m_state <= ESTABLISHED && m_txBuffer.HeadSequence () >= m_highTxMark) |
2325 |
if (m_state <= ESTABLISHED && m_txBuffer->HeadSequence () >= m_highTxMark) |
| 2313 |
{ |
2326 |
{ |
| 2314 |
return; |
2327 |
return; |
| 2315 |
} |
2328 |
} |
|
|
| 2348 |
{ |
2361 |
{ |
| 2349 |
NS_LOG_LOGIC ("PersistTimeout expired at " << Simulator::Now ().GetSeconds ()); |
2362 |
NS_LOG_LOGIC ("PersistTimeout expired at " << Simulator::Now ().GetSeconds ()); |
| 2350 |
m_persistTimeout = std::min (Seconds (60), Time (2 * m_persistTimeout)); // max persist timeout = 60s |
2363 |
m_persistTimeout = std::min (Seconds (60), Time (2 * m_persistTimeout)); // max persist timeout = 60s |
| 2351 |
Ptr<Packet> p = m_txBuffer.CopyFromSequence (1, m_nextTxSequence); |
2364 |
Ptr<Packet> p = m_txBuffer->CopyFromSequence (1, m_nextTxSequence); |
| 2352 |
TcpHeader tcpHeader; |
2365 |
TcpHeader tcpHeader; |
| 2353 |
tcpHeader.SetSequenceNumber (m_nextTxSequence); |
2366 |
tcpHeader.SetSequenceNumber (m_nextTxSequence); |
| 2354 |
tcpHeader.SetAckNumber (m_rxBuffer.NextRxSequence ()); |
2367 |
tcpHeader.SetAckNumber (m_rxBuffer->NextRxSequence ()); |
| 2355 |
tcpHeader.SetWindowSize (AdvertisedWindowSize ()); |
2368 |
tcpHeader.SetWindowSize (AdvertisedWindowSize ()); |
| 2356 |
if (m_endPoint != 0) |
2369 |
if (m_endPoint != 0) |
| 2357 |
{ |
2370 |
{ |
|
|
| 2384 |
void |
2397 |
void |
| 2385 |
TcpSocketBase::Retransmit () |
2398 |
TcpSocketBase::Retransmit () |
| 2386 |
{ |
2399 |
{ |
| 2387 |
m_nextTxSequence = m_txBuffer.HeadSequence (); // Start from highest Ack |
2400 |
m_nextTxSequence = m_txBuffer->HeadSequence (); // Start from highest Ack |
| 2388 |
m_dupAckCount = 0; |
2401 |
m_dupAckCount = 0; |
| 2389 |
DoRetransmit (); // Retransmit the packet |
2402 |
DoRetransmit (); // Retransmit the packet |
| 2390 |
} |
2403 |
} |
|
|
| 2407 |
return; |
2420 |
return; |
| 2408 |
} |
2421 |
} |
| 2409 |
// Retransmit non-data packet: Only if in FIN_WAIT_1 or CLOSING state |
2422 |
// Retransmit non-data packet: Only if in FIN_WAIT_1 or CLOSING state |
| 2410 |
if (m_txBuffer.Size () == 0) |
2423 |
if (m_txBuffer->Size () == 0) |
| 2411 |
{ |
2424 |
{ |
| 2412 |
if (m_state == FIN_WAIT_1 || m_state == CLOSING) |
2425 |
if (m_state == FIN_WAIT_1 || m_state == CLOSING) |
| 2413 |
{ // Must have lost FIN, re-send |
2426 |
{ // Must have lost FIN, re-send |
|
|
| 2416 |
return; |
2429 |
return; |
| 2417 |
} |
2430 |
} |
| 2418 |
// Retransmit a data packet: Call SendDataPacket |
2431 |
// Retransmit a data packet: Call SendDataPacket |
| 2419 |
NS_LOG_LOGIC ("TcpSocketBase " << this << " retxing seq " << m_txBuffer.HeadSequence ()); |
2432 |
NS_LOG_LOGIC ("TcpSocketBase " << this << " retxing seq " << m_txBuffer->HeadSequence ()); |
| 2420 |
uint32_t sz = SendDataPacket (m_txBuffer.HeadSequence (), m_segmentSize, true); |
2433 |
uint32_t sz = SendDataPacket (m_txBuffer->HeadSequence (), m_segmentSize, true); |
| 2421 |
// In case of RTO, advance m_nextTxSequence |
2434 |
// In case of RTO, advance m_nextTxSequence |
| 2422 |
m_nextTxSequence = std::max (m_nextTxSequence.Get (), m_txBuffer.HeadSequence () + sz); |
2435 |
m_nextTxSequence = std::max (m_nextTxSequence.Get (), m_txBuffer->HeadSequence () + sz); |
| 2423 |
|
2436 |
|
| 2424 |
} |
2437 |
} |
| 2425 |
|
2438 |
|
|
|
| 2451 |
void |
2464 |
void |
| 2452 |
TcpSocketBase::SetSndBufSize (uint32_t size) |
2465 |
TcpSocketBase::SetSndBufSize (uint32_t size) |
| 2453 |
{ |
2466 |
{ |
| 2454 |
m_txBuffer.SetMaxBufferSize (size); |
2467 |
m_txBuffer->SetMaxBufferSize (size); |
| 2455 |
} |
2468 |
} |
| 2456 |
|
2469 |
|
| 2457 |
uint32_t |
2470 |
uint32_t |
| 2458 |
TcpSocketBase::GetSndBufSize (void) const |
2471 |
TcpSocketBase::GetSndBufSize (void) const |
| 2459 |
{ |
2472 |
{ |
| 2460 |
return m_txBuffer.MaxBufferSize (); |
2473 |
return m_txBuffer->MaxBufferSize (); |
| 2461 |
} |
2474 |
} |
| 2462 |
|
2475 |
|
| 2463 |
void |
2476 |
void |
| 2464 |
TcpSocketBase::SetRcvBufSize (uint32_t size) |
2477 |
TcpSocketBase::SetRcvBufSize (uint32_t size) |
| 2465 |
{ |
2478 |
{ |
| 2466 |
m_rxBuffer.SetMaxBufferSize (size); |
2479 |
m_rxBuffer->SetMaxBufferSize (size); |
| 2467 |
} |
2480 |
} |
| 2468 |
|
2481 |
|
| 2469 |
uint32_t |
2482 |
uint32_t |
| 2470 |
TcpSocketBase::GetRcvBufSize (void) const |
2483 |
TcpSocketBase::GetRcvBufSize (void) const |
| 2471 |
{ |
2484 |
{ |
| 2472 |
return m_rxBuffer.MaxBufferSize (); |
2485 |
return m_rxBuffer->MaxBufferSize (); |
| 2473 |
} |
2486 |
} |
| 2474 |
|
2487 |
|
| 2475 |
void |
2488 |
void |
|
|
| 2640 |
TcpSocketBase::CalculateWScale () const |
2653 |
TcpSocketBase::CalculateWScale () const |
| 2641 |
{ |
2654 |
{ |
| 2642 |
NS_LOG_FUNCTION (this); |
2655 |
NS_LOG_FUNCTION (this); |
| 2643 |
uint32_t maxSpace = m_rxBuffer.MaxBufferSize (); |
2656 |
uint32_t maxSpace = m_rxBuffer->MaxBufferSize (); |
| 2644 |
uint8_t scale = 0; |
2657 |
uint8_t scale = 0; |
| 2645 |
|
2658 |
|
| 2646 |
while (maxSpace > m_maxWinSize) |
2659 |
while (maxSpace > m_maxWinSize) |
|
|
| 2656 |
} |
2669 |
} |
| 2657 |
|
2670 |
|
| 2658 |
NS_LOG_INFO ("Node " << m_node->GetId () << " calculated wscale factor of " << |
2671 |
NS_LOG_INFO ("Node " << m_node->GetId () << " calculated wscale factor of " << |
| 2659 |
static_cast<int> (scale) << " for buffer size " << m_rxBuffer.MaxBufferSize ()); |
2672 |
static_cast<int> (scale) << " for buffer size " << m_rxBuffer->MaxBufferSize ()); |
| 2660 |
return scale; |
2673 |
return scale; |
| 2661 |
} |
2674 |
} |
| 2662 |
|
2675 |
|
|
|
| 2733 |
return m_clockGranularity; |
2746 |
return m_clockGranularity; |
| 2734 |
} |
2747 |
} |
| 2735 |
|
2748 |
|
|
|
2749 |
Ptr<TcpTxBuffer> |
| 2750 |
TcpSocketBase::GetTxBuffer (void) const |
| 2751 |
{ |
| 2752 |
return m_txBuffer; |
| 2753 |
} |
| 2754 |
|
| 2755 |
Ptr<TcpRxBuffer> |
| 2756 |
TcpSocketBase::GetRxBuffer (void) const |
| 2757 |
{ |
| 2758 |
return m_rxBuffer; |
| 2759 |
} |
| 2760 |
|
| 2761 |
|
| 2736 |
//RttHistory methods |
2762 |
//RttHistory methods |
| 2737 |
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t) |
2763 |
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t) |
| 2738 |
: seq (s), count (c), time (t), retx (false) |
2764 |
: seq (s), count (c), time (t), retx (false) |