utils: Adding some NDN network-layer rate tracers
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.cc b/utils/tracers/ndn-l3-aggregate-tracer.cc
new file mode 100644
index 0000000..1280ede
--- /dev/null
+++ b/utils/tracers/ndn-l3-aggregate-tracer.cc
@@ -0,0 +1,193 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-l3-aggregate-tracer.h"
+
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/callback.h"
+#include "ns3/ndn-app.h"
+#include "ns3/ndn-face.h"
+#include "ns3/ndn-interest.h"
+#include "ns3/ndn-content-object.h"
+
+namespace ns3 {
+namespace ndn {
+
+L3AggregateTracer::L3AggregateTracer (Ptr<Node> node)
+: L3Tracer (node)
+{
+ Reset ();
+}
+
+L3AggregateTracer::L3AggregateTracer (const std::string &node)
+: L3Tracer (node)
+{
+ Reset ();
+}
+
+L3AggregateTracer::~L3AggregateTracer ()
+{
+};
+
+void
+L3AggregateTracer::Reset ()
+{
+ m_packets.Reset ();
+ m_bytes.Reset ();
+}
+
+
+void
+L3AggregateTracer::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" << "\t"
+
+ << "InInterestsBytes" << "\t"
+ << "OutInterestsBytes" << "\t"
+ << "DropInterestsBytes" << "\t"
+
+ << "InNacksBytes" << "\t"
+ << "OutNacksBytes" << "\t"
+ << "DropNacksBytes" << "\t"
+
+ << "InDataBytes" << "\t"
+ << "OutDataBytes" << "\t"
+ << "DropDataBytes";
+}
+
+void
+L3AggregateTracer::Print (std::ostream &os) const
+{
+ os << m_node << "\t"
+ << m_packets.m_inInterests << "\t"
+ << m_packets.m_outInterests << "\t"
+ << m_packets.m_dropInterests << "\t"
+
+ << m_packets.m_inNacks << "\t"
+ << m_packets.m_outNacks << "\t"
+ << m_packets.m_dropNacks << "\t"
+
+ << m_packets.m_inData << "\t"
+ << m_packets.m_outData << "\t"
+ << m_packets.m_dropData << "\t"
+
+ << m_bytes.m_inInterests << "\t"
+ << m_bytes.m_outInterests << "\t"
+ << m_bytes.m_dropInterests << "\t"
+
+ << m_bytes.m_inNacks << "\t"
+ << m_bytes.m_outNacks << "\t"
+ << m_bytes.m_dropNacks << "\t"
+
+ << m_bytes.m_inData << "\t"
+ << m_bytes.m_outData << "\t"
+ << m_bytes.m_dropData;
+}
+
+void
+L3AggregateTracer::OutInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_outInterests++;
+ m_bytes.m_outInterests += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::InInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_inInterests++;
+ m_bytes.m_inInterests += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::DropInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_dropInterests++;
+ m_bytes.m_dropInterests += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::OutNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_outNacks++;
+ m_bytes.m_outNacks += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::InNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_inNacks++;
+ m_bytes.m_inNacks += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::DropNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face>)
+{
+ m_packets.m_dropNacks++;
+ m_bytes.m_dropNacks += header->GetSerializedSize ();
+}
+
+void
+L3AggregateTracer::OutData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ bool fromCache, Ptr<const Face>)
+{
+ m_packets.m_outData++;
+ m_bytes.m_outData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+void
+L3AggregateTracer::InData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ Ptr<const Face>)
+{
+ m_packets.m_inData++;
+ m_bytes.m_inData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+void
+L3AggregateTracer::DropData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ Ptr<const Face>)
+{
+ m_packets.m_dropData++;
+ m_bytes.m_dropData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/tracers/ndn-l3-aggregate-tracer.h b/utils/tracers/ndn-l3-aggregate-tracer.h
new file mode 100644
index 0000000..bd9cbd0
--- /dev/null
+++ b/utils/tracers/ndn-l3-aggregate-tracer.h
@@ -0,0 +1,99 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_L3_AGGREGATE_TRACER_H
+#define NDN_L3_AGGREGATE_TRACER_H
+
+#include "ndn-l3-tracer.h"
+
+#include <ns3/nstime.h>
+#include <ns3/event-id.h>
+
+namespace ns3 {
+namespace ndn {
+
+class L3AggregateTracer : public L3Tracer
+{
+public:
+ L3AggregateTracer (Ptr<Node> node);
+ L3AggregateTracer (const std::string &node);
+ virtual ~L3AggregateTracer ();
+
+ virtual void
+ PrintHeader (std::ostream &os) const;
+
+ virtual void
+ Print (std::ostream &os) const;
+
+ virtual void
+ OutInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ InInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ DropInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ OutNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ InNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ DropNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ OutData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
+
+ virtual void
+ InData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
+
+ virtual void
+ DropData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
+
+protected:
+ void
+ Reset ();
+
+ void
+ PeriodicPrinter ();
+
+protected:
+ Stats m_packets;
+ Stats m_bytes;
+
+ Time m_period;
+ EventId m_printEvent;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_L3_AGGREGATE_TRACER_H
diff --git a/utils/tracers/ndn-l3-rate-tracer.cc b/utils/tracers/ndn-l3-rate-tracer.cc
new file mode 100644
index 0000000..6604f0b
--- /dev/null
+++ b/utils/tracers/ndn-l3-rate-tracer.cc
@@ -0,0 +1,262 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-l3-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/log.h"
+#include "ns3/node-list.h"
+
+#include "ns3/ndn-app.h"
+#include "ns3/ndn-face.h"
+#include "ns3/ndn-interest.h"
+#include "ns3/ndn-content-object.h"
+
+#include <fstream>
+#include <boost/lexical_cast.hpp>
+
+using namespace boost;
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("ndn.L3RateTracer");
+
+namespace ns3 {
+namespace ndn {
+
+
+boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
+L3RateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
+{
+ std::list<Ptr<L3RateTracer> > 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<L3RateTracer> trace = Create<L3RateTracer> (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);
+}
+
+
+L3RateTracer::L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
+ : L3Tracer (node)
+ , m_os (os)
+{
+ SetAveragingPeriod (Seconds (1.0));
+}
+
+L3RateTracer::L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node)
+ : L3Tracer (node)
+ , m_os (os)
+{
+ SetAveragingPeriod (Seconds (1.0));
+}
+
+L3RateTracer::~L3RateTracer ()
+{
+ m_printEvent.Cancel ();
+}
+
+void
+L3RateTracer::SetAveragingPeriod (const Time &period)
+{
+ m_period = period;
+ m_printEvent.Cancel ();
+ m_printEvent = Simulator::Schedule (m_period, &L3RateTracer::PeriodicPrinter, this);
+}
+
+void
+L3RateTracer::PeriodicPrinter ()
+{
+ Print (*m_os);
+ Reset ();
+
+ m_printEvent = Simulator::Schedule (m_period, &L3RateTracer::PeriodicPrinter, this);
+}
+
+void
+L3RateTracer::PrintHeader (std::ostream &os) const
+{
+ os << "Time" << "\t"
+
+ << "Node" << "\t"
+ << "FaceId" << "\t"
+ << "FaceDescr" << "\t"
+
+ << "Type" << "\t"
+ << "Packets" << "\t"
+ << "Kilobytes" << "\t"
+ << "PacketRaw" << "\t"
+ << "KilobytesRaw";
+}
+
+void
+L3RateTracer::Reset ()
+{
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
+ stats != m_stats.end ();
+ stats++)
+ {
+ stats->second.get<0> ().Reset ();
+ stats->second.get<1> ().Reset ();
+ }
+}
+
+const double alpha = 0.8;
+
+#define STATS(INDEX) stats->second.get<INDEX> ()
+#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
+
+#define PRINTER(printName, fieldName) \
+ 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" \
+ << stats->first->GetId () << "\t" \
+ << *stats->first << "\t" \
+ << printName << "\t" \
+ << STATS(2).fieldName << "\t" \
+ << STATS(3).fieldName << "\t" \
+ << STATS(0).fieldName << "\t" \
+ << STATS(1).fieldName << "\n";
+
+void
+L3RateTracer::Print (std::ostream &os) const
+{
+ for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
+ stats != m_stats.end ();
+ stats++)
+ {
+ Time time = Simulator::Now ();
+
+ PRINTER ("InInterests", m_inInterests);
+ PRINTER ("OutInterests", m_outInterests);
+ // PRINTER ("DropInterests", m_dropInterests);
+
+ PRINTER ("InNacks", m_inNacks);
+ PRINTER ("OutNacks", m_outNacks);
+ // PRINTER ("DropNacks", m_dropNacks);
+
+ PRINTER ("InData", m_inData);
+ PRINTER ("OutData", m_outData);
+ // PRINTER ("DropData", m_dropData);
+ }
+}
+
+
+void
+L3RateTracer::OutInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_outInterests ++;
+ m_stats[face].get<1> ().m_outInterests += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::InInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_inInterests ++;
+ m_stats[face].get<1> ().m_inInterests += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::DropInterests (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_dropInterests ++;
+ m_stats[face].get<1> ().m_dropInterests += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::OutNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_outNacks ++;
+ m_stats[face].get<1> ().m_outNacks += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::InNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_inNacks ++;
+ m_stats[face].get<1> ().m_inNacks += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::DropNacks (std::string context,
+ Ptr<const InterestHeader> header, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_dropNacks ++;
+ m_stats[face].get<1> ().m_dropNacks += header->GetSerializedSize ();
+}
+
+void
+L3RateTracer::OutData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ bool fromCache, Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_inData ++;
+ m_stats[face].get<1> ().m_inData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+void
+L3RateTracer::InData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_outData ++;
+ m_stats[face].get<1> ().m_outData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+void
+L3RateTracer::DropData (std::string context,
+ Ptr<const ContentObjectHeader> header, Ptr<const Packet> payload,
+ Ptr<const Face> face)
+{
+ m_stats[face].get<0> ().m_dropData ++;
+ m_stats[face].get<1> ().m_dropData += header->GetSerializedSize () + payload->GetSize ();
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/tracers/ndn-l3-rate-tracer.h b/utils/tracers/ndn-l3-rate-tracer.h
new file mode 100644
index 0000000..ced3113
--- /dev/null
+++ b/utils/tracers/ndn-l3-rate-tracer.h
@@ -0,0 +1,117 @@
+/* -*- 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_RATE_L3_TRACER_H
+#define CCNX_RATE_L3_TRACER_H
+
+#include "ndn-l3-tracer.h"
+
+#include "ns3/nstime.h"
+#include "ns3/event-id.h"
+
+#include <boost/tuple/tuple.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include <list>
+
+namespace ns3 {
+namespace ndn {
+
+/**
+ * @ingroup ccnx
+ * @brief CCNx network-layer rate tracer
+ */
+class L3RateTracer : public L3Tracer
+{
+public:
+ /**
+ * @brief Network layer tracer constructor
+ */
+ L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
+ L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
+ virtual ~L3RateTracer ();
+
+ static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
+ 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
+ OutInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ InInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ DropInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ OutNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ InNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ DropNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>);
+
+ virtual void
+ OutData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
+
+ virtual void
+ InData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
+
+ virtual void
+ DropData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
+
+private:
+ void
+ PeriodicPrinter ();
+
+ void
+ Reset ();
+
+private:
+ boost::shared_ptr<std::ostream> m_os;
+ Time m_period;
+ EventId m_printEvent;
+
+ mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
+};
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // CCNX_RATE_L3_TRACER_H
diff --git a/utils/tracers/ndn-l3-tracer.cc b/utils/tracers/ndn-l3-tracer.cc
new file mode 100644
index 0000000..847de2a
--- /dev/null
+++ b/utils/tracers/ndn-l3-tracer.cc
@@ -0,0 +1,91 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011 UCLA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndn-l3-tracer.h"
+#include "ns3/node.h"
+#include "ns3/packet.h"
+#include "ns3/config.h"
+#include "ns3/names.h"
+#include "ns3/callback.h"
+
+#include <boost/lexical_cast.hpp>
+
+#include "ns3/ndn-face.h"
+#include "ns3/ndn-interest.h"
+#include "ns3/ndn-content-object.h"
+
+using namespace std;
+
+namespace ns3 {
+namespace ndn {
+
+L3Tracer::L3Tracer (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;
+ }
+}
+
+L3Tracer::L3Tracer (const std::string &node)
+: m_node (node)
+{
+ Connect ();
+}
+
+L3Tracer::~L3Tracer ()
+{
+};
+
+
+void
+L3Tracer::Connect ()
+{
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/OutInterests",
+ MakeCallback (&L3Tracer::OutInterests, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/InInterests",
+ MakeCallback (&L3Tracer::InInterests, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/DropInterests",
+ MakeCallback (&L3Tracer::DropInterests, this));
+
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/OutData",
+ MakeCallback (&L3Tracer::OutData, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/InData",
+ MakeCallback (&L3Tracer::InData, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/DropData",
+ MakeCallback (&L3Tracer::DropData, this));
+
+ // only for some strategies
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/OutNacks",
+ MakeCallback (&L3Tracer::OutNacks, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/InNacks",
+ MakeCallback (&L3Tracer::InNacks, this));
+ Config::Connect ("/NodeList/"+m_node+"/$ns3::ndn::ForwardingStrategy/DropNacks",
+ MakeCallback (&L3Tracer::DropNacks, this));
+}
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/tracers/ndn-l3-tracer.h b/utils/tracers/ndn-l3-tracer.h
new file mode 100644
index 0000000..74c0ef9
--- /dev/null
+++ b/utils/tracers/ndn-l3-tracer.h
@@ -0,0 +1,135 @@
+/* -*- 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>
+ */
+
+#ifndef CCNX_L3_TRACER_H
+#define CCNX_L3_TRACER_H
+
+#include "ns3/ptr.h"
+#include "ns3/simple-ref-count.h"
+
+namespace ns3 {
+
+class Node;
+class Packet;
+
+namespace ndn {
+
+class InterestHeader;
+class Face;
+class ContentObjectHeader;
+
+class L3Tracer : public SimpleRefCount<L3Tracer>
+{
+public:
+ L3Tracer (Ptr<Node> node);
+ L3Tracer (const std::string &node);
+ virtual ~L3Tracer ();
+
+ void
+ Connect ();
+
+ virtual void
+ PrintHeader (std::ostream &os) const = 0;
+
+ virtual void
+ Print (std::ostream &os) const = 0;
+
+ virtual void
+ OutInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+ virtual void
+ InInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+ virtual void
+ DropInterests (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+ virtual void
+ OutNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+ virtual void
+ InNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+ virtual void
+ DropNacks (std::string context,
+ Ptr<const InterestHeader>, Ptr<const Face>) = 0;
+
+
+ virtual void
+ OutData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
+
+ virtual void
+ InData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>) = 0;
+
+ virtual void
+ DropData (std::string context,
+ Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>) = 0;
+
+protected:
+ std::string m_node;
+ Ptr<Node> m_nodePtr;
+
+ struct Stats
+ {
+ inline void Reset ()
+ {
+ 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;
+ }
+
+ double m_inInterests;
+ double m_outInterests;
+ double m_dropInterests;
+ double m_inNacks;
+ double m_outNacks;
+ double m_dropNacks;
+ double m_inData;
+ double m_outData;
+ double m_dropData;
+ };
+};
+
+inline std::ostream&
+operator << (std::ostream &os, const L3Tracer &tracer)
+{
+ os << "# ";
+ tracer.PrintHeader (os);
+ os << "\n";
+ tracer.Print (os);
+ return os;
+}
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // CCNX_L3_TRACER_H