tracers: simplification of ndn::CsTracer (there no real need for virtual calls)
diff --git a/docs/source/metric.rst b/docs/source/metric.rst
index 37e4381..d1d81ce 100644
--- a/docs/source/metric.rst
+++ b/docs/source/metric.rst
@@ -73,16 +73,16 @@
 Content store trace helper
 --------------------------
 
-- :ndnsim:`ndn::CsImpTracer`
+- :ndnsim:`ndn::CsTracer`
 
-    With the use of :ndnsim:`ndn::CsImpTracer` it is possible to obtain statistics of cache hits/cache misses on simulation nodes.
+    With the use of :ndnsim:`ndn::CsTracer` it is possible to obtain statistics of cache hits/cache misses on simulation nodes.
 
     The following code enables content store tracing:
 
     .. code-block:: c++
 
         // necessary includes
-        #include <ns3/ndnSIM/utils/tracers/ndn-cs-imp-tracer.h>
+        #include <ns3/ndnSIM/utils/tracers/ndn-cs-tracer.h>
 
 	...        
 
@@ -91,8 +91,8 @@
 
         // the following should be put just before calling Simulator::Run in the scenario
 
-        boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsImpTracer> > >
-           aggTracers = ndn::CsImpTracer::InstallAll ("cs-trace.txt", Seconds (1));
+        boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsTracer> > >
+           aggTracers = ndn::CsTracer::InstallAll ("cs-trace.txt", Seconds (1));
         
         Simulator::Run ();
         
diff --git a/examples/ndn-tree-cs-tracers.cc b/examples/ndn-tree-cs-tracers.cc
index 8707131..9d478fd 100644
--- a/examples/ndn-tree-cs-tracers.cc
+++ b/examples/ndn-tree-cs-tracers.cc
@@ -24,8 +24,8 @@
 #include "ns3/network-module.h"
 #include "ns3/ndnSIM-module.h"
 
-// for ndn::CsImptTracer
-#include <ns3/ndnSIM/utils/tracers/ndn-cs-imp-tracer.h>
+// for ndn::CsTracer
+#include <ns3/ndnSIM/utils/tracers/ndn-cs-tracer.h>
 
 using namespace ns3;
 
@@ -114,8 +114,8 @@
 
   Simulator::Stop (Seconds (20.0));
 
-  boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsImpTracer> > >
-    aggTracers = ndn::CsImpTracer::InstallAll ("cs-trace.txt", Seconds (1));
+  boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsTracer> > >
+    aggTracers = ndn::CsTracer::InstallAll ("cs-trace.txt", Seconds (1));
   
   Simulator::Run ();
   Simulator::Destroy ();
