app+utils+doc: Adding application-level trace helper to record Interest-Data delays
diff --git a/apps/ndn-app.cc b/apps/ndn-app.cc
index 3f982b6..dcf164d 100644
--- a/apps/ndn-app.cc
+++ b/apps/ndn-app.cc
@@ -90,7 +90,16 @@
 {
   m_protocolHandler = handler;
 }
-    
+
+uint32_t
+App::GetId () const
+{
+  if (m_face == 0)
+    return (uint32_t)-1;
+  else
+    return m_face->GetId ();
+}
+
 void
 App::OnInterest (const Ptr<const InterestHeader> &interest, Ptr<Packet> packet)
 {
diff --git a/apps/ndn-app.h b/apps/ndn-app.h
index f61d54b..94fb4a7 100644
--- a/apps/ndn-app.h
+++ b/apps/ndn-app.h
@@ -63,7 +63,13 @@
    */
   void
   RegisterProtocolHandler (ProtocolHandler handler);
-  
+
+  /**
+   * @brief Get application ID (ID of applications face)
+   */
+  uint32_t
+  GetId () const;
+   
   /**
    * @brief Method that will be called every time new Interest arrives
    * @param interest Interest header
@@ -88,7 +94,7 @@
   virtual void
   OnContentObject (const Ptr<const ContentObjectHeader> &contentObject,
                    Ptr<Packet> payload);
-        
+  
 protected:
   /**
    * @brief Do cleanup when application is destroyed
diff --git a/apps/ndn-consumer.cc b/apps/ndn-consumer.cc
index 794bcb9..e71a5f4 100644
--- a/apps/ndn-consumer.cc
+++ b/apps/ndn-consumer.cc
@@ -253,20 +253,12 @@
     {
       m_lastRetransmittedInterestDataDelay (this, seq, Simulator::Now () - entry->time);
     }
-  else
-    {
-      NS_ASSERT_MSG (entry != m_seqTimeouts.end (), "Something is now right");
-    }
 
   entry = m_seqLifetimes.find (seq);
   if (entry != m_seqLifetimes.end ())
     {
       m_firstInterestDataDelay (this, seq, Simulator::Now () - entry->time);
     }
-  else
-    {
-      NS_ASSERT_MSG (entry != m_seqLifetimes.end (), "Something is now right");
-    }
   
   m_seqLifetimes.erase (seq);
   m_seqTimeouts.erase (seq);
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index d99c245..f0485c3 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -256,106 +256,17 @@
 
         ./waf --run=ndn-congestion-alt-topo-plugin --visualize
 
-.. _trace example:
-
 3-level binary tree with packet-level trace helpers
 ---------------------------------------------------
 
-This example (``ndn-tree-tracers.cc``) demonstrates basic usage of :ref:`trace classes`.   
+:ref:`packet trace helper example`
 
-In this scenario we will use a tree-like topology, where consumers are installed on leaf nodes and producer is in the root of the tree:
-
-.. aafig::
-    :aspect: 60
-    :scale: 120
-                                                 
-     /--------\    /--------\    /--------\    /--------\
-     |"leaf-1"|    |"leaf-2"|    |"leaf-3"|    |"leaf-4"|
-     \--------/    \--------/    \--------/    \--------/
-           ^          ^                ^           ^	
-           |          |                |           |
-      	    \        /                  \         / 
-             \      /  			 \  	 /    10Mbps / 1ms
-              \    /  			  \ 	/
-               |  |  			   |   | 
-      	       v  v                        v   v     
-	    /-------\                    /-------\
-	    |"rtr-1"|                    |"rtr-2"|
-            \-------/                    \-------/
-                  ^                        ^                      
-		  |	 		   |
-		   \			  /  10 Mpbs / 1ms 
-		    +--------\  /--------+ 
-			     |  |      
-                             v  v
-			  /--------\
-			  | "root" |                                   
-                          \--------/
-
-The corresponding topology file (``topo-tree.txt``):
-
-.. literalinclude:: ../../examples/topologies/topo-tree.txt
-    :language: bash
-    :linenos:
-    :lines: 1-2,27-
-
-Example simulation (``ndn-tree-tracers.cc``) scenario that utilizes trace helpers:
-
-.. literalinclude:: ../../examples/ndn-tree-tracers.cc
-    :language: c++
-    :linenos:
-    :lines: 21-34,67-
-    :emphasize-lines: 7-11,63-67
-
-
-To run this scenario, use the following command::
-
-        ./waf --run=ndn-tree-tracers
-
-The successful run will create ``rate-trace.txt`` and ``aggregate-trace.txt`` files in the current directly, which can be analyzed manually or used as input to some graph/stats packages.
-
-For example, the following `R script <http://www.r-project.org/>`_ will build a number of nice graphs:
-
-.. image:: _static/root-rates.png
-   :alt: Interest/Data packet rates at the root node
-   :align: right
-
-.. image:: _static/root-5sec-counts.png
-   :alt: Interest/Data packet counts at the root node in 5-second intervals
-   :align: right
-
-.. literalinclude:: ../../examples/graphs/rate-graph.R
-    :language: r
-    :linenos:
-
-For more information about R and ggplot2, please refer to `R language manual <http://cran.r-project.org/manuals.html>`_, `ggplot2 module manual <http://docs.ggplot2.org/current/>`_.
-
-
-
-.. _cs trace helper example:
 
 3-level binary tree with content store trace helper
 ---------------------------------------------------
 
-This example (``ndn-tree-cs-tracers.cc``) demonstrates basic usage of :ref:`content store tracer helper class<cs trace helper>`.   
+:ref:`cs trace helper example`
 
-In this scenario we will use the same tree-like topology as in :ref:`previous example <trace example>`, where consumers are installed on leaf nodes and producer is in the root of the tree.
-The main difference is that each client request data from the same namespace: /root/1, /root/2, ...  Another small difference is that in this scenario we start our application not at the same time, but 10 ms apart.
-
-Example simulation (``ndn-tree-cs-tracers.cc``) scenario that utilizes trace helpers:
-
-.. literalinclude:: ../../examples/ndn-tree-cs-tracers.cc
-    :language: c++
-    :linenos:
-    :lines: 21-31,64-
-    :emphasize-lines: 7-11,25,46,48,65-66
-
-
-To run this scenario, use the following command::
-
-        ./waf --run=ndn-tree-cs-tracers
-
-The successful run will create ``cs-trace.txt``, which similarly to trace file from the :ref:`previous example <trace example>` can be analyzed manually or used as input to some graph/stats packages.
 
 3-node topology with Content Store respecting freshness field of ContentObjects
 -------------------------------------------------------------------------------
diff --git a/docs/source/metric.rst b/docs/source/metric.rst
index d1d81ce..c1cec1c 100644
--- a/docs/source/metric.rst
+++ b/docs/source/metric.rst
@@ -62,11 +62,79 @@
     A number of other tracers are available in ``plugins/tracers-broken`` folder, but they do not yet work with the current code.
     Eventually, we will port most of them to the current code, but it is not our main priority at the moment and would really appreciate help with writing new tracers and porting the old ones. 
 
+.. _packet trace helper example:
 
-Example
-+++++++
+Example of packet-level trace helpers
++++++++++++++++++++++++++++++++++++++
 
-Please refer to the :ref:`this example <trace example>`.
+This example (``ndn-tree-tracers.cc``) demonstrates basic usage of :ref:`trace classes`.   
+
+In this scenario we will use a tree-like topology, where consumers are installed on leaf nodes and producer is in the root of the tree:
+
+.. aafig::
+    :aspect: 60
+    :scale: 120
+                                                 
+     /--------\    /--------\    /--------\    /--------\
+     |"leaf-1"|    |"leaf-2"|    |"leaf-3"|    |"leaf-4"|
+     \--------/    \--------/    \--------/    \--------/
+           ^          ^                ^           ^	
+           |          |                |           |
+      	    \        /                  \         / 
+             \      /  			 \  	 /    10Mbps / 1ms
+              \    /  			  \ 	/
+               |  |  			   |   | 
+      	       v  v                        v   v     
+	    /-------\                    /-------\
+	    |"rtr-1"|                    |"rtr-2"|
+            \-------/                    \-------/
+                  ^                        ^                      
+		  |	 		   |
+		   \			  /  10 Mpbs / 1ms 
+		    +--------\  /--------+ 
+			     |  |      
+                             v  v
+			  /--------\
+			  | "root" |                                   
+                          \--------/
+
+The corresponding topology file (``topo-tree.txt``):
+
+.. literalinclude:: ../../examples/topologies/topo-tree.txt
+    :language: bash
+    :linenos:
+    :lines: 1-2,27-
+
+Example simulation (``ndn-tree-tracers.cc``) scenario that utilizes trace helpers:
+
+.. literalinclude:: ../../examples/ndn-tree-tracers.cc
+    :language: c++
+    :linenos:
+    :lines: 21-34,67-
+    :emphasize-lines: 7-11,63-67
+
+
+To run this scenario, use the following command::
+
+        ./waf --run=ndn-tree-tracers
+
+The successful run will create ``rate-trace.txt`` and ``aggregate-trace.txt`` files in the current directly, which can be analyzed manually or used as input to some graph/stats packages.
+
+For example, the following `R script <http://www.r-project.org/>`_ will build a number of nice graphs:
+
+.. image:: _static/root-rates.png
+   :alt: Interest/Data packet rates at the root node
+   :align: right
+
+.. image:: _static/root-5sec-counts.png
+   :alt: Interest/Data packet counts at the root node in 5-second intervals
+   :align: right
+
+.. literalinclude:: ../../examples/graphs/rate-graph.R
+    :language: r
+    :linenos:
+
+For more information about R and ggplot2, please refer to `R language manual <http://cran.r-project.org/manuals.html>`_, `ggplot2 module manual <http://docs.ggplot2.org/current/>`_.
 
 .. _cs trace helper:
 
@@ -103,10 +171,79 @@
 ..     Evaluate lifetime of the content store entries can be accomplished using modified version of the content stores.
 ..     In particular,
 
+.. _cs trace helper example:
+
+Example of content store trace helper
++++++++++++++++++++++++++++++++++++++
+
+This example (``ndn-tree-cs-tracers.cc``) demonstrates basic usage of content store tracer.
+
+In this scenario we will use the same tree-like topology as in :ref:`previous example <packet trace helper example>`, where consumers are installed on leaf nodes and producer is in the root of the tree.
+The main difference is that each client request data from the same namespace: /root/1, /root/2, ...  Another small difference is that in this scenario we start our application not at the same time, but 10 ms apart.
+
+Example simulation (``ndn-tree-cs-tracers.cc``) scenario that utilizes trace helpers:
+
+.. literalinclude:: ../../examples/ndn-tree-cs-tracers.cc
+    :language: c++
+    :linenos:
+    :lines: 21-31,64-
+    :emphasize-lines: 7-11,25,43,45,62-63
 
 
-Example
-+++++++
+To run this scenario, use the following command::
 
-:ref:`This example <cs trace helper example>` demonstrates one usage of content store tracer.
+        ./waf --run=ndn-tree-cs-tracers
+
+The successful run will create ``cs-trace.txt``, which similarly to trace file from the :ref:`tracing example <packet trace helper example>` can be analyzed manually or used as input to some graph/stats packages.
+
+
+Application-level trace helper
+------------------------------
+
+- :ndnsim:`ndn::AppDelayTracer`
+
+    With the use of :ndnsim:`ndn::AppDelayTracer` it is possible to obtain data about for delays between issuing Interest and receiving corresponding Data packet.  
+
+    The following code enables application-level Interest-Data delay tracing:
+
+    .. code-block:: c++
+
+        // necessary includes
+        #include <ns3/ndnSIM/utils/tracers/ndn-app-delay-tracer.h>
+
+	...        
+
+        // the following should be put just before calling Simulator::Run in the scenario
+
+        boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::AppDelayTracer> > >
+           tracers = ndn::AppDelayTracer::InstallAll ("app-delays-trace.txt");
+        
+        Simulator::Run ();
+        
+        ...
+
+.. _app delay trace helper example:
+
+Example of application-level trace helper
++++++++++++++++++++++++++++++++++++++++++
+
+This example (``ndn-tree-app-delay-tracer.cc``) demonstrates basic usage of application-level Interest-Data delay tracer.
+
+In this scenario we will use the same tree-like topology as in :ref:`packet trace helper example <packet trace helper example>`, where consumers are installed on leaf nodes and producer is in the root of the tree and clients request data from the same namespace: /root/1, /root/2, ...  
+
+Example simulation (``ndn-tree-app-delay-tracer.cc``) scenario that utilizes trace helpers:
+
+.. literalinclude:: ../../examples/ndn-tree-app-delay-tracer.cc
+    :language: c++
+    :linenos:
+    :lines: 21-31,64-
+    :emphasize-lines: 7-8,61-62
+
+
+To run this scenario, use the following command::
+
+        ./waf --run=ndn-tree-app-delay-tracer
+
+The successful run will create ``app-delays-trace.txt``, which similarly to trace file from the :ref:`packet trace helper example <packet trace helper example>` can be analyzed manually or used as input to some graph/stats packages.
+
 
diff --git a/examples/ndn-tree-app-delay-tracer.cc b/examples/ndn-tree-app-delay-tracer.cc
new file mode 100644
index 0000000..0b81c06
--- /dev/null
+++ b/examples/ndn-tree-app-delay-tracer.cc
@@ -0,0 +1,120 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011-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>
+ */
+
+// ndn-tree-app-delay-tracer.cc
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+// for ndn::AppDelayTracer
+#include <ns3/ndnSIM/utils/tracers/ndn-app-delay-tracer.h>
+
+using namespace ns3;
+
+/**
+ * This scenario simulates a tree topology (using topology reader module)
+ *
+ *    /------\      /------\      /------\      /------\
+ *    |leaf-1|      |leaf-2|      |leaf-3|      |leaf-4|
+ *    \------/      \------/      \------/      \------/
+ *         ^          ^                ^           ^	
+ *         |          |                |           |
+ *    	    \        /                  \         / 
+ *           \      /  			 \  	 /    10Mbps / 1ms
+ *            \    /  			  \ 	/
+ *             |  |  			   |   | 
+ *    	       v  v                        v   v     
+ *          /-------\                    /-------\
+ *          | rtr-1 |                    | rtr-2 |
+ *          \-------/                    \-------/
+ *                ^                        ^                      
+ *      	  |	 		   |
+ *      	   \			  /  10 Mpbs / 1ms 
+ *      	    +--------+  +--------+ 
+ *      		     |  |      
+ *                           v  v
+ *      		  /--------\
+ *      		  |  root  |
+ *                        \--------/
+ *
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ *     ./waf --run=ndn-tree-app-delay-tracer
+ */
+
+int
+main (int argc, char *argv[])
+{
+  CommandLine cmd;
+  cmd.Parse (argc, argv);
+
+  AnnotatedTopologyReader topologyReader ("", 1);
+  topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-tree.txt");
+  topologyReader.Read ();
+
+  // Install CCNx stack on all nodes
+  ndn::StackHelper ndnHelper;
+  ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
+  ndnHelper.InstallAll ();
+
+  // Installing global routing interface on all nodes
+  ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
+  ccnxGlobalRoutingHelper.InstallAll ();
+
+  // Getting containers for the consumer/producer
+  Ptr<Node> consumers[4] = { Names::Find<Node> ("leaf-1"), Names::Find<Node> ("leaf-2"),
+                             Names::Find<Node> ("leaf-3"), Names::Find<Node> ("leaf-4") };
+  Ptr<Node> producer = Names::Find<Node> ("root");
+
+  for (int i = 0; i < 4; i++)
+    {
+      ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+      consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 100 interests a second
+
+      // Each consumer will express the same data /root/<seq-no>
+      consumerHelper.SetPrefix ("/root");
+      ApplicationContainer app = consumerHelper.Install (consumers[i]);
+      app.Start (Seconds (0.01 * i));
+    }
+    
+  ndn::AppHelper producerHelper ("ns3::ndn::Producer");
+  producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));  
+
+  // Register /root prefix with global routing controller and
+  // install producer that will satisfy Interests in /root namespace
+  ccnxGlobalRoutingHelper.AddOrigins ("/root", producer);
+  producerHelper.SetPrefix ("/root");
+  producerHelper.Install (producer);
+
+  // Calculate and install FIBs
+  ccnxGlobalRoutingHelper.CalculateRoutes ();
+
+  Simulator::Stop (Seconds (20.0));
+
+  boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::AppDelayTracer> > >
+    tracers = ndn::AppDelayTracer::InstallAll ("app-delays-trace.txt");
+  
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff --git a/examples/ndn-tree-cs-tracers.cc b/examples/ndn-tree-cs-tracers.cc
index 9d478fd..496b9d5 100644
--- a/examples/ndn-tree-cs-tracers.cc
+++ b/examples/ndn-tree-cs-tracers.cc
@@ -77,9 +77,6 @@
   ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", "MaxSize", "100"); // default ContentStore parameters
   ndnHelper.InstallAll ();
 
