utils: Porting several new IPv4 tracers from the old code. Extending ndn-app-delay-tracer
diff --git a/docs/source/metric.rst b/docs/source/metric.rst
index 0e821f0..4f1fa94 100644
--- a/docs/source/metric.rst
+++ b/docs/source/metric.rst
@@ -13,7 +13,7 @@
 
 - :ndnsim:`ndn::L3AggregateTracer`
 
-    Tracing the aggregate number of Interests/Data packets forwarded by an NDN node 
+    Tracing the aggregate number of Interests/Data packets forwarded by an NDN node
 
     The following example enables tracing on all simulation nodes:
 
@@ -22,21 +22,21 @@
         // necessary includes
 	#include <ns3/ndnSIM/utils/tracers/ndn-l3-aggregate-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::L3AggregateTracer> > >
           aggTracers = ndn::L3AggregateTracer::InstallAll ("aggregate-trace.txt", Seconds (1.0));
-        
+
         Simulator::Run ();
-        
+
         ...
 
 
 - :ndnsim:`ndn::L3RateTracer`
 
-    Tracing the rate in bytes and in number of packets of Interest/Data packets forwarded by an NDN node 
+    Tracing the rate in bytes and in number of packets of Interest/Data packets forwarded by an NDN node
 
     The following example enables tracing on all simulation nodes:
 
@@ -45,57 +45,57 @@
         // necessary includes
 	#include <ns3/ndnSIM/utils/tracers/ndn-l3-rate-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::L3RateTracer> > >
           rateTracers = ndn::L3RateTracer::InstallAll ("rate-trace.txt", Seconds (1.0));
-        
+
         Simulator::Run ();
-        
+
         ...
 
 
 .. note::
 
     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. 
+    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 of packet-level trace helpers
 +++++++++++++++++++++++++++++++++++++
 
-This example (``ndn-tree-tracers.cc``) demonstrates basic usage of :ref:`trace classes`.   
+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     
+               |  |  			   |   |
+      	       v  v                        v   v
 	    /-------\                    /-------\
 	    |"rtr-1"|                    |"rtr-2"|
             \-------/                    \-------/
-                  ^                        ^                      
+                  ^                        ^
 		  |	 		   |
-		   \			  /  10 Mpbs / 1ms 
-		    +--------\  /--------+ 
-			     |  |      
+		   \			  /  10 Mpbs / 1ms
+		    +--------\  /--------+
+			     |  |
                              v  v
 			  /--------\
-			  | "root" |                                   
+			  | "root" |
                           \--------/
 
 The corresponding topology file (``topo-tree.txt``):
@@ -152,7 +152,7 @@
         // necessary includes
         #include <ns3/ndnSIM/utils/tracers/ndn-cs-tracer.h>
 
-	...        
+	...
 
         // Select implementation of content store. By default, the following is applied:
         // ndnHelper.SetContentStore ("ns3::ndn::cs::Stats::Lru", "MaxSize", "100");
@@ -161,9 +161,9 @@
 
         boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<ndn::CsTracer> > >
            aggTracers = ndn::CsTracer::InstallAll ("cs-trace.txt", Seconds (1));
-        
+
         Simulator::Run ();
-        
+
         ...
 
 .. - Tracing lifetime of content store entries
@@ -202,7 +202,7 @@
 
 - :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.  
+    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:
 
@@ -211,15 +211,15 @@
         // 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 ();
-        
+
         ...
 
     Output file format is tab-separated values, with first row specifying names of the columns.  Refer to the following table for the description of the columns:
@@ -227,6 +227,8 @@
     +-----------------+---------------------------------------------------------------------+
     | Column          | Description                                                         |
     +=================+=====================================================================+
+    | ``Time``        | simulation time when SeqNo was receivied                            |
+    +-----------------+---------------------------------------------------------------------+
     | ``Node``        | node id, global unique                                              |
     +-----------------+---------------------------------------------------------------------+
     | ``AppId``       | app id, local unique on the node, not global                        |
@@ -264,7 +266,7 @@
 
 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, ...  
+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:
 