diff --git a/utils/tracers/ndn-cs-imp-tracer.cc b/utils/tracers/ndn-cs-imp-tracer.cc
deleted file mode 100644
index 3016bf4..0000000
--- a/utils/tracers/ndn-cs-imp-tracer.cc
+++ /dev/null
@@ -1,164 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2011 UCLA
- *
- * 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 "ndn-cs-imp-tracer.h"
-
-#include "ns3/node.h"
-#include "ns3/packet.h"
-#include "ns3/config.h"
-#include "ns3/callback.h"
-#include "ns3/ndn-app.h"
-#include "ns3/ndn-interest.h"
-#include "ns3/ndn-content-object.h"
-#include "ns3/simulator.h"
-#include "ns3/node-list.h"
-#include "ns3/log.h"
-
-#include <fstream>
-
-NS_LOG_COMPONENT_DEFINE ("ndn.CsImpTracer");
-
-namespace ns3 {
-namespace ndn {
-
-boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsImpTracer> > >
-CsImpTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
-{
-  using namespace boost;
-  using namespace std;
-  
-  std::list<Ptr<CsImpTracer> > tracers;
-  boost::shared_ptr<std::ofstream> outputStream (new std::ofstream ());
-  outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
-
-  if (!outputStream->is_open ())
-    return boost::make_tuple (outputStream, tracers);
-
-  for (NodeList::Iterator node = NodeList::Begin ();
-       node != NodeList::End ();
-       node++)
-    {
-      NS_LOG_DEBUG ("Node: " << (*node)->GetId ());
-
-      Ptr<CsImpTracer> trace = Create<CsImpTracer> (outputStream, *node);
-      trace->SetAveragingPeriod (averagingPeriod);
-      tracers.push_back (trace);
-    }
-
-  if (tracers.size () > 0)
-    {
-      // *m_l3RateTrace << "# "; // not necessary for R's read.table
-      tracers.front ()->PrintHeader (*outputStream);
-      *outputStream << "\n";
-    }
-
-  return boost::make_tuple (outputStream, tracers);
-}
-
-
-
-CsImpTracer::CsImpTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
-  : CsTracer (node)
-  , m_os (os)
-{
-  Reset ();
-}
-
-CsImpTracer::CsImpTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
-  : CsTracer (node)
-  , m_os (os)
-{
-  Reset ();
-}
-
-CsImpTracer::~CsImpTracer ()
-{
-};
-
-void
-CsImpTracer::SetAveragingPeriod (const Time &period)
-{
-  m_period = period;
-  m_printEvent.Cancel ();
-  m_printEvent = Simulator::Schedule (m_period, &CsImpTracer::PeriodicPrinter, this);
-}
-
-void
-CsImpTracer::PeriodicPrinter ()
-{
-  Print (*m_os);
-  Reset ();
-  
-  m_printEvent = Simulator::Schedule (m_period, &CsImpTracer::PeriodicPrinter, this);
-}
-
-void
-CsImpTracer::PrintHeader (std::ostream &os) const
-{
-  os << "Time" << "\t"
-
-     << "Node" << "\t"
-//     << "FaceId" << "\t"
- //    << "FaceDescr" << "\t"
-
-     << "Type" << "\t"
-     << "Packets" << "\t";
-//     << "Kilobytes";
-}
-
-void
-CsImpTracer::Reset ()
-{
-	m_stats.Reset();
-}
-
-#define PRINTER(printName, fieldName) \
-  os << time.ToDouble (Time::S) << "\t"                                 \
-  << m_node << "\t"                                                     \
-  << printName << "\t"                                                  \
-  << m_stats.fieldName << "\n";
-
-
-void
-CsImpTracer::Print (std::ostream &os) const
-{
-  Time time = Simulator::Now ();
-
-  PRINTER ("CacheHits",   m_cacheHits);
-  PRINTER ("CacheMisses",  m_cacheMisses);
-}
-
-void 
-CsImpTracer::CacheHits (std::string context,
-			Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>)
-{
-	m_stats.m_cacheHits ++;
-}
-
-void 
-CsImpTracer::CacheMisses (std::string context, 
-			Ptr<const InterestHeader>)
-{
-	m_stats.m_cacheMisses ++;
-}
-
-
-} // namespace ndn
-} // namespace ns3
diff --git a/utils/tracers/ndn-cs-imp-tracer.h b/utils/tracers/ndn-cs-imp-tracer.h
deleted file mode 100644
index bc9c48d..0000000
--- a/utils/tracers/ndn-cs-imp-tracer.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2011 UCLA
- *
- * 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 NDN_CS_IMP_TRACER_H
-#define NDN_CS_IMP_TRACER_H
-
-#include "ndn-cs-tracer.h"
-
-#include <ns3/nstime.h>
-#include <ns3/event-id.h>
-
-#include <boost/tuple/tuple.hpp>
-#include <boost/shared_ptr.hpp>
-#include <map>
-#include <list>
-
-namespace ns3 {
-namespace ndn {
-
-/**
- * @ingroup ndn
- * @brief CCNx network-layer tracer for aggregate packet counts
- */
-class CsImpTracer : public CsTracer
-{
-public:
-  /**
-   * @brief Trace constructor that attaches to the node using node pointer
-   * @param os    reference to the output stream
-   * @param node  pointer to the node
-   */
-  CsImpTracer (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
-   */
-  CsImpTracer (boost::shared_ptr<std::ostream> os, const std::string &nodeName);
-
-  /**
-   * @brief Destructor
-   */
-  virtual ~CsImpTracer ();
-
-  /**
-   * @brief Helper method to install tracers on all simulation nodes
-   *
-   * @param file File to which traces will be written
-   * @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
-   *          for the lifetime of simulation, otherwise SEGFAULTs are inevitable
-   * 
-   */
-  static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsImpTracer> > >
-  InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
-
-protected: 
-  // from CsTracer
-  virtual void
-  PrintHeader (std::ostream &os) const;
-
-  virtual void
-  Print (std::ostream &os) const;
-
-  virtual void 
-  CacheHits (std::string context,
-  Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>);
-  
-  virtual void 
-  CacheMisses (std::string context,
-  Ptr<const InterestHeader>);
-
-protected:
-  void
-  SetAveragingPeriod (const Time &period);
-
-  void
-  Reset ();
-
-  void
-  PeriodicPrinter ();
-  
-protected:
-  boost::shared_ptr<std::ostream> m_os;
-
-  Time m_period;
-  EventId m_printEvent;
-  Stats m_stats;
-  
-//  mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
-};
-
-} // namespace ndn
-} // namespace ns3
-
-#endif // NDN_CS_IMP_TRACER_H
diff --git a/utils/tracers/ndn-cs-tracer.cc b/utils/tracers/ndn-cs-tracer.cc
index 742961f..6cab66f 100644
--- a/utils/tracers/ndn-cs-tracer.cc
+++ b/utils/tracers/ndn-cs-tracer.cc
@@ -15,7 +15,8 @@
  * 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>
+ * Author: Xiaoyan Hu <x......u@gmail.com>
+ *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
 
 #include "ndn-cs-tracer.h"
@@ -25,18 +26,66 @@
 #include "ns3/names.h"
 #include "ns3/callback.h"
 
-#include <boost/lexical_cast.hpp>
-
+#include "ns3/ndn-app.h"
 #include "ns3/ndn-interest.h"
 #include "ns3/ndn-content-object.h"
+#include "ns3/simulator.h"
+#include "ns3/node-list.h"
+#include "ns3/log.h"
+
+#include <boost/lexical_cast.hpp>
+
+#include <fstream>
+
+NS_LOG_COMPONENT_DEFINE ("ndn.CsTracer");
 
 using namespace std;
 
 namespace ns3 {
 namespace ndn {
-    
-CsTracer::CsTracer (Ptr<Node> node)
+
+
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer> > >
+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::ofstream> outputStream (new std::ofstream ());
+  outputStream->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
+
+  if (!outputStream->is_open ())
+    return boost::make_tuple (outputStream, tracers);
+
+  for (NodeList::Iterator node = NodeList::Begin ();
+       node != NodeList::End ();
+       node++)
+    {
+      NS_LOG_DEBUG ("Node: " << (*node)->GetId ());
+
+      Ptr<CsTracer> trace = Create<CsTracer> (outputStream, *node);
+      trace->SetAveragingPeriod (averagingPeriod);
+      tracers.push_back (trace);
+    }
+
+  if (tracers.size () > 0)
+    {
+      // *m_l3RateTrace << "# "; // not necessary for R's read.table
+      tracers.front ()->PrintHeader (*outputStream);
+      *outputStream << "\n";
+    }
+
+  return boost::make_tuple (outputStream, tracers);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+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 ());
 
@@ -49,8 +98,9 @@
     }
 }
 
