Merge feature branch 'feature-l2-tracer'
diff --git a/docs/source/_static/l2-rate-tracer.png b/docs/source/_static/l2-rate-tracer.png
new file mode 100644
index 0000000..c930bd4
--- /dev/null
+++ b/docs/source/_static/l2-rate-tracer.png
Binary files differ
diff --git a/docs/source/_static/topo-tree-25-node.png b/docs/source/_static/topo-tree-25-node.png
new file mode 100644
index 0000000..ba39687
--- /dev/null
+++ b/docs/source/_static/topo-tree-25-node.png
Binary files differ
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index e32ba85..e8bb522 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -308,3 +308,8 @@
 This will generate ``ndn-simple-trace.pcap``, which can be fed to tcpdump::
 
      tcpdump -r ndn-simple-trace.pcap
+
+25-node tree topology with L2Tracer
+-----------------------------------
+
+:ref:`Example of packet drop tracer (L2Tracer)`
diff --git a/docs/source/metric.rst b/docs/source/metric.rst
index 4f1fa94..758bd3a 100644
--- a/docs/source/metric.rst
+++ b/docs/source/metric.rst
@@ -56,6 +56,28 @@
 
         ...
 
+- :ndnsim:`L2Tracer`
+ 
+   This tracer is similar in spirit to :ndnsim:`ndn::L3RateTracer`, but it currently traces only packet drop on layer 2 (e.g.,
+   due to transmission queue overflow).
+
+   The following example enables tracing on all simulation nodes:
+
+    .. code-block:: c++
+
+        // necessary includes
+	#include <ns3/ndnSIM/utils/tracers/l2-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<L2RateTracer> > >
+            l2tracers = L2RateTracer::InstallAll ("drop-trace.txt", Seconds (0.5));
+
+        Simulator::Run ();
+
+        ...
 
 .. note::
 
