limits: Adding support for callback that fired every time a new slot becomes available
diff --git a/utils/ndn-limits-rate.cc b/utils/ndn-limits-rate.cc
index 27e2f0d..f323cdb 100644
--- a/utils/ndn-limits-rate.cc
+++ b/utils/ndn-limits-rate.cc
@@ -57,7 +57,7 @@
NS_ASSERT_MSG (GetObject<Face> ()->GetNode () != 0, "Node object should exist on the face");
m_isLeakScheduled = true;
- UniformVariable r (0,1);
+ UniformVariable r (0.0, 1.0);
Simulator::ScheduleWithContext (GetObject<Face> ()->GetNode ()->GetId (),
Seconds (r.GetValue ()), &LimitsRate::LeakBucket, this, 0.0);
}
@@ -120,6 +120,8 @@
NS_LOG_DEBUG ("Leak from " << m_bucket << " to " << std::max (0.0, m_bucket - leak));
}
#endif
+
+ double bucketOld = m_bucket;
m_bucket = std::max (0.0, m_bucket - leak);
@@ -129,6 +131,12 @@
{
newInterval = 1.001 / m_bucketLeak;
}
+
+ if (m_bucketMax - bucketOld < 1.0 &&
+ m_bucketMax - m_bucket >= 1.0) // limit number of times this stuff is called
+ {
+ this->FireAvailableSlotCallback ();
+ }
Simulator::Schedule (Seconds (newInterval), &LimitsRate::LeakBucket, this, newInterval);
}