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-cs-tracer.cc b/utils/tracers/ndn-cs-tracer.cc
index 40aed8f..0c1becb 100644
--- a/utils/tracers/ndn-cs-tracer.cc
+++ b/utils/tracers/ndn-cs-tracer.cc
@@ -44,13 +44,15 @@
namespace ns3 {
namespace ndn {
+static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer> > > > g_tracers;
+
template<class T>
static inline void
NullDeleter (T *ptr)
{
}
-boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsTracer> > >
+void
CsTracer::InstallAll (const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
using namespace boost;
@@ -64,7 +66,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;
}
@@ -88,10 +93,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<CsTracer> > >
+void
CsTracer::Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
using namespace boost;
@@ -105,7 +110,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;
}
@@ -129,10 +137,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<CsTracer> > >
+void
CsTracer::Install (Ptr<Node> node, const std::string &file, Time averagingPeriod/* = Seconds (0.5)*/)
{
using namespace boost;
@@ -146,7 +154,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;
}
@@ -165,14 +176,14 @@
*outputStream << "\n";
}
- return boost::make_tuple (outputStream, tracers);
+ g_tracers.push_back (boost::make_tuple (outputStream, tracers));
}
Ptr<CsTracer>
CsTracer::Install (Ptr<Node> node,
- boost::shared_ptr<std::ostream> outputStream,
- Time averagingPeriod/* = Seconds (0.5)*/)
+ boost::shared_ptr<std::ostream> outputStream,
+ Time averagingPeriod/* = Seconds (0.5)*/)
{
NS_LOG_DEBUG ("Node: " << node->GetId ());