28 #include "ndn-rtt-mean-deviation.h"
29 #include "ns3/simulator.h"
30 #include "ns3/double.h"
31 #include "ns3/integer.h"
32 #include "ns3/uinteger.h"
35 NS_LOG_COMPONENT_DEFINE (
"ndn.RttMeanDeviation");
43 NS_OBJECT_ENSURE_REGISTERED (RttMeanDeviation);
46 RttMeanDeviation::GetTypeId (
void)
48 static TypeId tid = TypeId (
"ns3::ndn::RttMeanDeviation")
49 .SetParent<RttEstimator> ()
50 .AddConstructor<RttMeanDeviation> ()
51 .AddAttribute (
"Gain",
52 "Gain used in estimating the RTT (smoothed RTT), must be 0 < Gain < 1",
54 MakeDoubleAccessor (&RttMeanDeviation::m_gain),
55 MakeDoubleChecker<double> ())
56 .AddAttribute (
"Gain2",
57 "Gain2 used in estimating the RTT (variance), must be 0 < Gain2 < 1",
59 MakeDoubleAccessor (&RttMeanDeviation::m_gain2),
60 MakeDoubleChecker<double> ())
65 RttMeanDeviation::RttMeanDeviation() :
68 NS_LOG_FUNCTION (
this);
71 RttMeanDeviation::RttMeanDeviation (
const RttMeanDeviation& c)
72 : RttEstimator (c), m_gain (c.m_gain), m_gain2 (c.m_gain2), m_variance (c.m_variance)
74 NS_LOG_FUNCTION (
this);
78 RttMeanDeviation::GetInstanceTypeId (
void)
const
85 NS_LOG_FUNCTION (
this << m);
88 Time err (m - m_currentEstimatedRtt);
89 double gErr = err.ToDouble (Time::S) * m_gain;
90 m_currentEstimatedRtt += Time::FromDouble (gErr, Time::S);
91 Time difference = Abs (err) - m_variance;
92 NS_LOG_DEBUG (
"m_variance += " << Time::FromDouble (difference.ToDouble (Time::S) * m_gain2, Time::S));
93 m_variance += Time::FromDouble (difference.ToDouble (Time::S) * m_gain2, Time::S);
97 m_currentEstimatedRtt = m;
100 m_variance = Seconds (m.ToDouble (Time::S) / 2);
101 NS_LOG_DEBUG (
"(first sample) m_variance += " << m);
108 NS_LOG_FUNCTION (
this);
110 double retval = std::min (m_maxRto.ToDouble (Time::S),
111 std::max (m_multiplier*m_minRto.ToDouble (Time::S),
112 m_multiplier*(m_currentEstimatedRtt.ToDouble (Time::S) + 4 * m_variance.ToDouble (Time::S))));
114 NS_LOG_DEBUG (
"RetransmitTimeout: return " << retval);
116 return Seconds (retval);
119 Ptr<RttEstimator> RttMeanDeviation::Copy ()
const
121 NS_LOG_FUNCTION (
this);
122 return CopyObject<RttMeanDeviation> (
this);
127 NS_LOG_FUNCTION (
this);
129 m_variance = Seconds (0);
133 void RttMeanDeviation::Gain (
double g)
135 NS_LOG_FUNCTION (
this);
136 NS_ASSERT_MSG( (g > 0) && (g < 1),
"RttMeanDeviation: Gain must be less than 1 and greater than 0" );
142 NS_LOG_FUNCTION (
this << seq << size);
144 RttHistory_t::iterator i;
145 for (i = m_history.begin (); i != m_history.end (); ++i)
155 if (i == m_history.end())
156 m_history.push_back (
RttHistory (seq, size, Simulator::Now () ));
161 NS_LOG_FUNCTION (
this << ackSeq);
165 Time m = Seconds (0.0);
166 if (m_history.size () == 0)
return (m);
168 for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
170 if (ackSeq == i->seq)
173 m = Simulator::Now () - i->time;
void Measurement(Time measure)
Add a new measurement to the estimator.
Time RetransmitTimeout()
Returns the estimated RTO.
Time AckSeq(SequenceNumber32 ackSeq)
Note that a particular ack sequence has been received.
Helper class to store RTT measurements.
void SentSeq(SequenceNumber32 seq, uint32_t size)
Note that a particular sequence has been sent.
void Reset()
Resets the estimation to its initial state.
virtual void Reset()
Resets the estimation to its initial state.
virtual void ResetMultiplier()
Resets the estimation multiplier to 1.