-  // ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Random", "MaxSize", "10");
-  // Config::ConnectWithoutContext ("/NodeList/1/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
-  
   // Installing global routing interface on all nodes
   ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
   ccnxGlobalRoutingHelper.InstallAll ();
diff --git a/examples/wscript b/examples/wscript
index c3fc672..a962ffa 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -38,3 +38,6 @@
 
         obj = bld.create_ns3_program('ndn-tree-cs-tracers', ['ndnSIM'])
         obj.source = 'ndn-tree-cs-tracers.cc'
+
+        obj = bld.create_ns3_program('ndn-tree-app-delay-tracer', ['ndnSIM'])
+        obj.source = 'ndn-tree-app-delay-tracer.cc'
diff --git a/utils/tracers/ndn-app-delay-tracer.cc b/utils/tracers/ndn-app-delay-tracer.cc
new file mode 100644
index 0000000..c84f176
--- /dev/null
+++ b/utils/tracers/ndn-app-delay-tracer.cc
@@ -0,0 +1,158 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013 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 "ndn-app-delay-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/names.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 <boost/lexical_cast.hpp>
+#include <boost/make_shared.hpp>
+
+#include <fstream>
+
+NS_LOG_COMPONENT_DEFINE ("ndn.AppDelayTracer");
+
+using namespace std;
+
+namespace ns3 {
+namespace ndn {
+
+
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > >
+AppDelayTracer::InstallAll (const std::string &file)
+{
+  using namespace boost;
+  using namespace std;
+  
+  std::list<Ptr<AppDelayTracer> > tracers;
+  boost::shared_ptr<std::ofstream> outputStream = make_shared<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<AppDelayTracer> trace = Create<AppDelayTracer> (outputStream, *node);
+      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);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
+
+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 ());
+
+  Connect ();
+
+  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)
+{
+  Connect ();
+}
+
+AppDelayTracer::~AppDelayTracer ()
+{
+};
+
+
+void
+AppDelayTracer::Connect ()
+{
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/LastRetransmittedInterestDataDelay",
+                                 MakeCallback (&AppDelayTracer::LastRetransmittedInterestDataDelay, this));
+
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/ApplicationList/*/LastRetransmittedInterestDataDelay",
+                                 MakeCallback (&AppDelayTracer::FirstInterestDataDelay, this));
+}
+
+void
+AppDelayTracer::PrintHeader (std::ostream &os) const
+{
+  os << "Node" << "\t"
+     << "AppId" << "\t"
+     << "SeqNo" << "\t"
+
+     << "Type" << "\t"
+     << "DelayS" << "\t"
+     << "DelayUS" << "\n";
+}
+
+void 
+AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay)
+{
+  *m_os << m_node << "\t"
+        << app->GetId () << "\t"
+        << seqno << "\t"
+        << "LastDelay" << "\t"
+        << delay.ToDouble (Time::S) << "\t"
+        << delay.ToDouble (Time::US) << "\n";
+}
+  
+void 
+AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay)
+{
+  *m_os << m_node << "\t"
+        << app->GetId () << "\t"
+        << seqno << "\t"
+        << "FullDelay" << "\t"
+        << delay.ToDouble (Time::S) << "\t"
+        << delay.ToDouble (Time::US) << "\n";
+}
+
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/tracers/ndn-app-delay-tracer.h b/utils/tracers/ndn-app-delay-tracer.h
new file mode 100644
index 0000000..af0007f
--- /dev/null
+++ b/utils/tracers/ndn-app-delay-tracer.h
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013 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 CCNX_APP_DELAY_TRACER_H
+#define CCNX_APP_DELAY_TRACER_H
+
+#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 <list>
+
+namespace ns3 {
+
+class Node;
+class Packet;
+
+namespace ndn {
+
+class App;
+
+/**
+ * @ingroup ndn
+ * @brief  network-layer tracer for aggregate packet counts
+ */
+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
+   * @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<AppDelayTracer> > >
+  InstallAll (const std::string &file);
+
+  /**
+   * @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);
+
+  /**
+   * @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);
+
+  /**
+   * @brief Destructor
+   */
+  ~AppDelayTracer ();
+
+  /**
+   * @brief Print head of the trace (e.g., for post-processing)
+   *
+   * @param os reference to output stream
+   */
+  void
+  PrintHeader (std::ostream &os) const;
+  
+private:
+  void
+  Connect ();
+
+  void 
+  LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay);
+  
+  void 
+  FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay);
+  
+private:
+  std::string m_node;
+  Ptr<Node> m_nodePtr;
+
+  boost::shared_ptr<std::ostream> m_os;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // CCNX_CS_TRACER_H
diff --git a/utils/tracers/ndn-cs-tracer.cc b/utils/tracers/ndn-cs-tracer.cc
index 6cab66f..2200665 100644
--- a/utils/tracers/ndn-cs-tracer.cc
+++ b/utils/tracers/ndn-cs-tracer.cc
@@ -113,10 +113,10 @@
 void
 CsTracer::Connect ()
 {
-  Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ContentStore/CacheHits",
-                   MakeCallback (&CsTracer::CacheHits, this));
-  Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ContentStore/CacheMisses",
-                   MakeCallback (&CsTracer::CacheMisses, this));
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/$ns3::ndn::ContentStore/CacheHits",
+                                 MakeCallback (&CsTracer::CacheHits, this));
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/$ns3::ndn::ContentStore/CacheMisses",
+                                 MakeCallback (&CsTracer::CacheMisses, this));
 
   Reset ();  
 }
