Implementing CcnxTraceHelper (only aggregate traces for now)
diff --git a/examples/abilene-topology.cc b/examples/abilene-topology.cc
index 02aa54b..660d899 100644
--- a/examples/abilene-topology.cc
+++ b/examples/abilene-topology.cc
@@ -26,10 +26,8 @@
 #include "ns3/point-to-point-grid.h"
 #include "ns3/ipv4-global-routing-helper.h"
 #include "ns3/animation-interface.h"
-// #include "ns3/ccnx-l3-protocol.h"
 
-#include <iostream>
-#include <sstream>
+#include "../helper/ccnx-trace-helper.h"
 #include "ns3/annotated-topology-reader.h"
 #include "../utils/spring-mobility-helper.h"
 
@@ -40,13 +38,6 @@
 
 NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
 
-// int transmittedInterests = 0;
-// int receivedInterests = 0;
-// int droppedInterests = 0;
-
-// int transmittedData = 0;
-// int receivedData = 0;
-// int droppedData = 0;
 
 void PrintTime ()
 {
@@ -72,187 +63,13 @@
 }
 
 
-struct AggregateAppTrace
-{
-  AggregateAppTrace ()
-    : m_transmittedInterests (0)
-    , m_transmittedData (0)
-    , m_receivedInterests (0)
-    , m_receivedNacks (0)
-    , m_receivedData (0)
-  {
-    Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/TransmittedInterests",
-                     MakeCallback (&AggregateAppTrace::TransmittedInterests, this));
 
-    Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedNacks",
-                     MakeCallback (&AggregateAppTrace::ReceivedNacks, this));
 
-    Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/ReceivedInterests",
-                     MakeCallback (&AggregateAppTrace::ReceivedInterests, this));
-  
-    Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/TransmittedContentObjects",
-                     MakeCallback (&AggregateAppTrace::TransmittedData, this));
 
