Small reorganization of utils/ folder contents
diff --git a/utils/stats/load-stats-face.cc b/utils/stats/load-stats-face.cc
new file mode 100644
index 0000000..df48f2b
--- /dev/null
+++ b/utils/stats/load-stats-face.cc
@@ -0,0 +1,152 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "load-stats-face.h"
+
+#include "ns3/log.h"
+
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/range_c.hpp>
+
+using namespace boost::mpl;
+using namespace boost::tuples;
+
+NS_LOG_COMPONENT_DEFINE ("ndn.LoadStatsFace");
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+std::ostream &
+operator << (std::ostream &os, const LoadStats::stats_tuple &tuple);
+
+void
+LoadStatsFace::Step ()
+{
+ m_count.Step ();
+ m_satisfied.Step ();
+ m_unsatisfied.Step ();
+ m_tx.Step ();
+ m_rx.Step ();
+}
+
+struct update_retval
+{
+ update_retval (const LoadStats &count, const LoadStats &other, LoadStats::stats_tuple &tuple)
+ : count_ (count)
+ , other_ (other)
+ , tuple_ (tuple) {}
+ const LoadStats &count_;
+ const LoadStats &other_;
+ LoadStats::stats_tuple &tuple_;
+
+ template< typename U >
+ void operator () (U)
+ {
+ if (count_.GetStats ().get<U::value> () < LoadStats::PRECISION)
+ tuple_.get<U::value> () = -1;
+ else
+ tuple_.get<U::value> () = other_.GetStats ().get<U::value> () / count_.GetStats ().get<U::value> ();
+ }
+};
+
+LoadStats::stats_tuple
+LoadStatsFace::GetSatisfiedRatio () const
+{
+ LoadStats::stats_tuple retval;
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (update_retval (m_count, m_satisfied, retval));
+
+ // NS_LOG_DEBUG (retval.get<0> () << ", " << retval.get<1> () << ", " << retval.get<2> ());
+ return retval;
+}
+
+LoadStats::stats_tuple
+LoadStatsFace::GetUnsatisfiedRatio () const
+{
+ LoadStats::stats_tuple retval;
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (update_retval (m_count, m_unsatisfied, retval));
+
+ // NS_LOG_DEBUG (retval.get<0> () << ", " << retval.get<1> () << ", " << retval.get<2> ());
+ return retval;
+}
+
+LoadStatsFace &
+LoadStatsFace::operator += (const LoadStatsFace &load)
+{
+ m_count += load.m_count;
+ m_satisfied += load.m_satisfied;
+ m_unsatisfied += load.m_unsatisfied;
+ m_tx += load.m_tx;
+ m_rx += load.m_rx;
+
+ return *this;
+}
+
+bool
+LoadStatsFace::IsZero () const
+{
+ return m_count.IsZero () && m_satisfied.IsZero () && m_unsatisfied.IsZero () && m_tx.IsZero () && m_rx.IsZero ();
+}
+
+struct print_tuple
+{
+ print_tuple (const LoadStats::stats_tuple &tuple, std::ostream &os)
+ : tuple_ (tuple)
+ , os_ (os)
+ {
+ }
+
+ const LoadStats::stats_tuple &tuple_;
+ std::ostream &os_;
+
+ template< typename U >
+ void operator () (U)
+ {
+ os_ << tuple_.get< U::value > () << " ";
+ }
+};
+
+
+std::ostream &
+operator << (std::ostream &os, const LoadStats::stats_tuple &tuple)
+{
+ for_each< range_c<int, 0, length<LoadStats::stats_tuple>::value> >
+ (print_tuple (tuple, os));
+
+ return os;
+}
+
+std::ostream &
+operator << (std::ostream &os, const LoadStatsFace &stats)
+{
+ LoadStats::stats_tuple
+ satisfied = stats.GetSatisfiedRatio (),
+ unsatisfied = stats.GetUnsatisfiedRatio ();
+
+ os << "ration satisfied: " << satisfied << "/ unsatisfied: " << unsatisfied;
+ return os;
+}
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
+
diff --git a/utils/stats/load-stats-face.h b/utils/stats/load-stats-face.h
new file mode 100644
index 0000000..70a4c36
--- /dev/null
+++ b/utils/stats/load-stats-face.h
@@ -0,0 +1,138 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef LOAD_STATS_FACE_H
+#define LOAD_STATS_FACE_H
+
+#include "load-stats.h"
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+class LoadStatsFace
+{
+public:
+ void
+ Step ();
+
+ inline LoadStats&
+ count ();
+
+ inline const LoadStats&
+ count () const;
+
+ inline LoadStats&
+ satisfied ();
+
+ inline const LoadStats&
+ satisfied () const;
+
+ inline LoadStats&
+ unsatisfied ();
+
+ inline const LoadStats&
+ unsatisfied () const;
+
+ inline LoadStats&
+ tx ();
+
+ inline const LoadStats&
+ tx () const;
+
+ inline LoadStats&
+ rx ();
+
+ inline const LoadStats&
+ rx () const;
+
+ //
+ LoadStats::stats_tuple
+ GetSatisfiedRatio () const;
+
+ LoadStats::stats_tuple
+ GetUnsatisfiedRatio () const;
+
+ LoadStatsFace &
+ operator += (const LoadStatsFace &load);
+
+ bool
+ IsZero () const;
+
+private:
+ LoadStats m_count;
+ LoadStats m_satisfied;
+ LoadStats m_unsatisfied;
+ LoadStats m_rx;
+ LoadStats m_tx;
+
+ friend std::ostream &
+ operator << (std::ostream &os, const LoadStatsFace &stats);
+};
+
+inline LoadStats&
+LoadStatsFace::count ()
+{ return m_count; }
+
+inline const LoadStats&
+LoadStatsFace::count () const
+{ return m_count; }
+
+inline LoadStats&
+LoadStatsFace::satisfied ()
+{ return m_satisfied; }
+
+inline const LoadStats&
+LoadStatsFace::satisfied () const
+{ return m_satisfied; }
+
+inline LoadStats&
+LoadStatsFace::unsatisfied ()
+{ return m_unsatisfied; }
+
+inline const LoadStats&
+LoadStatsFace::unsatisfied () const
+{ return m_unsatisfied; }
+
+inline LoadStats&
+LoadStatsFace::tx ()
+{ return m_tx; }
+
+inline const LoadStats&
+LoadStatsFace::tx () const
+{ return m_tx; }
+
+inline LoadStats&
+LoadStatsFace::rx ()
+{ return m_rx; }
+
+inline const LoadStats&
+LoadStatsFace::rx () const
+{ return m_rx; }
+
+
+std::ostream &
+operator << (std::ostream &os, const LoadStatsFace &stats);
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
+
+#endif // LOAD_STATS_FACE_H
diff --git a/utils/stats/load-stats-node.cc b/utils/stats/load-stats-node.cc
new file mode 100644
index 0000000..39e9d60
--- /dev/null
+++ b/utils/stats/load-stats-node.cc
@@ -0,0 +1,217 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "load-stats-node.h"
+#include "ns3/ndn-face.h"
+#include "ns3/log.h"
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+
+namespace ll = boost::lambda;
+
+NS_LOG_COMPONENT_DEFINE ("ndn.LoadStatsNode");
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+void
+LoadStatsNode::Step ()
+{
+ NS_LOG_FUNCTION (this);
+
+ m_pit.Step ();
+
+ for (stats_container::iterator item = m_incoming.begin ();
+ item != m_incoming.end ();
+ item ++)
+ {
+ item->second.Step ();
+ }
+
+ for (stats_container::iterator item = m_outgoing.begin ();
+ item != m_outgoing.end ();
+ item ++)
+ {
+ item->second.Step ();
+ }
+}
+
+void
+LoadStatsNode::NewPitEntry ()
+{
+ m_pit.count ()++;
+}
+
+void
+LoadStatsNode::AddIncoming (ns3::Ptr<Face> face)
+{
+ m_incoming [face].count ()++;
+}
+
+void
+LoadStatsNode::AddOutgoing (ns3::Ptr<Face> face)
+{
+ m_outgoing [face].count ()++;
+}
+
+void
+LoadStatsNode::Satisfy ()
+{
+ m_pit.satisfied ()++;
+
+ for (stats_container::iterator item = m_incoming.begin ();
+ item != m_incoming.end ();
+ item ++)
+ {
+ item->second.satisfied ()++;
+ }
+
+ for (stats_container::iterator item = m_outgoing.begin ();
+ item != m_outgoing.end ();
+ item ++)
+ {
+ item->second.satisfied ()++;
+ }
+}
+
+void
+LoadStatsNode::Timeout ()
+{
+ m_pit.unsatisfied ()++;
+
+ for (stats_container::iterator item = m_incoming.begin ();
+ item != m_incoming.end ();
+ item ++)
+ {
+ item->second.unsatisfied ()++;
+ }
+
+ for (stats_container::iterator item = m_outgoing.begin ();
+ item != m_outgoing.end ();
+ item ++)
+ {
+ item->second.unsatisfied ()++;
+ }
+}
+
+void
+LoadStatsNode::Rx (ns3::Ptr<Face> face, uint32_t amount)
+{
+ m_pit.rx () += amount;
+ m_incoming [face].rx () += amount;
+}
+
+void
+LoadStatsNode::Tx (ns3::Ptr<Face> face, uint32_t amount)
+{
+ m_pit.tx () += amount;
+ m_outgoing [face].tx () += amount;
+}
+
+
+LoadStatsNode &
+LoadStatsNode::operator += (const LoadStatsNode &stats)
+{
+ NS_LOG_FUNCTION (this << &stats);
+
+ m_pit += stats.m_pit;
+
+ // aggregate incoming
+ for (stats_container::const_iterator item = stats.m_incoming.begin ();
+ item != stats.m_incoming.end ();
+ item ++)
+ {
+ m_incoming [item->first] += item->second;
+ }
+
+ // aggregate outgoing
+ for (stats_container::const_iterator item = stats.m_outgoing.begin ();
+ item != stats.m_outgoing.end ();
+ item ++)
+ {
+ m_outgoing [item->first] += item->second;
+ }
+
+ return *this;
+}
+
+bool
+LoadStatsNode::IsZero () const
+{
+ bool zero = true;
+ for (stats_container::const_iterator item = m_incoming.begin ();
+ item != m_incoming.end ();
+ item ++)
+ {
+ zero &= item->second.IsZero ();
+ }
+
+ for (stats_container::const_iterator item = m_outgoing.begin ();
+ item != m_outgoing.end ();
+ item ++)
+ {
+ zero &= item->second.IsZero ();
+ }
+
+// std::for_each (m_incoming.begin (), m_incoming.end (),
+// zero &= ll::bind (&LoadStatsFace::IsZero,
+// ll::bind (&stats_container::value_type::second, ll::_1)));
+//
+// std::for_each (m_outgoing.begin (), m_outgoing.end (),
+// zero &= ll::bind (&LoadStatsFace::IsZero,
+// ll::bind (&stats_container::value_type::second, ll::_1)));
+
+ zero &= m_pit.IsZero ();
+
+ return zero;
+}
+
+
+void
+LoadStatsNode::RemoveFace (ns3::Ptr<Face> face)
+{
+ NS_LOG_FUNCTION (this);
+ m_incoming.erase (face);
+ m_outgoing.erase (face);
+}
+
+bool
+LoadStatsNode::operator == (const LoadStatsNode &other) const
+{
+ if (other.m_incoming.size () > 0 ||
+ other.m_outgoing.size () > 0 ||
+ !other.m_pit.IsZero ())
+ return false;
+
+ return IsZero ();
+}
+
+std::ostream&
+operator << (std::ostream &os, const LoadStatsNode &node)
+{
+ os << "PIT: " << node.m_pit;// << std::endl;
+ return os;
+}
+
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/stats/load-stats-node.h b/utils/stats/load-stats-node.h
new file mode 100644
index 0000000..365db55
--- /dev/null
+++ b/utils/stats/load-stats-node.h
@@ -0,0 +1,159 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef LOAD_STATS_NODE_H
+#define LOAD_STATS_NODE_H
+
+#include "load-stats-face.h"
+#include <map>
+#include "ns3/ptr.h"
+
+namespace ns3 {
+namespace ndn {
+
+class Face;
+
+namespace ndnSIM
+{
+
+// this thing is actually put into a tree node, associated with each "name entry"
+
+class LoadStatsNode
+{
+public:
+ typedef std::map< ns3::Ptr<Face>, LoadStatsFace > stats_container;
+
+ LoadStatsNode () {}
+ LoadStatsNode (const LoadStatsNode &) {}
+
+ void
+ Step ();
+
+ /**
+ * Increment face-independent counter
+ */
+ void
+ NewPitEntry ();
+
+ /**
+ * Increment counter to incoming list
+ */
+ void
+ AddIncoming (ns3::Ptr<Face> face);
+
+ /**
+ * Increment counter to outgoing list
+ */
+ void
+ AddOutgoing (ns3::Ptr<Face> face);
+
+ /**
+ * Increment counter to both incoming and outgoing lists, for all faces
+ */
+ void
+ Satisfy ();
+
+ /**
+ * Increment counter to both incoming and outgoing lists, for all faces
+ */
+ void
+ Timeout ();
+
+ /**
+ * Increment counter for Tx amount
+ */
+ void
+ Rx (ns3::Ptr<Face> face, uint32_t amount);
+
+ /**
+ * Increment counter for Tx amount
+ */
+ void
+ Tx (ns3::Ptr<Face> face, uint32_t amount);
+
+ LoadStatsNode &
+ operator += (const LoadStatsNode &stats);
+
+ inline const stats_container &
+ incoming () const;
+
+ inline const stats_container &
+ outgoing () const;
+
+ inline const LoadStatsFace &
+ pit () const;
+
+ bool
+ IsZero () const;
+
+ bool
+ operator == (const LoadStatsNode &other) const;
+
+ bool
+ operator != (const LoadStatsNode &other) const
+ {
+ return !(*this == other);
+ }
+
+ LoadStatsNode &
+ operator = (const LoadStatsNode &other)
+ {
+ // don't do any copying at all
+ return *this;
+ }
+
+ void
+ RemoveFace (ns3::Ptr<Face> face);
+
+private:
+ LoadStatsFace m_pit;
+ stats_container m_incoming;
+ stats_container m_outgoing;
+
+ friend std::ostream&
+ operator << (std::ostream &os, const LoadStatsNode &node);
+};
+
+inline const LoadStatsNode::stats_container &
+LoadStatsNode::incoming () const
+{
+ return m_incoming;
+}
+
+inline const LoadStatsNode::stats_container &
+LoadStatsNode::outgoing () const
+{
+ return m_outgoing;
+}
+
+inline const LoadStatsFace &
+LoadStatsNode::pit () const
+{
+ return m_pit;
+}
+
+std::ostream&
+operator << (std::ostream &os, const LoadStatsNode &node);
+
+} // ndnSIM
+} // ndn
+} // ns3
+
+#endif
diff --git a/utils/stats/load-stats.cc b/utils/stats/load-stats.cc
new file mode 100644
index 0000000..d785845
--- /dev/null
+++ b/utils/stats/load-stats.cc
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "load-stats.h"
+#include "ns3/log.h"
+
+// const double EXP_1 = (1-2.0/6.0);//exp (-1.0/5.0); /* 1/exp(1sec/5sec) */
+// const double EXP_2 = (1-2.0/31.0);//exp (-1.0/30.0); /* 1/exp(1sec/30sec) */
+// const double EXP_3 = (1-2.0/61.0);//exp (-1.0/60.0); /* 1/exp(1sec/60sec) */
+
+const double EXP_1 = exp (-1.0/5.0); /* 1/exp(1sec/5sec) */
+const double EXP_2 = exp (-1.0/30.0); /* 1/exp(1sec/30sec) */
+const double EXP_3 = exp (-1.0/60.0); /* 1/exp(1sec/60sec) */
+
+NS_LOG_COMPONENT_DEFINE ("ndn.LoadStats");
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+const double LoadStats::PRECISION = 0.1;
+
+LoadStats::LoadStats ()
+ : counter_ (0)
+ , avg1_ (0)
+ , avg2_ (0)
+ , avg3_ (0)
+{
+}
+
+void
+LoadStats::Step ()
+{
+ // NS_LOG_FUNCTION (this);
+
+ // do magic
+ avg1_ = EXP_1 * avg1_ + (1 - EXP_1) * counter_;
+ // avg2_ = EXP_2 * avg2_ + (1 - EXP_2) * counter_;
+ // avg3_ = EXP_3 * avg3_ + (1 - EXP_3) * counter_;
+
+ counter_ = 0;
+}
+
+LoadStats &
+LoadStats::operator ++ (int)
+{
+ counter_ ++;
+ return *this;
+}
+
+LoadStats &
+LoadStats::operator += (uint32_t amount)
+{
+ counter_ += amount;
+ return *this;
+}
+
+LoadStats &
+LoadStats::operator += (const LoadStats &stats)
+{
+ // NS_LOG_FUNCTION (this << &stats << stats.counter_);
+
+ counter_ += stats.counter_;
+ return *this;
+}
+
+LoadStats::stats_tuple
+LoadStats::GetStats () const
+{
+ return stats_tuple (avg1_, avg2_, avg3_);
+}
+
+bool
+LoadStats::IsZero () const
+{
+ return (counter_ == 0 &&
+ avg1_ < PRECISION &&
+ avg2_ < PRECISION &&
+ avg3_ < PRECISION);
+}
+
+std::ostream &
+operator << (std::ostream &os, const LoadStats &stats)
+{
+ os << stats.avg1_ << ", " << stats.avg2_ << ", " << stats.avg3_;
+ return os;
+}
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/stats/load-stats.h b/utils/stats/load-stats.h
new file mode 100644
index 0000000..3e71753
--- /dev/null
+++ b/utils/stats/load-stats.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef LOAD_STATS_H
+#define LOAD_STATS_H
+
+#include "ns3/nstime.h"
+#include <boost/tuple/tuple.hpp>
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+class LoadStats
+{
+public:
+ typedef boost::tuple<double, double, double> stats_tuple;
+
+ static const double PRECISION;
+
+ LoadStats ();
+
+ void
+ Step ();
+
+ // void
+ // Increment (uint32_t amount);
+
+ LoadStats &
+ operator ++ (int);
+
+ // uint32_t
+ // GetCounter () const;
+
+ LoadStats &
+ operator += (const LoadStats &stats);
+
+ LoadStats &
+ operator += (uint32_t amount);
+
+ stats_tuple
+ GetStats () const;
+
+ bool
+ IsZero () const;
+
+private:
+ uint32_t counter_;
+
+ double avg1_;
+ double avg2_;
+ double avg3_;
+
+ friend std::ostream &
+ operator << (std::ostream &os, const LoadStats &stats);
+};
+
+std::ostream &
+operator << (std::ostream &os, const LoadStats &stats);
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
+
+#endif // LOAD_STATS_H
diff --git a/utils/stats/stats-tree.cc b/utils/stats/stats-tree.cc
new file mode 100644
index 0000000..f84d902
--- /dev/null
+++ b/utils/stats/stats-tree.cc
@@ -0,0 +1,161 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "stats-tree.h"
+#include "ns3/ndn-face.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.StatsTree");
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+StatsTree::StatsTree ()
+ : m_tree ("")
+{
+}
+
+void
+StatsTree::Step ()
+{
+ NS_LOG_FUNCTION (this);
+
+ // walking the tree, aggregating and stepping on every node, starting the leaves
+ // for (trie_type::
+
+ WalkLeftRightRoot (&m_tree);
+ m_tree.payload ().Step ();
+ NS_LOG_DEBUG ("[" << m_tree.key () << "] " << m_tree.payload ());
+}
+
+void
+StatsTree::NewPitEntry (const NameComponents &key)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().NewPitEntry ();
+}
+
+void
+StatsTree::Incoming (const NameComponents &key, Ptr<Face> face)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().AddIncoming (face);
+}
+
+void
+StatsTree::Outgoing (const NameComponents &key, Ptr<Face> face)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().AddOutgoing (face);
+}
+
+void
+StatsTree::Satisfy (const NameComponents &key)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().Satisfy ();
+}
+
+void
+StatsTree::Timeout (const NameComponents &key)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().Timeout ();
+}
+
+void
+StatsTree::Rx (const NameComponents &key, Ptr<Face> face, uint32_t amount)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().Rx (face, amount);
+}
+
+void
+StatsTree::Tx (const NameComponents &key, Ptr<Face> face, uint32_t amount)
+{
+ std::pair<tree_type::iterator, bool> item = m_tree.insert (key, LoadStatsNode ());
+
+ item.first->payload ().Tx (face, amount);
+}
+
+// const LoadStatsNode &
+// StatsTree::Get (const NameComponents &key) const
+const LoadStatsNode &
+StatsTree::operator [] (const NameComponents &key) const
+{
+ tree_type::iterator foundItem, lastItem;
+ bool reachLast;
+ boost::tie (foundItem, reachLast, lastItem) = const_cast<tree_type&> (m_tree).find (key);
+
+ return lastItem->payload ();
+}
+
+const LoadStatsNode&
+StatsTree::WalkLeftRightRoot (tree_type *node)
+{
+ tree_type::point_iterator item (*node), end;
+
+ while (item != end)
+ {
+ node->payload () += WalkLeftRightRoot (&*item);
+ item->payload ().Step ();
+
+ NS_LOG_DEBUG ("[" << item->key () << "] " << item->payload ());
+ // item->prune (); // will do only if necessary
+
+ tree_type::point_iterator prune_iterator = item;
+ item++;
+
+ prune_iterator->prune_node ();
+ }
+
+ return node->payload ();
+}
+
+void
+StatsTree::RemoveFace (Ptr<Face> face)
+{
+ tree_type::recursive_iterator item (&m_tree), end;
+ for (; item != end; item ++)
+ {
+ item->payload ().RemoveFace (face);
+ }
+}
+
+std::ostream &
+operator << (std::ostream &os, const StatsTree &tree)
+{
+ // os << "[" << tree.m_tree.key () << "]: " << tree.m_tree.payload ();
+ os << tree.m_tree;
+ return os;
+}
+
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
+
diff --git a/utils/stats/stats-tree.h b/utils/stats/stats-tree.h
new file mode 100644
index 0000000..955f798
--- /dev/null
+++ b/utils/stats/stats-tree.h
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef STATS_TREE_H
+#define STATS_TREE_H
+
+#include "../trie/trie.h"
+#include "load-stats-node.h"
+#include "ns3/ndn-name-components.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+namespace ndn {
+namespace ndnSIM {
+
+class StatsTree
+{
+public:
+ typedef trie< NameComponents,
+ non_pointer_traits< LoadStatsNode >, void* > tree_type;
+
+ StatsTree ();
+
+ void
+ Step ();
+
+ void
+ NewPitEntry (const NameComponents &key);
+
+ void
+ Incoming (const NameComponents &key, Ptr<Face> face);
+
+ void
+ Outgoing (const NameComponents &key, Ptr<Face> face);
+
+ void
+ Satisfy (const NameComponents &key);
+
+ void
+ Timeout (const NameComponents &key);
+
+ void
+ Rx (const NameComponents &key, Ptr<Face> face, uint32_t amount);
+
+ void
+ Tx (const NameComponents &key, Ptr<Face> face, uint32_t amount);
+
+ // const LoadStatsNode &
+ // Get (const NameComponents &key) const;
+ const LoadStatsNode &
+ operator [] (const NameComponents &key) const;
+
+ void
+ RemoveFace (Ptr<Face> face);
+
+private:
+ const LoadStatsNode &
+ WalkLeftRightRoot (tree_type *node);
+
+
+private:
+ tree_type m_tree;
+
+ friend std::ostream &
+ operator << (std::ostream &os, const StatsTree &tree);
+};
+
+std::ostream &
+operator << (std::ostream &os, const StatsTree &tree);
+
+} // namespace ndnSIM
+} // namespace ndn
+} // namespace ns3
+
+#endif // STATS_TREE_H