30 #include "rtt-estimator.h"
31 #include "ns3/simulator.h"
32 #include "ns3/double.h"
33 #include "ns3/integer.h"
34 #include "ns3/uinteger.h"
41 NS_OBJECT_ENSURE_REGISTERED (RttEstimator);
44 RttEstimator::GetTypeId (
void)
46 static TypeId tid = TypeId (
"ns3::RttEstimator")
48 .AddAttribute (
"MaxMultiplier",
49 "Maximum RTO Multiplier",
51 MakeUintegerAccessor (&RttEstimator::m_maxMultiplier),
52 MakeUintegerChecker<uint16_t> ())
53 .AddAttribute (
"InitialEstimation",
54 "Initial RTT estimation",
56 MakeTimeAccessor (&RttEstimator::m_initialEstimatedRtt),
58 .AddAttribute (
"MinRTO",
59 "Minimum retransmit timeout value",
83 m_currentEstimatedRtt = estimate;
88 return m_currentEstimatedRtt;
94 : seq (s), count (c), time (t), retx (false)
99 RttHistory::RttHistory (
const RttHistory& h)
100 : seq (h.seq), count (h.count), time (h.time), retx (h.retx)
107 RttEstimator::RttEstimator ()
108 : m_next (1), m_history (),
118 m_currentEstimatedRtt = m_initialEstimatedRtt;
122 RttEstimator::RttEstimator (
const RttEstimator& c)
123 : Object (c), m_next (c.m_next), m_history (c.m_history),
124 m_maxMultiplier (c.m_maxMultiplier),
125 m_initialEstimatedRtt (c.m_initialEstimatedRtt),
126 m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto),
127 m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier)
132 RttEstimator::~RttEstimator ()
154 for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
163 i->count = ((seq + SequenceNumber32 (size)) - i->seq);
178 if (m_history.size () == 0)
return (m);
187 while(m_history.size () > 0)
191 m_history.pop_front ();
207 m_multiplier = (m_multiplier*2 < m_maxMultiplier) ? m_multiplier*2 : m_maxMultiplier;
208 NS_LOG_DEBUG (
"Multiplier increased to " << m_multiplier);
222 m_currentEstimatedRtt = m_initialEstimatedRtt;
237 RttMeanDeviation::GetTypeId (
void)
241 .AddConstructor<RttMeanDeviation> ()
242 .AddAttribute (
"Gain",
243 "Gain used in estimating the RTT, must be 0 < Gain < 1",
245 MakeDoubleAccessor (&RttMeanDeviation::m_gain),
246 MakeDoubleChecker<double> ())
251 RttMeanDeviation::RttMeanDeviation() :
257 RttMeanDeviation::RttMeanDeviation (
const RttMeanDeviation& c)
258 : RttEstimator (c), m_gain (c.m_gain), m_variance (c.m_variance)
274 Time err (m - m_currentEstimatedRtt);
275 double gErr = err.
ToDouble (Time::S) * m_gain;
277 Time difference = Abs (err) - m_variance;
283 m_currentEstimatedRtt = m;
296 int64_t temp = m_currentEstimatedRtt.
ToInteger (Time::MS) + 4 * m_variance.
ToInteger (Time::MS);
297 if (temp < m_minRto.
ToInteger (Time::MS))
301 temp = temp * m_multiplier;
310 return CopyObject<RttMeanDeviation> (
this);
323 NS_ASSERT_MSG( (g > 0) && (g < 1),
"RttMeanDeviation: Gain must be less than 1 and greater than 0" );
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
double ToDouble(enum Unit timeUnit) const
int64_t ToInteger(enum Unit timeUnit) const
The "Mean--Deviation" RTT estimator, as discussed by Van Jacobson.
#define NS_LOG_COMPONENT_DEFINE(name)
virtual TypeId GetInstanceTypeId(void) const
static Time FromDouble(double value, enum Unit timeUnit)
double GetSeconds(void) const
virtual void ResetMultiplier()
Resets the estimation multiplier to 1.
Time GetCurrentEstimate(void) const
gets the current RTT estimate.
Base class for all RTT Estimators.
virtual void Measurement(Time t)=0
Add a new measurement to the estimator. Pure virtual function.
virtual void SentSeq(SequenceNumber32 seq, uint32_t size)
Note that a particular sequence has been sent.
void ConstructSelf(const AttributeConstructionList &attributes)
Time GetMinRto(void) const
Get the Minimum RTO.
Time RetransmitTimeout()
Returns the estimated RTO.
void SetMinRto(Time minRto)
Sets the Minimum RTO.
virtual void Reset()
Resets the estimation to its initial state.
void Reset()
Resets sthe estimator.
virtual void IncreaseMultiplier()
Increase the estimation multiplier up to MaxMultiplier.
#define NS_ASSERT_MSG(condition, message)
static Time FromInteger(uint64_t value, enum Unit timeUnit)
void Measurement(Time measure)
Add a new measurement to the estimator.
virtual TypeId GetInstanceTypeId(void) const
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Helper class to store RTT measurements.
void SetCurrentEstimate(Time estimate)
Sets the current RTT estimate (forcefully).
#define NS_LOG_DEBUG(msg)
virtual void ClearSent()
Clear all history entries.
void Gain(double g)
Sets the estimator Gain.
Hold an floating point type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
virtual Time AckSeq(SequenceNumber32 ackSeq)
Note that a particular ack sequence has been received.