-    Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedContentObjects",
-                     MakeCallback (&AggregateAppTrace::ReceivedData, this));
-  }
-  
-  void
-  TransmittedInterests (std::string context,
-                        Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>)
-  {
-    m_transmittedInterests++;
-  }
-
-  void
-  TransmittedData (std::string context,
-                   Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
-                   Ptr<CcnxApp>, Ptr<CcnxFace>)
-  {
-    m_transmittedData++;
-  }
-
-  void
-  ReceivedInterests (std::string context,
-                     Ptr<const CcnxInterestHeader>,
-                     Ptr<CcnxApp>, Ptr<CcnxFace>)
-  {
-    m_receivedInterests++;
-  }
-
-  void
-  ReceivedNacks (std::string context,
-                 Ptr<const CcnxInterestHeader>,
-                 Ptr<CcnxApp>, Ptr<CcnxFace>)
-  {
-    m_receivedNacks++;
-  }
-  
-  void
-  ReceivedData (std::string context,
-                Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
-                Ptr<CcnxApp>, Ptr<CcnxFace>)
-  {
-    m_receivedData++;
-  }
-
-  uint64_t m_transmittedInterests;
-  uint64_t m_transmittedData;
-  uint64_t m_receivedInterests;
-  uint64_t m_receivedNacks;
-  uint64_t m_receivedData;
-};
-
-ostream&
-operator << (ostream &os, const AggregateAppTrace &trace)
-{
-  os << ">> (i): " << trace.m_transmittedInterests << "\n";
-  os << ">> (d): " << trace.m_transmittedData << "\n";
-  os << "<< (i): " << trace.m_receivedInterests << "\n";
-  os << "<< (d): " << trace.m_receivedData << "\n";
-  os << "<< (n): " << trace.m_receivedNacks << "\n";
-  return os;
-}
-
-struct AggregateCcnxTrace
-{
-  AggregateCcnxTrace (const std::string &node = "*")
-    : 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)
-  {
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/OutInterests",
-                     MakeCallback (&AggregateCcnxTrace::OutInterests, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InInterests",
-                     MakeCallback (&AggregateCcnxTrace::InInterests, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropInterests",
-                     MakeCallback (&AggregateCcnxTrace::DropInterests, this));
-
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutNacks",
-                     MakeCallback (&AggregateCcnxTrace::OutNacks, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InNacks",
-                     MakeCallback (&AggregateCcnxTrace::InNacks, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropNacks",
-                     MakeCallback (&AggregateCcnxTrace::DropNacks, this));
-
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutData",
-                     MakeCallback (&AggregateCcnxTrace::OutData, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InData",
-                     MakeCallback (&AggregateCcnxTrace::InData, this));
-    Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropData",
-                     MakeCallback (&AggregateCcnxTrace::DropData, this));
-  }
-
-  void OutInterests  (std::string context,
-                      Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
-  { m_outInterests++; }
-  void InInterests   (std::string context,
-                      Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
-  { m_inInterests++; }
-  void DropInterests (std::string context,
-                      Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
-  { m_dropInterests++; }
-
-  void OutNacks  (std::string context,
-                  Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
-  { m_outNacks++; }
-  void InNacks   (std::string context,
-                  Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
-  { m_inNacks++; }
-  void DropNacks (std::string context,
-                  Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
-  { m_dropNacks++; }
-
-  void OutData  (std::string context,
-                 Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>)
-  { m_inData++; }
-  void InData   (std::string context,
-                 Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>)
-  { m_outData++; }
-  void DropData (std::string context,
-                 Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
-  { m_dropData++; }
-
-  uint64_t m_inInterests;
-  uint64_t m_outInterests;
-  uint64_t m_dropInterests;
-  uint64_t m_inNacks;
-  uint64_t m_outNacks;
-  uint64_t m_dropNacks;
-  uint64_t m_inData;
-  uint64_t m_outData;
-  uint64_t m_dropData;
-};
-
-ostream&
-operator << (ostream &os, const AggregateCcnxTrace &trace)
-{
-  os << "(Interests)\n";
-  os << ">> (in):   " << trace.m_inInterests   << "\n";
-  os << ">> (out):  " << trace.m_outInterests  << "\n";
-  os << "<< (drop): " << trace.m_dropInterests << "\n";
-  os << "(Nacks)\n";
-  os << "<< (in):   " << trace.m_inNacks   << "\n";
-  os << "<< (out):  " << trace.m_outNacks  << "\n";
-  os << "<< (drop): " << trace.m_dropNacks << "\n";
-  os << "(Data)\n";
-  os << ">> (in):   " << trace.m_inData   << "\n";
-  os << ">> (out):  " << trace.m_outData  << "\n";
-  os << "<< (drop): " << trace.m_dropData << "\n";
-  return os;
-}
 
 int 
 main (int argc, char *argv[])
 {
-  // Packet::EnableChecking();
-  // Packet::EnablePrinting();
   string input ("./src/NDNabstraction/examples/abilene-topology.txt");
 
   Time finishTime = Seconds (20.0);
@@ -329,9 +146,16 @@
     }
 
   // NS_LOG_INFO ("Configure Tracing.");
-  AggregateAppTrace appTrace;
-  AggregateCcnxTrace ccnxTrace ("1");
-    
+  // CcnxAggregateAppTracer consumerTrace ("ns3::CcnxConsumer", "*");
+  // CcnxAggregateAppTracer producerTrace ("ns3::CcnxProducer", "*");
+  // CcnxAggregateL3Tracer ccnxTrace ("1");
+  CcnxTraceHelper traceHelper;
+  traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
+  traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
+  traceHelper.EnableAggregateL3All ();
+  traceHelper.SetL3TraceFile ("trace-l3.log");
+  traceHelper.SetAppTraceFile ("trace-app.log");
+  
   config.ConfigureAttributes ();  
   
   NS_LOG_INFO ("Run Simulation.");
@@ -339,7 +163,8 @@
   Simulator::Destroy ();
   NS_LOG_INFO ("Done.");
 
-  NS_LOG_INFO ("AppTrace: \n" << appTrace);
-  NS_LOG_INFO ("CcnxTrace: \n" << ccnxTrace);
+  // NS_LOG_INFO ("ConsumerTrace: \n" << consumerTrace);
+  // NS_LOG_INFO ("ProducerTrace: \n" << producerTrace);
+  // NS_LOG_INFO ("CcnxTrace: \n" << ccnxTrace);
   return 0;
 }
diff --git a/helper/ccnx-trace-helper.cc b/helper/ccnx-trace-helper.cc
new file mode 100644
index 0000000..3e006e4
--- /dev/null
+++ b/helper/ccnx-trace-helper.cc
@@ -0,0 +1,417 @@
+/* -*- 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 "ccnx-trace-helper.h"
+
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/ccnx-app.h"
+#include "ns3/ccnx-face.h"
+#include "ns3/packet.h"
+#include "ns3/log.h"
+#include "ns3/node-list.h"
+#include "ns3/object-vector.h"
+
+#include <fstream>
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+using namespace boost;
+
+NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
+
+namespace ns3 {
+    
+CcnxAppTracer::CcnxAppTracer (const std::string &app, const std::string &node, const std::string &appId)
+  : m_app (app)
+  , m_appId (appId)
+  , m_node (node)
+{
+  Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+appId+"/$"+m_app+"/TransmittedInterests",
+                   MakeCallback (&CcnxAppTracer::OutInterests, this));
+
+  Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+appId+"/$"+m_app+"/ReceivedNacks",
+                   MakeCallback (&CcnxAppTracer::InNacks, this));
+
+  Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+appId+"/$"+m_app+"/ReceivedInterests",
+                   MakeCallback (&CcnxAppTracer::InInterests, this));
+  
+  Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+appId+"/$"+m_app+"/TransmittedContentObjects",
+                   MakeCallback (&CcnxAppTracer::OutData, this));
+
+  Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+appId+"/$"+m_app+"/ReceivedContentObjects",
+                   MakeCallback (&CcnxAppTracer::InData, this));
+}
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+
+CcnxL3Tracer::CcnxL3Tracer (const std::string &node)
+: m_node (node)
+{
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/OutInterests",
+                   MakeCallback (&CcnxL3Tracer::OutInterests, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InInterests",
+                   MakeCallback (&CcnxL3Tracer::InInterests, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropInterests",
+                   MakeCallback (&CcnxL3Tracer::DropInterests, this));
+
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutNacks",
+                   MakeCallback (&CcnxL3Tracer::OutNacks, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InNacks",
+                   MakeCallback (&CcnxL3Tracer::InNacks, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropNacks",
+                   MakeCallback (&CcnxL3Tracer::DropNacks, this));
+
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutData",
+                   MakeCallback (&CcnxL3Tracer::OutData, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InData",
+                   MakeCallback (&CcnxL3Tracer::InData, this));
+  Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropData",
+                   MakeCallback (&CcnxL3Tracer::DropData, this));
+}
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+
+CcnxAggregateAppTracer::CcnxAggregateAppTracer (const std::string &app, const std::string &node, const std::string &appId)
+  : CcnxAppTracer (app, node, appId)
+  , m_inInterests (0)
+  , m_outInterests (0)
+  , m_inNacks (0)
+  , m_inData (0)
+  , m_outData (0)
+{
+}
+
+void
+CcnxAggregateAppTracer::PrintHeader (std::ostream &os) const
+{
+  os << "NodeId" << "\t"
+     << "App" << "\t"
+     << "AppId" << "\t"
+     << "InInterests" << "\t"
+     << "OutInterests" << "\t"
+    
+     << "InNacks" << "\t"
+    
+     << "InData" << "\t"
+     << "OutData";
+}
+
+void
+CcnxAggregateAppTracer::Print (std::ostream &os) const
+{
+  os << m_node << "\t"
+     << m_app << "\t"
+     << m_appId << "\t"
+     << m_inInterests << "\t"
+     << m_outInterests << "\t"
+    
+     << m_inNacks << "\t"
+    
+     << m_inData << "\t"
+     << m_outData;
+}
+
+void
+CcnxAggregateAppTracer::OutInterests (std::string context,
+                                      Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+  m_outInterests++;
+}
+
+void
+CcnxAggregateAppTracer::OutData (std::string context,
+                                 Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
+                                 Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+  m_outData++;
+}
+
+void
+CcnxAggregateAppTracer::InInterests (std::string context,
+                                     Ptr<const CcnxInterestHeader>,
+                                     Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+  m_inInterests++;
+}
+
+void
+CcnxAggregateAppTracer::InNacks (std::string context,
+                                 Ptr<const CcnxInterestHeader>,
+                                 Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+  m_inNacks++;
+}
+  
+void
+CcnxAggregateAppTracer::InData (std::string context,
+                                Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
+                                Ptr<CcnxApp>, Ptr<CcnxFace>)
+{
+  m_inData++;
+}
+
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+
+
+CcnxAggregateL3Tracer::CcnxAggregateL3Tracer (const std::string &node)
+  : CcnxL3Tracer (node)
+  , 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)
+{
+}
+
+void
+CcnxAggregateL3Tracer::PrintHeader (std::ostream &os) const
+{
+  os << "Node" << "\t"
+     << "InInterests" << "\t"
+     << "OutInterests" << "\t"
+     << "DropInterests" << "\t"
+    
+     << "InNacks" << "\t"
+     << "OutNacks" << "\t"
+     << "DropNacks" << "\t"
+    
+     << "InData" << "\t"
+     << "OutData" << "\t"
+     << "DropData";
+}
+
+void
+CcnxAggregateL3Tracer::Print (std::ostream &os) const
+{
+  os << m_node << "\t"
+     << m_inInterests   << "\t"
+     << m_outInterests  << "\t"
+     << m_dropInterests << "\t"
+  
+     << m_inNacks   << "\t"
+     << m_outNacks  << "\t"
+     << m_dropNacks << "\t"
+  
+     << m_inData   << "\t"
+     << m_outData  << "\t"
+     << m_dropData;
+}
+
+void
+CcnxAggregateL3Tracer::OutInterests  (std::string context,
+                                      Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
+{
+  m_outInterests++;
+}
+
+void
+CcnxAggregateL3Tracer::InInterests   (std::string context,
+                                      Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
+{
+  m_inInterests++;
+}
+
+void
+CcnxAggregateL3Tracer::DropInterests (std::string context,
+                                      Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
+{
+  m_dropInterests++;
+}
+
+void
+CcnxAggregateL3Tracer::OutNacks  (std::string context,
+                                  Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
+{
+  m_outNacks++;
+}
+
+void
+CcnxAggregateL3Tracer::InNacks   (std::string context,
+                                  Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
+{
+  m_inNacks++;
+}
+
+void
+CcnxAggregateL3Tracer::DropNacks (std::string context,
+                                  Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
+{
+  m_dropNacks++;
+}
+
+void
+CcnxAggregateL3Tracer::OutData  (std::string context,
+                                 Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>)
+{
+  m_inData++;
+}
+
+void
+CcnxAggregateL3Tracer::InData   (std::string context,
+                                 Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>)
+{
+  m_outData++;
+}
+
+void
+CcnxAggregateL3Tracer::DropData (std::string context,
+                                 Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
+{
+  m_dropData++;
+}
+
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+
+CcnxTraceHelper::~CcnxTraceHelper ()
+{
+  NS_LOG_FUNCTION (this);
+  
+  if (m_apps.size () > 0)
+    {
+      ofstream of;
+      if (!m_appTrace.empty ())
+        {
+          of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out);
+          of << "# ";
+          m_apps.front ()->PrintHeader (of);
+          of << "\n";
+        }
+      
+      for (std::list<Ptr<CcnxAggregateAppTracer> >::iterator app = m_apps.begin ();
+           app != m_apps.end ();
+           app++)
+        {
+          if (!m_appTrace.empty ())
+            {
+              (*app)->Print (of);
+              of << "\n";
+            }
+          else
+            {
+              NS_LOG_INFO (*(*app));
+            }
+        }
+    }
+
+  if (m_l3s.size () > 0)
+    {
+      ofstream of;
+      if (!m_l3Trace.empty ())
+        {
+          of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out);
+          of << "# ";
+          m_l3s.front ()->PrintHeader (of);
+          of << "\n";
+        }
+      
+      for (std::list<Ptr<CcnxAggregateL3Tracer> >::iterator l3 = m_l3s.begin ();
+           l3 != m_l3s.end ();
+           l3++)
+        {
+          if (!m_l3Trace.empty ())
+            {
+              (*l3)->Print (of);
+              of << "\n";
+            }
+          else
+            {
+              NS_LOG_INFO (*(*l3));
+            }
+        }
+    }
+}
+
+void
+CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
+{
+  NS_LOG_FUNCTION (this << appTrace);
+  m_appTrace = appTrace;
+}
+
+void
+CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
+{
+  NS_LOG_FUNCTION (this << l3Trace);
+  m_l3Trace = l3Trace;
+}
+
+void
+CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName)
+{
+  NS_LOG_FUNCTION (this << appName);
+  for (NodeList::Iterator node = NodeList::Begin ();
+       node != NodeList::End ();
+       node++)
+    {
+      ObjectVectorValue apps;
+      (*node)->GetAttribute ("ApplicationList", apps);
+
+      NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+      
+      uint32_t appId = 0;
+      for (ObjectVectorValue::Iterator app = apps.Begin ();
+           app != apps.End ();
+           app++, appId++)
+        {
+          NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
+          if ((*app)->GetInstanceTypeId ().GetName () == appName)
+            {
+              m_apps.push_back (Create<CcnxAggregateAppTracer> (appName,
+                                                                lexical_cast<string> ((*node)->GetId ()),
+                                                                lexical_cast<string> (appId)));
+            }
+        }
+    }
+}
+
+void
+CcnxTraceHelper::EnableAggregateL3All ()
+{
+  NS_LOG_FUNCTION (this);
+  
+  for (NodeList::Iterator node = NodeList::Begin ();
+       node != NodeList::End ();
+       node++)
+    {
+      NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
+      
+      m_l3s.push_back (Create<CcnxAggregateL3Tracer> (lexical_cast<string> ((*node)->GetId ())));
+    }
+}
+
+
+} // namespace ns3
diff --git a/helper/ccnx-trace-helper.h b/helper/ccnx-trace-helper.h
new file mode 100644
index 0000000..0a0906d
--- /dev/null
+++ b/helper/ccnx-trace-helper.h
@@ -0,0 +1,300 @@
+/* -*- 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 CCNX_TRACE_HELPER_H
+#define CCNX_TRACE_HELPER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/ccnx.h"
+
+namespace ns3 {
+
+class CcnxApp;
+
+class CcnxAppTracer : public SimpleRefCount<CcnxAppTracer>
+{
+public:
+  CcnxAppTracer (const std::string &app, const std::string &node = "*", const std::string &appId = "*");
+  virtual ~CcnxAppTracer ()  { };
+
+  virtual void
+  PrintHeader (std::ostream &os) const = 0;
+  
+  virtual void
+  Print (std::ostream &os) const = 0;
+
+  virtual void
+  OutInterests (std::string context,
+                Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0;
+
+  virtual void
+  InInterests  (std::string context,
+                Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0;
+
+  virtual void
+  InNacks (std::string context,
+           Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0;
+
+  virtual void
+  OutData (std::string context,
+           Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0;
+  
+  virtual void
+  InData  (std::string context,
+           Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>) = 0;
+
+protected:
+  std::string m_app;
+  std::string m_appId;
+  std::string m_node;
+};
+
+std::ostream&
+operator << (std::ostream &os, const CcnxAppTracer &tracer)
+{
+  os << "# ";
+  tracer.PrintHeader (os);
+  os << "\n";
+  tracer.Print (os);
+  return os;
+}
+
+class CcnxL3Tracer : public SimpleRefCount<CcnxL3Tracer>
+{
+public:
+  CcnxL3Tracer (const std::string &node = "*");
+  virtual ~CcnxL3Tracer () { };
+
+  virtual void
+  PrintHeader (std::ostream &os) const = 0;
+
+  virtual void
+  Print (std::ostream &os) const = 0;
+  
+  virtual void
+  OutInterests  (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  InInterests   (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  DropInterests (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0;
+  
+  virtual void
+  OutNacks  (std::string context,
+             Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  InNacks   (std::string context,
+             Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  DropNacks (std::string context,
+             Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0;
+
+  
+  virtual void
+  OutData  (std::string context,
+            Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  InData   (std::string context,
+            Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>) = 0;
+
+  virtual void
+  DropData (std::string context,
+            Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>) = 0;
+
+protected:
+  std::string m_node;
+};
+
+std::ostream&
+operator << (std::ostream &os, const CcnxL3Tracer &tracer)
+{
+  os << "# ";
+  tracer.PrintHeader (os);
+  os << "\n";
+  tracer.Print (os);
+  return os;
+}
+
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////
+
+class CcnxAggregateAppTracer : public CcnxAppTracer
+{
+public:
+  CcnxAggregateAppTracer (const std::string &app, const std::string &node = "*", const std::string &appId = "*");
+  virtual ~CcnxAggregateAppTracer () { };
+
+  virtual void
+  PrintHeader (std::ostream &os) const;
+
+  virtual void
+  Print (std::ostream &os) const;
+
+  virtual void
+  OutInterests (std::string context,
+                Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+  virtual void
+  InInterests  (std::string context,
+                Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+  virtual void
+  InNacks (std::string context,
+           Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+  virtual void
+  OutData (std::string context,
+           Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+  
+  virtual void
+  InData  (std::string context,
+           Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, Ptr<CcnxApp>, Ptr<CcnxFace>);
+
+private:
+  uint64_t m_inInterests;
+  uint64_t m_outInterests;
+  uint64_t m_inNacks;
+  uint64_t m_inData; 
+  uint64_t m_outData;
+};
+
+class CcnxAggregateL3Tracer : public CcnxL3Tracer
+{
+public:
+  CcnxAggregateL3Tracer (const std::string &node = "*");
+  virtual ~CcnxAggregateL3Tracer () { };
+  
+  virtual void
+  PrintHeader (std::ostream &os) const;
+
+  virtual void
+  Print (std::ostream &os) const;
+
+  virtual void
+  OutInterests  (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>);
+
+  virtual void
+  InInterests   (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>);
+
+  virtual void
+  DropInterests (std::string context,
+                 Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>);
+  
+  virtual void
+  OutNacks  (std::string context,
+             Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>);
+
+  virtual void
+  InNacks   (std::string context,
+             Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>);
+
+  virtual void
+  DropNacks (std::string context,
+             Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>);
+  
+  virtual void
+  OutData  (std::string context,
+            Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>);
+
+  virtual void
+  InData   (std::string context,
+            Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>);
+
+  virtual void
+  DropData (std::string context,
+            Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>);
+
+private:
+  uint64_t m_inInterests;
+  uint64_t m_outInterests;
+  uint64_t m_dropInterests;
+  uint64_t m_inNacks;
+  uint64_t m_outNacks;
+  uint64_t m_dropNacks;
+  uint64_t m_inData;
+  uint64_t m_outData;
+  uint64_t m_dropData;
+};
+
+class CcnxTraceHelper
+{
+public:
+  /**
+   * @brief Destructor that invokes trace output procedures
+   */
+  ~CcnxTraceHelper ();
+
+  /**
+   * @brief Set filename to output app trace.
+   *
+   * By default, trace is output to NS_LOG_INFO stream
+   *
+   * @param file File where trace will be written to
+   */
+  void
+  SetAppTraceFile (const std::string &appTrace = "apps.log");
+
+  /**
+   * @brief Set filename to output app trace.
+   *
+   * By default, trace is output to NS_LOG_INFO stream
+   *
+   * @param file File where trace will be written to
+   */
+  void
+  SetL3TraceFile (const std::string &l3Trace = "l3.log");
+  
+  /**
+   * @brief Enable aggregate app-level CCNx tracing on all CCNx applications (individual file per application)
+   *
+   * @param app  Class name of the application of interest
+   */
+  void
+  EnableAggregateAppAll (const std::string &app);
+
+  /**
+   * @brief Enable aggregate network-level CCNx tracing on all CCNx nodes (individual file per node)
+   */
+  void
+  EnableAggregateL3All ();
+
+private:
+  std::string m_appTrace;
+  std::list<Ptr<CcnxAggregateAppTracer> > m_apps;
+
+  std::string m_l3Trace;
+  std::list<Ptr<CcnxAggregateL3Tracer> > m_l3s;
+};
+
+
+} // namespace ns3
+
+#endif /* CCNX_TRACE_HELPER_H */