-CsTracer::CsTracer (const std::string &node)
+CsTracer::CsTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
 : m_node (node)
+, m_os (os)
 {
   Connect ();
 }
@@ -67,7 +117,75 @@
                    MakeCallback (&CsTracer::CacheHits, this));
   Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ContentStore/CacheMisses",
                    MakeCallback (&CsTracer::CacheMisses, this));
+
+  Reset ();  
 }
 
+
+void
+CsTracer::SetAveragingPeriod (const Time &period)
+{
+  m_period = period;
+  m_printEvent.Cancel ();
+  m_printEvent = Simulator::Schedule (m_period, &CsTracer::PeriodicPrinter, this);
+}
+
+void
+CsTracer::PeriodicPrinter ()
+{
+  Print (*m_os);
+  Reset ();
+  
+  m_printEvent = Simulator::Schedule (m_period, &CsTracer::PeriodicPrinter, this);
+}
+
+void
+CsTracer::PrintHeader (std::ostream &os) const
+{
+  os << "Time" << "\t"
+
+     << "Node" << "\t"
+
+     << "Type" << "\t"
+     << "Packets" << "\t";
+}
+
+void
+CsTracer::Reset ()
+{
+  m_stats.Reset();
+}
+
+#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
+{
+  Time time = Simulator::Now ();
+
+  PRINTER ("CacheHits",   m_cacheHits);
+  PRINTER ("CacheMisses", m_cacheMisses);
+}
+
+void 
+CsTracer::CacheHits (std::string context,
+                     Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>)
+{
+  m_stats.m_cacheHits ++;
+}
+
+void 
+CsTracer::CacheMisses (std::string context, 
+                       Ptr<const InterestHeader>)
+{
+  m_stats.m_cacheMisses ++;
+}
+
+
 } // namespace ndn
 } // namespace ns3
