utils/tracers: Modifying (simplifying) interface for ndnSIM tracers
Now most of the tracers internally keep created instances in a global
variable. From now on, to start tracing, one needs just install a
necessary tracer, like this:
ndn::L3RateTracer::InstallAll ("rate-trace.txt", Seconds (0.5));
Because of the change, it became possible to use the same tracers inside
python scripts.
Also, this commits contains corresponding documentation updates.
diff --git a/utils/tracers/ndn-l3-rate-tracer.cc b/utils/tracers/ndn-l3-rate-tracer.cc
index 43f8f0a..435a652 100644
--- a/utils/tracers/ndn-l3-rate-tracer.cc
+++ b/utils/tracers/ndn-l3-rate-tracer.cc
@@ -44,13 +44,15 @@
namespace ns3 {
namespace ndn {
+static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > > g_tracers;
+
template<class T>
static inline void
NullDeleter (T *ptr)
{
}
-boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
+void
L3RateTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
std::list<Ptr<L3RateTracer> > tracers;
@@ -61,7 +63,10 @@
os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!os->is_open ())
- return boost::make_tuple (outputStream, tracers);
+ {
+ NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
+ }
outputStream = os;
}
@@ -85,10 +90,10 @@
*outputStream << "\n";
}
- return boost::make_tuple (outputStream, tracers);
+ g_tracers.push_back (boost::make_tuple (outputStream, tracers));
}
-boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
+void
L3RateTracer::Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
using namespace boost;
@@ -102,7 +107,10 @@
os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!os->is_open ())
- return boost::make_tuple (outputStream, tracers);
+ {
+ NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
+ }
outputStream = os;
}
@@ -126,10 +134,10 @@
*outputStream << "\n";
}
- return boost::make_tuple (outputStream, tracers);
+ g_tracers.push_back (boost::make_tuple (outputStream, tracers));
}
-boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
+void
L3RateTracer::Install (Ptr<Node> node, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
using namespace boost;
@@ -143,7 +151,10 @@
os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!os->is_open ())
- return boost::make_tuple (outputStream, tracers);
+ {
+ NS_LOG_ERROR ("File " << file << " cannot be opened for writing. Tracing disabled");
+ return;
+ }
outputStream = os;
}
@@ -162,7 +173,7 @@
*outputStream << "\n";
}
- return boost::make_tuple (outputStream, tracers);
+ g_tracers.push_back (boost::make_tuple (outputStream, tracers));
}