@@ -173,15 +173,13 @@
 }
 
 void 
-CsTracer::CacheHits (std::string context,
-                     Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>)
+CsTracer::CacheHits (Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>)
 {
   m_stats.m_cacheHits ++;
 }
 
 void 
-CsTracer::CacheMisses (std::string context, 
-                       Ptr<const InterestHeader>)
+CsTracer::CacheMisses (Ptr<const InterestHeader>)
 {
   m_stats.m_cacheMisses ++;
 }
diff --git a/utils/tracers/ndn-cs-tracer.h b/utils/tracers/ndn-cs-tracer.h
index af7419a..b52de9c 100644
--- a/utils/tracers/ndn-cs-tracer.h
+++ b/utils/tracers/ndn-cs-tracer.h
@@ -117,12 +117,10 @@
   Connect ();
 
   void 
-  CacheHits (std::string context,
-  Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>);
+  CacheHits (Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>);
   
   void 
-  CacheMisses (std::string context,
-  Ptr<const InterestHeader>);
+  CacheMisses (Ptr<const InterestHeader>);
 
 private:
   void
diff --git a/utils/trie/lifetime-stats-policy.h b/utils/trie/lifetime-stats-policy.h
index 12906ca..905f532 100644
--- a/utils/trie/lifetime-stats-policy.h
+++ b/utils/trie/lifetime-stats-policy.h
@@ -137,7 +137,6 @@
       void
       set_traced_callback (TracedCallback< typename parent_trie::payload_traits::const_base_type, Time > *callback)
       {
-        std::cout << Simulator::GetContext () << " " << callback << std::endl;
         m_willRemoveEntry = callback;
       }