diff --git a/utils/tracers/ndn-cs-tracer.h b/utils/tracers/ndn-cs-tracer.h
index 5b057f7..af7419a 100644
--- a/utils/tracers/ndn-cs-tracer.h
+++ b/utils/tracers/ndn-cs-tracer.h
@@ -24,6 +24,13 @@
 
 #include "ns3/ptr.h"
 #include "ns3/simple-ref-count.h"
+#include <ns3/nstime.h>
+#include <ns3/event-id.h>
+
+#include <boost/tuple/tuple.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include <list>
 
 namespace ns3 {
 
@@ -35,71 +42,107 @@
 class InterestHeader;
 class ContentObjectHeader;
 
+namespace cs {
+
+struct Stats
+{
+  inline void Reset ()
+  {
+    m_cacheHits   = 0;
+    m_cacheMisses = 0;
+  }
+  double m_cacheHits;
+  double m_cacheMisses;
+};
+
+}  
+
 /**
- * @brief Base class for content store tracers (CacheHits and CacheMisses)
+ * @ingroup ndn
+ * @brief NDN tracer for cache performance (hits and misses)
  */
 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
+   * @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
+   *          for the lifetime of simulation, otherwise SEGFAULTs are inevitable
+   * 
+   */
+  static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer> > >
+  InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+
+  /**
    * @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 (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 (const std::string &node);
+  CsTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
 
   /**
    * @brief Destructor
    */
-  virtual ~CsTracer ();
+  ~CsTracer ();
 
   /**
    * @brief Print head of the trace (e.g., for post-processing)
    *
    * @param os reference to output stream
    */
-  virtual void
-  PrintHeader (std::ostream &os) const = 0;
+  void
+  PrintHeader (std::ostream &os) const;
 
   /**
    * @brief Print current trace data
    *
    * @param os reference to output stream
    */
-  virtual void
-  Print (std::ostream &os) const = 0;
+  void
+  Print (std::ostream &os) const;
   
-protected:
+private:
   void
   Connect ();
 
-  virtual void 
+  void 
   CacheHits (std::string context,
-  Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>) = 0;
+  Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>);
   
-  virtual void 
+  void 
   CacheMisses (std::string context,
-  Ptr<const InterestHeader>) = 0;
+  Ptr<const InterestHeader>);
 
-protected:
+private:
+  void
+  SetAveragingPeriod (const Time &period);
+
+  void
+  Reset ();
+
+  void
+  PeriodicPrinter ();
+  
+private:
   std::string m_node;
   Ptr<Node> m_nodePtr;
 
-  struct Stats
-  {
-    inline void Reset ()
-    {
-      m_cacheHits   = 0;
-      m_cacheMisses = 0;
-    }
-    double m_cacheHits;
-    double m_cacheMisses;
-  };
+  boost::shared_ptr<std::ostream> m_os;
+
+  Time m_period;
+  EventId m_printEvent;
+  cs::Stats m_stats;  
 };
 
 /**