21 #include "ndn-limits-rate.h"
24 #include "ns3/simulator.h"
25 #include "ns3/random-variable.h"
26 #include "ns3/ndn-face.h"
29 NS_LOG_COMPONENT_DEFINE (
"ndn.Limits.Rate");
34 NS_OBJECT_ENSURE_REGISTERED (LimitsRate);
37 LimitsRate::GetTypeId ()
39 static TypeId tid = TypeId (
"ns3::ndn::Limits::Rate")
42 .AddConstructor <LimitsRate> ()
44 .AddAttribute (
"RandomizeLeak",
"Randomize start time for token bucket leakage. May be helpful to prevent leak synchronizations",
45 TimeValue (Seconds (0.001)),
46 MakeTimeAccessor (&LimitsRate::m_leakRandomizationInteral),
54 LimitsRate::NotifyNewAggregate ()
56 super::NotifyNewAggregate ();
58 if (!m_isLeakScheduled)
60 if (GetObject<Face> () != 0)
62 NS_ASSERT_MSG (GetObject<Face> ()->GetNode () != 0,
"Node object should exist on the face");
64 m_isLeakScheduled =
true;
66 if (!m_leakRandomizationInteral.IsZero ())
68 UniformVariable r (0.0, m_leakRandomizationInteral.ToDouble (Time::S));
69 Simulator::ScheduleWithContext (GetObject<Face> ()->GetNode ()->GetId (),
70 Seconds (r.GetValue ()), &LimitsRate::LeakBucket,
this, 0.0);
74 Simulator::ScheduleWithContext (GetObject<Face> ()->GetNode ()->GetId (),
75 Seconds (0), &LimitsRate::LeakBucket,
this, 0.0);
98 NS_ASSERT_MSG (limit >= 0.0,
"Limit should be greater or equal to zero");
100 m_bucketLeak = std::min (limit,
GetMaxRate ());
109 return (m_bucketMax - m_bucket >= 1.0);
117 NS_ASSERT_MSG (m_bucketMax - m_bucket >= 1.0,
"Should not be possible, unless we IsBelowLimit was not checked correctly");
128 LimitsRate::LeakBucket (
double interval)
130 const double leak = m_bucketLeak * interval;
132 #ifdef NS3_LOG_ENABLE
135 NS_LOG_DEBUG (
"Leak from " << m_bucket <<
" to " << std::max (0.0, m_bucket - leak));
139 double bucketOld = m_bucket;
141 m_bucket = std::max (0.0, m_bucket - leak);
144 double newInterval = 1.0;
145 if (m_bucketLeak > 1.0)
147 newInterval = 1.001 / m_bucketLeak;
150 if (m_bucketMax - bucketOld < 1.0 &&
151 m_bucketMax - m_bucket >= 1.0)
153 this->FireAvailableSlotCallback ();
156 Simulator::Schedule (Seconds (newInterval), &LimitsRate::LeakBucket,
this, newInterval);
virtual bool IsBelowLimit()
Check if Interest limit is reached (token bucket is not empty)
virtual void BorrowLimit()
Get token from the bucket.
virtual bool IsEnabled() const
Check whether limits are enabled or not.
virtual void SetLimits(double rate, double delay)
Set limit for the number of outstanding interests.
Limits()
Default constructor.
virtual double GetMaxDelay() const
Get maximum delay for BDP product for window-based limits.
virtual void SetLimits(double rate, double delay)
Set limit for the number of outstanding interests.
virtual double GetMaxRate() const
Get maximum rate that needs to be enforced.
virtual void ReturnLimit()
Does nothing (token bucket leakage is time-dependent only)
virtual void UpdateCurrentLimit(double limit)
Update normalized amount that should be leaked every second (token bucket leak rate) and leak rate...