@@ -136,6 +158,48 @@
 
 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/>`_.
 
+.. _Example of packet drop tracer (L2Tracer):
+
+Example of packet drop tracer (L2Tracer)
+----------------------------------------
+
+This example (``ndn-tree-with-l2tracer.cc``) demonstrates basic usage of :ref:`trace classes`.
+
+In this scenario we will use a tree-like topology:
+
+.. image:: _static/topo-tree-25-node.png
+   :alt: 25-node tree topology
+
+The corresponding topology file (``topo-tree-25-node.txt``):
+
+.. literalinclude:: ../../examples/topologies/topo-tree-25-node.txt
+    :language: bash
+    :linenos:
+    :lines: 2-
+
+Example simulation (``ndn-tree-with-l2tracer.cc``) scenario that utilizes trace helpers:
+
+.. literalinclude:: ../../examples/ndn-tree-with-l2tracer.cc
+    :language: c++
+    :linenos:
+    :lines: 1-
+    :emphasize-lines: 7-8,19,135-139
+
+To run this scenario, use the following command::
+
+        ./waf --run=ndn-tree-with-l2tracer
+
+The successful run will create ``drop-trace.txt`` file 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:
+
+.. literalinclude:: ../../examples/graphs/drop-graph.R
+    :language: r
+    :linenos:
+
+.. image:: _static/l2-rate-tracer.png
+   :alt: Packet drop rates on routers
+
 .. _cs trace helper:
 
 Content store trace helper
diff --git a/examples/graphs/drop-graph.R b/examples/graphs/drop-graph.R
new file mode 100755
index 0000000..0f28f6e
--- /dev/null
+++ b/examples/graphs/drop-graph.R
@@ -0,0 +1,30 @@
+#!/usr/bin/env Rscript
+# Copyright (c) 2012-2013  Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+
+
+# install.packages ('ggplot2')
+library (ggplot2)
+## # install.packages ('scales')
+## library (scales)
+
+#########################
+# Rate trace processing #
+#########################
+data = read.table ("drop-trace.txt", header=T)
+data$Node = factor (data$Node)
+data$Kilobits <- data$Kilobytes * 8
+data$Type = factor (data$Type)
+
+## data.rtr = data[grep("Rtr", data$Node),]
+
+# graph rates on all nodes in Kilobits
+g.all <- ggplot (data, aes (x=Time, y=Kilobits, color=Type)) +
+  geom_point (size=2) +
+  geom_line () +
+  ylab ("Packet drop rate [Kbits/s]") +
+  facet_wrap (~ Node) +
+  theme_bw ()
+
+png ("drop-trace-all-nodes.png", width=800, height=500)
+print (g.all)
+x = dev.off ()
diff --git a/examples/ndn-tree-with-l2tracer.cc b/examples/ndn-tree-with-l2tracer.cc
new file mode 100644
index 0000000..d3e262e
--- /dev/null
+++ b/examples/ndn-tree-with-l2tracer.cc
@@ -0,0 +1,145 @@
+// ndn-simple-withl2tracer.cc
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+// for ndn::L2RateTracer
+#include <ns3/ndnSIM/utils/tracers/l2-rate-tracer.h>
+
+using namespace ns3;
+
+int
+main (int argc, char *argv[])
+{
+  CommandLine cmd;
+  cmd.Parse (argc, argv);
+
+  AnnotatedTopologyReader topologyReader ("", 10);
+  topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-tree-25-node.txt");
+  topologyReader.Read ();
+  
+  /****************************************************************************/
+  // Install CCNx stack on all nodes
+  ndn::StackHelper ccnxHelper;
+  ccnxHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "1000");
+  ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
+  ccnxHelper.InstallAll ();
+  /****************************************************************************/
+  // Installing global routing interface on all nodes
+  ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
+  ccnxGlobalRoutingHelper.InstallAll ();
+  /****************************************************************************/
+  // Getting containers for the consumer/producer
+  Ptr<Node> consumer1 = Names::Find<Node> ("Src1");
+  Ptr<Node> consumer2 = Names::Find<Node> ("Src2");
+  Ptr<Node> consumer3 = Names::Find<Node> ("Src3");
+  Ptr<Node> consumer4 = Names::Find<Node> ("Src4");
+  Ptr<Node> consumer5 = Names::Find<Node> ("Src5");
+  Ptr<Node> consumer6 = Names::Find<Node> ("Src6");
+  Ptr<Node> consumer7 = Names::Find<Node> ("Src7");
+  Ptr<Node> consumer8 = Names::Find<Node> ("Src8");
+  Ptr<Node> consumer9 = Names::Find<Node> ("Src9");
+
+  Ptr<Node> producer1 = Names::Find<Node> ("Dst1");
+  Ptr<Node> producer2 = Names::Find<Node> ("Dst2");
+  Ptr<Node> producer3 = Names::Find<Node> ("Dst3");
+  Ptr<Node> producer4 = Names::Find<Node> ("Dst4");
+  Ptr<Node> producer5 = Names::Find<Node> ("Dst5");
+  Ptr<Node> producer6 = Names::Find<Node> ("Dst6");
+  Ptr<Node> producer7 = Names::Find<Node> ("Dst7");
+  Ptr<Node> producer8 = Names::Find<Node> ("Dst8");
+  Ptr<Node> producer9 = Names::Find<Node> ("Dst9");
+  /****************************************************************************/
+  ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+  consumerHelper.SetAttribute ("Frequency", StringValue ("1000"));//interests per Second
+  consumerHelper.SetAttribute ("Randomize", StringValue ("uniform"));
+  /****************************************************************************/
+  // on the first to ninth consumer node install a Consumer application
+  // that will express interests in /dst1 to /dst9 namespace
+  consumerHelper.SetPrefix ("/dst9");
+  consumerHelper.Install (consumer1);
+
+  consumerHelper.SetPrefix ("/dst8");
+  consumerHelper.Install (consumer2);
+
+  consumerHelper.SetPrefix ("/dst7");
+  consumerHelper.Install (consumer3);
+
+  consumerHelper.SetPrefix ("/dst6");
+  consumerHelper.Install (consumer4);
+
+  consumerHelper.SetPrefix ("/dst5");
+  consumerHelper.Install (consumer5);
+
+  consumerHelper.SetPrefix ("/dst4");
+  consumerHelper.Install (consumer6);
+
+  consumerHelper.SetPrefix ("/dst3");
+  consumerHelper.Install (consumer7);
+
+  consumerHelper.SetPrefix ("/dst2");
+  consumerHelper.Install (consumer8);
+
+  consumerHelper.SetPrefix ("/dst1");
+  consumerHelper.Install (consumer9);
+  
+  /****************************************************************************/
+  ndn::AppHelper producerHelper ("ns3::ndn::Producer");
+  producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
+  /****************************************************************************/
+  // Register /dst1 to /dst9 prefix with global routing controller and
+  // install producer that will satisfy Interests in /dst1 to /dst9 namespace
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst1", producer1);
+  producerHelper.SetPrefix ("/dst1");
+  producerHelper.Install (producer1);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst2", producer2);
+  producerHelper.SetPrefix ("/dst2");
+  producerHelper.Install (producer2);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst3", producer3);
+  producerHelper.SetPrefix ("/dst3");
+  producerHelper.Install (producer3);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst4", producer4);
+  producerHelper.SetPrefix ("/dst4");
+  producerHelper.Install (producer4);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst5", producer5);
+  producerHelper.SetPrefix ("/dst5");
+  producerHelper.Install (producer5);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst6", producer6);
+  producerHelper.SetPrefix ("/dst6");
+  producerHelper.Install (producer6);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst7", producer7);
+  producerHelper.SetPrefix ("/dst7");
+  producerHelper.Install (producer7);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst8", producer8);
+  producerHelper.SetPrefix ("/dst8");
+  producerHelper.Install (producer8);
+
+  ccnxGlobalRoutingHelper.AddOrigins ("/dst9", producer9);
+  producerHelper.SetPrefix ("/dst9");
+  producerHelper.Install (producer9);
+
+  /*****************************************************************************/
+  // Calculate and install FIBs
+  ccnxGlobalRoutingHelper.CalculateRoutes ();
+
+  Simulator::Stop (Seconds (10.0));
+
+  /****************************************************************************/
+  //Tracer:
+
+  boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L2RateTracer> > >
+   l2tracers = L2RateTracer::InstallAll ("drop-trace.txt", Seconds (0.5));
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
diff --git a/examples/topologies/topo-tree-25-node.txt b/examples/topologies/topo-tree-25-node.txt
new file mode 100644
index 0000000..7b328f4
--- /dev/null
+++ b/examples/topologies/topo-tree-25-node.txt
@@ -0,0 +1,58 @@
+#Topology.Scenario3.txt
+
+router
+
+# node   comment  yPos    xPos
+Rtr1     NA        3        9
+Rtr2     NA        9        9
+Rtr3     NA        15       9
+Rtr7     NA        9        15
+Rtr4     NA        3        21
+Rtr5     NA        9        21
+Rtr6     NA        15       21
+Src1     NA        1        3
+Src2     NA        3        3
+Src3     NA        5        3
+Src4     NA        7        3
+Src5     NA        9        3
+Src6     NA        11       3
+Src7     NA        13       3
+Src8     NA        15       3
+Src9     NA        17       3
+Dst1     NA        1        27
+Dst2     NA        3        27
+Dst3     NA        5        27
+Dst4     NA        7        27
+Dst5     NA        9        27
+Dst6     NA        11       27
+Dst7     NA        13       27
+Dst8     NA        15       27
+Dst9     NA        17       27
+
+link
+# srcNode   dstNode     bandwidth   metric    delay   queue
+Src1        Rtr1        100Mbps      1        10ms     10
+Src2        Rtr1        100Mbps      1        10ms     10
+Src3        Rtr1        100Mbps      1        10ms     10
+Src4        Rtr2        100Mbps      1        10ms     10
+Src5        Rtr2        100Mbps      1        10ms     10
+Src6        Rtr2        100Mbps      1        10ms     10
+Src7        Rtr3        100Mbps      1        10ms     10
+Src8        Rtr3        100Mbps      1        10ms     10
+Src9        Rtr3        100Mbps      1        10ms     10
+Rtr1        Rtr7        10Mbps       1        10ms     10
+Rtr2        Rtr7        10Mbps       1        10ms     10
+Rtr3        Rtr7        10Mbps       1        10ms     10
+Rtr4        Rtr7        10Mbps       1        10ms     10
+Rtr5        Rtr7        10Mbps       1        10ms     10
+Rtr6        Rtr7        10Mbps       1        10ms     10
+Dst1        Rtr4        100Mbps      1        10ms     10
+Dst2        Rtr4        100Mbps      1        10ms     10
+Dst3        Rtr4        100Mbps      1        10ms     10
+Dst4        Rtr5        100Mbps      1        10ms     10
+Dst5        Rtr5        100Mbps      1        10ms     10
+Dst6        Rtr5        100Mbps      1        10ms     10
+Dst7        Rtr6        100Mbps      1        10ms     10
+Dst8        Rtr6        100Mbps      1        10ms     10
+Dst9        Rtr6        100Mbps      1        10ms     10
+
diff --git a/examples/wscript b/examples/wscript
index b33cbf3..965eb25 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -42,6 +42,9 @@
         obj = bld.create_ns3_program('ndn-tree-app-delay-tracer', ['ndnSIM'])
         obj.source = 'ndn-tree-app-delay-tracer.cc'
 
+        obj = bld.create_ns3_program('ndn-tree-with-l2tracer', ['ndnSIM'])
+        obj.source = 'ndn-tree-with-l2tracer.cc'
+
     obj = bld.create_ns3_program('ndn-simple-pit-policies', ['ndnSIM'])
     obj.source = 'ndn-simple-pit-policies.cc'
 
diff --git a/utils/tracers/l2-rate-tracer.cc b/utils/tracers/l2-rate-tracer.cc
new file mode 100644
index 0000000..823977b
--- /dev/null
+++ b/utils/tracers/l2-rate-tracer.cc
@@ -0,0 +1,155 @@
+/* -*- 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 "l2-rate-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#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 <boost/lexical_cast.hpp>
+#include <fstream>
+
+using namespace boost;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("L2RateTracer");
+
+namespace ns3 {
+
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L2RateTracer> > >
+L2RateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+{
+  std::list<Ptr<L2RateTracer> > 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<L2RateTracer> trace = Create<L2RateTracer> (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);
+}
+
+
+L2RateTracer::L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+  : L2Tracer (node)
+  , m_os (os)
+{
+  SetAveragingPeriod (Seconds (1.0));
+}
+
+L2RateTracer::~L2RateTracer ()
+{
+  m_printEvent.Cancel ();
+}
+
+void
+L2RateTracer::SetAveragingPeriod (const Time &period)
+{
+  m_period = period;
+  m_printEvent.Cancel ();
+  m_printEvent = Simulator::Schedule (m_period, &L2RateTracer::PeriodicPrinter, this);
+}
+
+void
+L2RateTracer::PeriodicPrinter ()
+{
+  Print (*m_os);
+  Reset ();
+
+  m_printEvent = Simulator::Schedule (m_period, &L2RateTracer::PeriodicPrinter, this);
+}
+
+void
+L2RateTracer::PrintHeader (std::ostream &os) const
+{
+  os << "Time" << "\t"
+
+     << "Node" << "\t"
+     << "Interface" << "\t"
+
+     << "Type" << "\t"
+     << "Packets" << "\t"
+     << "Kilobytes";
+}
+
+void
+L2RateTracer::Reset ()
+{
+  m_stats.get<0> ().Reset ();
+  m_stats.get<1> ().Reset ();
+}
+
+const double alpha = 0.8;
+
+#define STATS(INDEX) m_stats.get<INDEX> ()
+#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
+
+#define PRINTER(printName, fieldName, interface)                        \
+STATS(2).fieldName = /*new value*/alpha * RATE(0, fieldName) + /*old value*/(1-alpha) * STATS(2).fieldName; \
+STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
+                                                                        \
+ os << time.ToDouble (Time::S) << "\t"                                  \
+ << m_node << "\t"                                                      \
+ << interface << "\t"                                                  \
+ << printName << "\t"                                                   \
+ << STATS(2).fieldName  << "\t"                                         \
+ << STATS(3).fieldName << "\n";
+
+void
+L2RateTracer::Print (std::ostream &os) const
+{
+  Time time = Simulator::Now ();
+
+  PRINTER ("Drop", m_drop, "combined");
+}
+
+void
+L2RateTracer::Drop (Ptr<const Packet> packet)
+{
+  // no interface information... this should be part of this L2Tracer object data
+
+  m_stats.get<0> ().m_drop ++;
+  m_stats.get<1> ().m_drop += packet->GetSize ();
+}
+
+} // namespace ns3
diff --git a/utils/tracers/l2-rate-tracer.h b/utils/tracers/l2-rate-tracer.h
new file mode 100644
index 0000000..48105ac
--- /dev/null
+++ b/utils/tracers/l2-rate-tracer.h
@@ -0,0 +1,90 @@
+/* -*- 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 L2_RATE_TRACER_H
+#define L2_RATE_TRACER_H
+
+#include "l2-tracer.h"
+
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+
+#include <boost/tuple/tuple.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+
+namespace ns3 {
+
+/**
+ * @ingroup ndn
+ */
+class L2RateTracer : public L2Tracer
+{
+public:
+  /**
+   * @brief Network layer tracer constructor
+   */
+  L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+  virtual ~L2RateTracer ();
+
+  /**
+   * @brief Helper method to install tracers on all simulation nodes
+   *
+   * @param file File to which traces will be written
+   * @param averagingPeriod Defines averaging period for the rate calculation,
+   *        as well as 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<L2RateTracer> > >
+  InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
+
+  void
+  SetAveragingPeriod (const Time &period);
+
+  virtual void
+  PrintHeader (std::ostream &os) const;
+
+  virtual void
+  Print (std::ostream &os) const;
+
+  virtual void
+  Drop (Ptr<const Packet>);
+
+private:
+  void
+  PeriodicPrinter ();
+
+  void
+  Reset ();
+
+private:
+  boost::shared_ptr<std::ostream> m_os;
+  Time m_period;
+  EventId m_printEvent;
+
+  mutable boost::tuple<Stats, Stats, Stats, Stats> m_stats;
+};
+
+} // namespace ns3
+
+#endif // L2_RATE_TRACER_H
diff --git a/utils/tracers/l2-tracer.cc b/utils/tracers/l2-tracer.cc
new file mode 100644
index 0000000..a3dc05b
--- /dev/null
+++ b/utils/tracers/l2-tracer.cc
@@ -0,0 +1,54 @@
+/* -*- 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 "l2-tracer.h"
+#include "ns3/node.h"
+#include "ns3/config.h"
+#include "ns3/names.h"
+#include "ns3/callback.h"
+
+#include <boost/lexical_cast.hpp>
+
+using namespace std;
+
+namespace ns3 {
+
+L2Tracer::L2Tracer (Ptr<Node> node)
+: m_nodePtr (node)
+{
+  m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
+
+  Connect ();
+
+  string name = Names::FindName (node);
+  if (!name.empty ())
+    {
+      m_node = name;
+    }
+}
+
+void
+L2Tracer::Connect ()
+{
+  Config::ConnectWithoutContext ("/NodeList/"+m_node+"/DeviceList/*/TxQueue/Drop",
+                                 MakeCallback (&L2Tracer::Drop, this));
+}
+
+} // namespace ns3
diff --git a/utils/tracers/l2-tracer.h b/utils/tracers/l2-tracer.h
new file mode 100644
index 0000000..a937d66
--- /dev/null
+++ b/utils/tracers/l2-tracer.h
@@ -0,0 +1,84 @@
+/* -*- 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 L2_TRACER_H
+#define L2_TRACER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+#include "ns3/packet.h"
+
+namespace ns3 {
+
+class Node;
+
+class L2Tracer : public SimpleRefCount<L2Tracer>
+{
+public:
+  L2Tracer (Ptr<Node> node);
+  virtual ~L2Tracer () { };
+
+  void
+  Connect ();
+
+  virtual void
+  PrintHeader (std::ostream &os) const = 0;
+
+  virtual void
+  Print (std::ostream &os) const = 0;
+
+  virtual void
+  Drop (Ptr<const Packet>) = 0;
+
+  // Rx/Tx is NetDevice specific
+  // please refer to pyviz.cc in order to extend this tracer
+
+protected:
+  std::string m_node;
+  Ptr<Node> m_nodePtr;
+
+  struct Stats
+  {
+    void Reset ()
+    {
+      m_in = 0;
+      m_out = 0;
+      m_drop = 0;
+    }
+
+    uint64_t m_in;
+    uint64_t m_out;
+    uint64_t m_drop;
+  };
+};
+
+inline std::ostream&
+operator << (std::ostream &os, const L2Tracer &tracer)
+{
+  os << "# ";
+  tracer.PrintHeader (os);
+  os << "\n";
+  tracer.Print (os);
+  return os;
+}
+
+} // namespace ns3
+
+#endif // L2_TRACER_H