src: Updating code style to conform (more or less) to ndn-cxx style
Also, adding .clang-format that describes the applied style. Note that
this style requires a slightly customized version of clang-format.
diff --git a/utils/batches.cpp b/utils/batches.cpp
index 9eb92b3..6f593e3 100644
--- a/utils/batches.cpp
+++ b/utils/batches.cpp
@@ -22,13 +22,13 @@
namespace ns3 {
-ATTRIBUTE_HELPER_CPP (Batches);
+ATTRIBUTE_HELPER_CPP(Batches);
-std::ostream &
-operator << (std::ostream &os, const Batches &batch)
+std::ostream&
+operator<<(std::ostream& os, const Batches& batch)
{
- for (Batches::const_iterator i = batch.begin (); i != batch.end (); i++)
- os << i->get<0> () << " " << i->get<1> () << " ";
+ for (Batches::const_iterator i = batch.begin(); i != batch.end(); i++)
+ os << i->get<0>() << " " << i->get<1>() << " ";
return os;
}
@@ -37,21 +37,18 @@
* \brief Read components from input and add them to components. Will read input stream till eof
* Substrings separated by slashes will become separate components
*/
-std::istream &
-operator >> (std::istream &is, Batches &batch)
+std::istream&
+operator>>(std::istream& is, Batches& batch)
{
Time time;
uint32_t amount;
- while (!is.eof ())
- {
- is >> time >> amount;
- batch.Add (time, amount);
- // std::cout << time << ", " << amount << ". \n";
- }
-
- is.clear ();
+ while (!is.eof()) {
+ is >> time >> amount;
+ batch.Add(time, amount);
+ // std::cout << time << ", " << amount << ". \n";
+ }
+
+ is.clear();
return is;
}
-
-
}
diff --git a/utils/batches.hpp b/utils/batches.hpp
index 526ae29..457210f 100644
--- a/utils/batches.hpp
+++ b/utils/batches.hpp
@@ -31,15 +31,15 @@
/**
* @ingroup ndn-apps
- * @brief Class representing sets of (time, number) tuples with support of reading writing to streams
+ * @brief Class representing sets of (time, number) tuples with support of reading writing to
+ * streams
*/
-class Batches : public std::list<boost::tuple<Time, uint32_t> >
-{
+class Batches : public std::list<boost::tuple<Time, uint32_t>> {
public:
/**
* @brief Default constructor
*/
- Batches () { };
+ Batches(){};
/**
* @brief Add tuple
@@ -47,28 +47,28 @@
* @param amount number for the tuple
*/
void
- Add (const Time &when, uint32_t amount)
+ Add(const Time& when, uint32_t amount)
{
- push_back (boost::make_tuple<Time, uint32_t> (when, amount));
+ push_back(boost::make_tuple<Time, uint32_t>(when, amount));
}
};
-ATTRIBUTE_HELPER_HEADER (Batches);
+ATTRIBUTE_HELPER_HEADER(Batches);
/**
* @brief Output contents of the Batches to the std::ostream
* @param os reference to std::ostream
* @param batch constant reference to Batch object
*/
-std::ostream &
-operator << (std::ostream &os, const Batches &batch);
+std::ostream&
+operator<<(std::ostream& os, const Batches& batch);
/**
* \brief Read components from input and add them to components. Will read input stream till eof
* Substrings separated by slashes will become separate components
*/
-std::istream &
-operator >> (std::istream &is, Batches &batch);
+std::istream&
+operator>>(std::istream& is, Batches& batch);
} // namespace ns3
diff --git a/utils/mem-usage.hpp b/utils/mem-usage.hpp
index a18448a..e58b9ad 100644
--- a/utils/mem-usage.hpp
+++ b/utils/mem-usage.hpp
@@ -42,58 +42,53 @@
* @ingroup ndn-helpers
* @brief Utility class to evaluate current usage of RAM
*/
-class MemUsage
-{
+class MemUsage {
public:
/**
* @brief Get memory utilization in bytes
*/
- static inline
- int64_t
- Get ()
+ static inline int64_t
+ Get()
{
#if defined(__linux__)
-/*
-/proc/[pid]/statm
- Provides information about memory usage, measured in pages. The
- columns are:
+ /*
+ /proc/[pid]/statm
+ Provides information about memory usage, measured in pages. The
+ columns are:
- size (1) total program size
- (same as VmSize in /proc/[pid]/status)
- resident (2) resident set size
- (same as VmRSS in /proc/[pid]/status)
- share (3) shared pages (i.e., backed by a file)
- text (4) text (code)
- lib (5) library (unused in Linux 2.6)
- data (6) data + stack
- dt (7) dirty pages (unused in Linux 2.6)
+ size (1) total program size
+ (same as VmSize in /proc/[pid]/status)
+ resident (2) resident set size
+ (same as VmRSS in /proc/[pid]/status)
+ share (3) shared pages (i.e., backed by a file)
+ text (4) text (code)
+ lib (5) library (unused in Linux 2.6)
+ data (6) data + stack
+ dt (7) dirty pages (unused in Linux 2.6)
-Reference: http://man7.org/linux/man-pages/man5/proc.5.html
-*/
- std::ifstream is ("/proc/self/statm");
- if (!is.bad () && !is.eof ())
- {
- unsigned long vm;
- unsigned long rss;
- is >> vm // the first number: virtual memory
- >> rss; // the second number: resident set size
-
- return rss * getpagesize ();
- }
- else
- {
- return -1;
- }
+ Reference: http://man7.org/linux/man-pages/man5/proc.5.html
+ */
+ std::ifstream is("/proc/self/statm");
+ if (!is.bad() && !is.eof()) {
+ unsigned long vm;
+ unsigned long rss;
+ is >> vm // the first number: virtual memory
+ >> rss; // the second number: resident set size
+
+ return rss * getpagesize();
+ }
+ else {
+ return -1;
+ }
#elif defined(__APPLE__)
struct task_basic_info t_info;
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
- if (KERN_SUCCESS != task_info (mach_task_self (),
- TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count))
- {
- return -1; // something is wrong
- }
+ if (KERN_SUCCESS
+ != task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count)) {
+ return -1; // something is wrong
+ }
return t_info.resident_size;
#endif
diff --git a/utils/ndn-fw-hop-count-tag.cpp b/utils/ndn-fw-hop-count-tag.cpp
index f4d65db..027bdfe 100644
--- a/utils/ndn-fw-hop-count-tag.cpp
+++ b/utils/ndn-fw-hop-count-tag.cpp
@@ -24,41 +24,39 @@
namespace ndn {
TypeId
-FwHopCountTag::GetTypeId ()
+FwHopCountTag::GetTypeId()
{
- static TypeId tid = TypeId("ns3::ndn::FwHopCountTag")
- .SetParent<Tag>()
- .AddConstructor<FwHopCountTag>()
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::FwHopCountTag").SetParent<Tag>().AddConstructor<FwHopCountTag>();
return tid;
}
TypeId
-FwHopCountTag::GetInstanceTypeId () const
+FwHopCountTag::GetInstanceTypeId() const
{
- return FwHopCountTag::GetTypeId ();
+ return FwHopCountTag::GetTypeId();
}
uint32_t
-FwHopCountTag::GetSerializedSize () const
+FwHopCountTag::GetSerializedSize() const
{
return sizeof(uint32_t);
}
void
-FwHopCountTag::Serialize (TagBuffer i) const
+FwHopCountTag::Serialize(TagBuffer i) const
{
- i.WriteU32 (m_hopCount);
-}
-
-void
-FwHopCountTag::Deserialize (TagBuffer i)
-{
- m_hopCount = i.ReadU32 ();
+ i.WriteU32(m_hopCount);
}
void
-FwHopCountTag::Print (std::ostream &os) const
+FwHopCountTag::Deserialize(TagBuffer i)
+{
+ m_hopCount = i.ReadU32();
+}
+
+void
+FwHopCountTag::Print(std::ostream& os) const
{
os << m_hopCount;
}
diff --git a/utils/ndn-fw-hop-count-tag.hpp b/utils/ndn-fw-hop-count-tag.hpp
index f530961..6b4920c 100644
--- a/utils/ndn-fw-hop-count-tag.hpp
+++ b/utils/ndn-fw-hop-count-tag.hpp
@@ -30,56 +30,64 @@
* @ingroup ndn-fw
* @brief Packet tag that is used to track hop count for Interest-Data pairs
*/
-class FwHopCountTag : public Tag
-{
+class FwHopCountTag : public Tag {
public:
static TypeId
- GetTypeId (void);
+ GetTypeId(void);
/**
* @brief Default constructor
*/
- FwHopCountTag () : m_hopCount (0) { };
+ FwHopCountTag()
+ : m_hopCount(0){};
/**
* @brief Destructor
*/
- ~FwHopCountTag () { }
+ ~FwHopCountTag()
+ {
+ }
/**
* @brief Increment hop count
*/
void
- Increment () { m_hopCount ++; }
+ Increment()
+ {
+ m_hopCount++;
+ }
/**
* @brief Get value of hop count
*/
uint32_t
- Get () const { return m_hopCount; }
+ Get() const
+ {
+ return m_hopCount;
+ }
////////////////////////////////////////////////////////
// from ObjectBase
////////////////////////////////////////////////////////
virtual TypeId
- GetInstanceTypeId () const;
-
+ GetInstanceTypeId() const;
+
////////////////////////////////////////////////////////
// from Tag
////////////////////////////////////////////////////////
-
+
virtual uint32_t
- GetSerializedSize () const;
+ GetSerializedSize() const;
virtual void
- Serialize (TagBuffer i) const;
-
- virtual void
- Deserialize (TagBuffer i);
+ Serialize(TagBuffer i) const;
virtual void
- Print (std::ostream &os) const;
-
+ Deserialize(TagBuffer i);
+
+ virtual void
+ Print(std::ostream& os) const;
+
private:
uint32_t m_hopCount;
};
diff --git a/utils/ndn-limits-rate.cpp b/utils/ndn-limits-rate.cpp
index 3d2ebc7..8729231 100644
--- a/utils/ndn-limits-rate.cpp
+++ b/utils/ndn-limits-rate.cpp
@@ -26,134 +26,131 @@
#include "ns3/ndn-face.hpp"
#include "ns3/node.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.Limits.Rate");
+NS_LOG_COMPONENT_DEFINE("ndn.Limits.Rate");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (LimitsRate);
+NS_OBJECT_ENSURE_REGISTERED(LimitsRate);
TypeId
-LimitsRate::GetTypeId ()
+LimitsRate::GetTypeId()
{
- static TypeId tid = TypeId ("ns3::ndn::Limits::Rate")
- .SetGroupName ("Ndn")
- .SetParent <Limits> ()
- .AddConstructor <LimitsRate> ()
+ static TypeId tid =
+ TypeId("ns3::ndn::Limits::Rate")
+ .SetGroupName("Ndn")
+ .SetParent<Limits>()
+ .AddConstructor<LimitsRate>()
- .AddAttribute ("RandomizeLeak", "Randomize start time for token bucket leakage. May be helpful to prevent leak synchronizations",
- TimeValue (Seconds (0.001)),
- MakeTimeAccessor (&LimitsRate::m_leakRandomizationInteral),
- MakeTimeChecker ())
+ .AddAttribute("RandomizeLeak", "Randomize start time for token bucket leakage. May be "
+ "helpful to prevent leak synchronizations",
+ TimeValue(Seconds(0.001)),
+ MakeTimeAccessor(&LimitsRate::m_leakRandomizationInteral), MakeTimeChecker())
;
return tid;
}
void
-LimitsRate::NotifyNewAggregate ()
+LimitsRate::NotifyNewAggregate()
{
- super::NotifyNewAggregate ();
+ super::NotifyNewAggregate();
- if (!m_isLeakScheduled)
- {
- if (GetObject<Face> () != 0)
- {
- NS_ASSERT_MSG (GetObject<Face> ()->GetNode () != 0, "Node object should exist on the face");
+ if (!m_isLeakScheduled) {
+ if (GetObject<Face>() != 0) {
+ NS_ASSERT_MSG(GetObject<Face>()->GetNode() != 0, "Node object should exist on the face");
- m_isLeakScheduled = true;
+ m_isLeakScheduled = true;
- if (!m_leakRandomizationInteral.IsZero ())
- {
- UniformVariable r (0.0, m_leakRandomizationInteral.ToDouble (Time::S));
- Simulator::ScheduleWithContext (GetObject<Face> ()->GetNode ()->GetId (),
- Seconds (r.GetValue ()), &LimitsRate::LeakBucket, this, 0.0);
- }
- else
- {
- Simulator::ScheduleWithContext (GetObject<Face> ()->GetNode ()->GetId (),
- Seconds (0), &LimitsRate::LeakBucket, this, 0.0);
- }
-
- }
+ if (!m_leakRandomizationInteral.IsZero()) {
+ UniformVariable r(0.0, m_leakRandomizationInteral.ToDouble(Time::S));
+ Simulator::ScheduleWithContext(GetObject<Face>()->GetNode()->GetId(), Seconds(r.GetValue()),
+ &LimitsRate::LeakBucket, this, 0.0);
+ }
+ else {
+ Simulator::ScheduleWithContext(GetObject<Face>()->GetNode()->GetId(), Seconds(0),
+ &LimitsRate::LeakBucket, this, 0.0);
+ }
}
+ }
}
void
-LimitsRate::SetLimits (double rate, double delay)
+LimitsRate::SetLimits(double rate, double delay)
{
- super::SetLimits (rate, delay);
+ super::SetLimits(rate, delay);
// maximum allowed burst
- m_bucketMax = GetMaxRate () * GetMaxDelay ();
+ m_bucketMax = GetMaxRate() * GetMaxDelay();
// amount of packets allowed every second (leak rate)
- m_bucketLeak = GetMaxRate ();
+ m_bucketLeak = GetMaxRate();
}
-
void
-LimitsRate::UpdateCurrentLimit (double limit)
+LimitsRate::UpdateCurrentLimit(double limit)
{
- NS_ASSERT_MSG (limit >= 0.0, "Limit should be greater or equal to zero");
+ NS_ASSERT_MSG(limit >= 0.0, "Limit should be greater or equal to zero");
- m_bucketLeak = std::min (limit, GetMaxRate ());
- m_bucketMax = m_bucketLeak * GetMaxDelay ();
+ m_bucketLeak = std::min(limit, GetMaxRate());
+ m_bucketMax = m_bucketLeak * GetMaxDelay();
}
bool
-LimitsRate::IsBelowLimit ()
+LimitsRate::IsBelowLimit()
{
- if (!IsEnabled ()) return true;
+ if (!IsEnabled())
+ return true;
return (m_bucketMax - m_bucket >= 1.0);
}
void
-LimitsRate::BorrowLimit ()
+LimitsRate::BorrowLimit()
{
- if (!IsEnabled ()) return;
+ if (!IsEnabled())
+ return;
- NS_ASSERT_MSG (m_bucketMax - m_bucket >= 1.0, "Should not be possible, unless we IsBelowLimit was not checked correctly");
+ NS_ASSERT_MSG(m_bucketMax - m_bucket >= 1.0,
+ "Should not be possible, unless we IsBelowLimit was not checked correctly");
m_bucket += 1;
}
void
-LimitsRate::ReturnLimit ()
+LimitsRate::ReturnLimit()
{
// do nothing
}
void
-LimitsRate::LeakBucket (double interval)
+LimitsRate::LeakBucket(double interval)
{
const double leak = m_bucketLeak * interval;
#ifdef NS3_LOG_ENABLE
- if (m_bucket>1)
- {
- NS_LOG_DEBUG ("Leak from " << m_bucket << " to " << std::max (0.0, m_bucket - leak));
- }
+ if (m_bucket > 1) {
+ 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);
+ m_bucket = std::max(0.0, m_bucket - leak);
- // calculate interval so next time we will leak by 1.001, unless such interval would be more than 1 second
+ // calculate interval so next time we will leak by 1.001, unless such interval would be more than
+ // 1 second
double newInterval = 1.0;
- if (m_bucketLeak > 1.0)
- {
- newInterval = 1.001 / m_bucketLeak;
- }
+ if (m_bucketLeak > 1.0) {
+ 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 ();
- }
+ 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);
+ Simulator::Schedule(Seconds(newInterval), &LimitsRate::LeakBucket, this, newInterval);
}
} // namespace ndn
diff --git a/utils/ndn-limits-rate.hpp b/utils/ndn-limits-rate.hpp
index 4b8c699..a476247 100644
--- a/utils/ndn-limits-rate.hpp
+++ b/utils/ndn-limits-rate.hpp
@@ -19,7 +19,7 @@
*/
#ifndef _NDN_LIMITS_RATE_H_
-#define _NDN_LIMITS_RATE_H_
+#define _NDN_LIMITS_RATE_H_
#include "ndn-limits.hpp"
#include <ns3/nstime.h>
@@ -31,74 +31,74 @@
* \ingroup ndn-fw
* \brief Structure to manage limits for outstanding interests
*/
-class LimitsRate :
- public Limits
-{
+class LimitsRate : public Limits {
public:
typedef Limits super;
static TypeId
- GetTypeId ();
+ GetTypeId();
/**
* \brief Constructor
* \param prefix smart pointer to the prefix for the FIB entry
*/
- LimitsRate ()
- : m_isLeakScheduled (false)
- , m_bucketMax (0)
- , m_bucketLeak (1)
- , m_bucket (0)
- { }
+ LimitsRate()
+ : m_isLeakScheduled(false)
+ , m_bucketMax(0)
+ , m_bucketLeak(1)
+ , m_bucket(0)
+ {
+ }
- virtual
- ~LimitsRate () { }
+ virtual ~LimitsRate()
+ {
+ }
virtual void
- SetLimits (double rate, double delay);
+ SetLimits(double rate, double delay);
- virtual
- double
- GetMaxLimit () const
+ virtual double
+ GetMaxLimit() const
{
- return GetMaxRate ();
+ return GetMaxRate();
}
/**
* @brief Check if Interest limit is reached (token bucket is not empty)
*/
virtual bool
- IsBelowLimit ();
+ IsBelowLimit();
/**
* @brief Get token from the bucket
*/
virtual void
- BorrowLimit ();
+ BorrowLimit();
/**
* @brief Does nothing (token bucket leakage is time-dependent only)
*/
virtual void
- ReturnLimit ();
+ ReturnLimit();
/**
- * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and leak rate
+ * @brief Update normalized amount that should be leaked every second (token bucket leak rate) and
+ * leak rate
*/
virtual void
- UpdateCurrentLimit (double limit);
+ UpdateCurrentLimit(double limit);
/**
* @brief Get normalized amount that should be leaked every second (token bucket leak rate)
*/
virtual double
- GetCurrentLimit () const
+ GetCurrentLimit() const
{
return m_bucketLeak;
}
virtual double
- GetCurrentLimitRate () const
+ GetCurrentLimitRate() const
{
return m_bucketLeak;
}
@@ -106,7 +106,7 @@
protected:
// from Node
void
- NotifyNewAggregate ();
+ NotifyNewAggregate();
private:
/**
@@ -115,19 +115,21 @@
* @param interval Time interval for leakage. Used to calculate size of the leak
*/
void
- LeakBucket (double interval);
+ LeakBucket(double interval);
private:
bool m_isLeakScheduled;
- double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can be issued at the same time)
- double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token bucket leak rate)
- double m_bucket; ///< \brief Value representing current size of the Interest allowance for this face (current size of token bucket)
+ double m_bucketMax; ///< \brief Maximum Interest allowance for this face (maximum tokens that can
+ /// be issued at the same time)
+ double m_bucketLeak; ///< \brief Normalized amount that should be leaked every second (token
+ /// bucket leak rate)
+ double m_bucket; ///< \brief Value representing current size of the Interest allowance for this
+ /// face (current size of token bucket)
Time m_leakRandomizationInteral;
};
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-limits-window.cpp b/utils/ndn-limits-window.cpp
index a2630a4..c5c5098 100644
--- a/utils/ndn-limits-window.cpp
+++ b/utils/ndn-limits-window.cpp
@@ -22,66 +22,68 @@
#include "ns3/log.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.Limits.Window");
+NS_LOG_COMPONENT_DEFINE("ndn.Limits.Window");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (LimitsWindow);
+NS_OBJECT_ENSURE_REGISTERED(LimitsWindow);
TypeId
-LimitsWindow::GetTypeId ()
+LimitsWindow::GetTypeId()
{
- static TypeId tid = TypeId ("ns3::ndn::Limits::Window")
- .SetGroupName ("Ndn")
- .SetParent <Limits> ()
- .AddConstructor <LimitsWindow> ()
-
- .AddTraceSource ("CurMaxLimit",
- "Current maximum limit",
- MakeTraceSourceAccessor (&LimitsWindow::m_curMaxLimit))
+ static TypeId tid = TypeId("ns3::ndn::Limits::Window")
+ .SetGroupName("Ndn")
+ .SetParent<Limits>()
+ .AddConstructor<LimitsWindow>()
- .AddTraceSource ("Outstanding",
- "Number of outstanding interests",
- MakeTraceSourceAccessor (&LimitsWindow::m_outstanding))
- ;
+ .AddTraceSource("CurMaxLimit", "Current maximum limit",
+ MakeTraceSourceAccessor(&LimitsWindow::m_curMaxLimit))
+
+ .AddTraceSource("Outstanding", "Number of outstanding interests",
+ MakeTraceSourceAccessor(&LimitsWindow::m_outstanding));
return tid;
}
void
-LimitsWindow::UpdateCurrentLimit (double limit)
+LimitsWindow::UpdateCurrentLimit(double limit)
{
- NS_ASSERT_MSG (limit >= 0.0, "Limit should be greater or equal to zero");
-
- m_curMaxLimit = std::min (limit, GetMaxRate () * GetMaxDelay ());
+ NS_ASSERT_MSG(limit >= 0.0, "Limit should be greater or equal to zero");
+
+ m_curMaxLimit = std::min(limit, GetMaxRate() * GetMaxDelay());
}
bool
-LimitsWindow::IsBelowLimit ()
+LimitsWindow::IsBelowLimit()
{
- if (!IsEnabled ()) return true;
+ if (!IsEnabled())
+ return true;
return (m_curMaxLimit - m_outstanding >= 1.0);
}
void
-LimitsWindow::BorrowLimit ()
+LimitsWindow::BorrowLimit()
{
- if (!IsEnabled ()) return;
+ if (!IsEnabled())
+ return;
- NS_ASSERT_MSG (m_curMaxLimit - m_outstanding >= 1.0, "Should not be possible, unless we IsBelowLimit was not checked correctly");
+ NS_ASSERT_MSG(m_curMaxLimit - m_outstanding >= 1.0,
+ "Should not be possible, unless we IsBelowLimit was not checked correctly");
m_outstanding += 1;
}
void
-LimitsWindow::ReturnLimit ()
+LimitsWindow::ReturnLimit()
{
- if (!IsEnabled ()) return;
+ if (!IsEnabled())
+ return;
- NS_ASSERT_MSG (m_outstanding >= (uint32_t)1, "Should not be possible, unless we decreasing this number twice somewhere");
+ NS_ASSERT_MSG(m_outstanding >= (uint32_t)1,
+ "Should not be possible, unless we decreasing this number twice somewhere");
m_outstanding -= 1;
- FireAvailableSlotCallback ();
+ FireAvailableSlotCallback();
}
} // namespace ndn
diff --git a/utils/ndn-limits-window.hpp b/utils/ndn-limits-window.hpp
index 2fcea6f..b407e02 100644
--- a/utils/ndn-limits-window.hpp
+++ b/utils/ndn-limits-window.hpp
@@ -19,7 +19,7 @@
*/
#ifndef _NDN_LIMITS_WINDOW_H_
-#define _NDN_LIMITS_WINDOW_H_
+#define _NDN_LIMITS_WINDOW_H_
#include "ndn-limits.hpp"
@@ -30,83 +30,81 @@
* \ingroup ndn-fw
* \brief Structure to manage limits for outstanding interests (window-based limiting)
*/
-class LimitsWindow :
- public Limits
-{
+class LimitsWindow : public Limits {
public:
typedef Limits super;
-
+
static TypeId
- GetTypeId ();
-
+ GetTypeId();
+
/**
* @brief Default Constructor
*/
- LimitsWindow ()
- : m_outstanding (0)
- { }
+ LimitsWindow()
+ : m_outstanding(0)
+ {
+ }
/**
* @brief Virtual destructor
*/
- virtual
- ~LimitsWindow () { }
+ virtual ~LimitsWindow()
+ {
+ }
// from ndn::Limits
virtual void
- SetLimits (double rate, double delay)
+ SetLimits(double rate, double delay)
{
- super::SetLimits (rate, delay);
+ super::SetLimits(rate, delay);
- m_curMaxLimit = GetMaxRate () * GetMaxDelay ();
+ m_curMaxLimit = GetMaxRate() * GetMaxDelay();
}
- virtual
- double
- GetMaxLimit () const
- {
- return GetMaxRate () * GetMaxDelay ();
- }
-
- virtual void
- UpdateCurrentLimit (double limit);
-
virtual double
- GetCurrentLimit () const
+ GetMaxLimit() const
+ {
+ return GetMaxRate() * GetMaxDelay();
+ }
+
+ virtual void
+ UpdateCurrentLimit(double limit);
+
+ virtual double
+ GetCurrentLimit() const
{
return m_curMaxLimit;
}
virtual double
- GetCurrentLimitRate () const
+ GetCurrentLimitRate() const
{
- return m_curMaxLimit / GetMaxDelay ();
+ return m_curMaxLimit / GetMaxDelay();
}
-
+
/**
- * @brief Check if current interest window (number of pending interests) if less than maximum
+ * @brief Check if current interest window (number of pending interests) if less than maximum
*/
virtual bool
- IsBelowLimit ();
+ IsBelowLimit();
/**
* @brief Increase current window of outstanding interests
*/
virtual void
- BorrowLimit ();
+ BorrowLimit();
/**
* @brief Decrease current window of outstanding interests
*/
virtual void
- ReturnLimit ();
-
+ ReturnLimit();
+
private:
- TracedValue< double > m_curMaxLimit;
- TracedValue< double > m_outstanding;
+ TracedValue<double> m_curMaxLimit;
+ TracedValue<double> m_outstanding;
};
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-limits.cpp b/utils/ndn-limits.cpp
index 4519500..037b313 100644
--- a/utils/ndn-limits.cpp
+++ b/utils/ndn-limits.cpp
@@ -24,44 +24,40 @@
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.Limits");
+NS_LOG_COMPONENT_DEFINE("ndn.Limits");
namespace ns3 {
namespace ndn {
TypeId
-Limits::GetTypeId ()
+Limits::GetTypeId()
{
- static TypeId tid = TypeId ("ns3::ndn::Limits")
- .SetGroupName ("Ndn")
- .SetParent <Object> ()
-
+ static TypeId tid = TypeId("ns3::ndn::Limits").SetGroupName("Ndn").SetParent<Object>()
+
;
return tid;
}
-Limits::Limits ()
- : m_maxRate (-1)
- , m_maxDelay (1.0)
- , m_handler (MakeNullCallback<void> ())
- , m_linkDelay (0)
+Limits::Limits()
+ : m_maxRate(-1)
+ , m_maxDelay(1.0)
+ , m_handler(MakeNullCallback<void>())
+ , m_linkDelay(0)
{
}
-
void
-Limits::RegisterAvailableSlotCallback (CallbackHandler handler)
+Limits::RegisterAvailableSlotCallback(CallbackHandler handler)
{
m_handler = handler;
}
void
-Limits::FireAvailableSlotCallback ()
+Limits::FireAvailableSlotCallback()
{
- if (!m_handler.IsNull ())
- m_handler ();
+ if (!m_handler.IsNull())
+ m_handler();
}
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-limits.hpp b/utils/ndn-limits.hpp
index d8f848b..ebb8d15 100644
--- a/utils/ndn-limits.hpp
+++ b/utils/ndn-limits.hpp
@@ -19,7 +19,7 @@
*/
#ifndef _NDN_LIMITS_H_
-#define _NDN_LIMITS_H_
+#define _NDN_LIMITS_H_
#include "ns3/ptr.h"
#include "ns3/object.h"
@@ -30,45 +30,44 @@
/**
* \ingroup ndn-fw
- * \brief Abstract class to manage Interest limits
+ * \brief Abstract class to manage Interest limits
*/
-class Limits :
- public Object
-{
+class Limits : public Object {
public:
typedef Callback<void> CallbackHandler;
static TypeId
- GetTypeId ();
+ GetTypeId();
/**
* @brief Default constructor
*/
- Limits ();
+ Limits();
/**
* @brief Virtual destructor
*/
- virtual
- ~Limits () {}
-
+ virtual ~Limits()
+ {
+ }
+
/**
* @brief Set limit for the number of outstanding interests
* @param rate Maximum rate that needs to be enforced
* @param delay Maximum delay for BDP product for window-based limits
*/
virtual void
- SetLimits (double rate, double delay)
+ SetLimits(double rate, double delay)
{
m_maxRate = rate;
m_maxDelay = delay;
- }
+ }
/**
* @brief Get maximum rate that needs to be enforced
*/
virtual double
- GetMaxRate () const
+ GetMaxRate() const
{
return m_maxRate;
}
@@ -77,7 +76,7 @@
* @brief Get maximum delay for BDP product for window-based limits
*/
virtual double
- GetMaxDelay () const
+ GetMaxDelay() const
{
return m_maxDelay;
}
@@ -85,15 +84,14 @@
/**
* @brief Get maximum limit (interpretation of the limit depends on realization)
*/
- virtual
- double
- GetMaxLimit () const = 0;
+ virtual double
+ GetMaxLimit() const = 0;
/**
* @brief Check whether limits are enabled or not
*/
virtual inline bool
- IsEnabled () const
+ IsEnabled() const
{
return m_maxRate > 0.0;
}
@@ -104,11 +102,12 @@
*
* Note that interpretation of this value may be different in different ndn::Limit realizations
*
- * All realizations will try to guarantee that if limit is larger than previously set value of maximum limit,
+ * All realizations will try to guarantee that if limit is larger than previously set value of
+ *maximum limit,
* then the current limit will be limited to that maximum value
*/
virtual void
- UpdateCurrentLimit (double limit) = 0;
+ UpdateCurrentLimit(double limit) = 0;
/**
* @brief Get value of the current limit
@@ -116,17 +115,18 @@
* Note that interpretation of this value may be different in different ndn::Limit realizations
*/
virtual double
- GetCurrentLimit () const = 0;
+ GetCurrentLimit() const = 0;
/**
* @brief Get value of the current limit in terms of maximum rate that needs to be enforced
*
- * Compared to GetCurrentLimit, this method guarantees that the returned value is maximum number of packets
+ * Compared to GetCurrentLimit, this method guarantees that the returned value is maximum number
+ *of packets
* that can be send out within one second (max "rate")
*/
virtual double
- GetCurrentLimitRate () const = 0;
-
+ GetCurrentLimitRate() const = 0;
+
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@@ -135,7 +135,7 @@
* @brief Realization-specific method called to check availability of the limit
*/
virtual bool
- IsBelowLimit () = 0;
+ IsBelowLimit() = 0;
/**
* @brief "Borrow" limit
@@ -143,13 +143,13 @@
* IsBelowLimit **must** be true, otherwise assert fail
*/
virtual void
- BorrowLimit () = 0;
+ BorrowLimit() = 0;
/**
* @brief "Return" limit
*/
virtual void
- ReturnLimit () = 0;
+ ReturnLimit() = 0;
/**
* @brief Set link delay (in seconds)
@@ -157,7 +157,7 @@
* This is a supplementary information that may or may not be useful for limits
*/
virtual void
- SetLinkDelay (double delay)
+ SetLinkDelay(double delay)
{
m_linkDelay = delay;
}
@@ -166,11 +166,11 @@
* @brief Get link delay (in seconds)
*/
virtual double
- GetLinkDelay () const
+ GetLinkDelay() const
{
return m_linkDelay;
}
-
+
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
@@ -179,12 +179,12 @@
* @brief Set callback which will be called when exhausted limit gets a new slot
*/
void
- RegisterAvailableSlotCallback (CallbackHandler handler);
+ RegisterAvailableSlotCallback(CallbackHandler handler);
protected:
void
- FireAvailableSlotCallback ();
-
+ FireAvailableSlotCallback();
+
private:
double m_maxRate;
double m_maxDelay;
@@ -193,7 +193,6 @@
double m_linkDelay;
};
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-rtt-estimator.cpp b/utils/ndn-rtt-estimator.cpp
index 9e63cef..376c4ab 100644
--- a/utils/ndn-rtt-estimator.cpp
+++ b/utils/ndn-rtt-estimator.cpp
@@ -35,220 +35,222 @@
#include "ns3/uinteger.h"
#include "ns3/log.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.RttEstimator");
+NS_LOG_COMPONENT_DEFINE("ndn.RttEstimator");
namespace ns3 {
namespace ndn {
-NS_OBJECT_ENSURE_REGISTERED (RttEstimator);
+NS_OBJECT_ENSURE_REGISTERED(RttEstimator);
TypeId
-RttEstimator::GetTypeId (void)
+RttEstimator::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::RttEstimator")
- .SetParent<Object> ()
- .AddAttribute ("MaxMultiplier",
- "Maximum RTO Multiplier",
- UintegerValue (64),
- MakeUintegerAccessor (&RttEstimator::m_maxMultiplier),
- MakeUintegerChecker<uint16_t> ())
- .AddAttribute ("InitialEstimation",
- "Initial RTT estimation",
- TimeValue (Seconds (1.0)),
- MakeTimeAccessor (&RttEstimator::m_initialEstimatedRtt),
- MakeTimeChecker ())
- .AddAttribute ("MinRTO",
- "Minimum retransmit timeout value",
- TimeValue (Seconds (0.2)), // RFC2988 says min RTO=1 sec, but Linux uses 200ms. See http://www.postel.org/pipermail/end2end-interest/2004-November/004402.html
- MakeTimeAccessor (&RttEstimator::SetMinRto,
- &RttEstimator::GetMinRto),
- MakeTimeChecker ())
- .AddAttribute ("MaxRTO",
- "Maximum retransmit timeout value",
- TimeValue (Seconds (200.0)),
- MakeTimeAccessor (&RttEstimator::SetMaxRto,
- &RttEstimator::GetMaxRto),
- MakeTimeChecker ())
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::RttEstimator")
+ .SetParent<Object>()
+ .AddAttribute("MaxMultiplier", "Maximum RTO Multiplier", UintegerValue(64),
+ MakeUintegerAccessor(&RttEstimator::m_maxMultiplier),
+ MakeUintegerChecker<uint16_t>())
+ .AddAttribute("InitialEstimation", "Initial RTT estimation", TimeValue(Seconds(1.0)),
+ MakeTimeAccessor(&RttEstimator::m_initialEstimatedRtt), MakeTimeChecker())
+ .AddAttribute("MinRTO", "Minimum retransmit timeout value",
+ TimeValue(
+ Seconds(0.2)), // RFC2988 says min RTO=1 sec, but Linux uses 200ms. See
+ // http://www.postel.org/pipermail/end2end-interest/2004-November/004402.html
+ MakeTimeAccessor(&RttEstimator::SetMinRto, &RttEstimator::GetMinRto),
+ MakeTimeChecker())
+ .AddAttribute("MaxRTO", "Maximum retransmit timeout value", TimeValue(Seconds(200.0)),
+ MakeTimeAccessor(&RttEstimator::SetMaxRto, &RttEstimator::GetMaxRto),
+ MakeTimeChecker());
return tid;
}
void
-RttEstimator::SetMinRto (Time minRto)
+RttEstimator::SetMinRto(Time minRto)
{
- NS_LOG_FUNCTION (this << minRto);
+ NS_LOG_FUNCTION(this << minRto);
m_minRto = minRto;
}
Time
-RttEstimator::GetMinRto (void) const
+RttEstimator::GetMinRto(void) const
{
return m_minRto;
}
void
-RttEstimator::SetMaxRto (Time maxRto)
+RttEstimator::SetMaxRto(Time maxRto)
{
- NS_LOG_FUNCTION (this << maxRto);
+ NS_LOG_FUNCTION(this << maxRto);
m_maxRto = maxRto;
}
Time
-RttEstimator::GetMaxRto (void) const
+RttEstimator::GetMaxRto(void) const
{
return m_maxRto;
}
void
-RttEstimator::SetCurrentEstimate (Time estimate)
+RttEstimator::SetCurrentEstimate(Time estimate)
{
- NS_LOG_FUNCTION (this << estimate);
+ NS_LOG_FUNCTION(this << estimate);
m_currentEstimatedRtt = estimate;
}
Time
-RttEstimator::GetCurrentEstimate (void) const
+RttEstimator::GetCurrentEstimate(void) const
{
return m_currentEstimatedRtt;
}
-
-//RttHistory methods
-RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
- : seq (s), count (c), time (t), retx (false)
+// RttHistory methods
+RttHistory::RttHistory(SequenceNumber32 s, uint32_t c, Time t)
+ : seq(s)
+ , count(c)
+ , time(t)
+ , retx(false)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
-RttHistory::RttHistory (const RttHistory& h)
- : seq (h.seq), count (h.count), time (h.time), retx (h.retx)
+RttHistory::RttHistory(const RttHistory& h)
+ : seq(h.seq)
+ , count(h.count)
+ , time(h.time)
+ , retx(h.retx)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
// Base class methods
-RttEstimator::RttEstimator ()
- : m_next (1),
- m_nSamples (0),
- m_multiplier (1),
- m_history ()
+RttEstimator::RttEstimator()
+ : m_next(1)
+ , m_nSamples(0)
+ , m_multiplier(1)
+ , m_history()
{
- NS_LOG_FUNCTION (this);
- //note next=1 everywhere since first segment will have sequence 1
+ NS_LOG_FUNCTION(this);
+ // note next=1 everywhere since first segment will have sequence 1
// We need attributes initialized here, not later, so use the
// ConstructSelf() technique documented in the manual
- ObjectBase::ConstructSelf (AttributeConstructionList ());
+ ObjectBase::ConstructSelf(AttributeConstructionList());
m_currentEstimatedRtt = m_initialEstimatedRtt;
- NS_LOG_DEBUG ("Initialize m_currentEstimatedRtt to " << m_currentEstimatedRtt.GetSeconds () << " sec.");
+ NS_LOG_DEBUG("Initialize m_currentEstimatedRtt to " << m_currentEstimatedRtt.GetSeconds()
+ << " sec.");
}
-RttEstimator::RttEstimator (const RttEstimator& c)
- : Object (c), m_next (c.m_next),
- m_maxMultiplier (c.m_maxMultiplier),
- m_initialEstimatedRtt (c.m_initialEstimatedRtt),
- m_currentEstimatedRtt (c.m_currentEstimatedRtt), m_minRto (c.m_minRto), m_maxRto (c.m_maxRto),
- m_nSamples (c.m_nSamples), m_multiplier (c.m_multiplier),
- m_history (c.m_history)
+RttEstimator::RttEstimator(const RttEstimator& c)
+ : Object(c)
+ , m_next(c.m_next)
+ , m_maxMultiplier(c.m_maxMultiplier)
+ , m_initialEstimatedRtt(c.m_initialEstimatedRtt)
+ , m_currentEstimatedRtt(c.m_currentEstimatedRtt)
+ , m_minRto(c.m_minRto)
+ , m_maxRto(c.m_maxRto)
+ , m_nSamples(c.m_nSamples)
+ , m_multiplier(c.m_multiplier)
+ , m_history(c.m_history)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
-RttEstimator::~RttEstimator ()
+RttEstimator::~RttEstimator()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
TypeId
-RttEstimator::GetInstanceTypeId (void) const
+RttEstimator::GetInstanceTypeId(void) const
{
- return GetTypeId ();
+ return GetTypeId();
}
-void RttEstimator::SentSeq (SequenceNumber32 seq, uint32_t size)
+void
+RttEstimator::SentSeq(SequenceNumber32 seq, uint32_t size)
{
- NS_LOG_FUNCTION (this << seq << size);
+ NS_LOG_FUNCTION(this << seq << size);
// Note that a particular sequence has been sent
- if (seq == m_next)
- { // This is the next expected one, just log at end
- m_history.push_back (RttHistory (seq, size, Simulator::Now () ));
- m_next = seq + SequenceNumber32 (size); // Update next expected
- }
- else
- { // This is a retransmit, find in list and mark as re-tx
- for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
- {
- if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32 (i->count))))
- { // Found it
- i->retx = true;
- // One final test..be sure this re-tx does not extend "next"
- if ((seq + SequenceNumber32 (size)) > m_next)
- {
- m_next = seq + SequenceNumber32 (size);
- i->count = ((seq + SequenceNumber32 (size)) - i->seq); // And update count in hist
- }
- break;
- }
+ if (seq == m_next) { // This is the next expected one, just log at end
+ m_history.push_back(RttHistory(seq, size, Simulator::Now()));
+ m_next = seq + SequenceNumber32(size); // Update next expected
+ }
+ else { // This is a retransmit, find in list and mark as re-tx
+ for (RttHistory_t::iterator i = m_history.begin(); i != m_history.end(); ++i) {
+ if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32(i->count)))) { // Found it
+ i->retx = true;
+ // One final test..be sure this re-tx does not extend "next"
+ if ((seq + SequenceNumber32(size)) > m_next) {
+ m_next = seq + SequenceNumber32(size);
+ i->count = ((seq + SequenceNumber32(size)) - i->seq); // And update count in hist
}
+ break;
+ }
}
+ }
}
-Time RttEstimator::AckSeq (SequenceNumber32 ackSeq)
+Time
+RttEstimator::AckSeq(SequenceNumber32 ackSeq)
{
- NS_LOG_FUNCTION (this << ackSeq);
+ NS_LOG_FUNCTION(this << ackSeq);
// An ack has been received, calculate rtt and log this measurement
// Note we use a linear search (O(n)) for this since for the common
// case the ack'ed packet will be at the head of the list
- Time m = Seconds (0.0);
- if (m_history.size () == 0) return (m); // No pending history, just exit
- RttHistory& h = m_history.front ();
- if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count)))
- { // Ok to use this sample
- m = Simulator::Now () - h.time; // Elapsed time
- Measurement (m); // Log the measurement
- ResetMultiplier (); // Reset multiplier on valid measurement
- }
+ Time m = Seconds(0.0);
+ if (m_history.size() == 0)
+ return (m); // No pending history, just exit
+ RttHistory& h = m_history.front();
+ if (!h.retx && ackSeq >= (h.seq + SequenceNumber32(h.count))) { // Ok to use this sample
+ m = Simulator::Now() - h.time; // Elapsed time
+ Measurement(m); // Log the measurement
+ ResetMultiplier(); // Reset multiplier on valid measurement
+ }
// Now delete all ack history with seq <= ack
- while(m_history.size () > 0)
- {
- RttHistory& h = m_history.front ();
- if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) break; // Done removing
- m_history.pop_front (); // Remove
- }
+ while (m_history.size() > 0) {
+ RttHistory& h = m_history.front();
+ if ((h.seq + SequenceNumber32(h.count)) > ackSeq)
+ break; // Done removing
+ m_history.pop_front(); // Remove
+ }
return m;
}
-void RttEstimator::ClearSent ()
+void
+RttEstimator::ClearSent()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
// Clear all history entries
m_next = 1;
- m_history.clear ();
+ m_history.clear();
}
-void RttEstimator::IncreaseMultiplier ()
+void
+RttEstimator::IncreaseMultiplier()
{
- NS_LOG_FUNCTION (this);
- m_multiplier = (m_multiplier*2 < m_maxMultiplier) ? m_multiplier*2 : m_maxMultiplier;
- NS_LOG_DEBUG ("Multiplier increased to " << m_multiplier);
+ NS_LOG_FUNCTION(this);
+ m_multiplier = (m_multiplier * 2 < m_maxMultiplier) ? m_multiplier * 2 : m_maxMultiplier;
+ NS_LOG_DEBUG("Multiplier increased to " << m_multiplier);
}
-void RttEstimator::ResetMultiplier ()
+void
+RttEstimator::ResetMultiplier()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
m_multiplier = 1;
}
-void RttEstimator::Reset ()
+void
+RttEstimator::Reset()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
// Reset to initial state
m_next = 1;
m_currentEstimatedRtt = m_initialEstimatedRtt;
- m_history.clear (); // Remove all info from the history
+ m_history.clear(); // Remove all info from the history
m_nSamples = 0;
- ResetMultiplier ();
+ ResetMultiplier();
}
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-rtt-estimator.hpp b/utils/ndn-rtt-estimator.hpp
index 8da703b..58cc754 100644
--- a/utils/ndn-rtt-estimator.hpp
+++ b/utils/ndn-rtt-estimator.hpp
@@ -42,13 +42,13 @@
*/
class RttHistory {
public:
- RttHistory (SequenceNumber32 s, uint32_t c, Time t);
- RttHistory (const RttHistory& h); // Copy constructor
+ RttHistory(SequenceNumber32 s, uint32_t c, Time t);
+ RttHistory(const RttHistory& h); // Copy constructor
public:
- SequenceNumber32 seq; // First sequence number in packet sent
- uint32_t count; // Number of bytes sent
- Time time; // Time this one was sent
- bool retx; // True if this has been retransmitted
+ SequenceNumber32 seq; // First sequence number in packet sent
+ uint32_t count; // Number of bytes sent
+ Time time; // Time this one was sent
+ bool retx; // True if this has been retransmitted
};
typedef std::deque<RttHistory> RttHistory_t;
@@ -60,110 +60,127 @@
*/
class RttEstimator : public Object {
public:
- static TypeId GetTypeId (void);
+ static TypeId
+ GetTypeId(void);
RttEstimator();
- RttEstimator (const RttEstimator&);
+ RttEstimator(const RttEstimator&);
virtual ~RttEstimator();
- virtual TypeId GetInstanceTypeId (void) const;
+ virtual TypeId
+ GetInstanceTypeId(void) const;
/**
* \brief Note that a particular sequence has been sent
* \param seq the packet sequence number.
* \param size the packet size.
*/
- virtual void SentSeq (SequenceNumber32 seq, uint32_t size);
+ virtual void
+ SentSeq(SequenceNumber32 seq, uint32_t size);
/**
* \brief Note that a particular ack sequence has been received
* \param ackSeq the ack sequence number.
* \return The measured RTT for this ack.
*/
- virtual Time AckSeq (SequenceNumber32 ackSeq);
+ virtual Time
+ AckSeq(SequenceNumber32 ackSeq);
/**
* \brief Clear all history entries
*/
- virtual void ClearSent ();
+ virtual void
+ ClearSent();
/**
* \brief Add a new measurement to the estimator. Pure virtual function.
* \param t the new RTT measure.
*/
- virtual void Measurement (Time t) = 0;
+ virtual void
+ Measurement(Time t) = 0;
/**
* \brief Returns the estimated RTO. Pure virtual function.
* \return the estimated RTO.
*/
- virtual Time RetransmitTimeout () = 0;
+ virtual Time
+ RetransmitTimeout() = 0;
- virtual Ptr<RttEstimator> Copy () const = 0;
+ virtual Ptr<RttEstimator>
+ Copy() const = 0;
/**
* \brief Increase the estimation multiplier up to MaxMultiplier.
*/
- virtual void IncreaseMultiplier ();
+ virtual void
+ IncreaseMultiplier();
/**
* \brief Resets the estimation multiplier to 1.
*/
- virtual void ResetMultiplier ();
+ virtual void
+ ResetMultiplier();
/**
* \brief Resets the estimation to its initial state.
*/
- virtual void Reset ();
+ virtual void
+ Reset();
/**
* \brief Sets the Minimum RTO.
* \param minRto The minimum RTO returned by the estimator.
*/
- void SetMinRto (Time minRto);
+ void
+ SetMinRto(Time minRto);
/**
* \brief Get the Minimum RTO.
* \return The minimum RTO returned by the estimator.
*/
- Time GetMinRto (void) const;
+ Time
+ GetMinRto(void) const;
/**
* \brief Sets the Maximum RTO.
* \param minRto The maximum RTO returned by the estimator.
*/
- void SetMaxRto (Time maxRto);
+ void
+ SetMaxRto(Time maxRto);
/**
* \brief Get the Maximum RTO.
* \return The maximum RTO returned by the estimator.
*/
- Time GetMaxRto (void) const;
+ Time
+ GetMaxRto(void) const;
/**
* \brief Sets the current RTT estimate (forcefully).
* \param estimate The current RTT estimate.
*/
- void SetCurrentEstimate (Time estimate);
+ void
+ SetCurrentEstimate(Time estimate);
/**
* \brief gets the current RTT estimate.
* \return The current RTT estimate.
*/
- Time GetCurrentEstimate (void) const;
+ Time
+ GetCurrentEstimate(void) const;
private:
- SequenceNumber32 m_next; // Next expected sequence to be sent
+ SequenceNumber32 m_next; // Next expected sequence to be sent
uint16_t m_maxMultiplier;
Time m_initialEstimatedRtt;
protected:
- Time m_currentEstimatedRtt; // Current estimate
- Time m_minRto; // minimum value of the timeout
- Time m_maxRto; // maximum value of the timeout
- uint32_t m_nSamples; // Number of samples
- uint16_t m_multiplier; // RTO Multiplier
+ Time m_currentEstimatedRtt; // Current estimate
+ Time m_minRto; // minimum value of the timeout
+ Time m_maxRto; // maximum value of the timeout
+ uint32_t m_nSamples; // Number of samples
+ uint16_t m_multiplier; // RTO Multiplier
RttHistory_t m_history; // List of sent packet
};
diff --git a/utils/ndn-rtt-mean-deviation.cpp b/utils/ndn-rtt-mean-deviation.cpp
index 8e99069..c6c7218 100644
--- a/utils/ndn-rtt-mean-deviation.cpp
+++ b/utils/ndn-rtt-mean-deviation.cpp
@@ -32,7 +32,7 @@
#include "ns3/uinteger.h"
#include "ns3/log.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.RttMeanDeviation");
+NS_LOG_COMPONENT_DEFINE("ndn.RttMeanDeviation");
namespace ns3 {
namespace ndn {
@@ -40,143 +40,147 @@
//---------------------------------------------------------------------------------
// A modified version of Mean-Deviation Estimator optimized for NDN packet delivery
-NS_OBJECT_ENSURE_REGISTERED (RttMeanDeviation);
+NS_OBJECT_ENSURE_REGISTERED(RttMeanDeviation);
TypeId
-RttMeanDeviation::GetTypeId (void)
+RttMeanDeviation::GetTypeId(void)
{
- static TypeId tid = TypeId ("ns3::ndn::RttMeanDeviation")
- .SetParent<RttEstimator> ()
- .AddConstructor<RttMeanDeviation> ()
- .AddAttribute ("Gain",
- "Gain used in estimating the RTT (smoothed RTT), must be 0 < Gain < 1",
- DoubleValue (0.125),
- MakeDoubleAccessor (&RttMeanDeviation::m_gain),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Gain2",
- "Gain2 used in estimating the RTT (variance), must be 0 < Gain2 < 1",
- DoubleValue (0.25),
- MakeDoubleAccessor (&RttMeanDeviation::m_gain2),
- MakeDoubleChecker<double> ())
- ;
+ static TypeId tid =
+ TypeId("ns3::ndn::RttMeanDeviation")
+ .SetParent<RttEstimator>()
+ .AddConstructor<RttMeanDeviation>()
+ .AddAttribute("Gain", "Gain used in estimating the RTT (smoothed RTT), must be 0 < Gain < 1",
+ DoubleValue(0.125), MakeDoubleAccessor(&RttMeanDeviation::m_gain),
+ MakeDoubleChecker<double>())
+ .AddAttribute("Gain2", "Gain2 used in estimating the RTT (variance), must be 0 < Gain2 < 1",
+ DoubleValue(0.25), MakeDoubleAccessor(&RttMeanDeviation::m_gain2),
+ MakeDoubleChecker<double>());
return tid;
}
-RttMeanDeviation::RttMeanDeviation() :
- m_variance (0)
+RttMeanDeviation::RttMeanDeviation()
+ : m_variance(0)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
-RttMeanDeviation::RttMeanDeviation (const RttMeanDeviation& c)
- : RttEstimator (c), m_gain (c.m_gain), m_gain2 (c.m_gain2), m_variance (c.m_variance)
+RttMeanDeviation::RttMeanDeviation(const RttMeanDeviation& c)
+ : RttEstimator(c)
+ , m_gain(c.m_gain)
+ , m_gain2(c.m_gain2)
+ , m_variance(c.m_variance)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
}
TypeId
-RttMeanDeviation::GetInstanceTypeId (void) const
+RttMeanDeviation::GetInstanceTypeId(void) const
{
- return GetTypeId ();
+ return GetTypeId();
}
-void RttMeanDeviation::Measurement (Time m)
+void
+RttMeanDeviation::Measurement(Time m)
{
- NS_LOG_FUNCTION (this << m);
- if (m_nSamples)
- { // Not first
- Time err (m - m_currentEstimatedRtt);
- double gErr = err.ToDouble (Time::S) * m_gain;
- m_currentEstimatedRtt += Time::FromDouble (gErr, Time::S);
- Time difference = Abs (err) - m_variance;
- NS_LOG_DEBUG ("m_variance += " << Time::FromDouble (difference.ToDouble (Time::S) * m_gain2, Time::S));
- m_variance += Time::FromDouble (difference.ToDouble (Time::S) * m_gain2, Time::S);
- }
- else
- { // First sample
- m_currentEstimatedRtt = m; // Set estimate to current
- //variance = sample / 2; // And variance to current / 2
- // m_variance = m; // try this why????
- m_variance = Seconds (m.ToDouble (Time::S) / 2);
- NS_LOG_DEBUG ("(first sample) m_variance += " << m);
- }
+ NS_LOG_FUNCTION(this << m);
+ if (m_nSamples) { // Not first
+ Time err(m - m_currentEstimatedRtt);
+ double gErr = err.ToDouble(Time::S) * m_gain;
+ m_currentEstimatedRtt += Time::FromDouble(gErr, Time::S);
+ Time difference = Abs(err) - m_variance;
+ NS_LOG_DEBUG(
+ "m_variance += " << Time::FromDouble(difference.ToDouble(Time::S) * m_gain2, Time::S));
+ m_variance += Time::FromDouble(difference.ToDouble(Time::S) * m_gain2, Time::S);
+ }
+ else { // First sample
+ m_currentEstimatedRtt = m; // Set estimate to current
+ // variance = sample / 2; // And variance to current / 2
+ // m_variance = m; // try this why????
+ m_variance = Seconds(m.ToDouble(Time::S) / 2);
+ NS_LOG_DEBUG("(first sample) m_variance += " << m);
+ }
m_nSamples++;
}
-Time RttMeanDeviation::RetransmitTimeout ()
+Time
+RttMeanDeviation::RetransmitTimeout()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
- double retval = std::min (m_maxRto.ToDouble (Time::S),
- std::max (m_multiplier*m_minRto.ToDouble (Time::S),
- m_multiplier*(m_currentEstimatedRtt.ToDouble (Time::S) + 4 * m_variance.ToDouble (Time::S))));
+ double retval = std::min(m_maxRto.ToDouble(Time::S),
+ std::max(m_multiplier * m_minRto.ToDouble(Time::S),
+ m_multiplier * (m_currentEstimatedRtt.ToDouble(Time::S)
+ + 4 * m_variance.ToDouble(Time::S))));
- NS_LOG_DEBUG ("RetransmitTimeout: return " << retval);
+ NS_LOG_DEBUG("RetransmitTimeout: return " << retval);
- return Seconds (retval);
+ return Seconds(retval);
}
-Ptr<RttEstimator> RttMeanDeviation::Copy () const
+Ptr<RttEstimator>
+RttMeanDeviation::Copy() const
{
- NS_LOG_FUNCTION (this);
- return CopyObject<RttMeanDeviation> (this);
+ NS_LOG_FUNCTION(this);
+ return CopyObject<RttMeanDeviation>(this);
}
-void RttMeanDeviation::Reset ()
+void
+RttMeanDeviation::Reset()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION(this);
// Reset to initial state
- m_variance = Seconds (0);
- RttEstimator::Reset ();
+ m_variance = Seconds(0);
+ RttEstimator::Reset();
}
-void RttMeanDeviation::Gain (double g)
+void
+RttMeanDeviation::Gain(double g)
{
- NS_LOG_FUNCTION (this);
- NS_ASSERT_MSG( (g > 0) && (g < 1), "RttMeanDeviation: Gain must be less than 1 and greater than 0" );
+ NS_LOG_FUNCTION(this);
+ NS_ASSERT_MSG((g > 0) && (g < 1),
+ "RttMeanDeviation: Gain must be less than 1 and greater than 0");
m_gain = g;
}
-void RttMeanDeviation::SentSeq (SequenceNumber32 seq, uint32_t size)
-{
- NS_LOG_FUNCTION (this << seq << size);
+void
+RttMeanDeviation::SentSeq(SequenceNumber32 seq, uint32_t size)
+{
+ NS_LOG_FUNCTION(this << seq << size);
RttHistory_t::iterator i;
- for (i = m_history.begin (); i != m_history.end (); ++i)
- {
- if (seq == i->seq)
- { // Found it
- i->retx = true;
- break;
- }
+ for (i = m_history.begin(); i != m_history.end(); ++i) {
+ if (seq == i->seq) { // Found it
+ i->retx = true;
+ break;
+ }
}
// Note that a particular sequence has been sent
if (i == m_history.end())
- m_history.push_back (RttHistory (seq, size, Simulator::Now () ));
+ m_history.push_back(RttHistory(seq, size, Simulator::Now()));
}
-Time RttMeanDeviation::AckSeq (SequenceNumber32 ackSeq)
+Time
+RttMeanDeviation::AckSeq(SequenceNumber32 ackSeq)
{
- NS_LOG_FUNCTION (this << ackSeq);
+ NS_LOG_FUNCTION(this << ackSeq);
// An ack has been received, calculate rtt and log this measurement
// Note we use a linear search (O(n)) for this since for the common
// case the ack'ed packet will be at the head of the list
- Time m = Seconds (0.0);
- if (m_history.size () == 0) return (m); // No pending history, just exit
+ Time m = Seconds(0.0);
+ if (m_history.size() == 0)
+ return (m); // No pending history, just exit
- for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
- {
- if (ackSeq == i->seq)
- { // Found it
- if (!i->retx) {
- m = Simulator::Now () - i->time;// Elapsed time
- Measurement (m); // Log the measurement
- ResetMultiplier (); // Reset multiplier on valid measurement
- }
- m_history.erase(i);
- break;
+ for (RttHistory_t::iterator i = m_history.begin(); i != m_history.end(); ++i) {
+ if (ackSeq == i->seq) { // Found it
+ if (!i->retx) {
+ m = Simulator::Now() - i->time; // Elapsed time
+ Measurement(m); // Log the measurement
+ ResetMultiplier(); // Reset multiplier on valid measurement
}
+ m_history.erase(i);
+ break;
+ }
}
return m;
@@ -184,4 +188,3 @@
} // namespace ndn
} // namespace ns3
-
diff --git a/utils/ndn-rtt-mean-deviation.hpp b/utils/ndn-rtt-mean-deviation.hpp
index 428bff8..fdb6144 100644
--- a/utils/ndn-rtt-mean-deviation.hpp
+++ b/utils/ndn-rtt-mean-deviation.hpp
@@ -25,7 +25,6 @@
// Georgia Tech Network Simulator - Round Trip Time Estimation Class
// George F. Riley. Georgia Tech, Spring 2002
-
#ifndef NDN_RTT_MEAN_DEVIATION_H
#define NDN_RTT_MEAN_DEVIATION_H
@@ -37,7 +36,8 @@
/**
* \ingroup ndn-apps
*
- * \brief The modified version of "Mean--Deviation" RTT estimator, as discussed by Van Jacobson that better suits NDN communication model
+ * \brief The modified version of "Mean--Deviation" RTT estimator, as discussed by Van Jacobson that
+ *better suits NDN communication model
*
* This class implements the "Mean--Deviation" RTT estimator, as discussed
* by Van Jacobson and Michael J. Karels, in
@@ -46,25 +46,34 @@
*/
class RttMeanDeviation : public RttEstimator {
public:
- static TypeId GetTypeId (void);
+ static TypeId
+ GetTypeId(void);
- RttMeanDeviation ();
- RttMeanDeviation (const RttMeanDeviation&);
+ RttMeanDeviation();
+ RttMeanDeviation(const RttMeanDeviation&);
- virtual TypeId GetInstanceTypeId (void) const;
+ virtual TypeId
+ GetInstanceTypeId(void) const;
- void SentSeq (SequenceNumber32 seq, uint32_t size);
- Time AckSeq (SequenceNumber32 ackSeq);
- void Measurement (Time measure);
- Time RetransmitTimeout ();
- Ptr<RttEstimator> Copy () const;
- void Reset ();
- void Gain (double g);
+ void
+ SentSeq(SequenceNumber32 seq, uint32_t size);
+ Time
+ AckSeq(SequenceNumber32 ackSeq);
+ void
+ Measurement(Time measure);
+ Time
+ RetransmitTimeout();
+ Ptr<RttEstimator>
+ Copy() const;
+ void
+ Reset();
+ void
+ Gain(double g);
private:
- double m_gain; // Filter gain
- double m_gain2; // Filter gain
- Time m_variance; // Current variance
+ double m_gain; // Filter gain
+ double m_gain2; // Filter gain
+ Time m_variance; // Current variance
};
} // namespace ndn
diff --git a/utils/tracers/l2-rate-tracer.cpp b/utils/tracers/l2-rate-tracer.cpp
index 41ae00b..f5c4d22 100644
--- a/utils/tracers/l2-rate-tracer.cpp
+++ b/utils/tracers/l2-rate-tracer.cpp
@@ -34,153 +34,150 @@
using namespace boost;
using namespace std;
-NS_LOG_COMPONENT_DEFINE ("L2RateTracer");
+NS_LOG_COMPONENT_DEFINE("L2RateTracer");
namespace ns3 {
-static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L2RateTracer> > > > g_tracers;
+static std::list<boost::tuple<boost::shared_ptr<std::ostream>, std::list<Ptr<L2RateTracer>>>>
+ g_tracers;
template<class T>
static inline void
-NullDeleter (T *ptr)
+NullDeleter(T* ptr)
{
}
void
-L2RateTracer::Destroy ()
+L2RateTracer::Destroy()
{
- g_tracers.clear ();
+ g_tracers.clear();
}
void
-L2RateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L2RateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/)
{
- std::list<Ptr<L2RateTracer> > tracers;
+ std::list<Ptr<L2RateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeList::Iterator node = NodeList::Begin ();
- node != NodeList::End ();
- node++)
- {
- NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- Ptr<L2RateTracer> trace = Create<L2RateTracer> (outputStream, *node);
- trace->SetAveragingPeriod (averagingPeriod);
- tracers.push_back (trace);
- }
+ for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
+ NS_LOG_DEBUG("Node: " << lexical_cast<string>((*node)->GetId()));
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ Ptr<L2RateTracer> trace = Create<L2RateTracer>(outputStream, *node);
+ trace->SetAveragingPeriod(averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
-
-L2RateTracer::L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
- : L2Tracer (node)
- , m_os (os)
+L2RateTracer::L2RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : L2Tracer(node)
+ , m_os(os)
{
- SetAveragingPeriod (Seconds (1.0));
+ SetAveragingPeriod(Seconds(1.0));
}
-L2RateTracer::~L2RateTracer ()
+L2RateTracer::~L2RateTracer()
{
- m_printEvent.Cancel ();
+ m_printEvent.Cancel();
}
void
-L2RateTracer::SetAveragingPeriod (const Time &period)
+L2RateTracer::SetAveragingPeriod(const Time& period)
{
m_period = period;
- m_printEvent.Cancel ();
- m_printEvent = Simulator::Schedule (m_period, &L2RateTracer::PeriodicPrinter, this);
+ m_printEvent.Cancel();
+ m_printEvent = Simulator::Schedule(m_period, &L2RateTracer::PeriodicPrinter, this);
}
void
-L2RateTracer::PeriodicPrinter ()
+L2RateTracer::PeriodicPrinter()
{
- Print (*m_os);
- Reset ();
+ Print(*m_os);
+ Reset();
- m_printEvent = Simulator::Schedule (m_period, &L2RateTracer::PeriodicPrinter, this);
+ m_printEvent = Simulator::Schedule(m_period, &L2RateTracer::PeriodicPrinter, this);
}
void
-L2RateTracer::PrintHeader (std::ostream &os) const
+L2RateTracer::PrintHeader(std::ostream& os) const
{
- os << "Time" << "\t"
+ os << "Time"
+ << "\t"
- << "Node" << "\t"
- << "Interface" << "\t"
+ << "Node"
+ << "\t"
+ << "Interface"
+ << "\t"
- << "Type" << "\t"
- << "Packets" << "\t"
- << "Kilobytes" << "\t"
- << "PacketsRaw" << "\t"
+ << "Type"
+ << "\t"
+ << "Packets"
+ << "\t"
+ << "Kilobytes"
+ << "\t"
+ << "PacketsRaw"
+ << "\t"
<< "KilobytesRaw";
}
void
-L2RateTracer::Reset ()
+L2RateTracer::Reset()
{
- m_stats.get<0> ().Reset ();
- m_stats.get<1> ().Reset ();
+ m_stats.get<0>().Reset();
+ m_stats.get<1>().Reset();
}
const double alpha = 0.8;
-#define STATS(INDEX) m_stats.get<INDEX> ()
-#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
+#define STATS(INDEX) m_stats.get<INDEX>()
+#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble(Time::S)
-#define PRINTER(printName, fieldName, interface) \
-STATS(2).fieldName = /*new value*/alpha * RATE(0, fieldName) + /*old value*/(1-alpha) * STATS(2).fieldName; \
-STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
- \
- os << time.ToDouble (Time::S) << "\t" \
- << m_node << "\t" \
- << interface << "\t" \
- << printName << "\t" \
- << STATS(2).fieldName << "\t" \
- << STATS(3).fieldName << "\t" \
- << STATS(0).fieldName << "\t" \
- << STATS(1).fieldName / 1024.0 << "\n";
+#define PRINTER(printName, fieldName, interface) \
+ STATS(2).fieldName = \
+ /*new value*/ alpha * RATE(0, fieldName) + /*old value*/ (1 - alpha) * STATS(2).fieldName; \
+ STATS(3).fieldName = /*new value*/ alpha * RATE(1, fieldName) / 1024.0 \
+ + /*old value*/ (1 - alpha) * STATS(3).fieldName; \
+ \
+ os << time.ToDouble(Time::S) << "\t" << m_node << "\t" << interface << "\t" << printName << "\t" \
+ << STATS(2).fieldName << "\t" << STATS(3).fieldName << "\t" << STATS(0).fieldName << "\t" \
+ << STATS(1).fieldName / 1024.0 << "\n";
void
-L2RateTracer::Print (std::ostream &os) const
+L2RateTracer::Print(std::ostream& os) const
{
- Time time = Simulator::Now ();
+ Time time = Simulator::Now();
- PRINTER ("Drop", m_drop, "combined");
+ PRINTER("Drop", m_drop, "combined");
}
void
-L2RateTracer::Drop (Ptr<const Packet> packet)
+L2RateTracer::Drop(Ptr<const Packet> packet)
{
// no interface information... this should be part of this L2Tracer object data
- m_stats.get<0> ().m_drop ++;
- m_stats.get<1> ().m_drop += packet->GetSize ();
+ m_stats.get<0>().m_drop++;
+ m_stats.get<1>().m_drop += packet->GetSize();
}
} // namespace ns3
diff --git a/utils/tracers/l2-rate-tracer.hpp b/utils/tracers/l2-rate-tracer.hpp
index 275b213..79f16c4 100644
--- a/utils/tracers/l2-rate-tracer.hpp
+++ b/utils/tracers/l2-rate-tracer.hpp
@@ -38,28 +38,29 @@
*
* @todo Finish implementation
*/
-class L2RateTracer : public L2Tracer
-{
+class L2RateTracer : public L2Tracer {
public:
/**
* @brief Network layer tracer constructor
*/
- L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
- virtual ~L2RateTracer ();
+ L2RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ virtual ~L2RateTracer();
/**
* @brief Helper method to install tracers on all simulation nodes
*
* @param file File to which traces will be written
* @param averagingPeriod Defines averaging period for the rate calculation,
- * as well as how often data will be written into the trace file (default, every half second)
+ * as well as how often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+ InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Explicit request to remove all statically created tracers
@@ -68,26 +69,26 @@
* or if it is desired to do a postprocessing of the resulting data
*/
static void
- Destroy ();
+ Destroy();
void
- SetAveragingPeriod (const Time &period);
+ SetAveragingPeriod(const Time& period);
virtual void
- PrintHeader (std::ostream &os) const;
+ PrintHeader(std::ostream& os) const;
virtual void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
virtual void
- Drop (Ptr<const Packet>);
+ Drop(Ptr<const Packet>);
private:
void
- PeriodicPrinter ();
+ PeriodicPrinter();
void
- Reset ();
+ Reset();
private:
boost::shared_ptr<std::ostream> m_os;
diff --git a/utils/tracers/l2-tracer.cpp b/utils/tracers/l2-tracer.cpp
index 631db7c..bf1fcf1 100644
--- a/utils/tracers/l2-tracer.cpp
+++ b/utils/tracers/l2-tracer.cpp
@@ -32,31 +32,29 @@
namespace ns3 {
-L2Tracer::L2Tracer (Ptr<Node> node)
-: m_nodePtr (node)
+L2Tracer::L2Tracer(Ptr<Node> node)
+ : m_nodePtr(node)
{
- m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+ m_node = boost::lexical_cast<string>(m_nodePtr->GetId());
- Connect ();
+ Connect();
- string name = Names::FindName (node);
- if (!name.empty ())
- {
- m_node = name;
- }
+ string name = Names::FindName(node);
+ if (!name.empty()) {
+ m_node = name;
+ }
}
void
-L2Tracer::Connect ()
+L2Tracer::Connect()
{
- for (uint32_t devId = 0; devId < m_nodePtr->GetNDevices (); devId ++)
- {
- Ptr<PointToPointNetDevice> p2pnd = DynamicCast<PointToPointNetDevice> (m_nodePtr->GetDevice (devId));
- if (p2pnd)
- {
- p2pnd->GetQueue ()->TraceConnectWithoutContext ("Drop", MakeCallback (&L2Tracer::Drop, this));
- }
+ for (uint32_t devId = 0; devId < m_nodePtr->GetNDevices(); devId++) {
+ Ptr<PointToPointNetDevice> p2pnd =
+ DynamicCast<PointToPointNetDevice>(m_nodePtr->GetDevice(devId));
+ if (p2pnd) {
+ p2pnd->GetQueue()->TraceConnectWithoutContext("Drop", MakeCallback(&L2Tracer::Drop, this));
}
+ }
}
} // namespace ns3
diff --git a/utils/tracers/l2-tracer.hpp b/utils/tracers/l2-tracer.hpp
index e6378b5..a2cd3a6 100644
--- a/utils/tracers/l2-tracer.hpp
+++ b/utils/tracers/l2-tracer.hpp
@@ -35,23 +35,22 @@
*
* @todo Finish implementation
*/
-class L2Tracer : public SimpleRefCount<L2Tracer>
-{
+class L2Tracer : public SimpleRefCount<L2Tracer> {
public:
- L2Tracer (Ptr<Node> node);
- virtual ~L2Tracer () { };
+ L2Tracer(Ptr<Node> node);
+ virtual ~L2Tracer(){};
void
- Connect ();
+ Connect();
virtual void
- PrintHeader (std::ostream &os) const = 0;
+ PrintHeader(std::ostream& os) const = 0;
virtual void
- Print (std::ostream &os) const = 0;
+ Print(std::ostream& os) const = 0;
virtual void
- Drop (Ptr<const Packet>) = 0;
+ Drop(Ptr<const Packet>) = 0;
// Rx/Tx is NetDevice specific
// please refer to pyviz.cc in order to extend this tracer
@@ -60,9 +59,9 @@
std::string m_node;
Ptr<Node> m_nodePtr;
- struct Stats
- {
- void Reset ()
+ struct Stats {
+ void
+ Reset()
{
m_in = 0;
m_out = 0;
@@ -76,12 +75,12 @@
};
inline std::ostream&
-operator << (std::ostream &os, const L2Tracer &tracer)
+operator<<(std::ostream& os, const L2Tracer& tracer)
{
os << "# ";
- tracer.PrintHeader (os);
+ tracer.PrintHeader(os);
os << "\n";
- tracer.Print (os);
+ tracer.Print(os);
return os;
}
diff --git a/utils/tracers/ndn-app-delay-tracer.cpp b/utils/tracers/ndn-app-delay-tracer.cpp
index 01a5af4..666f945 100644
--- a/utils/tracers/ndn-app-delay-tracer.cpp
+++ b/utils/tracers/ndn-app-delay-tracer.cpp
@@ -37,162 +37,143 @@
#include <fstream>
-NS_LOG_COMPONENT_DEFINE ("ndn.AppDelayTracer");
+NS_LOG_COMPONENT_DEFINE("ndn.AppDelayTracer");
using namespace std;
namespace ns3 {
namespace ndn {
-static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > > > g_tracers;
+static std::list<boost::tuple<boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer>>>>
+ g_tracers;
template<class T>
static inline void
-NullDeleter (T *ptr)
+NullDeleter(T* ptr)
{
}
void
-AppDelayTracer::Destroy ()
+AppDelayTracer::Destroy()
{
- g_tracers.clear ();
+ g_tracers.clear();
}
void
-AppDelayTracer::InstallAll (const std::string &file)
+AppDelayTracer::InstallAll(const std::string& file)
{
using namespace boost;
using namespace std;
- std::list<Ptr<AppDelayTracer> > tracers;
+ std::list<Ptr<AppDelayTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeList::Iterator node = NodeList::Begin ();
- node != NodeList::End ();
- node++)
- {
- Ptr<AppDelayTracer> trace = Install (*node, outputStream);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
+ Ptr<AppDelayTracer> trace = Install(*node, outputStream);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-AppDelayTracer::Install (const NodeContainer &nodes, const std::string &file)
+AppDelayTracer::Install(const NodeContainer& nodes, const std::string& file)
{
using namespace boost;
using namespace std;
- std::list<Ptr<AppDelayTracer> > tracers;
+ std::list<Ptr<AppDelayTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeContainer::Iterator node = nodes.Begin ();
- node != nodes.End ();
- node++)
- {
- Ptr<AppDelayTracer> trace = Install (*node, outputStream);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
+ Ptr<AppDelayTracer> trace = Install(*node, outputStream);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-AppDelayTracer::Install (Ptr<Node> node, const std::string &file)
+AppDelayTracer::Install(Ptr<Node> node, const std::string& file)
{
using namespace boost;
using namespace std;
- std::list<Ptr<AppDelayTracer> > tracers;
+ std::list<Ptr<AppDelayTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- Ptr<AppDelayTracer> trace = Install (node, outputStream);
- tracers.push_back (trace);
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ Ptr<AppDelayTracer> trace = Install(node, outputStream);
+ tracers.push_back(trace);
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
-
Ptr<AppDelayTracer>
-AppDelayTracer::Install (Ptr<Node> node,
- boost::shared_ptr<std::ostream> outputStream)
+AppDelayTracer::Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream)
{
- NS_LOG_DEBUG ("Node: " << node->GetId ());
+ NS_LOG_DEBUG("Node: " << node->GetId());
- Ptr<AppDelayTracer> trace = Create<AppDelayTracer> (outputStream, node);
+ Ptr<AppDelayTracer> trace = Create<AppDelayTracer>(outputStream, node);
return trace;
}
@@ -201,86 +182,86 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
-: m_nodePtr (node)
-, m_os (os)
+AppDelayTracer::AppDelayTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : m_nodePtr(node)
+ , m_os(os)
{
- m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+ m_node = boost::lexical_cast<string>(m_nodePtr->GetId());
- Connect ();
+ Connect();
- string name = Names::FindName (node);
- if (!name.empty ())
- {
- m_node = name;
- }
+ string name = Names::FindName(node);
+ if (!name.empty()) {
+ m_node = name;
+ }
}
-AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
-: m_node (node)
-, m_os (os)
+AppDelayTracer::AppDelayTracer(boost::shared_ptr<std::ostream> os, const std::string& node)
+ : m_node(node)
+ , m_os(os)
{
- Connect ();
+ Connect();
}
-AppDelayTracer::~AppDelayTracer ()
-{
-};
-
+AppDelayTracer::~AppDelayTracer(){};
void
-AppDelayTracer::Connect ()
+AppDelayTracer::Connect()
{
- Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/LastRetransmittedInterestDataDelay",
- MakeCallback (&AppDelayTracer::LastRetransmittedInterestDataDelay, this));
+ Config::ConnectWithoutContext("/NodeList/" + m_node
+ + "/ApplicationList/*/LastRetransmittedInterestDataDelay",
+ MakeCallback(&AppDelayTracer::LastRetransmittedInterestDataDelay,
+ this));
- Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/FirstInterestDataDelay",
- MakeCallback (&AppDelayTracer::FirstInterestDataDelay, this));
+ Config::ConnectWithoutContext("/NodeList/" + m_node + "/ApplicationList/*/FirstInterestDataDelay",
+ MakeCallback(&AppDelayTracer::FirstInterestDataDelay, this));
}
void
-AppDelayTracer::PrintHeader (std::ostream &os) const
+AppDelayTracer::PrintHeader(std::ostream& os) const
{
- os << "Time" << "\t"
- << "Node" << "\t"
- << "AppId" << "\t"
- << "SeqNo" << "\t"
+ os << "Time"
+ << "\t"
+ << "Node"
+ << "\t"
+ << "AppId"
+ << "\t"
+ << "SeqNo"
+ << "\t"
- << "Type" << "\t"
- << "DelayS" << "\t"
- << "DelayUS" << "\t"
- << "RetxCount" << "\t"
- << "HopCount" << "";
+ << "Type"
+ << "\t"
+ << "DelayS"
+ << "\t"
+ << "DelayUS"
+ << "\t"
+ << "RetxCount"
+ << "\t"
+ << "HopCount"
+ << "";
}
void
-AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount)
+AppDelayTracer::LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay,
+ int32_t hopCount)
{
- *m_os << Simulator::Now ().ToDouble (Time::S) << "\t"
- << m_node << "\t"
- << app->GetId () << "\t"
+ *m_os << Simulator::Now().ToDouble(Time::S) << "\t" << m_node << "\t" << app->GetId() << "\t"
<< seqno << "\t"
- << "LastDelay" << "\t"
- << delay.ToDouble (Time::S) << "\t"
- << delay.ToDouble (Time::US) << "\t"
- << 1 << "\t"
+ << "LastDelay"
+ << "\t" << delay.ToDouble(Time::S) << "\t" << delay.ToDouble(Time::US) << "\t" << 1 << "\t"
<< hopCount << "\n";
}
void
-AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount)
+AppDelayTracer::FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount,
+ int32_t hopCount)
{
- *m_os << Simulator::Now ().ToDouble (Time::S) << "\t"
- << m_node << "\t"
- << app->GetId () << "\t"
+ *m_os << Simulator::Now().ToDouble(Time::S) << "\t" << m_node << "\t" << app->GetId() << "\t"
<< seqno << "\t"
- << "FullDelay" << "\t"
- << delay.ToDouble (Time::S) << "\t"
- << delay.ToDouble (Time::US) << "\t"
- << retxCount << "\t"
- << hopCount << "\n";
+ << "FullDelay"
+ << "\t" << delay.ToDouble(Time::S) << "\t" << delay.ToDouble(Time::US) << "\t" << retxCount
+ << "\t" << hopCount << "\n";
}
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/tracers/ndn-app-delay-tracer.hpp b/utils/tracers/ndn-app-delay-tracer.hpp
index d911fc9..64b695a 100644
--- a/utils/tracers/ndn-app-delay-tracer.hpp
+++ b/utils/tracers/ndn-app-delay-tracer.hpp
@@ -44,20 +44,20 @@
* @ingroup ndn-tracers
* @brief Tracer to obtain application-level delays
*/
-class AppDelayTracer : public SimpleRefCount<AppDelayTracer>
-{
+class AppDelayTracer : public SimpleRefCount<AppDelayTracer> {
public:
/**
* @brief Helper method to install tracers on all simulation nodes
*
* @param file File to which traces will be written. If filename is -, then std::out is used
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
- *
+ *
*/
static void
- InstallAll (const std::string &file);
+ InstallAll(const std::string& file);
/**
* @brief Helper method to install tracers on the selected simulation nodes
@@ -65,39 +65,44 @@
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (const NodeContainer &nodes, const std::string &file);
+ Install(const NodeContainer& nodes, const std::string& file);
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (Ptr<Node> node, const std::string &file);
+ Install(Ptr<Node> node, const std::string& file);
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param outputStream Smart pointer to a stream
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*/
static Ptr<AppDelayTracer>
- Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
+ Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream);
/**
* @brief Explicit request to remove all statically created tracers
@@ -106,26 +111,26 @@
* or if it is desired to do a postprocessing of the resulting data
*/
static void
- Destroy ();
-
+ Destroy();
+
/**
* @brief Trace constructor that attaches to all applications on the node using node's pointer
* @param os reference to the output stream
* @param node pointer to the node
*/
- AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ AppDelayTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
/**
* @brief Trace constructor that attaches to all applications on the node using node's name
* @param os reference to the output stream
* @param nodeName name of the node registered using Names::Add
*/
- AppDelayTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
+ AppDelayTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
/**
* @brief Destructor
*/
- ~AppDelayTracer ();
+ ~AppDelayTracer();
/**
* @brief Print head of the trace (e.g., for post-processing)
@@ -133,18 +138,19 @@
* @param os reference to output stream
*/
void
- PrintHeader (std::ostream &os) const;
-
+ PrintHeader(std::ostream& os) const;
+
private:
void
- Connect ();
+ Connect();
- void
- LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
-
- void
- FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount, int32_t hopCount);
-
+ void
+ LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount);
+
+ void
+ FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t rextCount,
+ int32_t hopCount);
+
private:
std::string m_node;
Ptr<Node> m_nodePtr;
diff --git a/utils/tracers/ndn-cs-tracer.cpp b/utils/tracers/ndn-cs-tracer.cpp
index 74fa3dd..bc5d8de 100644
--- a/utils/tracers/ndn-cs-tracer.cpp
+++ b/utils/tracers/ndn-cs-tracer.cpp
@@ -38,164 +38,146 @@
#include <fstream>
-NS_LOG_COMPONENT_DEFINE ("ndn.CsTracer");
+NS_LOG_COMPONENT_DEFINE("ndn.CsTracer");
using namespace std;
namespace ns3 {
namespace ndn {
-static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer> > > > g_tracers;
+static std::list<boost::tuple<boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer>>>> g_tracers;
template<class T>
static inline void
-NullDeleter (T *ptr)
+NullDeleter(T* ptr)
{
}
void
-CsTracer::Destroy ()
+CsTracer::Destroy()
{
- g_tracers.clear ();
+ g_tracers.clear();
}
void
-CsTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
-{
- using namespace boost;
- using namespace std;
-
- std::list<Ptr<CsTracer> > tracers;
- boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
-
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
- }
-
- for (NodeList::Iterator node = NodeList::Begin ();
- node != NodeList::End ();
- node++)
- {
- Ptr<CsTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
-
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
-
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
-}
-
-void
-CsTracer::Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+CsTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<CsTracer> > tracers;
+ std::list<Ptr<CsTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeContainer::Iterator node = nodes.Begin ();
- node != nodes.End ();
- node++)
- {
- Ptr<CsTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
+ Ptr<CsTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-CsTracer::Install (Ptr<Node> node, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+CsTracer::Install(const NodeContainer& nodes, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<CsTracer> > tracers;
+ std::list<Ptr<CsTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- Ptr<CsTracer> trace = Install (node, outputStream, averagingPeriod);
- tracers.push_back (trace);
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
+ Ptr<CsTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
+void
+CsTracer::Install(Ptr<Node> node, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
+{
+ using namespace boost;
+ using namespace std;
+
+ std::list<Ptr<CsTracer>> tracers;
+ boost::shared_ptr<std::ostream> outputStream;
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
+
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
+ }
+
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
+
+ Ptr<CsTracer> trace = Install(node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
+}
Ptr<CsTracer>
-CsTracer::Install (Ptr<Node> node,
- boost::shared_ptr<std::ostream> outputStream,
- Time averagingPeriod/* = Seconds (0.5)*/)
+CsTracer::Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
- NS_LOG_DEBUG ("Node: " << node->GetId ());
+ NS_LOG_DEBUG("Node: " << node->GetId());
- Ptr<CsTracer> trace = Create<CsTracer> (outputStream, node);
- trace->SetAveragingPeriod (averagingPeriod);
+ Ptr<CsTracer> trace = Create<CsTracer>(outputStream, node);
+ trace->SetAveragingPeriod(averagingPeriod);
return trace;
}
@@ -204,106 +186,101 @@
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
-CsTracer::CsTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
-: m_nodePtr (node)
-, m_os (os)
+CsTracer::CsTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : m_nodePtr(node)
+ , m_os(os)
{
- m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+ m_node = boost::lexical_cast<string>(m_nodePtr->GetId());
- Connect ();
+ Connect();
- string name = Names::FindName (node);
- if (!name.empty ())
- {
- m_node = name;
- }
+ string name = Names::FindName(node);
+ if (!name.empty()) {
+ m_node = name;
+ }
}
-CsTracer::CsTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
-: m_node (node)
-, m_os (os)
+CsTracer::CsTracer(boost::shared_ptr<std::ostream> os, const std::string& node)
+ : m_node(node)
+ , m_os(os)
{
- Connect ();
+ Connect();
}
-CsTracer::~CsTracer ()
-{
-};
-
+CsTracer::~CsTracer(){};
void
-CsTracer::Connect ()
+CsTracer::Connect()
{
- Ptr<ContentStore> cs = m_nodePtr->GetObject<ContentStore> ();
- cs->TraceConnectWithoutContext ("CacheHits", MakeCallback (&CsTracer::CacheHits, this));
- cs->TraceConnectWithoutContext ("CacheMisses", MakeCallback (&CsTracer::CacheMisses, this));
+ Ptr<ContentStore> cs = m_nodePtr->GetObject<ContentStore>();
+ cs->TraceConnectWithoutContext("CacheHits", MakeCallback(&CsTracer::CacheHits, this));
+ cs->TraceConnectWithoutContext("CacheMisses", MakeCallback(&CsTracer::CacheMisses, this));
- Reset ();
+ Reset();
}
-
void
-CsTracer::SetAveragingPeriod (const Time &period)
+CsTracer::SetAveragingPeriod(const Time& period)
{
m_period = period;
- m_printEvent.Cancel ();
- m_printEvent = Simulator::Schedule (m_period, &CsTracer::PeriodicPrinter, this);
+ m_printEvent.Cancel();
+ m_printEvent = Simulator::Schedule(m_period, &CsTracer::PeriodicPrinter, this);
}
void
-CsTracer::PeriodicPrinter ()
+CsTracer::PeriodicPrinter()
{
- Print (*m_os);
- Reset ();
-
- m_printEvent = Simulator::Schedule (m_period, &CsTracer::PeriodicPrinter, this);
+ Print(*m_os);
+ Reset();
+
+ m_printEvent = Simulator::Schedule(m_period, &CsTracer::PeriodicPrinter, this);
}
void
-CsTracer::PrintHeader (std::ostream &os) const
+CsTracer::PrintHeader(std::ostream& os) const
{
- os << "Time" << "\t"
+ os << "Time"
+ << "\t"
- << "Node" << "\t"
+ << "Node"
+ << "\t"
- << "Type" << "\t"
- << "Packets" << "\t";
+ << "Type"
+ << "\t"
+ << "Packets"
+ << "\t";
}
void
-CsTracer::Reset ()
+CsTracer::Reset()
{
m_stats.Reset();
}
-#define PRINTER(printName, fieldName) \
- os << time.ToDouble (Time::S) << "\t" \
- << m_node << "\t" \
- << printName << "\t" \
- << m_stats.fieldName << "\n";
-
+#define PRINTER(printName, fieldName) \
+ os << time.ToDouble(Time::S) << "\t" << m_node << "\t" << printName << "\t" << m_stats.fieldName \
+ << "\n";
void
-CsTracer::Print (std::ostream &os) const
+CsTracer::Print(std::ostream& os) const
{
- Time time = Simulator::Now ();
+ Time time = Simulator::Now();
- PRINTER ("CacheHits", m_cacheHits);
- PRINTER ("CacheMisses", m_cacheMisses);
+ PRINTER("CacheHits", m_cacheHits);
+ PRINTER("CacheMisses", m_cacheMisses);
}
-void
-CsTracer::CacheHits (Ptr<const Interest>, Ptr<const Data>)
+void
+CsTracer::CacheHits(Ptr<const Interest>, Ptr<const Data>)
{
- m_stats.m_cacheHits ++;
+ m_stats.m_cacheHits++;
}
-void
-CsTracer::CacheMisses (Ptr<const Interest>)
+void
+CsTracer::CacheMisses(Ptr<const Interest>)
{
- m_stats.m_cacheMisses ++;
+ m_stats.m_cacheMisses++;
}
-
} // namespace ndn
} // namespace ns3
diff --git a/utils/tracers/ndn-cs-tracer.hpp b/utils/tracers/ndn-cs-tracer.hpp
index eb07585..939df9b 100644
--- a/utils/tracers/ndn-cs-tracer.hpp
+++ b/utils/tracers/ndn-cs-tracer.hpp
@@ -49,80 +49,87 @@
namespace cs {
/// @cond include_hidden
-struct Stats
-{
- inline void Reset ()
+struct Stats {
+ inline void
+ Reset()
{
- m_cacheHits = 0;
+ m_cacheHits = 0;
m_cacheMisses = 0;
}
double m_cacheHits;
double m_cacheMisses;
};
/// @endcond
-
-}
+}
/**
* @ingroup ndn-tracers
* @brief NDN tracer for cache performance (hits and misses)
*/
-class CsTracer : public SimpleRefCount<CsTracer>
-{
+class CsTracer : public SimpleRefCount<CsTracer> {
public:
/**
* @brief Helper method to install tracers on all simulation nodes
*
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
- *
+ *
*/
static void
- InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+ InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on the selected simulation nodes
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param outputStream Smart pointer to a stream
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*/
static Ptr<CsTracer>
- Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
+ Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod = Seconds(0.5));
/**
* @brief Explicit request to remove all statically created tracers
@@ -131,26 +138,26 @@
* or if it is desired to do a postprocessing of the resulting data
*/
static void
- Destroy ();
-
+ Destroy();
+
/**
* @brief Trace constructor that attaches to the node using node pointer
* @param os reference to the output stream
* @param node pointer to the node
*/
- CsTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ CsTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
/**
* @brief Trace constructor that attaches to the node using node name
* @param os reference to the output stream
* @param nodeName name of the node registered using Names::Add
*/
- CsTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
+ CsTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
/**
* @brief Destructor
*/
- ~CsTracer ();
+ ~CsTracer();
/**
* @brief Print head of the trace (e.g., for post-processing)
@@ -158,7 +165,7 @@
* @param os reference to output stream
*/
void
- PrintHeader (std::ostream &os) const;
+ PrintHeader(std::ostream& os) const;
/**
* @brief Print current trace data
@@ -166,28 +173,28 @@
* @param os reference to output stream
*/
void
- Print (std::ostream &os) const;
-
-private:
- void
- Connect ();
-
- void
- CacheHits (Ptr<const Interest>, Ptr<const Data>);
-
- void
- CacheMisses (Ptr<const Interest>);
+ Print(std::ostream& os) const;
private:
void
- SetAveragingPeriod (const Time &period);
+ Connect();
void
- Reset ();
+ CacheHits(Ptr<const Interest>, Ptr<const Data>);
void
- PeriodicPrinter ();
-
+ CacheMisses(Ptr<const Interest>);
+
+private:
+ void
+ SetAveragingPeriod(const Time& period);
+
+ void
+ Reset();
+
+ void
+ PeriodicPrinter();
+
private:
std::string m_node;
Ptr<Node> m_nodePtr;
@@ -196,19 +203,19 @@
Time m_period;
EventId m_printEvent;
- cs::Stats m_stats;
+ cs::Stats m_stats;
};
/**
* @brief Helper to dump the trace to an output stream
*/
inline std::ostream&
-operator << (std::ostream &os, const CsTracer &tracer)
+operator<<(std::ostream& os, const CsTracer& tracer)
{
os << "# ";
- tracer.PrintHeader (os);
+ tracer.PrintHeader(os);
os << "\n";
- tracer.Print (os);
+ tracer.Print(os);
return os;
}
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.cpp b/utils/tracers/ndn-l3-aggregate-tracer.cpp
index 556a792..d9fc671 100644
--- a/utils/tracers/ndn-l3-aggregate-tracer.cpp
+++ b/utils/tracers/ndn-l3-aggregate-tracer.cpp
@@ -36,388 +36,349 @@
#include <fstream>
-NS_LOG_COMPONENT_DEFINE ("ndn.L3AggregateTracer");
+NS_LOG_COMPONENT_DEFINE("ndn.L3AggregateTracer");
namespace ns3 {
namespace ndn {
-static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > > > g_tracers;
+static std::list<boost::tuple<boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer>>>>
+ g_tracers;
template<class T>
static inline void
-NullDeleter (T *ptr)
+NullDeleter(T* ptr)
{
}
void
-L3AggregateTracer::Destroy ()
+L3AggregateTracer::Destroy()
{
- g_tracers.clear ();
+ g_tracers.clear();
}
void
-L3AggregateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3AggregateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<L3AggregateTracer> > tracers;
+ std::list<Ptr<L3AggregateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeList::Iterator node = NodeList::Begin ();
- node != NodeList::End ();
- node++)
- {
- Ptr<L3AggregateTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
+ Ptr<L3AggregateTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-L3AggregateTracer::Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3AggregateTracer::Install(const NodeContainer& nodes, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<L3AggregateTracer> > tracers;
+ std::list<Ptr<L3AggregateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeContainer::Iterator node = nodes.Begin ();
- node != nodes.End ();
- node++)
- {
- Ptr<L3AggregateTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
+ Ptr<L3AggregateTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-L3AggregateTracer::Install (Ptr<Node> node, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3AggregateTracer::Install(Ptr<Node> node, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<L3AggregateTracer> > tracers;
+ std::list<Ptr<L3AggregateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- Ptr<L3AggregateTracer> trace = Install (node, outputStream, averagingPeriod);
- tracers.push_back (trace);
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ Ptr<L3AggregateTracer> trace = Install(node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
-
Ptr<L3AggregateTracer>
-L3AggregateTracer::Install (Ptr<Node> node,
- boost::shared_ptr<std::ostream> outputStream,
- Time averagingPeriod/* = Seconds (0.5)*/)
+L3AggregateTracer::Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
- NS_LOG_DEBUG ("Node: " << node->GetId ());
+ NS_LOG_DEBUG("Node: " << node->GetId());
- Ptr<L3AggregateTracer> trace = Create<L3AggregateTracer> (outputStream, node);
- trace->SetAveragingPeriod (averagingPeriod);
+ Ptr<L3AggregateTracer> trace = Create<L3AggregateTracer>(outputStream, node);
+ trace->SetAveragingPeriod(averagingPeriod);
return trace;
}
-L3AggregateTracer::L3AggregateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
- : L3Tracer (node)
- , m_os (os)
+L3AggregateTracer::L3AggregateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : L3Tracer(node)
+ , m_os(os)
{
- Reset ();
+ Reset();
}
-L3AggregateTracer::L3AggregateTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
- : L3Tracer (node)
- , m_os (os)
+L3AggregateTracer::L3AggregateTracer(boost::shared_ptr<std::ostream> os, const std::string& node)
+ : L3Tracer(node)
+ , m_os(os)
{
- Reset ();
+ Reset();
}
-L3AggregateTracer::~L3AggregateTracer ()
-{
-};
+L3AggregateTracer::~L3AggregateTracer(){};
void
-L3AggregateTracer::SetAveragingPeriod (const Time &period)
+L3AggregateTracer::SetAveragingPeriod(const Time& period)
{
m_period = period;
- m_printEvent.Cancel ();
- m_printEvent = Simulator::Schedule (m_period, &L3AggregateTracer::PeriodicPrinter, this);
+ m_printEvent.Cancel();
+ m_printEvent = Simulator::Schedule(m_period, &L3AggregateTracer::PeriodicPrinter, this);
}
void
-L3AggregateTracer::PeriodicPrinter ()
+L3AggregateTracer::PeriodicPrinter()
{
- Print (*m_os);
- Reset ();
+ Print(*m_os);
+ Reset();
- m_printEvent = Simulator::Schedule (m_period, &L3AggregateTracer::PeriodicPrinter, this);
+ m_printEvent = Simulator::Schedule(m_period, &L3AggregateTracer::PeriodicPrinter, this);
}
void
-L3AggregateTracer::PrintHeader (std::ostream &os) const
+L3AggregateTracer::PrintHeader(std::ostream& os) const
{
- os << "Time" << "\t"
+ os << "Time"
+ << "\t"
- << "Node" << "\t"
- << "FaceId" << "\t"
- << "FaceDescr" << "\t"
+ << "Node"
+ << "\t"
+ << "FaceId"
+ << "\t"
+ << "FaceDescr"
+ << "\t"
- << "Type" << "\t"
- << "Packets" << "\t"
+ << "Type"
+ << "\t"
+ << "Packets"
+ << "\t"
<< "Kilobytes";
}
void
-L3AggregateTracer::Reset ()
+L3AggregateTracer::Reset()
{
- for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.begin ();
- stats != m_stats.end ();
- stats++)
- {
- stats->second.get<0> ().Reset ();
- stats->second.get<1> ().Reset ();
- }
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats>>::iterator stats = m_stats.begin();
+ stats != m_stats.end(); stats++) {
+ stats->second.get<0>().Reset();
+ stats->second.get<1>().Reset();
+ }
}
+#define STATS(INDEX) stats->second.get<INDEX>()
-#define STATS(INDEX) stats->second.get<INDEX> ()
-
-#define PRINTER(printName, fieldName) \
- os << time.ToDouble (Time::S) << "\t" \
- << m_node << "\t"; \
- if (stats->first) \
- { \
- os \
- << stats->first->GetId () << "\t" \
- << *stats->first << "\t"; \
- } \
- else \
- { \
- os << "-1\tall\t"; \
- } \
- os \
- << printName << "\t" \
- << STATS(0).fieldName << "\t" \
- << STATS(1).fieldName / 1024.0 << "\n";
-
+#define PRINTER(printName, fieldName) \
+ os << time.ToDouble(Time::S) << "\t" << m_node << "\t"; \
+ if (stats->first) { \
+ os << stats->first->GetId() << "\t" << *stats->first << "\t"; \
+ } \
+ else { \
+ os << "-1\tall\t"; \
+ } \
+ os << printName << "\t" << STATS(0).fieldName << "\t" << STATS(1).fieldName / 1024.0 << "\n";
void
-L3AggregateTracer::Print (std::ostream &os) const
+L3AggregateTracer::Print(std::ostream& os) const
{
- Time time = Simulator::Now ();
+ Time time = Simulator::Now();
- for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.begin ();
- stats != m_stats.end ();
- stats++)
- {
- if (!stats->first)
- continue;
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats>>::iterator stats = m_stats.begin();
+ stats != m_stats.end(); stats++) {
+ if (!stats->first)
+ continue;
- PRINTER ("InInterests", m_inInterests);
- PRINTER ("OutInterests", m_outInterests);
- PRINTER ("DropInterests", m_dropInterests);
+ PRINTER("InInterests", m_inInterests);
+ PRINTER("OutInterests", m_outInterests);
+ PRINTER("DropInterests", m_dropInterests);
- PRINTER ("InNacks", m_inNacks);
- PRINTER ("OutNacks", m_outNacks);
- PRINTER ("DropNacks", m_dropNacks);
+ PRINTER("InNacks", m_inNacks);
+ PRINTER("OutNacks", m_outNacks);
+ PRINTER("DropNacks", m_dropNacks);
- PRINTER ("InData", m_inData);
- PRINTER ("OutData", m_outData);
- PRINTER ("DropData", m_dropData);
- }
+ PRINTER("InData", m_inData);
+ PRINTER("OutData", m_outData);
+ PRINTER("DropData", m_dropData);
+ }
{
- std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.find (Ptr<const Face> (0));
- if (stats != m_stats.end ())
- {
- PRINTER ("SatisfiedInterests", m_satisfiedInterests);
- PRINTER ("TimedOutInterests", m_timedOutInterests);
- }
+ std::map<Ptr<const Face>, boost::tuple<Stats, Stats>>::iterator stats =
+ m_stats.find(Ptr<const Face>(0));
+ if (stats != m_stats.end()) {
+ PRINTER("SatisfiedInterests", m_satisfiedInterests);
+ PRINTER("TimedOutInterests", m_timedOutInterests);
+ }
}
}
void
-L3AggregateTracer::OutInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3AggregateTracer::OutInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_outInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_outInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::InInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3AggregateTracer::InInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_inInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_inInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::DropInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3AggregateTracer::DropInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_dropInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_dropInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::OutNacks (Ptr<const Interest> nack, Ptr<const Face> face)
+L3AggregateTracer::OutNacks(Ptr<const Interest> nack, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outNacks ++;
- if (nack->GetWire ())
- {
- m_stats[face].get<1> ().m_outNacks += nack->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outNacks++;
+ if (nack->GetWire()) {
+ m_stats[face].get<1>().m_outNacks += nack->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::InNacks (Ptr<const Interest> nack, Ptr<const Face> face)
+L3AggregateTracer::InNacks(Ptr<const Interest> nack, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inNacks ++;
- if (nack->GetWire ())
- {
- m_stats[face].get<1> ().m_inNacks += nack->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inNacks++;
+ if (nack->GetWire()) {
+ m_stats[face].get<1>().m_inNacks += nack->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::DropNacks (Ptr<const Interest> nack, Ptr<const Face> face)
+L3AggregateTracer::DropNacks(Ptr<const Interest> nack, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropNacks ++;
- if (nack->GetWire ())
- {
- m_stats[face].get<1> ().m_dropNacks += nack->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropNacks++;
+ if (nack->GetWire()) {
+ m_stats[face].get<1>().m_dropNacks += nack->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::OutData (Ptr<const Data> data,
- bool fromCache, Ptr<const Face> face)
+L3AggregateTracer::OutData(Ptr<const Data> data, bool fromCache, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_outData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_outData += data->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::InData (Ptr<const Data> data,
- Ptr<const Face> face)
+L3AggregateTracer::InData(Ptr<const Data> data, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_inData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_inData += data->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::DropData (Ptr<const Data> data,
- Ptr<const Face> face)
+L3AggregateTracer::DropData(Ptr<const Data> data, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_dropData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_dropData += data->GetWire()->GetSize();
+ }
}
void
-L3AggregateTracer::SatisfiedInterests (Ptr<const pit::Entry>)
+L3AggregateTracer::SatisfiedInterests(Ptr<const pit::Entry>)
{
- m_stats[0].get<0> ().m_satisfiedInterests ++;
+ m_stats[0].get<0>().m_satisfiedInterests++;
// no "size" stats
}
void
-L3AggregateTracer::TimedOutInterests (Ptr<const pit::Entry>)
+L3AggregateTracer::TimedOutInterests(Ptr<const pit::Entry>)
{
- m_stats[0].get<0> ().m_timedOutInterests ++;
+ m_stats[0].get<0>().m_timedOutInterests++;
// no "size" stats
}
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.hpp b/utils/tracers/ndn-l3-aggregate-tracer.hpp
index a94d2f5..bedfccc 100644
--- a/utils/tracers/ndn-l3-aggregate-tracer.hpp
+++ b/utils/tracers/ndn-l3-aggregate-tracer.hpp
@@ -39,49 +39,54 @@
* @ingroup ndn-tracers
* @brief NDN network-layer tracer for aggregate packet counts
*/
-class L3AggregateTracer : public L3Tracer
-{
+class L3AggregateTracer : public L3Tracer {
public:
/**
* @brief Helper method to install tracers on all simulation nodes
*
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+ InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on the selected simulation nodes
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*
*/
static void
- Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Explicit request to remove all statically created tracers
@@ -90,91 +95,93 @@
* or if it is desired to do a postprocessing of the resulting data
*/
static void
- Destroy ();
+ Destroy();
/**
* @brief Trace constructor that attaches to the node using node pointer
* @param os reference to the output stream
* @param node pointer to the node
*/
- L3AggregateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ L3AggregateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
/**
* @brief Trace constructor that attaches to the node using node name
* @param os reference to the output stream
* @param nodeName name of the node registered using Names::Add
*/
- L3AggregateTracer (boost::shared_ptr<std::ostream> os, const std::string &nodeName);
+ L3AggregateTracer(boost::shared_ptr<std::ostream> os, const std::string& nodeName);
/**
* @brief Destructor
*/
- virtual ~L3AggregateTracer ();
+ virtual ~L3AggregateTracer();
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param outputStream Smart pointer to a stream
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*/
static Ptr<L3AggregateTracer>
- Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
+ Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod = Seconds(0.5));
protected:
// from L3Tracer
virtual void
- PrintHeader (std::ostream &os) const;
+ PrintHeader(std::ostream& os) const;
virtual void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
virtual void
- OutInterests (Ptr<const Interest>, Ptr<const Face>);
+ OutInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- InInterests (Ptr<const Interest>, Ptr<const Face>);
+ InInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- DropInterests (Ptr<const Interest>, Ptr<const Face>);
+ DropInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- OutNacks (Ptr<const Interest>, Ptr<const Face>);
+ OutNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- InNacks (Ptr<const Interest>, Ptr<const Face>);
+ InNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- DropNacks (Ptr<const Interest>, Ptr<const Face>);
+ DropNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>);
+ OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>);
virtual void
- InData (Ptr<const Data>, Ptr<const Face>);
+ InData(Ptr<const Data>, Ptr<const Face>);
virtual void
- DropData (Ptr<const Data>, Ptr<const Face>);
-
+ DropData(Ptr<const Data>, Ptr<const Face>);
virtual void
- SatisfiedInterests (Ptr<const pit::Entry>);
+ SatisfiedInterests(Ptr<const pit::Entry>);
virtual void
- TimedOutInterests (Ptr<const pit::Entry>);
+ TimedOutInterests(Ptr<const pit::Entry>);
protected:
void
- SetAveragingPeriod (const Time &period);
+ SetAveragingPeriod(const Time& period);
void
- Reset ();
+ Reset();
void
- PeriodicPrinter ();
+ PeriodicPrinter();
protected:
boost::shared_ptr<std::ostream> m_os;
@@ -182,7 +189,7 @@
Time m_period;
EventId m_printEvent;
- mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
+ mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats>> m_stats;
};
} // namespace ndn
diff --git a/utils/tracers/ndn-l3-rate-tracer.cpp b/utils/tracers/ndn-l3-rate-tracer.cpp
index ca80bef..38170bc 100644
--- a/utils/tracers/ndn-l3-rate-tracer.cpp
+++ b/utils/tracers/ndn-l3-rate-tracer.cpp
@@ -39,433 +39,392 @@
using namespace boost;
using namespace std;
-NS_LOG_COMPONENT_DEFINE ("ndn.L3RateTracer");
+NS_LOG_COMPONENT_DEFINE("ndn.L3RateTracer");
namespace ns3 {
namespace ndn {
-static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > > g_tracers;
+static std::list<boost::tuple<boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer>>>>
+ g_tracers;
template<class T>
static inline void
-NullDeleter (T *ptr)
+NullDeleter(T* ptr)
{
}
void
-L3RateTracer::Destroy ()
+L3RateTracer::Destroy()
{
- g_tracers.clear ();
+ g_tracers.clear();
}
void
-L3RateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3RateTracer::InstallAll(const std::string& file, Time averagingPeriod /* = Seconds (0.5)*/)
{
- std::list<Ptr<L3RateTracer> > tracers;
+ std::list<Ptr<L3RateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeList::Iterator node = NodeList::Begin ();
- node != NodeList::End ();
- node++)
- {
- Ptr<L3RateTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
+ Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-L3RateTracer::Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3RateTracer::Install(const NodeContainer& nodes, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<L3RateTracer> > tracers;
+ std::list<Ptr<L3RateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- for (NodeContainer::Iterator node = nodes.Begin ();
- node != nodes.End ();
- node++)
- {
- Ptr<L3RateTracer> trace = Install (*node, outputStream, averagingPeriod);
- tracers.push_back (trace);
- }
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
+ Ptr<L3RateTracer> trace = Install(*node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
+ }
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
void
-L3RateTracer::Install (Ptr<Node> node, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+L3RateTracer::Install(Ptr<Node> node, const std::string& file,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
using namespace boost;
using namespace std;
- std::list<Ptr<L3RateTracer> > tracers;
+ std::list<Ptr<L3RateTracer>> tracers;
boost::shared_ptr<std::ostream> outputStream;
- if (file != "-")
- {
- boost::shared_ptr<std::ofstream> os (new std::ofstream ());
- os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+ if (file != "-") {
+ boost::shared_ptr<std::ofstream> os(new std::ofstream());
+ os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
- if (!os->is_open ())
- {
- NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
- return;
- }
-
- outputStream = os;
- }
- else
- {
- outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
+ if (!os->is_open()) {
+ NS_LOG_ERROR("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
}
- Ptr<L3RateTracer> trace = Install (node, outputStream, averagingPeriod);
- tracers.push_back (trace);
+ outputStream = os;
+ }
+ else {
+ outputStream = boost::shared_ptr<std::ostream>(&std::cout, NullDeleter<std::ostream>);
+ }
- if (tracers.size () > 0)
- {
- // *m_l3RateTrace << "# "; // not necessary for R's read.table
- tracers.front ()->PrintHeader (*outputStream);
- *outputStream << "\n";
- }
+ Ptr<L3RateTracer> trace = Install(node, outputStream, averagingPeriod);
+ tracers.push_back(trace);
- g_tracers.push_back (boost::make_tuple (outputStream, tracers));
+ if (tracers.size() > 0) {
+ // *m_l3RateTrace << "# "; // not necessary for R's read.table
+ tracers.front()->PrintHeader(*outputStream);
+ *outputStream << "\n";
+ }
+
+ g_tracers.push_back(boost::make_tuple(outputStream, tracers));
}
-
Ptr<L3RateTracer>
-L3RateTracer::Install (Ptr<Node> node,
- boost::shared_ptr<std::ostream> outputStream,
- Time averagingPeriod/* = Seconds (0.5)*/)
+L3RateTracer::Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod /* = Seconds (0.5)*/)
{
- NS_LOG_DEBUG ("Node: " << node->GetId ());
+ NS_LOG_DEBUG("Node: " << node->GetId());
- Ptr<L3RateTracer> trace = Create<L3RateTracer> (outputStream, node);
- trace->SetAveragingPeriod (averagingPeriod);
+ Ptr<L3RateTracer> trace = Create<L3RateTracer>(outputStream, node);
+ trace->SetAveragingPeriod(averagingPeriod);
return trace;
}
-
-L3RateTracer::L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
- : L3Tracer (node)
- , m_os (os)
+L3RateTracer::L3RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : L3Tracer(node)
+ , m_os(os)
{
- SetAveragingPeriod (Seconds (1.0));
+ SetAveragingPeriod(Seconds(1.0));
}
-L3RateTracer::L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
- : L3Tracer (node)
- , m_os (os)
+L3RateTracer::L3RateTracer(boost::shared_ptr<std::ostream> os, const std::string& node)
+ : L3Tracer(node)
+ , m_os(os)
{
- SetAveragingPeriod (Seconds (1.0));
+ SetAveragingPeriod(Seconds(1.0));
}
-L3RateTracer::~L3RateTracer ()
+L3RateTracer::~L3RateTracer()
{
- m_printEvent.Cancel ();
+ m_printEvent.Cancel();
}
void
-L3RateTracer::SetAveragingPeriod (const Time &period)
+L3RateTracer::SetAveragingPeriod(const Time& period)
{
m_period = period;
- m_printEvent.Cancel ();
- m_printEvent = Simulator::Schedule (m_period, &L3RateTracer::PeriodicPrinter, this);
+ m_printEvent.Cancel();
+ m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this);
}
void
-L3RateTracer::PeriodicPrinter ()
+L3RateTracer::PeriodicPrinter()
{
- Print (*m_os);
- Reset ();
+ Print(*m_os);
+ Reset();
- m_printEvent = Simulator::Schedule (m_period, &L3RateTracer::PeriodicPrinter, this);
+ m_printEvent = Simulator::Schedule(m_period, &L3RateTracer::PeriodicPrinter, this);
}
void
-L3RateTracer::PrintHeader (std::ostream &os) const
+L3RateTracer::PrintHeader(std::ostream& os) const
{
- os << "Time" << "\t"
+ os << "Time"
+ << "\t"
- << "Node" << "\t"
- << "FaceId" << "\t"
- << "FaceDescr" << "\t"
+ << "Node"
+ << "\t"
+ << "FaceId"
+ << "\t"
+ << "FaceDescr"
+ << "\t"
- << "Type" << "\t"
- << "Packets" << "\t"
- << "Kilobytes" << "\t"
- << "PacketRaw" << "\t"
+ << "Type"
+ << "\t"
+ << "Packets"
+ << "\t"
+ << "Kilobytes"
+ << "\t"
+ << "PacketRaw"
+ << "\t"
<< "KilobytesRaw";
}
void
-L3RateTracer::Reset ()
+L3RateTracer::Reset()
{
- for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
- stats != m_stats.end ();
- stats++)
- {
- stats->second.get<0> ().Reset ();
- stats->second.get<1> ().Reset ();
- }
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>>::iterator stats =
+ m_stats.begin();
+ stats != m_stats.end(); stats++) {
+ stats->second.get<0>().Reset();
+ stats->second.get<1>().Reset();
+ }
}
const double alpha = 0.8;
-#define STATS(INDEX) stats->second.get<INDEX> ()
-#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
+#define STATS(INDEX) stats->second.get<INDEX>()
+#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble(Time::S)
-#define PRINTER(printName, fieldName) \
- STATS(2).fieldName = /*new value*/alpha * RATE(0, fieldName) + /*old value*/(1-alpha) * STATS(2).fieldName; \
- STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
- \
- os << time.ToDouble (Time::S) << "\t" \
- << m_node << "\t"; \
- if (stats->first) \
- { \
- os \
- << stats->first->GetId () << "\t" \
- << *stats->first << "\t"; \
- } \
- else \
- { \
- os << "-1\tall\t"; \
- } \
- os \
- << printName << "\t" \
- << STATS(2).fieldName << "\t" \
- << STATS(3).fieldName << "\t" \
- << STATS(0).fieldName << "\t" \
- << STATS(1).fieldName / 1024.0 << "\n";
+#define PRINTER(printName, fieldName) \
+ STATS(2).fieldName = \
+ /*new value*/ alpha * RATE(0, fieldName) + /*old value*/ (1 - alpha) * STATS(2).fieldName; \
+ STATS(3).fieldName = /*new value*/ alpha * RATE(1, fieldName) / 1024.0 \
+ + /*old value*/ (1 - alpha) * STATS(3).fieldName; \
+ \
+ os << time.ToDouble(Time::S) << "\t" << m_node << "\t"; \
+ if (stats->first) { \
+ os << stats->first->GetId() << "\t" << *stats->first << "\t"; \
+ } \
+ else { \
+ os << "-1\tall\t"; \
+ } \
+ os << printName << "\t" << STATS(2).fieldName << "\t" << STATS(3).fieldName << "\t" \
+ << STATS(0).fieldName << "\t" << STATS(1).fieldName / 1024.0 << "\n";
void
-L3RateTracer::Print (std::ostream &os) const
+L3RateTracer::Print(std::ostream& os) const
{
- Time time = Simulator::Now ();
+ Time time = Simulator::Now();
- for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
- stats != m_stats.end ();
- stats++)
- {
- if (!stats->first)
- continue;
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>>::iterator stats =
+ m_stats.begin();
+ stats != m_stats.end(); stats++) {
+ if (!stats->first)
+ continue;
- PRINTER ("InInterests", m_inInterests);
- PRINTER ("OutInterests", m_outInterests);
- PRINTER ("DropInterests", m_dropInterests);
+ PRINTER("InInterests", m_inInterests);
+ PRINTER("OutInterests", m_outInterests);
+ PRINTER("DropInterests", m_dropInterests);
- PRINTER ("InNacks", m_inNacks);
- PRINTER ("OutNacks", m_outNacks);
- PRINTER ("DropNacks", m_dropNacks);
+ PRINTER("InNacks", m_inNacks);
+ PRINTER("OutNacks", m_outNacks);
+ PRINTER("DropNacks", m_dropNacks);
- PRINTER ("InData", m_inData);
- PRINTER ("OutData", m_outData);
- PRINTER ("DropData", m_dropData);
+ PRINTER("InData", m_inData);
+ PRINTER("OutData", m_outData);
+ PRINTER("DropData", m_dropData);
- PRINTER ("InSatisfiedInterests", m_satisfiedInterests);
- PRINTER ("InTimedOutInterests", m_timedOutInterests);
+ PRINTER("InSatisfiedInterests", m_satisfiedInterests);
+ PRINTER("InTimedOutInterests", m_timedOutInterests);
- PRINTER ("OutSatisfiedInterests", m_outSatisfiedInterests);
- PRINTER ("OutTimedOutInterests", m_outTimedOutInterests);
- }
+ PRINTER("OutSatisfiedInterests", m_outSatisfiedInterests);
+ PRINTER("OutTimedOutInterests", m_outTimedOutInterests);
+ }
{
- std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.find (Ptr<const Face> (0));
- if (stats != m_stats.end ())
- {
- PRINTER ("SatisfiedInterests", m_satisfiedInterests);
- PRINTER ("TimedOutInterests", m_timedOutInterests);
- }
+ std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>>::iterator stats =
+ m_stats.find(Ptr<const Face>(0));
+ if (stats != m_stats.end()) {
+ PRINTER("SatisfiedInterests", m_satisfiedInterests);
+ PRINTER("TimedOutInterests", m_timedOutInterests);
+ }
}
}
-
void
-L3RateTracer::OutInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::OutInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_outInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_outInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::InInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::InInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_inInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_inInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::DropInterests (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::DropInterests(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropInterests ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_dropInterests += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropInterests++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_dropInterests += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::OutNacks (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::OutNacks(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outNacks ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_outNacks += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outNacks++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_outNacks += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::InNacks (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::InNacks(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inNacks ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_inNacks += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inNacks++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_inNacks += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::DropNacks (Ptr<const Interest> interest, Ptr<const Face> face)
+L3RateTracer::DropNacks(Ptr<const Interest> interest, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropNacks ++;
- if (interest->GetWire ())
- {
- m_stats[face].get<1> ().m_dropNacks += interest->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropNacks++;
+ if (interest->GetWire()) {
+ m_stats[face].get<1>().m_dropNacks += interest->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::OutData (Ptr<const Data> data,
- bool fromCache, Ptr<const Face> face)
+L3RateTracer::OutData(Ptr<const Data> data, bool fromCache, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_outData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_outData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_outData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_outData += data->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::InData (Ptr<const Data> data,
- Ptr<const Face> face)
+L3RateTracer::InData(Ptr<const Data> data, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_inData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_inData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_inData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_inData += data->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::DropData (Ptr<const Data> data,
- Ptr<const Face> face)
+L3RateTracer::DropData(Ptr<const Data> data, Ptr<const Face> face)
{
- m_stats[face].get<0> ().m_dropData ++;
- if (data->GetWire ())
- {
- m_stats[face].get<1> ().m_dropData += data->GetWire ()->GetSize ();
- }
+ m_stats[face].get<0>().m_dropData++;
+ if (data->GetWire()) {
+ m_stats[face].get<1>().m_dropData += data->GetWire()->GetSize();
+ }
}
void
-L3RateTracer::SatisfiedInterests (Ptr<const pit::Entry> entry)
+L3RateTracer::SatisfiedInterests(Ptr<const pit::Entry> entry)
{
- m_stats[0].get<0> ().m_satisfiedInterests ++;
+ m_stats[0].get<0>().m_satisfiedInterests++;
// no "size" stats
- for (pit::Entry::in_container::const_iterator i = entry->GetIncoming ().begin ();
- i != entry->GetIncoming ().end ();
- i++)
- {
- m_stats[i->m_face].get<0> ().m_satisfiedInterests ++;
-}
+ for (pit::Entry::in_container::const_iterator i = entry->GetIncoming().begin();
+ i != entry->GetIncoming().end(); i++) {
+ m_stats[i->m_face].get<0>().m_satisfiedInterests++;
+ }
- for (pit::Entry::out_container::const_iterator i = entry->GetOutgoing ().begin ();
- i != entry->GetOutgoing ().end ();
- i++)
- {
- m_stats[i->m_face].get<0> ().m_outSatisfiedInterests ++;
- }
+ for (pit::Entry::out_container::const_iterator i = entry->GetOutgoing().begin();
+ i != entry->GetOutgoing().end(); i++) {
+ m_stats[i->m_face].get<0>().m_outSatisfiedInterests++;
+ }
}
void
-L3RateTracer::TimedOutInterests (Ptr<const pit::Entry> entry)
+L3RateTracer::TimedOutInterests(Ptr<const pit::Entry> entry)
{
- m_stats[0].get<0> ().m_timedOutInterests ++;
+ m_stats[0].get<0>().m_timedOutInterests++;
// no "size" stats
-
- for (pit::Entry::in_container::const_iterator i = entry->GetIncoming ().begin ();
- i != entry->GetIncoming ().end ();
- i++)
- {
- m_stats[i->m_face].get<0> ().m_timedOutInterests ++;
-}
- for (pit::Entry::out_container::const_iterator i = entry->GetOutgoing ().begin ();
- i != entry->GetOutgoing ().end ();
- i++)
- {
- m_stats[i->m_face].get<0> ().m_outTimedOutInterests ++;
- }
-}
+ for (pit::Entry::in_container::const_iterator i = entry->GetIncoming().begin();
+ i != entry->GetIncoming().end(); i++) {
+ m_stats[i->m_face].get<0>().m_timedOutInterests++;
+ }
+ for (pit::Entry::out_container::const_iterator i = entry->GetOutgoing().begin();
+ i != entry->GetOutgoing().end(); i++) {
+ m_stats[i->m_face].get<0>().m_outTimedOutInterests++;
+ }
+}
} // namespace ndn
} // namespace ns3
diff --git a/utils/tracers/ndn-l3-rate-tracer.hpp b/utils/tracers/ndn-l3-rate-tracer.hpp
index 1a6a401..21bb06c 100644
--- a/utils/tracers/ndn-l3-rate-tracer.hpp
+++ b/utils/tracers/ndn-l3-rate-tracer.hpp
@@ -39,38 +39,40 @@
* @ingroup ndn-tracers
* @brief NDN network-layer rate tracer
*/
-class L3RateTracer : public L3Tracer
-{
+class L3RateTracer : public L3Tracer {
public:
/**
* @brief Helper method to install tracers on all simulation nodes
*
* @param file File to which traces will be written. If filename is -, then std::out is used
* @param averagingPeriod Defines averaging period for the rate calculation,
- * as well as how often data will be written into the trace file (default, every half second)
+ * as well as how often data will be written into the trace file (default, every half
+ *second)
*/
static void
- InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+ InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on the selected simulation nodes
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*/
static void
- Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param file File to which traces will be written. If filename is -, then std::out is used
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*/
static void
- Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
+ Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
/**
* @brief Explicit request to remove all statically created tracers
@@ -79,98 +81,101 @@
* or if it is desired to do a postprocessing of the resulting data
*/
static void
- Destroy ();
-
+ Destroy();
+
/**
* @brief Trace constructor that attaches to the node using node pointer
* @param os reference to the output stream
* @param node pointer to the node
*/
- L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ L3RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
/**
* @brief Trace constructor that attaches to the node using node name
* @param os reference to the output stream
* @param nodeName name of the node registered using Names::Add
*/
- L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
+ L3RateTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
/**
* @brief Destructor
*/
- virtual ~L3RateTracer ();
+ virtual ~L3RateTracer();
/**
* @brief Helper method to install tracers on a specific simulation node
*
* @param nodes Nodes on which to install tracer
* @param outputStream Smart pointer to a stream
- * @param averagingPeriod How often data will be written into the trace file (default, every half second)
+ * @param averagingPeriod How often data will be written into the trace file (default, every half
+ *second)
*
- * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
+ * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
+ *tuple needs to be preserved
* for the lifetime of simulation, otherwise SEGFAULTs are inevitable
*/
static Ptr<L3RateTracer>
- Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
-
+ Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod = Seconds(0.5));
+
// from L3Tracer
virtual void
- PrintHeader (std::ostream &os) const;
+ PrintHeader(std::ostream& os) const;
virtual void
- Print (std::ostream &os) const;
+ Print(std::ostream& os) const;
protected:
// from L3Tracer
virtual void
- OutInterests (Ptr<const Interest>, Ptr<const Face>);
+ OutInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- InInterests (Ptr<const Interest>, Ptr<const Face>);
+ InInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- DropInterests (Ptr<const Interest>, Ptr<const Face>);
+ DropInterests(Ptr<const Interest>, Ptr<const Face>);
virtual void
- OutNacks (Ptr<const Interest>, Ptr<const Face>);
+ OutNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- InNacks (Ptr<const Interest>, Ptr<const Face>);
+ InNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- DropNacks (Ptr<const Interest>, Ptr<const Face>);
+ DropNacks(Ptr<const Interest>, Ptr<const Face>);
virtual void
- OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>);
+ OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>);
virtual void
- InData (Ptr<const Data>, Ptr<const Face>);
+ InData(Ptr<const Data>, Ptr<const Face>);
virtual void
- DropData (Ptr<const Data>, Ptr<const Face>);
+ DropData(Ptr<const Data>, Ptr<const Face>);
virtual void
- SatisfiedInterests (Ptr<const pit::Entry>);
+ SatisfiedInterests(Ptr<const pit::Entry>);
virtual void
- TimedOutInterests (Ptr<const pit::Entry>);
+ TimedOutInterests(Ptr<const pit::Entry>);
private:
void
- SetAveragingPeriod (const Time &period);
+ SetAveragingPeriod(const Time& period);
void
- PeriodicPrinter ();
+ PeriodicPrinter();
void
- Reset ();
+ Reset();
private:
boost::shared_ptr<std::ostream> m_os;
Time m_period;
EventId m_printEvent;
- mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
+ mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>> m_stats;
};
} // namespace ndn
diff --git a/utils/tracers/ndn-l3-tracer.cpp b/utils/tracers/ndn-l3-tracer.cpp
index c69a4d3..8d59eb0 100644
--- a/utils/tracers/ndn-l3-tracer.cpp
+++ b/utils/tracers/ndn-l3-tracer.cpp
@@ -38,52 +38,50 @@
namespace ns3 {
namespace ndn {
-L3Tracer::L3Tracer (Ptr<Node> node)
-: m_nodePtr (node)
+L3Tracer::L3Tracer(Ptr<Node> node)
+ : m_nodePtr(node)
{
- m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+ m_node = boost::lexical_cast<string>(m_nodePtr->GetId());
- Connect ();
+ Connect();
- string name = Names::FindName (node);
- if (!name.empty ())
- {
- m_node = name;
- }
+ string name = Names::FindName(node);
+ if (!name.empty()) {
+ m_node = name;
+ }
}
-L3Tracer::L3Tracer (const std::string &node)
-: m_node (node)
+L3Tracer::L3Tracer(const std::string& node)
+ : m_node(node)
{
- Connect ();
+ Connect();
}
-L3Tracer::~L3Tracer ()
-{
-};
-
+L3Tracer::~L3Tracer(){};
void
-L3Tracer::Connect ()
+L3Tracer::Connect()
{
- Ptr<ForwardingStrategy> fw = m_nodePtr->GetObject<ForwardingStrategy> ();
-
- fw->TraceConnectWithoutContext ("OutInterests", MakeCallback (&L3Tracer::OutInterests, this));
- fw->TraceConnectWithoutContext ("InInterests", MakeCallback (&L3Tracer::InInterests, this));
- fw->TraceConnectWithoutContext ("DropInterests", MakeCallback (&L3Tracer::DropInterests, this));
-
- fw->TraceConnectWithoutContext ("OutData", MakeCallback (&L3Tracer::OutData, this));
- fw->TraceConnectWithoutContext ("InData", MakeCallback (&L3Tracer::InData, this));
- fw->TraceConnectWithoutContext ("DropData", MakeCallback (&L3Tracer::DropData, this));
+ Ptr<ForwardingStrategy> fw = m_nodePtr->GetObject<ForwardingStrategy>();
+
+ fw->TraceConnectWithoutContext("OutInterests", MakeCallback(&L3Tracer::OutInterests, this));
+ fw->TraceConnectWithoutContext("InInterests", MakeCallback(&L3Tracer::InInterests, this));
+ fw->TraceConnectWithoutContext("DropInterests", MakeCallback(&L3Tracer::DropInterests, this));
+
+ fw->TraceConnectWithoutContext("OutData", MakeCallback(&L3Tracer::OutData, this));
+ fw->TraceConnectWithoutContext("InData", MakeCallback(&L3Tracer::InData, this));
+ fw->TraceConnectWithoutContext("DropData", MakeCallback(&L3Tracer::DropData, this));
// only for some strategies
- fw->TraceConnectWithoutContext ("OutNacks", MakeCallback (&L3Tracer::OutNacks, this));
- fw->TraceConnectWithoutContext ("InNacks", MakeCallback (&L3Tracer::InNacks, this));
- fw->TraceConnectWithoutContext ("DropNacks", MakeCallback (&L3Tracer::DropNacks, this));
-
+ fw->TraceConnectWithoutContext("OutNacks", MakeCallback(&L3Tracer::OutNacks, this));
+ fw->TraceConnectWithoutContext("InNacks", MakeCallback(&L3Tracer::InNacks, this));
+ fw->TraceConnectWithoutContext("DropNacks", MakeCallback(&L3Tracer::DropNacks, this));
+
// satisfied/timed out PIs
- fw->TraceConnectWithoutContext ("SatisfiedInterests", MakeCallback (&L3Tracer::SatisfiedInterests, this));
- fw->TraceConnectWithoutContext ("TimedOutInterests", MakeCallback (&L3Tracer::TimedOutInterests, this));
+ fw->TraceConnectWithoutContext("SatisfiedInterests",
+ MakeCallback(&L3Tracer::SatisfiedInterests, this));
+ fw->TraceConnectWithoutContext("TimedOutInterests",
+ MakeCallback(&L3Tracer::TimedOutInterests, this));
}
} // namespace ndn
diff --git a/utils/tracers/ndn-l3-tracer.hpp b/utils/tracers/ndn-l3-tracer.hpp
index 2f132bd..d3534fa 100644
--- a/utils/tracers/ndn-l3-tracer.hpp
+++ b/utils/tracers/ndn-l3-tracer.hpp
@@ -49,25 +49,24 @@
* @ingroup ndn-tracers
* @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
*/
-class L3Tracer : public SimpleRefCount<L3Tracer>
-{
+class L3Tracer : public SimpleRefCount<L3Tracer> {
public:
/**
* @brief Trace constructor that attaches to the node using node pointer
* @param node pointer to the node
*/
- L3Tracer (Ptr<Node> node);
+ L3Tracer(Ptr<Node> node);
/**
* @brief Trace constructor that attaches to the node using node name
* @param nodeName name of the node registered using Names::Add
*/
- L3Tracer (const std::string &node);
+ L3Tracer(const std::string& node);
/**
* @brief Destructor
*/
- virtual ~L3Tracer ();
+ virtual ~L3Tracer();
/**
* @brief Print head of the trace (e.g., for post-processing)
@@ -75,7 +74,7 @@
* @param os reference to output stream
*/
virtual void
- PrintHeader (std::ostream &os) const = 0;
+ PrintHeader(std::ostream& os) const = 0;
/**
* @brief Print current trace data
@@ -83,63 +82,62 @@
* @param os reference to output stream
*/
virtual void
- Print (std::ostream &os) const = 0;
+ Print(std::ostream& os) const = 0;
protected:
void
- Connect ();
+ Connect();
virtual void
- OutInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
+ OutInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- InInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
+ InInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- DropInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
+ DropInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- OutNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
+ OutNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- InNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
+ InNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- DropNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
-
+ DropNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
virtual void
- OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>) = 0;
+ OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>) = 0;
virtual void
- InData (Ptr<const Data>, Ptr<const Face>) = 0;
+ InData(Ptr<const Data>, Ptr<const Face>) = 0;
virtual void
- DropData (Ptr<const Data>, Ptr<const Face>) = 0;
+ DropData(Ptr<const Data>, Ptr<const Face>) = 0;
virtual void
- SatisfiedInterests (Ptr<const pit::Entry>) = 0;
+ SatisfiedInterests(Ptr<const pit::Entry>) = 0;
virtual void
- TimedOutInterests (Ptr<const pit::Entry>) = 0;
+ TimedOutInterests(Ptr<const pit::Entry>) = 0;
protected:
std::string m_node;
Ptr<Node> m_nodePtr;
- struct Stats
- {
- inline void Reset ()
+ struct Stats {
+ inline void
+ Reset()
{
- m_inInterests = 0;
- m_outInterests = 0;
+ m_inInterests = 0;
+ m_outInterests = 0;
m_dropInterests = 0;
- m_inNacks = 0;
- m_outNacks = 0;
- m_dropNacks = 0;
- m_inData = 0;
- m_outData = 0;
- m_dropData = 0;
+ m_inNacks = 0;
+ m_outNacks = 0;
+ m_dropNacks = 0;
+ m_inData = 0;
+ m_outData = 0;
+ m_dropData = 0;
m_satisfiedInterests = 0;
m_timedOutInterests = 0;
@@ -167,12 +165,12 @@
* @brief Helper to dump the trace to an output stream
*/
inline std::ostream&
-operator << (std::ostream &os, const L3Tracer &tracer)
+operator<<(std::ostream& os, const L3Tracer& tracer)
{
os << "# ";
- tracer.PrintHeader (os);
+ tracer.PrintHeader(os);
os << "\n";
- tracer.Print (os);
+ tracer.Print(os);
return os;
}
diff --git a/utils/trie/aggregate-stats-policy.hpp b/utils/trie/aggregate-stats-policy.hpp
index ce466dd..b2cb0bd 100644
--- a/utils/trie/aggregate-stats-policy.hpp
+++ b/utils/trie/aggregate-stats-policy.hpp
@@ -32,80 +32,84 @@
* @brief Traits for policy that just keeps track of number of elements
* It's doing a rather expensive job, but just in case it needs to be extended later
*/
-struct aggregate_stats_policy_traits
-{
+struct aggregate_stats_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "AggregateStats"; }
- struct policy_hook_type { };
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- struct type { };
+ return "AggregateStats";
+ }
+ struct policy_hook_type {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
+ template<class Container>
+ struct container_hook {
+ struct type {
+ };
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
// typedef typename boost::intrusive::list< Container, Hook > policy_container;
// could be just typedef
- class type
- {
+ class type {
public:
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , m_updates (0)
- , m_inserts (0)
- , m_lookups (0)
- , m_erases (0)
+ type(Base& base)
+ : base_(base)
+ , m_updates(0)
+ , m_inserts(0)
+ , m_lookups(0)
+ , m_erases(0)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
- m_updates ++;
+ m_updates++;
// do nothing
}
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- m_inserts ++;
+ m_inserts++;
return true;
}
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
- m_lookups ++;
+ m_lookups++;
}
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- m_erases ++;
+ m_erases++;
}
- inline void
- set_max_size (uint32_t) {}
+ inline void set_max_size(uint32_t)
+ {
+ }
inline uint32_t
- get_max_size () const { return 0; }
+ get_max_size() const
+ {
+ return 0;
+ }
inline void
- clear ()
+ clear()
{
// is called only at the end of simulation
}
inline void
- ResetStats ()
+ ResetStats()
{
m_updates = 0;
m_inserts = 0;
@@ -114,23 +118,36 @@
}
inline uint64_t
- GetUpdates () const { return m_updates; }
+ GetUpdates() const
+ {
+ return m_updates;
+ }
inline uint64_t
- GetInserts () const { return m_inserts; }
+ GetInserts() const
+ {
+ return m_inserts;
+ }
inline uint64_t
- GetLookups () const { return m_lookups; }
+ GetLookups() const
+ {
+ return m_lookups;
+ }
inline uint64_t
- GetErases () const { return m_erases; }
+ GetErases() const
+ {
+ return m_erases;
+ }
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
-
+ Base& base_;
+
uint64_t m_updates;
uint64_t m_inserts;
uint64_t m_lookups;
diff --git a/utils/trie/counting-policy.hpp b/utils/trie/counting-policy.hpp
index 2c8656c..a44c290 100644
--- a/utils/trie/counting-policy.hpp
+++ b/utils/trie/counting-policy.hpp
@@ -32,76 +32,75 @@
* @brief Traits for policy that just keeps track of number of elements
* It's doing a rather expensive job, but just in case it needs to be extended later
*/
-struct counting_policy_traits
-{
+struct counting_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Counting"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- // could be class/struct implementation
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Counting";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
+ template<class Container>
+ struct container_hook {
+ // could be class/struct implementation
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
+ type(Base& base)
+ : base_(base)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- policy_container::push_back (*item);
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
};
};
};
diff --git a/utils/trie/detail/functor-hook.hpp b/utils/trie/detail/functor-hook.hpp
index f34969c..b0daadd 100644
--- a/utils/trie/detail/functor-hook.hpp
+++ b/utils/trie/detail/functor-hook.hpp
@@ -29,36 +29,43 @@
namespace detail {
template<class BaseHook, class ValueType, int N>
-struct FunctorHook
-{
+struct FunctorHook {
typedef typename BaseHook::template index<N>::type hook_type;
- typedef hook_type* hook_ptr;
- typedef const hook_type* const_hook_ptr;
-
- typedef ValueType value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
-
- //Required static functions
- static hook_ptr to_hook_ptr (value_type &value)
- { return &value.policy_hook_.template get<N> (); }
-
- static const_hook_ptr to_hook_ptr(const value_type &value)
- { return &value.policy_hook_.template get<N> (); }
-
- static pointer to_value_ptr(hook_ptr n)
+ typedef hook_type* hook_ptr;
+ typedef const hook_type* const_hook_ptr;
+
+ typedef ValueType value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+
+ // Required static functions
+ static hook_ptr
+ to_hook_ptr(value_type& value)
{
- return
- boost::intrusive::get_parent_from_member<value_type>
- (static_cast<BaseHook*> (boost::intrusive::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
- &value_type::policy_hook_);
+ return &value.policy_hook_.template get<N>();
}
- static const_pointer to_value_ptr(const_hook_ptr n)
+
+ static const_hook_ptr
+ to_hook_ptr(const value_type& value)
{
- return
- boost::intrusive::get_parent_from_member<value_type>
- (static_cast<const BaseHook*> (boost::intrusive::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
- &value_type::policy_hook_);
+ return &value.policy_hook_.template get<N>();
+ }
+
+ static pointer
+ to_value_ptr(hook_ptr n)
+ {
+ return boost::intrusive::get_parent_from_member<value_type>(
+ static_cast<BaseHook*>(
+ boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)),
+ &value_type::policy_hook_);
+ }
+ static const_pointer
+ to_value_ptr(const_hook_ptr n)
+ {
+ return boost::intrusive::get_parent_from_member<value_type>(
+ static_cast<const BaseHook*>(
+ boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)),
+ &value_type::policy_hook_);
}
};
diff --git a/utils/trie/detail/multi-policy-container.hpp b/utils/trie/detail/multi-policy-container.hpp
index c1251e9..00bfbf1 100644
--- a/utils/trie/detail/multi-policy-container.hpp
+++ b/utils/trie/detail/multi-policy-container.hpp
@@ -29,144 +29,180 @@
namespace ndnSIM {
namespace detail {
-template< class Base, class Value >
-struct policy_wrap
-{
- policy_wrap (Base &base) : value_ (base) { }
+template<class Base, class Value>
+struct policy_wrap {
+ policy_wrap(Base& base)
+ : value_(base)
+ {
+ }
Value value_;
};
-template< class Base, class Super/*empy_wrap/previous level*/, class Value/*policy_wrap< element in vector >*/ >
-struct inherit_with_base : Super, Value
-{
- inherit_with_base (Base &base) : Super (base), Value (base) { }
+template<class Base, class Super /*empy_wrap/previous level*/,
+ class Value /*policy_wrap< element in vector >*/>
+struct inherit_with_base : Super, Value {
+ inherit_with_base(Base& base)
+ : Super(base)
+ , Value(base)
+ {
+ }
void
- update (typename Base::iterator item)
+ update(typename Base::iterator item)
{
- Value::value_.update (item);
- Super::update (item);
+ Value::value_.update(item);
+ Super::update(item);
}
bool
- insert (typename Base::iterator item)
+ insert(typename Base::iterator item)
{
- bool ok = Value::value_.insert (item);
+ bool ok = Value::value_.insert(item);
if (!ok)
return false;
- ok = Super::insert (item);
- if (!ok)
- {
- Value::value_.erase (item);
- return false;
- }
+ ok = Super::insert(item);
+ if (!ok) {
+ Value::value_.erase(item);
+ return false;
+ }
return true;
}
void
- lookup (typename Base::iterator item)
+ lookup(typename Base::iterator item)
{
- Value::value_.lookup (item);
- Super::lookup (item);
+ Value::value_.lookup(item);
+ Super::lookup(item);
}
void
- erase (typename Base::iterator item)
+ erase(typename Base::iterator item)
{
- Value::value_.erase (item);
- Super::erase (item);
- }
+ Value::value_.erase(item);
+ Super::erase(item);
+ }
void
- clear ()
+ clear()
{
- Value::value_.clear ();
- Super::clear ();
+ Value::value_.clear();
+ Super::clear();
}
};
-template< class Base >
-struct empty_policy_wrap
-{
- empty_policy_wrap (Base &base) { }
+template<class Base>
+struct empty_policy_wrap {
+ empty_policy_wrap(Base& base)
+ {
+ }
- void update (typename Base::iterator item) {}
- bool insert (typename Base::iterator item) { return true; }
- void lookup (typename Base::iterator item) {}
- void erase (typename Base::iterator item) {}
- void clear () {}
+ void
+ update(typename Base::iterator item)
+ {
+ }
+ bool
+ insert(typename Base::iterator item)
+ {
+ return true;
+ }
+ void
+ lookup(typename Base::iterator item)
+ {
+ }
+ void
+ erase(typename Base::iterator item)
+ {
+ }
+ void
+ clear()
+ {
+ }
};
-template< class Base, class Vector >
+template<class Base, class Vector>
struct multi_policy_container
- : public boost::mpl::fold< Vector,
- empty_policy_wrap<Base>,
- inherit_with_base<Base,
- boost::mpl::_1/*empty/previous*/,
- policy_wrap<Base, boost::mpl::_2>/*element in vector*/>
- >::type
-{
- typedef typename boost::mpl::fold< Vector,
- empty_policy_wrap<Base>,
- inherit_with_base<Base,
- boost::mpl::_1/*empty/previous*/,
- policy_wrap<Base, boost::mpl::_2>/*element in vector*/>
- >::type super;
+ : public boost::mpl::
+ fold<Vector, empty_policy_wrap<Base>,
+ inherit_with_base<Base, boost::mpl::_1 /*empty/previous*/,
+ policy_wrap<Base, boost::mpl::_2> /*element in vector*/>>::type {
+ typedef typename boost::mpl::
+ fold<Vector, empty_policy_wrap<Base>,
+ inherit_with_base<Base, boost::mpl::_1 /*empty/previous*/,
+ policy_wrap<Base, boost::mpl::_2> /*element in vector*/>>::type super;
typedef typename boost::mpl::at_c<Vector, 0>::type::iterator iterator;
typedef typename boost::mpl::at_c<Vector, 0>::type::const_iterator const_iterator;
- iterator begin () { return this->get<0> ().begin (); }
- const_iterator begin () const { return this->get<0> ().begin (); }
+ iterator
+ begin()
+ {
+ return this->get<0>().begin();
+ }
+ const_iterator
+ begin() const
+ {
+ return this->get<0>().begin();
+ }
- iterator end () { return this->get<0> ().end (); }
- const_iterator end () const { return this->get<0> ().end (); }
+ iterator
+ end()
+ {
+ return this->get<0>().end();
+ }
+ const_iterator
+ end() const
+ {
+ return this->get<0>().end();
+ }
- size_t size () const { return this->get<0> ().size (); }
-
- multi_policy_container (Base &base)
- : super (base)
- { }
+ size_t
+ size() const
+ {
+ return this->get<0>().size();
+ }
+
+ multi_policy_container(Base& base)
+ : super(base)
+ {
+ }
template<int N>
- struct index
- {
+ struct index {
typedef typename boost::mpl::at_c<Vector, N>::type type;
};
-
+
template<class T>
- T &
- get ()
+ T&
+ get()
{
- return static_cast< policy_wrap<Base, T> &> (*this).value_;
+ return static_cast<policy_wrap<Base, T>&>(*this).value_;
}
template<class T>
- const T &
- get () const
+ const T&
+ get() const
{
- return static_cast< const policy_wrap<Base, T> &> (*this).value_;
+ return static_cast<const policy_wrap<Base, T>&>(*this).value_;
}
template<int N>
- typename boost::mpl::at_c<Vector, N>::type &
- get ()
+ typename boost::mpl::at_c<Vector, N>::type&
+ get()
{
typedef typename boost::mpl::at_c<Vector, N>::type T;
- return static_cast< policy_wrap<Base, T> &> (*this).value_;
+ return static_cast<policy_wrap<Base, T>&>(*this).value_;
}
template<int N>
- const typename boost::mpl::at_c<Vector, N>::type &
- get () const
+ const typename boost::mpl::at_c<Vector, N>::type&
+ get() const
{
typedef typename boost::mpl::at_c<Vector, N>::type T;
- return static_cast< const policy_wrap<Base, T> &> (*this).value_;
+ return static_cast<const policy_wrap<Base, T>&>(*this).value_;
}
};
-
} // detail
} // ndnSIM
} // ndn
diff --git a/utils/trie/detail/multi-type-container.hpp b/utils/trie/detail/multi-type-container.hpp
index d4971c4..56dc89e 100644
--- a/utils/trie/detail/multi-type-container.hpp
+++ b/utils/trie/detail/multi-type-container.hpp
@@ -30,54 +30,51 @@
namespace ndnSIM {
namespace detail {
-template <class T>
-struct wrap
-{
+template<class T>
+struct wrap {
T value_;
};
-template< class Vector >
+template<class Vector>
struct multi_type_container
- : public boost::mpl::inherit_linearly< Vector, boost::mpl::inherit<wrap<boost::mpl::_2>, boost::mpl::_1 >
- >::type
-{
+ : public boost::mpl::inherit_linearly<Vector, boost::mpl::inherit<wrap<boost::mpl::_2>,
+ boost::mpl::_1>>::type {
template<int N>
- struct index
- {
+ struct index {
typedef typename boost::mpl::at_c<Vector, N>::type type;
};
-
+
template<class T>
- T &
- get ()
+ T&
+ get()
{
- return static_cast< wrap<T> &> (*this).value_;
+ return static_cast<wrap<T>&>(*this).value_;
}
template<class T>
- const T &
- get () const
+ const T&
+ get() const
{
- return static_cast< const wrap<T> &> (*this).value_;
- }
-
- template<int N>
- typename boost::mpl::at_c<Vector, N>::type &
- get ()
- {
- typedef typename boost::mpl::at_c<Vector, N>::type T;
- return static_cast< wrap<T> &> (*this).value_;
+ return static_cast<const wrap<T>&>(*this).value_;
}
template<int N>
- const typename boost::mpl::at_c<Vector, N>::type &
- get () const
+ typename boost::mpl::at_c<Vector, N>::type&
+ get()
{
typedef typename boost::mpl::at_c<Vector, N>::type T;
- return static_cast< const wrap<T> &> (*this).value_;
+ return static_cast<wrap<T>&>(*this).value_;
+ }
+
+ template<int N>
+ const typename boost::mpl::at_c<Vector, N>::type&
+ get() const
+ {
+ typedef typename boost::mpl::at_c<Vector, N>::type T;
+ return static_cast<const wrap<T>&>(*this).value_;
}
};
-
+
} // detail
} // ndnSIM
} // ndn
diff --git a/utils/trie/empty-policy.hpp b/utils/trie/empty-policy.hpp
index c610717..7d077b6 100644
--- a/utils/trie/empty-policy.hpp
+++ b/utils/trie/empty-policy.hpp
@@ -28,29 +28,47 @@
/**
* @brief Traits for empty (bogus) replacement policy
*/
-struct empty_policy_traits
-{
+struct empty_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return ""; }
+ static std::string
+ GetName()
+ {
+ return "";
+ }
typedef void* policy_hook_type;
- template<class Container> struct container_hook { typedef void* type; };
+ template<class Container>
+ struct container_hook {
+ typedef void* type;
+ };
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- struct type
- {
- inline type (Base &base) {}
-
- inline void update (typename Container::iterator) { }
- inline bool insert (typename Container::iterator) { return true; }
- inline void lookup (typename Container::iterator item) { }
- inline void erase (typename Container::iterator item) { }
- inline void clear () { }
+ template<class Base, class Container, class Hook>
+ struct policy {
+ struct type {
+ inline type(Base& base)
+ {
+ }
+
+ inline void update(typename Container::iterator)
+ {
+ }
+ inline bool insert(typename Container::iterator)
+ {
+ return true;
+ }
+ inline void
+ lookup(typename Container::iterator item)
+ {
+ }
+ inline void
+ erase(typename Container::iterator item)
+ {
+ }
+ inline void
+ clear()
+ {
+ }
};
};
};
diff --git a/utils/trie/fifo-policy.hpp b/utils/trie/fifo-policy.hpp
index 7ab4ec7..2527c16 100644
--- a/utils/trie/fifo-policy.hpp
+++ b/utils/trie/fifo-policy.hpp
@@ -31,94 +31,92 @@
/**
* @brief Traits for First In First Out replacement policy
*/
-struct fifo_policy_traits
-{
+struct fifo_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Fifo"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- // could be class/struct implementation
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Fifo";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
+ template<class Container>
+ struct container_hook {
+ // could be class/struct implementation
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- if (max_size_ != 0 && policy_container::size () >= max_size_)
- {
- base_.erase (&(*policy_container::begin ()));
- }
-
- policy_container::push_back (*item);
+ if (max_size_ != 0 && policy_container::size() >= max_size_) {
+ base_.erase(&(*policy_container::begin()));
+ }
+
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/utils/trie/lfu-policy.hpp b/utils/trie/lfu-policy.hpp
index c6d6108..897dc49 100644
--- a/utils/trie/lfu-policy.hpp
+++ b/utils/trie/lfu-policy.hpp
@@ -31,124 +31,125 @@
/**
* @brief Traits for LFU replacement policy
*/
-struct lfu_policy_traits
-{
+struct lfu_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Lfu"; }
-
- struct policy_hook_type : public boost::intrusive::set_member_hook<> { double frequency; };
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Lfu";
+ }
+
+ struct policy_hook_type : public boost::intrusive::set_member_hook<> {
+ double frequency;
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- static double& get_order (typename Container::iterator item)
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ static double&
+ get_order(typename Container::iterator item)
{
- return static_cast<policy_hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->frequency;
+ return static_cast<policy_hook_type*>(policy_container::value_traits::to_node_ptr(*item))
+ ->frequency;
}
- static const double& get_order (typename Container::const_iterator item)
+ static const double&
+ get_order(typename Container::const_iterator item)
{
- return static_cast<const policy_hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->frequency;
+ return static_cast<const policy_hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->frequency;
}
template<class Key>
- struct MemberHookLess
- {
- bool operator () (const Key &a, const Key &b) const
+ struct MemberHookLess {
+ bool
+ operator()(const Key& a, const Key& b) const
{
- return get_order (&a) < get_order (&b);
+ return get_order(&a) < get_order(&b);
}
};
- typedef boost::intrusive::multiset< Container,
- boost::intrusive::compare< MemberHookLess< Container > >,
- Hook > policy_container;
+ typedef boost::intrusive::multiset<Container,
+ boost::intrusive::compare<MemberHookLess<Container>>,
+ Hook> policy_container;
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_order methods from outside
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
- get_order (item) += 1;
- policy_container::insert (*item);
+ policy_container::erase(policy_container::s_iterator_to(*item));
+ get_order(item) += 1;
+ policy_container::insert(*item);
}
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- get_order (item) = 0;
+ get_order(item) = 0;
- if (max_size_ != 0 && policy_container::size () >= max_size_)
- {
- // this erases the "least frequently used item" from cache
- base_.erase (&(*policy_container::begin ()));
- }
+ if (max_size_ != 0 && policy_container::size() >= max_size_) {
+ // this erases the "least frequently used item" from cache
+ base_.erase(&(*policy_container::begin()));
+ }
- policy_container::insert (*item);
+ policy_container::insert(*item);
return true;
}
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
- get_order (item) += 1;
- policy_container::insert (*item);
+ policy_container::erase(policy_container::s_iterator_to(*item));
+ get_order(item) += 1;
+ policy_container::insert(*item);
}
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/utils/trie/lru-policy.hpp b/utils/trie/lru-policy.hpp
index a248117..77a65ca 100644
--- a/utils/trie/lru-policy.hpp
+++ b/utils/trie/lru-policy.hpp
@@ -31,99 +31,95 @@
/**
* @brief Traits for Least Recently Used replacement policy
*/
-struct lru_policy_traits
-{
+struct lru_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Lru"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Lru";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef Container parent_trie;
-
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
+
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do relocation
- policy_container::splice (policy_container::end (),
- *this,
- policy_container::s_iterator_to (*item));
+ policy_container::splice(policy_container::end(), *this,
+ policy_container::s_iterator_to(*item));
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- if (max_size_ != 0 && policy_container::size () >= max_size_)
- {
- base_.erase (&(*policy_container::begin ()));
- }
-
- policy_container::push_back (*item);
+ if (max_size_ != 0 && policy_container::size() >= max_size_) {
+ base_.erase(&(*policy_container::begin()));
+ }
+
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do relocation
- policy_container::splice (policy_container::end (),
- *this,
- policy_container::s_iterator_to (*item));
- }
-
- inline void
- erase (typename parent_trie::iterator item)
- {
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::splice(policy_container::end(), *this,
+ policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ erase(typename parent_trie::iterator item)
{
- policy_container::clear ();
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- set_max_size (size_t max_size)
+ clear()
+ {
+ policy_container::clear();
+ }
+
+ inline void
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/utils/trie/multi-policy.hpp b/utils/trie/multi-policy.hpp
index 125df02..170f691 100644
--- a/utils/trie/multi-policy.hpp
+++ b/utils/trie/multi-policy.hpp
@@ -40,144 +40,148 @@
namespace ndnSIM {
template<typename Policies> // e.g., mpl::vector1< lru_policy_traits >
-struct multi_policy_traits
-{
+struct multi_policy_traits {
typedef Policies policy_traits;
- struct getHook { template<class Item> struct apply { typedef typename Item::policy_hook_type type; }; };
- typedef detail::multi_type_container< typename boost::mpl::transform1<policy_traits, getHook>::type > policy_hook_type;
-
+ struct getHook {
+ template<class Item>
+ struct apply {
+ typedef typename Item::policy_hook_type type;
+ };
+ };
+ typedef detail::multi_type_container<
+ typename boost::mpl::transform1<policy_traits, getHook>::type> policy_hook_type;
+
template<class Container>
- struct container_hook
- {
+ struct container_hook {
typedef policy_hook_type type;
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> policies_range;
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value>
+ policies_range;
- struct getPolicy
- {
+ struct getPolicy {
template<class Number>
- struct apply
- {
- typedef
- typename boost::mpl::at_c<policy_traits, Number::value>::type::
- template policy<Base,
- Container,
- boost::intrusive::function_hook< detail::FunctorHook <Hook,
- Container,
- Number::value> > >::type
- type;
+ struct apply {
+ typedef typename boost::mpl::at_c<policy_traits, Number::value>::type::
+ template policy<Base, Container,
+ boost::intrusive::function_hook<detail::FunctorHook<Hook, Container,
+ Number::value>>>::type
+ type;
};
};
-
- typedef
- typename boost::mpl::transform1<policies_range,
- getPolicy,
- boost::mpl::back_inserter< boost::mpl::vector0<> > >::type policies;
-
-
- typedef detail::multi_policy_container< Base, policies > policy_container;
-
- class type : public policy_container
- {
+
+ typedef typename boost::mpl::transform1<policies_range, getPolicy,
+ boost::mpl::back_inserter<boost::mpl::vector0<>>>::type
+ policies;
+
+ typedef detail::multi_policy_container<Base, policies> policy_container;
+
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_time methods from outside
typedef Container parent_trie;
- type (Base &base)
- : policy_container (base)
+ type(Base& base)
+ : policy_container(base)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
- policy_container::update (item);
+ policy_container::update(item);
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- return policy_container::insert (item);
- }
-
- inline void
- lookup (typename parent_trie::iterator item)
- {
- policy_container::lookup (item);
- }
-
- inline void
- erase (typename parent_trie::iterator item)
- {
- policy_container::erase (item);
- }
-
- inline void
- clear ()
- {
- policy_container::clear ();
+ return policy_container::insert(item);
}
- struct max_size_setter
+ inline void
+ lookup(typename parent_trie::iterator item)
{
- max_size_setter (policy_container &container, size_t size) : m_container (container), m_size (size) { }
-
- template< typename U > void operator() (U index)
+ policy_container::lookup(item);
+ }
+
+ inline void
+ erase(typename parent_trie::iterator item)
+ {
+ policy_container::erase(item);
+ }
+
+ inline void
+ clear()
+ {
+ policy_container::clear();
+ }
+
+ struct max_size_setter {
+ max_size_setter(policy_container& container, size_t size)
+ : m_container(container)
+ , m_size(size)
{
- m_container.template get<U::value> ().set_max_size (m_size);
+ }
+
+ template<typename U>
+ void
+ operator()(U index)
+ {
+ m_container.template get<U::value>().set_max_size(m_size);
}
private:
- policy_container &m_container;
+ policy_container& m_container;
size_t m_size;
};
-
+
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
- boost::mpl::for_each< boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> >
- (max_size_setter (*this, max_size));
+ boost::mpl::for_each<boost::mpl::range_c<int, 0,
+ boost::mpl::size<policy_traits>::type::value>>(
+ max_size_setter(*this, max_size));
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
// as max size should be the same everywhere, get the value from the first available policy
- return policy_container::template get<0> ().get_max_size ();
+ return policy_container::template get<0>().get_max_size();
}
-
};
};
-
- struct name_getter
- {
- name_getter (std::string &name) : m_name (name) { }
-
- template< typename U > void operator() (U index)
+ struct name_getter {
+ name_getter(std::string& name)
+ : m_name(name)
{
- if (!m_name.empty ())
- m_name += "::";
- m_name += boost::mpl::at_c< policy_traits, U::value >::type::GetName ();
}
- std::string &m_name;
+ template<typename U>
+ void
+ operator()(U index)
+ {
+ if (!m_name.empty())
+ m_name += "::";
+ m_name += boost::mpl::at_c<policy_traits, U::value>::type::GetName();
+ }
+
+ std::string& m_name;
};
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName ()
+ static std::string
+ GetName()
{
// combine names of all internal policies
std::string name;
- boost::mpl::for_each< boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value> > (name_getter (name));
-
+ boost::mpl::for_each<boost::mpl::range_c<int, 0, boost::mpl::size<policy_traits>::type::value>>(
+ name_getter(name));
+
return name;
}
};
diff --git a/utils/trie/payload-policy.hpp b/utils/trie/payload-policy.hpp
index a474afd..9193442 100644
--- a/utils/trie/payload-policy.hpp
+++ b/utils/trie/payload-policy.hpp
@@ -32,96 +32,88 @@
* @brief Traits for policy that keeps items in a sorted order using payload member
*/
template<class Member>
-struct payload_policy_traits
-{
- struct policy_hook_type : public boost::intrusive::set_member_hook<> {};
-
- template<class Container>
- struct container_hook
- {
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+struct payload_policy_traits {
+ struct policy_hook_type : public boost::intrusive::set_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef Container parent_trie;
-
- type (Base &base)
- : base_ (base)
- , max_size_ (100)
+
+ type(Base& base)
+ : base_(base)
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do relocation
- policy_container::splice (policy_container::end (),
- *this,
- policy_container::s_iterator_to (*item));
+ policy_container::splice(policy_container::end(), *this,
+ policy_container::s_iterator_to(*item));
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- if (policy_container::size () >= max_size_)
- {
- base_.erase (&(*policy_container::begin ()));
- }
-
- policy_container::push_back (*item);
+ if (policy_container::size() >= max_size_) {
+ base_.erase(&(*policy_container::begin()));
+ }
+
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do relocation
- policy_container::splice (policy_container::end (),
- *this,
- policy_container::s_iterator_to (*item));
- }
-
- inline void
- erase (typename parent_trie::iterator item)
- {
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::splice(policy_container::end(), *this,
+ policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ erase(typename parent_trie::iterator item)
{
- policy_container::clear ();
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- set_max_size (size_t max_size)
+ clear()
+ {
+ policy_container::clear();
+ }
+
+ inline void
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
+ type()
+ : base_(*((Base*)0)){};
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/utils/trie/payload-with-policy.hpp b/utils/trie/payload-with-policy.hpp
index 7db278b..4010511 100644
--- a/utils/trie/payload-with-policy.hpp
+++ b/utils/trie/payload-with-policy.hpp
@@ -25,32 +25,29 @@
namespace ndn {
namespace ndnSIM {
-template<typename PayloadTraits,
- typename IndexTraits>
-class payload_with_index
-{
+template<typename PayloadTraits, typename IndexTraits>
+class payload_with_index {
public:
typedef PayloadTraits::pointer_type iterator;
-
- typedef typename IndexTraits::template index<
- PayloadTraits,
- typename IndexTraits::template container_hook<parent_trie>::type >::type index_container;
- inline
- payload_with_index ()
- : index_ (*this)
+ typedef typename IndexTraits::
+ template index<PayloadTraits,
+ typename IndexTraits::template container_hook<parent_trie>::type>::type
+ index_container;
+
+ inline payload_with_index()
+ : index_(*this)
{
}
- inline std::pair< iterator, bool >
- insert (typename iterator payload)
+ inline std::pair<iterator, bool>
+ insert(typename iterator payload)
{
- bool ok = policy_.insert (s_iterator_to (item.first));
- if (!ok)
- {
- item.first->erase (); // cannot insert
- return std::make_pair (end (), false);
- }
+ bool ok = policy_.insert(s_iterator_to(item.first));
+ if (!ok) {
+ item.first->erase(); // cannot insert
+ return std::make_pair(end(), false);
+ }
return item;
}
@@ -61,7 +58,7 @@
// iterator foundItem, lastItem;
// bool reachLast;
// boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
-
+
// if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
// return; // nothing to invalidate
diff --git a/utils/trie/persistent-policy.hpp b/utils/trie/persistent-policy.hpp
index 9b706b0..c8f116c 100644
--- a/utils/trie/persistent-policy.hpp
+++ b/utils/trie/persistent-policy.hpp
@@ -32,84 +32,83 @@
* @brief Traits for persistent replacement policy
*
* In this policy entries are added until there is a space (controlled by set_max_size call).
- * If maximum is reached, new entries will not be added and nothing will be removed from the container
+ * If maximum is reached, new entries will not be added and nothing will be removed from the
+ *container
*/
-struct persistent_policy_traits
-{
+struct persistent_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Persistent"; }
-
- struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Persistent";
+ }
+
+ struct policy_hook_type : public boost::intrusive::list_member_hook<> {
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- typedef typename boost::intrusive::list< Container, Hook > policy_container;
-
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ typedef typename boost::intrusive::list<Container, Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef Container parent_trie;
-
- type (Base &base)
- : base_ (base)
- , max_size_ (100) // when 0, policy is not enforced
+
+ type(Base& base)
+ : base_(base)
+ , max_size_(100) // when 0, policy is not enforced
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- if (max_size_ != 0 && policy_container::size () >= max_size_)
+ if (max_size_ != 0 && policy_container::size() >= max_size_)
return false;
-
- policy_container::push_back (*item);
+
+ policy_container::push_back(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing
}
-
+
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
@@ -118,7 +117,7 @@
// type () : base_(*((Base*)0)) { };
private:
- Base &base_;
+ Base& base_;
size_t max_size_;
};
};
diff --git a/utils/trie/random-policy.hpp b/utils/trie/random-policy.hpp
index 1a7308c..7264bed 100644
--- a/utils/trie/random-policy.hpp
+++ b/utils/trie/random-policy.hpp
@@ -33,130 +33,129 @@
/**
* @brief Traits for random replacement policy
*/
-struct random_policy_traits
-{
+struct random_policy_traits {
/// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
- static std::string GetName () { return "Random"; }
-
- struct policy_hook_type : public boost::intrusive::set_member_hook<> { uint32_t randomOrder; };
-
- template<class Container>
- struct container_hook
+ static std::string
+ GetName()
{
- typedef boost::intrusive::member_hook< Container,
- policy_hook_type,
- &Container::policy_hook_ > type;
+ return "Random";
+ }
+
+ struct policy_hook_type : public boost::intrusive::set_member_hook<> {
+ uint32_t randomOrder;
};
- template<class Base,
- class Container,
- class Hook>
- struct policy
- {
- static uint32_t& get_order (typename Container::iterator item)
+ template<class Container>
+ struct container_hook {
+ typedef boost::intrusive::member_hook<Container, policy_hook_type, &Container::policy_hook_>
+ type;
+ };
+
+ template<class Base, class Container, class Hook>
+ struct policy {
+ static uint32_t&
+ get_order(typename Container::iterator item)
{
- return static_cast<typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->randomOrder;
+ return static_cast<typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->randomOrder;
}
-
- static const uint32_t& get_order (typename Container::const_iterator item)
+
+ static const uint32_t&
+ get_order(typename Container::const_iterator item)
{
- return static_cast<const typename policy_container::value_traits::hook_type*>
- (policy_container::value_traits::to_node_ptr(*item))->randomOrder;
+ return static_cast<const typename policy_container::value_traits::hook_type*>(
+ policy_container::value_traits::to_node_ptr(*item))->randomOrder;
}
-
+
template<class Key>
- struct MemberHookLess
- {
- bool operator () (const Key &a, const Key &b) const
+ struct MemberHookLess {
+ bool
+ operator()(const Key& a, const Key& b) const
{
- return get_order (&a) < get_order (&b);
+ return get_order(&a) < get_order(&b);
}
};
- typedef boost::intrusive::multiset< Container,
- boost::intrusive::compare< MemberHookLess< Container > >,
- Hook > policy_container;
-
+ typedef boost::intrusive::multiset<Container,
+ boost::intrusive::compare<MemberHookLess<Container>>,
+ Hook> policy_container;
+
// could be just typedef
- class type : public policy_container
- {
+ class type : public policy_container {
public:
typedef policy policy_base; // to get access to get_order methods from outside
typedef Container parent_trie;
- type (Base &base)
- : base_ (base)
- , u_rand (0, std::numeric_limits<uint32_t>::max ())
- , max_size_ (100)
+ type(Base& base)
+ : base_(base)
+ , u_rand(0, std::numeric_limits<uint32_t>::max())
+ , max_size_(100)
{
}
inline void
- update (typename parent_trie::iterator item)
+ update(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
-
+
inline bool
- insert (typename parent_trie::iterator item)
+ insert(typename parent_trie::iterator item)
{
- get_order (item) = u_rand.GetValue ();
+ get_order(item) = u_rand.GetValue();
- if (max_size_ != 0 && policy_container::size () >= max_size_)
- {
- if (MemberHookLess<Container>() (*item, *policy_container::begin ()))
- {
- // std::cout << "Cannot add. Signaling fail\n";
- // just return false. Indicating that insert "failed"
- return false;
- }
- else
- {
- // removing some random element
- base_.erase (&(*policy_container::begin ()));
- }
+ if (max_size_ != 0 && policy_container::size() >= max_size_) {
+ if (MemberHookLess<Container>()(*item, *policy_container::begin())) {
+ // std::cout << "Cannot add. Signaling fail\n";
+ // just return false. Indicating that insert "failed"
+ return false;
}
+ else {
+ // removing some random element
+ base_.erase(&(*policy_container::begin()));
+ }
+ }
- policy_container::insert (*item);
+ policy_container::insert(*item);
return true;
}
-
+
inline void
- lookup (typename parent_trie::iterator item)
+ lookup(typename parent_trie::iterator item)
{
// do nothing. it's random policy
}
-
+
inline void
- erase (typename parent_trie::iterator item)
+ erase(typename parent_trie::iterator item)
{
- policy_container::erase (policy_container::s_iterator_to (*item));
+ policy_container::erase(policy_container::s_iterator_to(*item));
}
inline void
- clear ()
+ clear()
{
- policy_container::clear ();
+ policy_container::clear();
}
inline void
- set_max_size (size_t max_size)
+ set_max_size(size_t max_size)
{
max_size_ = max_size;
}
inline size_t
- get_max_size () const
+ get_max_size() const
{
return max_size_;
}
private:
- type () : base_(*((Base*)0)) { };
-
+ type()
+ : base_(*((Base*)0)){};
+
private:
- Base &base_;
+ Base& base_;
ns3::UniformVariable u_rand;
size_t max_size_;
};
diff --git a/utils/trie/trie-with-policy.hpp b/utils/trie/trie-with-policy.hpp
index f09f13b..790dd0f 100644
--- a/utils/trie/trie-with-policy.hpp
+++ b/utils/trie/trie-with-policy.hpp
@@ -27,93 +27,86 @@
namespace ndn {
namespace ndnSIM {
-template<typename FullKey,
- typename PayloadTraits,
- typename PolicyTraits
- >
-class trie_with_policy
-{
+template<typename FullKey, typename PayloadTraits, typename PolicyTraits>
+class trie_with_policy {
public:
- typedef trie< FullKey,
- PayloadTraits,
- typename PolicyTraits::policy_hook_type > parent_trie;
+ typedef trie<FullKey, PayloadTraits, typename PolicyTraits::policy_hook_type> parent_trie;
typedef typename parent_trie::iterator iterator;
typedef typename parent_trie::const_iterator const_iterator;
- typedef typename PolicyTraits::template policy<
- trie_with_policy<FullKey, PayloadTraits, PolicyTraits>,
- parent_trie,
- typename PolicyTraits::template container_hook<parent_trie>::type >::type policy_container;
+ typedef typename PolicyTraits::
+ template policy<trie_with_policy<FullKey, PayloadTraits, PolicyTraits>, parent_trie,
+ typename PolicyTraits::template container_hook<parent_trie>::type>::type
+ policy_container;
- inline
- trie_with_policy (size_t bucketSize = 1, size_t bucketIncrement = 1)
- : trie_ (name::Component (), bucketSize, bucketIncrement)
- , policy_ (*this)
+ inline trie_with_policy(size_t bucketSize = 1, size_t bucketIncrement = 1)
+ : trie_(name::Component(), bucketSize, bucketIncrement)
+ , policy_(*this)
{
}
- inline std::pair< iterator, bool >
- insert (const FullKey &key, typename PayloadTraits::insert_type payload)
+ inline std::pair<iterator, bool>
+ insert(const FullKey& key, typename PayloadTraits::insert_type payload)
{
- std::pair<iterator, bool> item =
- trie_.insert (key, payload);
+ std::pair<iterator, bool> item = trie_.insert(key, payload);
if (item.second) // real insert
- {
- bool ok = policy_.insert (s_iterator_to (item.first));
- if (!ok)
- {
- item.first->erase (); // cannot insert
- return std::make_pair (end (), false);
- }
+ {
+ bool ok = policy_.insert(s_iterator_to(item.first));
+ if (!ok) {
+ item.first->erase(); // cannot insert
+ return std::make_pair(end(), false);
}
- else
- {
- return std::make_pair (s_iterator_to (item.first), false);
- }
+ }
+ else {
+ return std::make_pair(s_iterator_to(item.first), false);
+ }
return item;
}
inline void
- erase (const FullKey &key)
+ erase(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
- if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
+ if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload)
return; // nothing to invalidate
- erase (lastItem);
+ erase(lastItem);
}
inline void
- erase (iterator node)
+ erase(iterator node)
{
- if (node == end ()) return;
+ if (node == end())
+ return;
- policy_.erase (s_iterator_to (node));
- node->erase (); // will do cleanup here
+ policy_.erase(s_iterator_to(node));
+ node->erase(); // will do cleanup here
}
inline void
- clear ()
+ clear()
{
- policy_.clear ();
- trie_.clear ();
+ policy_.clear();
+ trie_.clear();
}
template<typename Modifier>
bool
- modify (iterator position, Modifier mod)
+ modify(iterator position, Modifier mod)
{
- if (position == end ()) return false;
- if (position->payload () == PayloadTraits::empty_payload) return false;
+ if (position == end())
+ return false;
+ if (position->payload() == PayloadTraits::empty_payload)
+ return false;
- mod (*position->payload ());
- policy_.update (position);
+ mod(*position->payload());
+ policy_.update(position);
return true;
}
@@ -121,14 +114,14 @@
* @brief Find a node that has the exact match with the key
*/
inline iterator
- find_exact (const FullKey &key)
+ find_exact(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
- if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload)
- return end ();
+ if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload)
+ return end();
return lastItem;
}
@@ -137,15 +130,14 @@
* @brief Find a node that has the longest common prefix with key (FIB/PIT lookup)
*/
inline iterator
- longest_prefix_match (const FullKey &key)
+ longest_prefix_match(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
- if (foundItem != trie_.end ())
- {
- policy_.lookup (s_iterator_to (foundItem));
- }
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
+ if (foundItem != trie_.end()) {
+ policy_.lookup(s_iterator_to(foundItem));
+ }
return foundItem;
}
@@ -154,15 +146,14 @@
*/
template<class Predicate>
inline iterator
- longest_prefix_match_if (const FullKey &key, Predicate pred)
+ longest_prefix_match_if(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find_if (key, pred);
- if (foundItem != trie_.end ())
- {
- policy_.lookup (s_iterator_to (foundItem));
- }
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find_if(key, pred);
+ if (foundItem != trie_.end()) {
+ policy_.lookup(s_iterator_to(foundItem));
+ }
return foundItem;
}
@@ -180,29 +171,26 @@
* @brief Find a node that has prefix at least as the key (cache lookup)
*/
inline iterator
- deepest_prefix_match (const FullKey &key)
+ deepest_prefix_match(const FullKey& key)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- if (foundItem == trie_.end ())
- {
- foundItem = lastItem->find (); // should be something
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ if (foundItem == trie_.end()) {
+ foundItem = lastItem->find(); // should be something
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
/**
@@ -210,30 +198,27 @@
*/
template<class Predicate>
inline iterator
- deepest_prefix_match_if (const FullKey &key, Predicate pred)
+ deepest_prefix_match_if(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- foundItem = lastItem->find_if (pred); // may or may not find something
- if (foundItem == trie_.end ())
- {
- return trie_.end ();
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ foundItem = lastItem->find_if(pred); // may or may not find something
+ if (foundItem == trie_.end()) {
+ return trie_.end();
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
/**
@@ -244,51 +229,61 @@
*/
template<class Predicate>
inline iterator
- deepest_prefix_match_if_next_level (const FullKey &key, Predicate pred)
+ deepest_prefix_match_if_next_level(const FullKey& key, Predicate pred)
{
iterator foundItem, lastItem;
bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = trie_.find (key);
+ boost::tie(foundItem, reachLast, lastItem) = trie_.find(key);
// guard in case we don't have anything in the trie
- if (lastItem == trie_.end ())
- return trie_.end ();
+ if (lastItem == trie_.end())
+ return trie_.end();
- if (reachLast)
- {
- foundItem = lastItem->find_if_next_level (pred); // may or may not find something
- if (foundItem == trie_.end ())
- {
- return trie_.end ();
- }
- policy_.lookup (s_iterator_to (foundItem));
- return foundItem;
+ if (reachLast) {
+ foundItem = lastItem->find_if_next_level(pred); // may or may not find something
+ if (foundItem == trie_.end()) {
+ return trie_.end();
}
- else
- { // couldn't find a node that has prefix at least as key
- return trie_.end ();
- }
+ policy_.lookup(s_iterator_to(foundItem));
+ return foundItem;
+ }
+ else { // couldn't find a node that has prefix at least as key
+ return trie_.end();
+ }
}
-
- iterator end () const
+
+ iterator
+ end() const
{
return 0;
}
- const parent_trie &
- getTrie () const { return trie_; }
+ const parent_trie&
+ getTrie() const
+ {
+ return trie_;
+ }
- parent_trie &
- getTrie () { return trie_; }
+ parent_trie&
+ getTrie()
+ {
+ return trie_;
+ }
- const policy_container &
- getPolicy () const { return policy_; }
+ const policy_container&
+ getPolicy() const
+ {
+ return policy_;
+ }
- policy_container &
- getPolicy () { return policy_; }
+ policy_container&
+ getPolicy()
+ {
+ return policy_;
+ }
static inline iterator
- s_iterator_to (typename parent_trie::iterator item)
+ s_iterator_to(typename parent_trie::iterator item)
{
if (item == 0)
return 0;
@@ -297,7 +292,7 @@
}
private:
- parent_trie trie_;
+ parent_trie trie_;
mutable policy_container policy_;
};
diff --git a/utils/trie/trie.hpp b/utils/trie/trie.hpp
index 1e37cbd..9afc8d1 100644
--- a/utils/trie/trie.hpp
+++ b/utils/trie/trie.hpp
@@ -40,33 +40,32 @@
// Allow customization for payload
//
template<typename Payload, typename BasePayload = Payload>
-struct pointer_payload_traits
-{
- typedef Payload payload_type; // general type of the payload
- typedef Payload* storage_type; // how the payload is actually stored
- typedef Payload* insert_type; // what parameter is inserted
+struct pointer_payload_traits {
+ typedef Payload payload_type; // general type of the payload
+ typedef Payload* storage_type; // how the payload is actually stored
+ typedef Payload* insert_type; // what parameter is inserted
- typedef Payload* return_type; // what is returned on access
- typedef const Payload* const_return_type; // what is returned on const access
+ typedef Payload* return_type; // what is returned on access
+ typedef const Payload* const_return_type; // what is returned on const access
- typedef BasePayload* base_type; // base type of the entry (when implementation details need to be hidden)
- typedef const BasePayload* const_base_type; // const base type of the entry (when implementation details need to be hidden)
+ typedef BasePayload*
+ base_type; // base type of the entry (when implementation details need to be hidden)
+ typedef const BasePayload*
+ const_base_type; // const base type of the entry (when implementation details need to be hidden)
static Payload* empty_payload;
};
template<typename Payload, typename BasePayload>
-Payload*
-pointer_payload_traits<Payload, BasePayload>::empty_payload = 0;
+Payload* pointer_payload_traits<Payload, BasePayload>::empty_payload = 0;
template<typename Payload, typename BasePayload = Payload>
-struct smart_pointer_payload_traits
-{
- typedef Payload payload_type;
- typedef ns3::Ptr<Payload> storage_type;
- typedef ns3::Ptr<Payload> insert_type;
+struct smart_pointer_payload_traits {
+ typedef Payload payload_type;
+ typedef ns3::Ptr<Payload> storage_type;
+ typedef ns3::Ptr<Payload> insert_type;
- typedef ns3::Ptr<Payload> return_type;
+ typedef ns3::Ptr<Payload> return_type;
typedef ns3::Ptr<const Payload> const_return_type;
typedef ns3::Ptr<BasePayload> base_type;
@@ -76,51 +75,44 @@
};
template<typename Payload, typename BasePayload>
-ns3::Ptr<Payload>
-smart_pointer_payload_traits<Payload, BasePayload>::empty_payload = 0;
+ns3::Ptr<Payload> smart_pointer_payload_traits<Payload, BasePayload>::empty_payload = 0;
template<typename Payload, typename BasePayload = Payload>
-struct non_pointer_traits
-{
- typedef Payload payload_type;
- typedef Payload storage_type;
- typedef const Payload & insert_type; // nothing to insert
+struct non_pointer_traits {
+ typedef Payload payload_type;
+ typedef Payload storage_type;
+ typedef const Payload& insert_type; // nothing to insert
- typedef Payload& return_type;
- typedef const Payload & const_return_type;
+ typedef Payload& return_type;
+ typedef const Payload& const_return_type;
- typedef BasePayload& base_type;
+ typedef BasePayload& base_type;
typedef const BasePayload& const_base_type;
static Payload empty_payload;
};
template<typename Payload, typename BasePayload>
-Payload
-non_pointer_traits<Payload, BasePayload>::empty_payload = Payload ();
-
+Payload non_pointer_traits<Payload, BasePayload>::empty_payload = Payload();
////////////////////////////////////////////////////
// forward declarations
//
-template<typename FullKey,
- typename PayloadTraits,
- typename PolicyHook >
+template<typename FullKey, typename PayloadTraits, typename PolicyHook>
class trie;
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
inline std::ostream&
-operator << (std::ostream &os,
- const trie<FullKey, PayloadTraits, PolicyHook> &trie_node);
+operator<<(std::ostream& os, const trie<FullKey, PayloadTraits, PolicyHook>& trie_node);
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
bool
-operator== (const trie<FullKey, PayloadTraits, PolicyHook> &a,
- const trie<FullKey, PayloadTraits, PolicyHook> &b);
+operator==(const trie<FullKey, PayloadTraits, PolicyHook>& a,
+ const trie<FullKey, PayloadTraits, PolicyHook>& b);
-template<typename FullKey, typename PayloadTraits, typename PolicyHook >
+template<typename FullKey, typename PayloadTraits, typename PolicyHook>
std::size_t
-hash_value (const trie<FullKey, PayloadTraits, PolicyHook> &trie_node);
+hash_value(const trie<FullKey, PayloadTraits, PolicyHook>& trie_node);
///////////////////////////////////////////////////
// actual definition
@@ -131,15 +123,12 @@
template<class T>
class trie_point_iterator;
-template<typename FullKey,
- typename PayloadTraits,
- typename PolicyHook >
-class trie
-{
+template<typename FullKey, typename PayloadTraits, typename PolicyHook>
+class trie {
public:
typedef typename FullKey::partial_type Key;
- typedef trie* iterator;
+ typedef trie* iterator;
typedef const trie* const_iterator;
typedef trie_iterator<trie, trie> recursive_iterator;
@@ -150,126 +139,119 @@
typedef PayloadTraits payload_traits;
- inline
- trie (const Key &key, size_t bucketSize = 1, size_t bucketIncrement = 1)
- : key_ (key)
- , initialBucketSize_ (bucketSize)
- , bucketIncrement_ (bucketIncrement)
- , bucketSize_ (initialBucketSize_)
- , buckets_ (new bucket_type [bucketSize_]) //cannot use normal pointer, because lifetime of buckets should be larger than lifetime of the container
- , children_ (bucket_traits (buckets_.get (), bucketSize_))
- , payload_ (PayloadTraits::empty_payload)
- , parent_ (0)
+ inline trie(const Key& key, size_t bucketSize = 1, size_t bucketIncrement = 1)
+ : key_(key)
+ , initialBucketSize_(bucketSize)
+ , bucketIncrement_(bucketIncrement)
+ , bucketSize_(initialBucketSize_)
+ , buckets_(new bucket_type[bucketSize_]) // cannot use normal pointer, because lifetime of
+ // buckets should be larger than lifetime of the
+ // container
+ , children_(bucket_traits(buckets_.get(), bucketSize_))
+ , payload_(PayloadTraits::empty_payload)
+ , parent_(0)
{
}
- inline
- ~trie ()
+ inline ~trie()
{
payload_ = PayloadTraits::empty_payload; // necessary for smart pointers...
- children_.clear_and_dispose (trie_delete_disposer ());
+ children_.clear_and_dispose(trie_delete_disposer());
}
void
- clear ()
+ clear()
{
- children_.clear_and_dispose (trie_delete_disposer ());
+ children_.clear_and_dispose(trie_delete_disposer());
}
template<class Predicate>
void
- clear_if (Predicate cond)
+ clear_if(Predicate cond)
{
- recursive_iterator trieNode (this);
- recursive_iterator end (0);
+ recursive_iterator trieNode(this);
+ recursive_iterator end(0);
- while (trieNode != end)
- {
- if (cond (*trieNode))
- {
- trieNode = recursive_iterator (trieNode->erase ());
- }
- trieNode ++;
+ while (trieNode != end) {
+ if (cond(*trieNode)) {
+ trieNode = recursive_iterator(trieNode->erase());
}
+ trieNode++;
+ }
}
// actual entry
- friend bool
- operator== <> (const trie<FullKey, PayloadTraits, PolicyHook> &a,
- const trie<FullKey, PayloadTraits, PolicyHook> &b);
+ friend bool operator==<>(const trie<FullKey, PayloadTraits, PolicyHook>& a,
+ const trie<FullKey, PayloadTraits, PolicyHook>& b);
friend std::size_t
- hash_value <> (const trie<FullKey, PayloadTraits, PolicyHook> &trie_node);
+ hash_value<>(const trie<FullKey, PayloadTraits, PolicyHook>& trie_node);
inline std::pair<iterator, bool>
- insert (const FullKey &key,
- typename PayloadTraits::insert_type payload)
+ insert(const FullKey& key, typename PayloadTraits::insert_type payload)
{
- trie *trieNode = this;
+ trie* trieNode = this;
- BOOST_FOREACH (const Key &subkey, key)
- {
- typename unordered_set::iterator item = trieNode->children_.find (subkey);
- if (item == trieNode->children_.end ())
- {
- trie *newNode = new trie (subkey, initialBucketSize_, bucketIncrement_);
- // std::cout << "new " << newNode << "\n";
- newNode->parent_ = trieNode;
+ BOOST_FOREACH (const Key& subkey, key) {
+ typename unordered_set::iterator item = trieNode->children_.find(subkey);
+ if (item == trieNode->children_.end()) {
+ trie* newNode = new trie(subkey, initialBucketSize_, bucketIncrement_);
+ // std::cout << "new " << newNode << "\n";
+ newNode->parent_ = trieNode;
- if (trieNode->children_.size () >= trieNode->bucketSize_)
- {
- trieNode->bucketSize_ += trieNode->bucketIncrement_;
- trieNode->bucketIncrement_ *= 2; // increase bucketIncrement exponentially
+ if (trieNode->children_.size() >= trieNode->bucketSize_) {
+ trieNode->bucketSize_ += trieNode->bucketIncrement_;
+ trieNode->bucketIncrement_ *= 2; // increase bucketIncrement exponentially
- buckets_array newBuckets (new bucket_type [trieNode->bucketSize_]);
- trieNode->children_.rehash (bucket_traits (newBuckets.get (), trieNode->bucketSize_));
- trieNode->buckets_.swap (newBuckets);
- }
+ buckets_array newBuckets(new bucket_type[trieNode->bucketSize_]);
+ trieNode->children_.rehash(bucket_traits(newBuckets.get(), trieNode->bucketSize_));
+ trieNode->buckets_.swap(newBuckets);
+ }
- std::pair< typename unordered_set::iterator, bool > ret =
- trieNode->children_.insert (*newNode);
+ std::pair<typename unordered_set::iterator, bool> ret =
+ trieNode->children_.insert(*newNode);
- trieNode = &(*ret.first);
- }
- else
- trieNode = &(*item);
+ trieNode = &(*ret.first);
}
+ else
+ trieNode = &(*item);
+ }
- if (trieNode->payload_ == PayloadTraits::empty_payload)
- {
- trieNode->payload_ = payload;
- return std::make_pair (trieNode, true);
- }
+ if (trieNode->payload_ == PayloadTraits::empty_payload) {
+ trieNode->payload_ = payload;
+ return std::make_pair(trieNode, true);
+ }
else
- return std::make_pair (trieNode, false);
+ return std::make_pair(trieNode, false);
}
/**
* @brief Removes payload (if it exists) and if there are no children, prunes parents trie
*/
inline iterator
- erase ()
+ erase()
{
payload_ = PayloadTraits::empty_payload;
- return prune ();
+ return prune();
}
/**
* @brief Do exactly as erase, but without erasing the payload
*/
inline iterator
- prune ()
+ prune()
{
- if (payload_ == PayloadTraits::empty_payload &&
- children_.size () == 0)
- {
- if (parent_ == 0) return this;
+ if (payload_ == PayloadTraits::empty_payload && children_.size() == 0) {
+ if (parent_ == 0)
+ return this;
- trie *parent = parent_;
- parent->children_.erase_and_dispose (*this, trie_delete_disposer ()); // delete this; basically, committing a suicide
+ trie* parent = parent_;
+ parent->children_
+ .erase_and_dispose(*this,
+ trie_delete_disposer()); // delete this; basically, committing a suicide
- return parent->prune ();
- }
+ return parent->prune();
+ }
return this;
}
@@ -277,16 +259,17 @@
* @brief Perform prune of the node, but without attempting to parent of the node
*/
inline void
- prune_node ()
+ prune_node()
{
- if (payload_ == PayloadTraits::empty_payload &&
- children_.size () == 0)
- {
- if (parent_ == 0) return;
+ if (payload_ == PayloadTraits::empty_payload && children_.size() == 0) {
+ if (parent_ == 0)
+ return;
- trie *parent = parent_;
- parent->children_.erase_and_dispose (*this, trie_delete_disposer ()); // delete this; basically, committing a suicide
- }
+ trie* parent = parent_;
+ parent->children_
+ .erase_and_dispose(*this,
+ trie_delete_disposer()); // delete this; basically, committing a suicide
+ }
}
// inline boost::tuple<const iterator, bool, const iterator>
@@ -302,30 +285,27 @@
* @return ->second is true if prefix in ->first is longer than key
*/
inline boost::tuple<iterator, bool, iterator>
- find (const FullKey &key)
+ find(const FullKey& key)
{
- trie *trieNode = this;
+ trie* trieNode = this;
iterator foundNode = (payload_ != PayloadTraits::empty_payload) ? this : 0;
bool reachLast = true;
- BOOST_FOREACH (const Key &subkey, key)
- {
- typename unordered_set::iterator item = trieNode->children_.find (subkey);
- if (item == trieNode->children_.end ())
- {
- reachLast = false;
- break;
- }
- else
- {
- trieNode = &(*item);
-
- if (trieNode->payload_ != PayloadTraits::empty_payload)
- foundNode = trieNode;
- }
+ BOOST_FOREACH (const Key& subkey, key) {
+ typename unordered_set::iterator item = trieNode->children_.find(subkey);
+ if (item == trieNode->children_.end()) {
+ reachLast = false;
+ break;
}
+ else {
+ trieNode = &(*item);
- return boost::make_tuple (foundNode, reachLast, trieNode);
+ if (trieNode->payload_ != PayloadTraits::empty_payload)
+ foundNode = trieNode;
+ }
+ }
+
+ return boost::make_tuple(foundNode, reachLast, trieNode);
}
/**
@@ -336,55 +316,50 @@
*/
template<class Predicate>
inline boost::tuple<iterator, bool, iterator>
- find_if (const FullKey &key, Predicate pred)
+ find_if(const FullKey& key, Predicate pred)
{
- trie *trieNode = this;
+ trie* trieNode = this;
iterator foundNode = (payload_ != PayloadTraits::empty_payload) ? this : 0;
bool reachLast = true;
- BOOST_FOREACH (const Key &subkey, key)
- {
- typename unordered_set::iterator item = trieNode->children_.find (subkey);
- if (item == trieNode->children_.end ())
- {
- reachLast = false;
- break;
- }
- else
- {
- trieNode = &(*item);
-
- if (trieNode->payload_ != PayloadTraits::empty_payload &&
- pred (trieNode->payload_))
- {
- foundNode = trieNode;
- }
- }
+ BOOST_FOREACH (const Key& subkey, key) {
+ typename unordered_set::iterator item = trieNode->children_.find(subkey);
+ if (item == trieNode->children_.end()) {
+ reachLast = false;
+ break;
}
+ else {
+ trieNode = &(*item);
- return boost::make_tuple (foundNode, reachLast, trieNode);
+ if (trieNode->payload_ != PayloadTraits::empty_payload && pred(trieNode->payload_)) {
+ foundNode = trieNode;
+ }
+ }
+ }
+
+ return boost::make_tuple(foundNode, reachLast, trieNode);
}
/**
* @brief Find next payload of the sub-trie
- * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration )
+ * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration
+ * )
*/
inline iterator
- find ()
+ find()
{
if (payload_ != PayloadTraits::empty_payload)
return this;
typedef trie<FullKey, PayloadTraits, PolicyHook> trie;
- for (typename trie::unordered_set::iterator subnode = children_.begin ();
- subnode != children_.end ();
- subnode++ )
- // BOOST_FOREACH (trie &subnode, children_)
- {
- iterator value = subnode->find ();
- if (value != 0)
- return value;
- }
+ for (typename trie::unordered_set::iterator subnode = children_.begin();
+ subnode != children_.end(); subnode++)
+ // BOOST_FOREACH (trie &subnode, children_)
+ {
+ iterator value = subnode->find();
+ if (value != 0)
+ return value;
+ }
return 0;
}
@@ -392,25 +367,25 @@
/**
* @brief Find next payload of the sub-trie satisfying the predicate
* @param pred predicate
- * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration )
+ * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration
+ * )
*/
template<class Predicate>
inline const iterator
- find_if (Predicate pred)
+ find_if(Predicate pred)
{
- if (payload_ != PayloadTraits::empty_payload && pred (payload_))
+ if (payload_ != PayloadTraits::empty_payload && pred(payload_))
return this;
typedef trie<FullKey, PayloadTraits, PolicyHook> trie;
- for (typename trie::unordered_set::iterator subnode = children_.begin ();
- subnode != children_.end ();
- subnode++ )
- // BOOST_FOREACH (const trie &subnode, children_)
- {
- iterator value = subnode->find_if (pred);
- if (value != 0)
- return value;
- }
+ for (typename trie::unordered_set::iterator subnode = children_.begin();
+ subnode != children_.end(); subnode++)
+ // BOOST_FOREACH (const trie &subnode, children_)
+ {
+ iterator value = subnode->find_if(pred);
+ if (value != 0)
+ return value;
+ }
return 0;
}
@@ -421,84 +396,83 @@
*
* This version check predicate only for the next level children
*
- * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration )
+ * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration
+ *)
*/
template<class Predicate>
inline const iterator
- find_if_next_level (Predicate pred)
+ find_if_next_level(Predicate pred)
{
typedef trie<FullKey, PayloadTraits, PolicyHook> trie;
- for (typename trie::unordered_set::iterator subnode = children_.begin ();
- subnode != children_.end ();
- subnode++ )
- {
- if (pred (subnode->key ()))
- {
- return subnode->find ();
- }
+ for (typename trie::unordered_set::iterator subnode = children_.begin();
+ subnode != children_.end(); subnode++) {
+ if (pred(subnode->key())) {
+ return subnode->find();
}
+ }
return 0;
}
- iterator end ()
+ iterator
+ end()
{
return 0;
}
- const_iterator end () const
+ const_iterator
+ end() const
{
return 0;
}
typename PayloadTraits::const_return_type
- payload () const
+ payload() const
{
return payload_;
}
typename PayloadTraits::return_type
- payload ()
+ payload()
{
return payload_;
}
void
- set_payload (typename PayloadTraits::insert_type payload)
+ set_payload(typename PayloadTraits::insert_type payload)
{
payload_ = payload;
}
- Key key () const
+ Key
+ key() const
{
return key_;
}
inline void
- PrintStat (std::ostream &os) const;
+ PrintStat(std::ostream& os) const;
private:
- //The disposer object function
- struct trie_delete_disposer
- {
- void operator() (trie *delete_this)
+ // The disposer object function
+ struct trie_delete_disposer {
+ void
+ operator()(trie* delete_this)
{
delete delete_this;
}
};
template<class D>
- struct array_disposer
- {
- void operator() (D *array)
+ struct array_disposer {
+ void
+ operator()(D* array)
{
- delete [] array;
+ delete[] array;
}
};
- friend
- std::ostream&
- operator<< < > (std::ostream &os, const trie &trie_node);
+ friend std::ostream& operator<<<>(std::ostream& os, const trie& trie_node);
public:
PolicyHook policy_hook_;
@@ -508,12 +482,11 @@
// necessary typedefs
typedef trie self_type;
- typedef boost::intrusive::member_hook< trie,
- boost::intrusive::unordered_set_member_hook< >,
- &trie::unordered_set_member_hook_ > member_hook;
+ typedef boost::intrusive::member_hook<trie, boost::intrusive::unordered_set_member_hook<>,
+ &trie::unordered_set_member_hook_> member_hook;
- typedef boost::intrusive::unordered_set< trie, member_hook > unordered_set;
- typedef typename unordered_set::bucket_type bucket_type;
+ typedef boost::intrusive::unordered_set<trie, member_hook> unordered_set;
+ typedef typename unordered_set::bucket_type bucket_type;
typedef typename unordered_set::bucket_traits bucket_traits;
template<class T, class NonConstT>
@@ -532,204 +505,267 @@
size_t bucketIncrement_;
size_t bucketSize_;
- typedef boost::interprocess::unique_ptr< bucket_type, array_disposer<bucket_type> > buckets_array;
+ typedef boost::interprocess::unique_ptr<bucket_type, array_disposer<bucket_type>> buckets_array;
buckets_array buckets_;
unordered_set children_;
typename PayloadTraits::storage_type payload_;
- trie *parent_; // to make cleaning effective
+ trie* parent_; // to make cleaning effective
};
-
-
-
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
inline std::ostream&
-operator << (std::ostream &os, const trie<FullKey, PayloadTraits, PolicyHook> &trie_node)
+operator<<(std::ostream& os, const trie<FullKey, PayloadTraits, PolicyHook>& trie_node)
{
- os << "# " << trie_node.key_ << ((trie_node.payload_ != PayloadTraits::empty_payload)?"*":"") << std::endl;
+ os << "# " << trie_node.key_ << ((trie_node.payload_ != PayloadTraits::empty_payload) ? "*" : "")
+ << std::endl;
typedef trie<FullKey, PayloadTraits, PolicyHook> trie;
- for (typename trie::unordered_set::const_iterator subnode = trie_node.children_.begin ();
- subnode != trie_node.children_.end ();
- subnode++ )
+ for (typename trie::unordered_set::const_iterator subnode = trie_node.children_.begin();
+ subnode != trie_node.children_.end(); subnode++)
// BOOST_FOREACH (const trie &subnode, trie_node.children_)
- {
- os << "\"" << &trie_node << "\"" << " [label=\"" << trie_node.key_ << ((trie_node.payload_ != PayloadTraits::empty_payload)?"*":"") << "\"]\n";
- os << "\"" << &(*subnode) << "\"" << " [label=\"" << subnode->key_ << ((subnode->payload_ != PayloadTraits::empty_payload)?"*":"") << "\"]""\n";
+ {
+ os << "\"" << &trie_node << "\""
+ << " [label=\"" << trie_node.key_
+ << ((trie_node.payload_ != PayloadTraits::empty_payload) ? "*" : "") << "\"]\n";
+ os << "\"" << &(*subnode) << "\""
+ << " [label=\"" << subnode->key_
+ << ((subnode->payload_ != PayloadTraits::empty_payload) ? "*" : "") << "\"]"
+ "\n";
- os << "\"" << &trie_node << "\"" << " -> " << "\"" << &(*subnode) << "\"" << "\n";
- os << *subnode;
- }
+ os << "\"" << &trie_node << "\""
+ << " -> "
+ << "\"" << &(*subnode) << "\""
+ << "\n";
+ os << *subnode;
+ }
return os;
}
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
inline void
-trie<FullKey, PayloadTraits, PolicyHook>
-::PrintStat (std::ostream &os) const
+trie<FullKey, PayloadTraits, PolicyHook>::PrintStat(std::ostream& os) const
{
- os << "# " << key_ << ((payload_ != PayloadTraits::empty_payload)?"*":"") << ": " << children_.size() << " children" << std::endl;
- for (size_t bucket = 0, maxbucket = children_.bucket_count ();
- bucket < maxbucket;
- bucket++)
- {
- os << " " << children_.bucket_size (bucket);
- }
+ os << "# " << key_ << ((payload_ != PayloadTraits::empty_payload) ? "*" : "") << ": "
+ << children_.size() << " children" << std::endl;
+ for (size_t bucket = 0, maxbucket = children_.bucket_count(); bucket < maxbucket; bucket++) {
+ os << " " << children_.bucket_size(bucket);
+ }
os << "\n";
typedef trie<FullKey, PayloadTraits, PolicyHook> trie;
- for (typename trie::unordered_set::const_iterator subnode = children_.begin ();
- subnode != children_.end ();
- subnode++ )
+ for (typename trie::unordered_set::const_iterator subnode = children_.begin();
+ subnode != children_.end(); subnode++)
// BOOST_FOREACH (const trie &subnode, children_)
- {
- subnode->PrintStat (os);
- }
+ {
+ subnode->PrintStat(os);
+ }
}
-
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
inline bool
-operator == (const trie<FullKey, PayloadTraits, PolicyHook> &a,
- const trie<FullKey, PayloadTraits, PolicyHook> &b)
+operator==(const trie<FullKey, PayloadTraits, PolicyHook>& a,
+ const trie<FullKey, PayloadTraits, PolicyHook>& b)
{
return a.key_ == b.key_;
}
template<typename FullKey, typename PayloadTraits, typename PolicyHook>
inline std::size_t
-hash_value (const trie<FullKey, PayloadTraits, PolicyHook> &trie_node)
+hash_value(const trie<FullKey, PayloadTraits, PolicyHook>& trie_node)
{
- return boost::hash_value (trie_node.key_);
+ return boost::hash_value(trie_node.key_);
}
-
-
template<class Trie, class NonConstTrie> // hack for boost < 1.47
-class trie_iterator
-{
+class trie_iterator {
public:
- trie_iterator () : trie_ (0) {}
- trie_iterator (typename Trie::iterator item) : trie_ (item) {}
- trie_iterator (Trie &item) : trie_ (&item) {}
-
- Trie & operator* () { return *trie_; }
- const Trie & operator* () const { return *trie_; }
- Trie * operator-> () { return trie_; }
- const Trie * operator-> () const { return trie_; }
- bool operator== (trie_iterator<const Trie, NonConstTrie> &other) const { return (trie_ == other.trie_); }
- bool operator== (trie_iterator<Trie, NonConstTrie> &other) { return (trie_ == other.trie_); }
- bool operator!= (trie_iterator<const Trie, NonConstTrie> &other) const { return !(*this == other); }
- bool operator!= (trie_iterator<Trie, NonConstTrie> &other) { return !(*this == other); }
-
- trie_iterator<Trie,NonConstTrie> &
- operator++ (int)
+ trie_iterator()
+ : trie_(0)
{
- if (trie_->children_.size () > 0)
- trie_ = &(*trie_->children_.begin ());
+ }
+ trie_iterator(typename Trie::iterator item)
+ : trie_(item)
+ {
+ }
+ trie_iterator(Trie& item)
+ : trie_(&item)
+ {
+ }
+
+ Trie& operator*()
+ {
+ return *trie_;
+ }
+ const Trie& operator*() const
+ {
+ return *trie_;
+ }
+ Trie* operator->()
+ {
+ return trie_;
+ }
+ const Trie* operator->() const
+ {
+ return trie_;
+ }
+ bool
+ operator==(trie_iterator<const Trie, NonConstTrie>& other) const
+ {
+ return (trie_ == other.trie_);
+ }
+ bool
+ operator==(trie_iterator<Trie, NonConstTrie>& other)
+ {
+ return (trie_ == other.trie_);
+ }
+ bool
+ operator!=(trie_iterator<const Trie, NonConstTrie>& other) const
+ {
+ return !(*this == other);
+ }
+ bool
+ operator!=(trie_iterator<Trie, NonConstTrie>& other)
+ {
+ return !(*this == other);
+ }
+
+ trie_iterator<Trie, NonConstTrie>&
+ operator++(int)
+ {
+ if (trie_->children_.size() > 0)
+ trie_ = &(*trie_->children_.begin());
else
- trie_ = goUp ();
+ trie_ = goUp();
return *this;
}
- trie_iterator<Trie,NonConstTrie> &
- operator++ ()
+ trie_iterator<Trie, NonConstTrie>&
+ operator++()
{
(*this)++;
return *this;
}
private:
- typedef typename boost::mpl::if_< boost::is_same<Trie, NonConstTrie>,
- typename Trie::unordered_set::iterator,
- typename Trie::unordered_set::const_iterator>::type set_iterator;
+ typedef typename boost::mpl::if_<boost::is_same<Trie, NonConstTrie>,
+ typename Trie::unordered_set::iterator,
+ typename Trie::unordered_set::const_iterator>::type set_iterator;
- Trie* goUp ()
+ Trie*
+ goUp()
{
- if (trie_->parent_ != 0)
- {
- // typename Trie::unordered_set::iterator item =
- set_iterator item = const_cast<NonConstTrie*>(trie_)->parent_->children_.iterator_to (const_cast<NonConstTrie&> (*trie_));
- item++;
- if (item != trie_->parent_->children_.end ())
- {
- return &(*item);
- }
- else
- {
- trie_ = trie_->parent_;
- return goUp ();
- }
+ if (trie_->parent_ != 0) {
+ // typename Trie::unordered_set::iterator item =
+ set_iterator item = const_cast<NonConstTrie*>(trie_)
+ ->parent_->children_.iterator_to(const_cast<NonConstTrie&>(*trie_));
+ item++;
+ if (item != trie_->parent_->children_.end()) {
+ return &(*item);
}
+ else {
+ trie_ = trie_->parent_;
+ return goUp();
+ }
+ }
else
return 0;
}
+
private:
- Trie *trie_;
+ Trie* trie_;
};
-
template<class Trie>
-class trie_point_iterator
-{
+class trie_point_iterator {
private:
- typedef typename boost::mpl::if_< boost::is_same<Trie, const Trie>,
- typename Trie::unordered_set::const_iterator,
- typename Trie::unordered_set::iterator>::type set_iterator;
+ typedef typename boost::mpl::if_<boost::is_same<Trie, const Trie>,
+ typename Trie::unordered_set::const_iterator,
+ typename Trie::unordered_set::iterator>::type set_iterator;
public:
- trie_point_iterator () : trie_ (0) {}
- trie_point_iterator (typename Trie::iterator item) : trie_ (item) {}
- trie_point_iterator (Trie &item)
+ trie_point_iterator()
+ : trie_(0)
{
- if (item.children_.size () != 0)
- trie_ = &*item.children_.begin ();
+ }
+ trie_point_iterator(typename Trie::iterator item)
+ : trie_(item)
+ {
+ }
+ trie_point_iterator(Trie& item)
+ {
+ if (item.children_.size() != 0)
+ trie_ = &*item.children_.begin();
else
trie_ = 0;
}
- Trie & operator* () { return *trie_; }
- const Trie & operator* () const { return *trie_; }
- Trie * operator-> () { return trie_; }
- const Trie * operator-> () const { return trie_; }
- bool operator== (trie_point_iterator<const Trie> &other) const { return (trie_ == other.trie_); }
- bool operator== (trie_point_iterator<Trie> &other) { return (trie_ == other.trie_); }
- bool operator!= (trie_point_iterator<const Trie> &other) const { return !(*this == other); }
- bool operator!= (trie_point_iterator<Trie> &other) { return !(*this == other); }
-
- trie_point_iterator<Trie> &
- operator++ (int)
+ Trie& operator*()
{
- if (trie_->parent_ != 0)
- {
- set_iterator item = trie_->parent_->children_.iterator_to (*trie_);
- item ++;
- if (item == trie_->parent_->children_.end ())
- trie_ = 0;
- else
- trie_ = &*item;
- }
- else
- {
+ return *trie_;
+ }
+ const Trie& operator*() const
+ {
+ return *trie_;
+ }
+ Trie* operator->()
+ {
+ return trie_;
+ }
+ const Trie* operator->() const
+ {
+ return trie_;
+ }
+ bool
+ operator==(trie_point_iterator<const Trie>& other) const
+ {
+ return (trie_ == other.trie_);
+ }
+ bool
+ operator==(trie_point_iterator<Trie>& other)
+ {
+ return (trie_ == other.trie_);
+ }
+ bool
+ operator!=(trie_point_iterator<const Trie>& other) const
+ {
+ return !(*this == other);
+ }
+ bool
+ operator!=(trie_point_iterator<Trie>& other)
+ {
+ return !(*this == other);
+ }
+
+ trie_point_iterator<Trie>&
+ operator++(int)
+ {
+ if (trie_->parent_ != 0) {
+ set_iterator item = trie_->parent_->children_.iterator_to(*trie_);
+ item++;
+ if (item == trie_->parent_->children_.end())
trie_ = 0;
- }
+ else
+ trie_ = &*item;
+ }
+ else {
+ trie_ = 0;
+ }
return *this;
}
- trie_point_iterator<Trie> &
- operator++ ()
+ trie_point_iterator<Trie>&
+ operator++()
{
(*this)++;
return *this;
}
private:
- Trie *trie_;
+ Trie* trie_;
};
-
} // ndnSIM
} // ndn
} // ns3