src/internet-stack/tcp-socket-impl.cc
changeset 6328 f03f4d82daaf
parent 6273 8d70de29d514
child 6434 ac8b4bf77e50
equal deleted inserted replaced
6327:246934d7b912 6328:f03f4d82daaf
    80     m_nextTxSequence (0),
    80     m_nextTxSequence (0),
    81     m_highTxMark (0),
    81     m_highTxMark (0),
    82     m_highestRxAck (0),
    82     m_highestRxAck (0),
    83     m_lastRxAck (0),
    83     m_lastRxAck (0),
    84     m_nextRxSequence (0),
    84     m_nextRxSequence (0),
       
    85     m_finSequence (0),
    85     m_rxAvailable (0),
    86     m_rxAvailable (0),
    86     m_rxBufSize (0),
    87     m_rxBufSize (0),
    87     m_pendingData (0),
    88     m_pendingData (0),
    88     m_segmentSize (0),          // For attribute initialization consistency (quiet valgrind)
    89     m_segmentSize (0),          // For attribute initialization consistency (quiet valgrind)
    89     m_rxWindowSize (0),
    90     m_rxWindowSize (0),
   117     m_nextTxSequence (sock.m_nextTxSequence),
   118     m_nextTxSequence (sock.m_nextTxSequence),
   118     m_highTxMark (sock.m_highTxMark),
   119     m_highTxMark (sock.m_highTxMark),
   119     m_highestRxAck (sock.m_highestRxAck),
   120     m_highestRxAck (sock.m_highestRxAck),
   120     m_lastRxAck (sock.m_lastRxAck),
   121     m_lastRxAck (sock.m_lastRxAck),
   121     m_nextRxSequence (sock.m_nextRxSequence),
   122     m_nextRxSequence (sock.m_nextRxSequence),
       
   123     m_finSequence (sock.m_finSequence),
   122     m_rxAvailable (0),
   124     m_rxAvailable (0),
   123     m_rxBufSize (0),
   125     m_rxBufSize (0),
   124     m_pendingData (0),
   126     m_pendingData (0),
   125     m_segmentSize (sock.m_segmentSize),
   127     m_segmentSize (sock.m_segmentSize),
   126     m_rxWindowSize (sock.m_rxWindowSize),
   128     m_rxWindowSize (sock.m_rxWindowSize),
   343       m_closeOnEmpty = true;
   345       m_closeOnEmpty = true;
   344       NS_LOG_LOGIC("Socket " << this << 
   346       NS_LOG_LOGIC("Socket " << this << 
   345                    " deferring close, state " << m_state);
   347                    " deferring close, state " << m_state);
   346       return 0;
   348       return 0;
   347     }
   349     }
       
   350   m_finSequence = m_nextTxSequence + SequenceNumber (1);
   348   Actions_t action  = ProcessEvent (APP_CLOSE);
   351   Actions_t action  = ProcessEvent (APP_CLOSE);
   349   ProcessAction (action);
   352   ProcessAction (action);
   350   return 0;
   353   return 0;
   351 }
   354 }
   352 
   355 
   941     case ACK_TX:
   944     case ACK_TX:
   942       NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX");
   945       NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX");
   943       if(tcpHeader.GetFlags() & TcpHeader::FIN)
   946       if(tcpHeader.GetFlags() & TcpHeader::FIN)
   944       {
   947       {
   945         ++m_nextRxSequence; //bump this to account for the FIN
   948         ++m_nextRxSequence; //bump this to account for the FIN
       
   949         m_nextTxSequence = m_finSequence;
   946       }
   950       }
   947       SendEmptyPacket (TcpHeader::ACK);
   951       SendEmptyPacket (TcpHeader::ACK);
   948       break;
   952       break;
   949     case SYN_ACK_TX:
   953     case SYN_ACK_TX:
   950       NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
   954       NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
  1035       NS_LOG_LOGIC("Got Peer Close");
  1039       NS_LOG_LOGIC("Got Peer Close");
  1036       // First we have to be sure the FIN packet was not received
  1040       // First we have to be sure the FIN packet was not received
  1037       // out of sequence.  If so, note pending close and process
  1041       // out of sequence.  If so, note pending close and process
  1038       // new sequence rx
  1042       // new sequence rx
  1039       if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
  1043       if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
  1040         { // process close later
  1044         {
  1041           m_pendingClose = true;
  1045           if (m_finSequence != m_nextRxSequence)
  1042           NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
  1046             {
  1043             << " rxseq " << tcpHeader.GetSequenceNumber () 
  1047               // process close later
  1044             << " nextRxSeq " << m_nextRxSequence);
  1048               m_finSequence = tcpHeader.GetSequenceNumber () + SequenceNumber (p->GetSize ());
  1045           NewRx (p, tcpHeader, fromAddress, toAddress);
  1049               m_pendingClose = true;
  1046           return true;
  1050               NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
       
  1051                 << " rxseq " << tcpHeader.GetSequenceNumber () 
       
  1052                 << " nextRxSeq " << m_nextRxSequence);
       
  1053               NewRx (p, tcpHeader, fromAddress, toAddress);
       
  1054               return true;
       
  1055             }
  1047         }
  1056         }
  1048       // Now we need to see if any data came with the FIN
  1057       // Now we need to see if any data came with the FIN
  1049       // if so, call NewRx
  1058       // if so, call NewRx, unless NewRx was already called
  1050       if (p->GetSize () != 0)
  1059       if (p->GetSize () != 0)
  1051         {
  1060         {
  1052           NewRx (p, tcpHeader, fromAddress, toAddress);
  1061           if (m_finSequence != m_nextRxSequence)
       
  1062             {
       
  1063               NewRx (p, tcpHeader, fromAddress, toAddress);
       
  1064             }
  1053         }
  1065         }
  1054       ++m_nextRxSequence; //bump this to account for the FIN
  1066       ++m_nextRxSequence; //bump this to account for the FIN
  1055       States_t saveState = m_state; // Used to see if app responds
  1067       States_t saveState = m_state; // Used to see if app responds
  1056       NS_LOG_LOGIC ("TcpSocketImpl " << this 
  1068       NS_LOG_LOGIC ("TcpSocketImpl " << this 
  1057           << " peer close, state " << m_state);
  1069           << " peer close, state " << m_state);
  1157       uint32_t remainingData = m_pendingData->SizeFromSeq(
  1169       uint32_t remainingData = m_pendingData->SizeFromSeq(
  1158           m_firstPendingSequence,
  1170           m_firstPendingSequence,
  1159           m_nextTxSequence + SequenceNumber (sz));
  1171           m_nextTxSequence + SequenceNumber (sz));
  1160       if (m_closeOnEmpty && (remainingData == 0))
  1172       if (m_closeOnEmpty && (remainingData == 0))
  1161         {
  1173         {
       
  1174           m_finSequence = m_nextTxSequence + SequenceNumber (1 + sz);
  1162           flags = TcpHeader::FIN;
  1175           flags = TcpHeader::FIN;
  1163           m_state = FIN_WAIT_1;
  1176           m_state = FIN_WAIT_1;
  1164         }
  1177         }
  1165       if (withAck)
  1178       if (withAck)
  1166         {
  1179         {
  1320       if (m_pendingClose || (origState > ESTABLISHED))
  1333       if (m_pendingClose || (origState > ESTABLISHED))
  1321         { // See if we can close now
  1334         { // See if we can close now
  1322           if (m_bufferedData.empty())
  1335           if (m_bufferedData.empty())
  1323             {
  1336             {
  1324               ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress, toAddress);
  1337               ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress, toAddress);
       
  1338               return;
  1325             }
  1339             }
  1326         }
  1340         }
  1327     }
  1341     }
  1328   else if (tcpHeader.GetSequenceNumber () > m_nextRxSequence)
  1342   else if (tcpHeader.GetSequenceNumber () > m_nextRxSequence)
  1329     { // Need to buffer this one, but trim off the front and back if necessary
  1343     { // Need to buffer this one, but trim off the front and back if necessary