Slight API change. Now there is only one CcnxAppHelper that can create all CcnxApps
diff --git a/model/ccnx-face.cc b/model/ccnx-face.cc
index 18b2015..95c0b7f 100644
--- a/model/ccnx-face.cc
+++ b/model/ccnx-face.cc
@@ -27,6 +27,7 @@
#include "ns3/assert.h"
#include "ns3/uinteger.h"
#include "ns3/double.h"
+#include "ns3/simulator.h"
#include <boost/ref.hpp>
@@ -72,6 +73,7 @@
, m_protocolHandler (MakeNullCallback<void,const Ptr<CcnxFace>&,const Ptr<const Packet>&> ())
, m_ifup (false)
, m_id ((uint32_t)-1)
+ , m_lastLeakTime (0)
{
NS_LOG_FUNCTION (this);
@@ -109,6 +111,8 @@
if (!IsUp ())
return false;
+
+ LeakBucket ();
if (m_bucketMax > 0)
{
@@ -155,10 +159,21 @@
}
void
-CcnxFace::LeakBucket (const Time &interval)
+CcnxFace::LeakBucket ()
{
+ if (m_lastLeakTime.IsZero ())
+ {
+ m_lastLeakTime = Simulator::Now ();
+ return;
+ }
+
+ Time interval = Simulator::Now () - m_lastLeakTime;
const double leak = m_bucketLeak * interval.ToDouble (Time::S);
- m_bucket = std::max (0.0, m_bucket - leak);
+ if (leak >= 1.0)
+ {
+ m_bucket = std::max (0.0, m_bucket - leak);
+ m_lastLeakTime = Simulator::Now ();
+ }
// NS_LOG_DEBUG ("max: " << m_bucketMax << ", Current bucket: " << m_bucket << ", leak size: " << leak << ", interval: " << interval << ", " << m_bucketLeak);
}
@@ -177,12 +192,6 @@
m_bucketLeak = leak;
}
-void
-CcnxFace::LeakBucketByOnePacket ()
-{
- m_bucket = std::max (0.0, m_bucket-1.0);
-}
-
// void
// CcnxFace::SetMetric (uint16_t metric)
// {
@@ -202,6 +211,7 @@
* NetDevice states, such as found in real implementations
* (where the device may be down but face state is still up).
*/
+
bool
CcnxFace::IsUp (void) const
{
diff --git a/model/ccnx-face.h b/model/ccnx-face.h
index b63b1e7..98969e2 100644
--- a/model/ccnx-face.h
+++ b/model/ccnx-face.h
@@ -178,16 +178,12 @@
SetBucketLeak (double leak);
/**
- * @brief Leak the Interest allowance bucket by (1/interval) * m_bucketMax amount
- *
- * @param interval Time interval with which the bucket is leaked
+ * @brief Leak the Interest allowance bucket by (1/interval) * m_bucketMax amount,
+ * where interval is time between two consecutive calls of LeakBucket
*/
void
- LeakBucket (const Time &interval);
+ LeakBucket ();
- void
- LeakBucketByOnePacket ();
-
/**
* \brief Compare two faces. Only two faces on the same node could be compared.
*
@@ -228,7 +224,8 @@
private:
ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to CCNx stack
bool m_ifup; ///< \brief flag indicating that the interface is UP
- uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness)
+ uint32_t m_id; ///< \brief id of the interface in CCNx stack (per-node uniqueness)
+ Time m_lastLeakTime;
};
std::ostream& operator<< (std::ostream& os, const CcnxFace &face);
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 5b55906..7f5f195 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -31,6 +31,7 @@
#include "ns3/pointer.h"
#include "ns3/boolean.h"
#include "ns3/string.h"
+#include "ns3/simulator.h"
#include "ns3/ccnx-header-helper.h"
@@ -74,12 +75,12 @@
MakePointerAccessor (&CcnxL3Protocol::SetForwardingStrategy, &CcnxL3Protocol::GetForwardingStrategy),
MakePointerChecker<CcnxForwardingStrategy> ())
- .AddAttribute ("BucketLeakInterval",
- "Interval to leak buckets",
- StringValue ("100ms"),
- MakeTimeAccessor (&CcnxL3Protocol::GetBucketLeakInterval,
- &CcnxL3Protocol::SetBucketLeakInterval),
- MakeTimeChecker ())
+ // .AddAttribute ("BucketLeakInterval",
+ // "Interval to leak buckets",
+ // StringValue ("100ms"),
+ // MakeTimeAccessor (&CcnxL3Protocol::GetBucketLeakInterval,
+ // &CcnxL3Protocol::SetBucketLeakInterval),
+ // MakeTimeChecker ())
;
return tid;
}
@@ -133,9 +134,6 @@
{
NS_LOG_FUNCTION (this);
- if (m_bucketLeakEvent.IsRunning ())
- m_bucketLeakEvent.Cancel ();
-
for (CcnxFaceList::iterator i = m_faces.begin (); i != m_faces.end (); ++i)
{
*i = 0;
@@ -635,37 +633,37 @@
Simulator::Now () + m_pit->GetPitEntryPruningTimeout ()));
}
-void
-CcnxL3Protocol::SetBucketLeakInterval (Time interval)
-{
- m_bucketLeakInterval = interval;
+// void
+// CcnxL3Protocol::SetBucketLeakInterval (Time interval)
+// {
+// m_bucketLeakInterval = interval;
- if (m_bucketLeakEvent.IsRunning ())
- m_bucketLeakEvent.Cancel ();
+// if (m_bucketLeakEvent.IsRunning ())
+// m_bucketLeakEvent.Cancel ();
- m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval,
- &CcnxL3Protocol::LeakBuckets, this);
-}
+// m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval,
+// &CcnxL3Protocol::LeakBuckets, this);
+// }
-Time
-CcnxL3Protocol::GetBucketLeakInterval () const
-{
- return m_bucketLeakInterval;
-}
+// Time
+// CcnxL3Protocol::GetBucketLeakInterval () const
+// {
+// return m_bucketLeakInterval;
+// }
-void
-CcnxL3Protocol::LeakBuckets ()
-{
- // NS_LOG_FUNCTION (this);
+// void
+// CcnxL3Protocol::LeakBuckets ()
+// {
+// // NS_LOG_FUNCTION (this);
- BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces)
- {
- face->LeakBucket (m_bucketLeakInterval);
- }
+// BOOST_FOREACH (const Ptr<CcnxFace> &face, m_faces)
+// {
+// face->LeakBucket (m_bucketLeakInterval);
+// }
- m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval,
- &CcnxL3Protocol::LeakBuckets,
- this);
-}
+// m_bucketLeakEvent = Simulator::Schedule (m_bucketLeakInterval,
+// &CcnxL3Protocol::LeakBuckets,
+// this);
+// }
} //namespace ns3
diff --git a/model/ccnx-l3-protocol.h b/model/ccnx-l3-protocol.h
index 8ac24d6..d3e1b44 100644
--- a/model/ccnx-l3-protocol.h
+++ b/model/ccnx-l3-protocol.h
@@ -23,13 +23,11 @@
#include <list>
#include <vector>
-#include <stdint.h>
+
#include "ns3/ptr.h"
#include "ns3/net-device.h"
#include "ns3/nstime.h"
-#include "ns3/simulator.h"
-#include "ns3/ccnx-producer-helper.h"
#include "ccnx-content-store.h"
#include "ccnx-pit.h"
#include "ccnx-fib.h"
@@ -181,17 +179,17 @@
CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
- /// \brief Set buckets leak interval
- void
- SetBucketLeakInterval (Time interval);
+ // /// \brief Set buckets leak interval
+ // void
+ // SetBucketLeakInterval (Time interval);
- /// \brief Get buckets leak interval
- Time
- GetBucketLeakInterval () const;
+ // /// \brief Get buckets leak interval
+ // Time
+ // GetBucketLeakInterval () const;
- /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
- void
- LeakBuckets ();
+ // /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
+ // void
+ // LeakBuckets ();
void
GiveUpInterest (const CcnxPitEntry &pitEntry,
@@ -209,9 +207,9 @@
Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Ptr<CcnxFib> m_fib; ///< \brief FIB
Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
-
- Time m_bucketLeakInterval;
- EventId m_bucketLeakEvent;
+
+ // Time m_bucketLeakInterval;
+ // EventId m_bucketLeakEvent;
};
} // Namespace ns3
diff --git a/model/ccnx-name-components.cc b/model/ccnx-name-components.cc
index 323a3f8..fd0064f 100644
--- a/model/ccnx-name-components.cc
+++ b/model/ccnx-name-components.cc
@@ -93,7 +93,8 @@
istream_iterator<char> eos; // end of stream
std::string component = "";
- for (istream_iterator<char> it (is); it != eos; it++)
+ istream_iterator<char> it (is);
+ for (; it != eos; it++)
{
if (*it == '/')
{
@@ -107,6 +108,9 @@
if (component != "")
components.Add (component);
+ is.clear ();
+ // NS_LOG_ERROR (components << ", bad: " << is.bad () <<", fail: " << is.fail ());
+
return is;
}