diff --git a/utils/tracers/ipv4-app-tracer.cc b/utils/tracers/ipv4-app-tracer.cc
index 57fb612..75c8b87 100644
--- a/utils/tracers/ipv4-app-tracer.cc
+++ b/utils/tracers/ipv4-app-tracer.cc
@@ -31,10 +31,9 @@
 using namespace boost;
 
 namespace ns3 {
-    
-Ipv4AppTracer::Ipv4AppTracer (Ptr<Node> node, const std::string &appId)
-  : m_appId (appId)
-  , m_nodePtr (node)
+
+Ipv4AppTracer::Ipv4AppTracer (Ptr<Node> node)
+  : m_nodePtr (node)
 {
   m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
 
@@ -55,15 +54,6 @@
 
   Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/LocalDeliver",
                    MakeCallback (&Ipv4AppTracer::Rx, this));
-  
-  // Config::Connect ("/NodeList/"+m_node+"/$ns3::Ipv4L3Protocol/Tx",
-  //                  MakeCallback (&Ipv4AppTracer::Rx, this));
-
-  // Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::PacketSink/Rx",
-  //                  MakeCallback (&Ipv4AppTracer::InData, this));
-
-  // Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$ns3::BulkSendApplication/Tx",
-  //                  MakeCallback (&Ipv4AppTracer::OutData, this));
 }
 
 
diff --git a/utils/tracers/ipv4-app-tracer.h b/utils/tracers/ipv4-app-tracer.h
index f24c6c3..0322d96 100644
--- a/utils/tracers/ipv4-app-tracer.h
+++ b/utils/tracers/ipv4-app-tracer.h
@@ -32,7 +32,7 @@
 class Ipv4AppTracer : public SimpleRefCount<Ipv4AppTracer>
 {
 public:
-  Ipv4AppTracer (Ptr<Node> node, const std::string &appId = "*");
+  Ipv4AppTracer (Ptr<Node> node);
   virtual ~Ipv4AppTracer ()  { };
 
   void
@@ -40,21 +40,19 @@
 
   virtual void
   PrintHeader (std::ostream &os) const = 0;
-  
+
   virtual void
   Print (std::ostream &os) const = 0;
 
   virtual void
   Rx (std::string context,
       const Ipv4Header &, Ptr<const Packet>, uint32_t) = 0;
-  
+
   virtual void
   Tx (std::string context,
       const Ipv4Header &, Ptr<const Packet>, uint32_t) = 0;
-  
+
 protected:
-  std::string m_app;
-  std::string m_appId;
   std::string m_node;
   Ptr<Node> m_nodePtr;
 };
diff --git a/utils/tracers/ipv4-seqs-app-tracer.cc b/utils/tracers/ipv4-seqs-app-tracer.cc
index 3147ed0..170f280 100644
--- a/utils/tracers/ipv4-seqs-app-tracer.cc
+++ b/utils/tracers/ipv4-seqs-app-tracer.cc
@@ -24,19 +24,60 @@
 #include "ns3/config.h"
 #include "ns3/callback.h"
 #include "ns3/simulator.h"
+#include "ns3/node-list.h"
+#include "ns3/node.h"
+#include "ns3/log.h"
 
 #include "ns3/tcp-l4-protocol.h"
 #include "ns3/tcp-header.h"
 #include "ns3/ipv4-header.h"
 
+#include <boost/lexical_cast.hpp>
+#include <fstream>
+
+NS_LOG_COMPONENT_DEFINE ("Ipv4SeqsAppTracer");
+
+using namespace boost;
+using namespace std;
+
 namespace ns3 {
-    
-Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (std::ostream &os, Ptr<Node> node, const std::string &appId)
-  : Ipv4AppTracer (node, appId)
+
+Ipv4SeqsAppTracer::Ipv4SeqsAppTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+  : Ipv4AppTracer (node)
   , m_os (os)
 {
 }
 
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4SeqsAppTracer> > >
+Ipv4SeqsAppTracer::InstallAll (const std::string &file)
+{
+  std::list<Ptr<Ipv4SeqsAppTracer> > 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: " << lexical_cast<string> ((*node)->GetId ()));
+
+      Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (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);
+}
+
 void
 Ipv4SeqsAppTracer::Reset ()
 {
@@ -47,8 +88,6 @@
 {
   os << "Time\t"
      << "Node\t"
-     << "AppName\t"
-     << "AppId\t"
      << "Type\t"
      << "SeqNo";
 }
@@ -59,13 +98,11 @@
 }
 
 #define PRINTER(type,size)                                         \
- m_os                                                              \
+ *m_os                                                              \
  << Simulator::Now ().ToDouble (Time::S) << "\t"                   \
  << m_node << "\t"                                                 \
- << m_app << "\t"                                                  \
- << m_appId << "\t"                                                \
  << type << "\t"                                                   \
- << size / 1040.0 << std::endl;
+ << static_cast<uint32_t> (size / 1040.0) << std::endl;
 
 void
 Ipv4SeqsAppTracer::Tx (std::string context,
@@ -86,25 +123,11 @@
 
   if (tcp.GetFlags () | TcpHeader::ACK)
     {
-      PRINTER("InAck", tcp.GetAckNumber ().GetValue ());
+      if (tcp.GetAckNumber ().GetValue () > 1000) // a little bit more cheating
+        {
+          PRINTER("InAck", tcp.GetAckNumber ().GetValue ());
+        }
     }
 }
-  
-
-// void
-// Ipv4SeqsAppTracer::InData (std::string context,
-//                            Ptr<const Packet> packet, const Address &address)
-// {
-//   PRINTER ("InData", m_inSeq);
-//   m_inSeq += packet->GetSize ();
-// }
-  
-// void
-// Ipv4SeqsAppTracer::OutData (std::string context,
-//                             Ptr<const Packet> packet)
-// {
-//   PRINTER ("OutData", m_outSeq);
-//   m_outSeq += packet->GetSize ();
-// }
 
 } // namespace ns3
