app+utils+doc: Adding application-level trace helper to record Interest-Data delays
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;
}