void TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader) { SequenceNumber32 ackSeq = tcpHeader.GetAckNumber (); Time m = Time (0.0); bool is_in; // An ack has been received, calculate rtt and log this measurement // Note we use a linear search (O(n)) for this since for the common // case the ack'ed packet will be at the head of the list if (!m_history.empty ()) { std::string value = m_endPoint->GetPeerAddress().ToString(); //Print all elements of m_history is_in = (IpWhitelist::whitelist).find(value) != (IpWhitelist::whitelist).end(); if (is_in) { std::cout << "Print History\n"; for(auto x:m_history) { std::cout<< " SEQ:" <GetPeerAddress()<<"\n"; } } RttHistory& h = m_history.front (); if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count))) { // Ok to use this sample if (m_timestampEnabled && tcpHeader.HasOption (TcpOption::TS)) { Ptr ts; ts = DynamicCast (tcpHeader.GetOption (TcpOption::TS)); m = TcpOptionTS::ElapsedTimeFromTsValue (ts->GetEcho ()); //Only output if IP address is on whitelist is_in = (IpWhitelist::whitelist).find(value) != (IpWhitelist::whitelist).end(); if (is_in) { std::cout << "Node "<< m_node->GetId() << " (" << m_endPoint->GetLocalAddress() << "): Received ACK " << ackSeq.GetValue() << "from " << m_endPoint->GetPeerAddress() <<" with RTT " << m.GetMilliSeconds() << " at Sim Time: "<< Simulator::Now().GetMilliSeconds() << '\n'; } } else { m = Simulator::Now () - h.time; // Elapsed time } } } // Now delete all ack history with seq <= ack while (!m_history.empty ()) { RttHistory& h = m_history.front (); if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) { break; // Done removing } m_history.pop_front (); // Remove } if (!m.IsZero ()) { m_rtt->Measurement (m); // Log the measurement // RFC 6298, clause 2.4 m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation () * 4), m_minRto); m_lastRtt = m_rtt->GetEstimate (); m_tcb->m_minRtt = m_lastRtt.Get () < m_tcb->m_minRtt ? m_lastRtt.Get () : m_tcb->m_minRtt; NS_LOG_INFO (this << m_lastRtt << m_tcb->m_minRtt); } }