diff --git a/utils/tracers/ipv4-seqs-app-tracer.h b/utils/tracers/ipv4-seqs-app-tracer.h
index 9ae24ac..5baa9f5 100644
--- a/utils/tracers/ipv4-seqs-app-tracer.h
+++ b/utils/tracers/ipv4-seqs-app-tracer.h
@@ -22,15 +22,30 @@
 #define IPV4_SEQS_APP_TRACER_H
 
 #include "ipv4-app-tracer.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/tuple/tuple.hpp>
 
 namespace ns3 {
 
 class Ipv4SeqsAppTracer : public Ipv4AppTracer
 {
 public:
-  Ipv4SeqsAppTracer (std::ostream &os, Ptr<Node> node, const std::string &appId = "*");
+  Ipv4SeqsAppTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
   virtual ~Ipv4SeqsAppTracer () { };
 
+  /**
+   * @brief Helper method to install tracers on all simulation nodes
+   *
+   * @param file File to which traces will be written
+   *
+   * @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<Ipv4SeqsAppTracer> > >
+  InstallAll (const std::string &file);
+
+
   virtual void
   PrintHeader (std::ostream &os) const;
 
@@ -50,7 +65,7 @@
   Reset ();
 
 protected:
-  std::ostream& m_os;
+  boost::shared_ptr<std::ostream> m_os;
 };
 
 } // namespace ns3
diff --git a/utils/tracers/ndn-app-delay-tracer.cc b/utils/tracers/ndn-app-delay-tracer.cc
index 3893d33..d659247 100644
--- a/utils/tracers/ndn-app-delay-tracer.cc
+++ b/utils/tracers/ndn-app-delay-tracer.cc
@@ -50,7 +50,7 @@
 {
   using namespace boost;
   using namespace std;
-  
+
   std::list<Ptr<AppDelayTracer> > tracers;
   boost::shared_ptr<std::ofstream> outputStream = make_shared<std::ofstream> ();
 
@@ -122,7 +122,8 @@
 void
 AppDelayTracer::PrintHeader (std::ostream &os) const
 {
-  os << "Node" << "\t"
+  os << "Time" << "\t"
+     << "Node" << "\t"
      << "AppId" << "\t"
      << "SeqNo" << "\t"
 
@@ -133,10 +134,11 @@
      << "HopCount"  << "";
 }
 
-void 
+void
 AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount)
 {
-  *m_os << m_node << "\t"
+  *m_os << Simulator::Now ().ToDouble (Time::S) << "\t"
+        << m_node << "\t"
         << app->GetId () << "\t"
         << seqno << "\t"
         << "LastDelay" << "\t"
@@ -145,11 +147,12 @@
         << 1 << "\t"
         << hopCount << "\n";
 }
-  
-void 
+
+void
 AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount)
 {
-  *m_os << m_node << "\t"
+  *m_os << Simulator::Now ().ToDouble (Time::S) << "\t"
+        << m_node << "\t"
         << app->GetId () << "\t"
         << seqno << "\t"
         << "FullDelay" << "\t"