31 #include "ndn-rtt-estimator.h" 
   32 #include "ns3/simulator.h" 
   33 #include "ns3/double.h" 
   34 #include "ns3/integer.h" 
   35 #include "ns3/uinteger.h" 
   38 NS_LOG_COMPONENT_DEFINE (
"ndn.RttEstimator");
 
   44 NS_OBJECT_ENSURE_REGISTERED (RttEstimator);
 
   47 RttEstimator::GetTypeId (
void)
 
   49   static TypeId tid = TypeId (
"ns3::ndn::RttEstimator")
 
   51     .AddAttribute (
"MaxMultiplier",
 
   52                    "Maximum RTO Multiplier",
 
   54                    MakeUintegerAccessor (&RttEstimator::m_maxMultiplier),
 
   55                    MakeUintegerChecker<uint16_t> ())
 
   56     .AddAttribute (
"InitialEstimation",
 
   57                    "Initial RTT estimation",
 
   58                    TimeValue (Seconds (1.0)),
 
   59                    MakeTimeAccessor (&RttEstimator::m_initialEstimatedRtt),
 
   61     .AddAttribute (
"MinRTO",
 
   62                    "Minimum retransmit timeout value",
 
   63                    TimeValue (Seconds (0.2)), 
 
   67     .AddAttribute (
"MaxRTO",
 
   68                    "Maximum retransmit timeout value",
 
   69                    TimeValue (Seconds (200.0)),
 
   80   NS_LOG_FUNCTION (
this << minRto);
 
   92   NS_LOG_FUNCTION (
this << maxRto);
 
  104   NS_LOG_FUNCTION (
this << estimate);
 
  105   m_currentEstimatedRtt = estimate;
 
  110   return m_currentEstimatedRtt;
 
  115 RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
 
  116   : seq (s), count (c), time (t), retx (false)
 
  118   NS_LOG_FUNCTION (
this);
 
  121 RttHistory::RttHistory (
const RttHistory& h)
 
  122   : seq (h.seq), count (h.count), time (h.time), retx (h.retx)
 
  124   NS_LOG_FUNCTION (
this);
 
  129 RttEstimator::RttEstimator ()
 
  135   NS_LOG_FUNCTION (
this);
 
  140   ObjectBase::ConstructSelf (AttributeConstructionList ());
 
  141   m_currentEstimatedRtt = m_initialEstimatedRtt;
 
  142   NS_LOG_DEBUG (
"Initialize m_currentEstimatedRtt to " << m_currentEstimatedRtt.GetSeconds () << 
" sec.");
 
  145 RttEstimator::RttEstimator (
const RttEstimator& c)
 
  146   : Object (c), m_next (c.m_next),
 
  147     m_maxMultiplier (c.m_maxMultiplier),
 
  148     m_initialEstimatedRtt (c.m_initialEstimatedRtt),
 
  149     m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto), m_maxRto (c.m_maxRto),
 
  150     m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier),
 
  151     m_history (c.m_history)
 
  153   NS_LOG_FUNCTION (
this);
 
  156 RttEstimator::~RttEstimator ()
 
  158   NS_LOG_FUNCTION (
this);
 
  162 RttEstimator::GetInstanceTypeId (
void)
 const 
  169   NS_LOG_FUNCTION (
this << seq << size);
 
  173       m_history.push_back (
RttHistory (seq, size, Simulator::Now () ));
 
  174       m_next = seq + SequenceNumber32 (size); 
 
  178       for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
 
  180           if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32 (i->count))))
 
  184               if ((seq + SequenceNumber32 (size)) > m_next)
 
  186                   m_next = seq + SequenceNumber32 (size);
 
  187                   i->count = ((seq + SequenceNumber32 (size)) - i->seq); 
 
  197   NS_LOG_FUNCTION (
this << ackSeq);
 
  201   Time m = Seconds (0.0);
 
  202   if (m_history.size () == 0) 
return (m);    
 
  204   if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count)))
 
  206       m = Simulator::Now () - h.time; 
 
  211   while(m_history.size () > 0)
 
  214       if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) 
break;               
 
  215       m_history.pop_front (); 
 
  222   NS_LOG_FUNCTION (
this);
 
  230   NS_LOG_FUNCTION (
this);
 
  231   m_multiplier = (m_multiplier*2 < m_maxMultiplier) ? m_multiplier*2 : m_maxMultiplier;
 
  232   NS_LOG_DEBUG (
"Multiplier increased to " << m_multiplier);
 
  237   NS_LOG_FUNCTION (
this);
 
  243   NS_LOG_FUNCTION (
this);
 
  246   m_currentEstimatedRtt = m_initialEstimatedRtt;
 
void SetCurrentEstimate(Time estimate)
Sets the current RTT estimate (forcefully). 
 
virtual void SentSeq(SequenceNumber32 seq, uint32_t size)
Note that a particular sequence has been sent. 
 
virtual void ClearSent()
Clear all history entries. 
 
Time GetMaxRto(void) const 
Get the Maximum RTO. 
 
Helper class to store RTT measurements. 
 
Time GetCurrentEstimate(void) const 
gets the current RTT estimate. 
 
void SetMinRto(Time minRto)
Sets the Minimum RTO. 
 
virtual void Reset()
Resets the estimation to its initial state. 
 
virtual void Measurement(Time t)=0
Add a new measurement to the estimator. 
 
virtual Time AckSeq(SequenceNumber32 ackSeq)
Note that a particular ack sequence has been received. 
 
virtual void IncreaseMultiplier()
Increase the estimation multiplier up to MaxMultiplier. 
 
void SetMaxRto(Time maxRto)
Sets the Maximum RTO. 
 
virtual void ResetMultiplier()
Resets the estimation multiplier to 1. 
 
Time GetMinRto(void) const 
Get the Minimum RTO.