21 #include "ndn-l3-aggregate-tracer.h"
24 #include "ns3/packet.h"
25 #include "ns3/config.h"
26 #include "ns3/callback.h"
27 #include "ns3/ndn-app.h"
28 #include "ns3/ndn-face.h"
29 #include "ns3/ndn-interest.h"
30 #include "ns3/ndn-data.h"
31 #include "ns3/ndn-pit-entry.h"
33 #include "ns3/simulator.h"
34 #include "ns3/node-list.h"
39 NS_LOG_COMPONENT_DEFINE (
"ndn.L3AggregateTracer");
44 static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > > > g_tracers;
61 using namespace boost;
64 std::list<Ptr<L3AggregateTracer> > tracers;
65 boost::shared_ptr<std::ostream> outputStream;
68 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
69 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
73 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
81 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
84 for (NodeList::Iterator node = NodeList::Begin ();
85 node != NodeList::End ();
88 Ptr<L3AggregateTracer> trace =
Install (*node, outputStream, averagingPeriod);
89 tracers.push_back (trace);
92 if (tracers.size () > 0)
95 tracers.front ()->PrintHeader (*outputStream);
96 *outputStream <<
"\n";
99 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
105 using namespace boost;
108 std::list<Ptr<L3AggregateTracer> > tracers;
109 boost::shared_ptr<std::ostream> outputStream;
112 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
113 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
117 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
125 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
128 for (NodeContainer::Iterator node = nodes.Begin ();
129 node != nodes.End ();
132 Ptr<L3AggregateTracer> trace =
Install (*node, outputStream, averagingPeriod);
133 tracers.push_back (trace);
136 if (tracers.size () > 0)
139 tracers.front ()->PrintHeader (*outputStream);
140 *outputStream <<
"\n";
143 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
149 using namespace boost;
152 std::list<Ptr<L3AggregateTracer> > tracers;
153 boost::shared_ptr<std::ostream> outputStream;
156 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
157 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
161 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
169 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
172 Ptr<L3AggregateTracer> trace =
Install (node, outputStream, averagingPeriod);
173 tracers.push_back (trace);
175 if (tracers.size () > 0)
178 tracers.front ()->PrintHeader (*outputStream);
179 *outputStream <<
"\n";
182 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
186 Ptr<L3AggregateTracer>
188 boost::shared_ptr<std::ostream> outputStream,
189 Time averagingPeriod)
191 NS_LOG_DEBUG (
"Node: " << node->GetId ());
193 Ptr<L3AggregateTracer> trace = Create<L3AggregateTracer> (outputStream, node);
194 trace->SetAveragingPeriod (averagingPeriod);
218 L3AggregateTracer::SetAveragingPeriod (
const Time &period)
221 m_printEvent.Cancel ();
222 m_printEvent = Simulator::Schedule (m_period, &L3AggregateTracer::PeriodicPrinter,
this);
226 L3AggregateTracer::PeriodicPrinter ()
231 m_printEvent = Simulator::Schedule (m_period, &L3AggregateTracer::PeriodicPrinter,
this);
241 <<
"FaceDescr" <<
"\t"
249 L3AggregateTracer::Reset ()
251 for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.begin ();
252 stats != m_stats.end ();
255 stats->second.get<0> ().Reset ();
256 stats->second.get<1> ().Reset ();
261 #define STATS(INDEX) stats->second.get<INDEX> ()
263 #define PRINTER(printName, fieldName) \
264 os << time.ToDouble (Time::S) << "\t" \
269 << stats->first->GetId () << "\t" \
270 << *stats->first << "\t"; \
277 << printName << "\t" \
278 << STATS(0).fieldName << "\t" \
279 << STATS(1).fieldName / 1024.0 << "\n";
285 Time time = Simulator::Now ();
287 for (std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.begin ();
288 stats != m_stats.end ();
294 PRINTER (
"InInterests", m_inInterests);
295 PRINTER (
"OutInterests", m_outInterests);
296 PRINTER (
"DropInterests", m_dropInterests);
298 PRINTER (
"InNacks", m_inNacks);
299 PRINTER (
"OutNacks", m_outNacks);
300 PRINTER (
"DropNacks", m_dropNacks);
302 PRINTER (
"InData", m_inData);
303 PRINTER (
"OutData", m_outData);
304 PRINTER (
"DropData", m_dropData);
308 std::map<Ptr<const Face>, boost::tuple<Stats, Stats> >::iterator stats = m_stats.find (Ptr<const Face> (0));
309 if (stats != m_stats.end ())
311 PRINTER (
"SatisfiedInterests", m_satisfiedInterests);
312 PRINTER (
"TimedOutInterests", m_timedOutInterests);
318 L3AggregateTracer::OutInterests (Ptr<const Interest> interest, Ptr<const Face> face)
320 m_stats[face].get<0> ().m_outInterests ++;
321 if (interest->GetWire ())
323 m_stats[face].get<1> ().m_outInterests += interest->GetWire ()->GetSize ();
328 L3AggregateTracer::InInterests (Ptr<const Interest> interest, Ptr<const Face> face)
330 m_stats[face].get<0> ().m_inInterests ++;
331 if (interest->GetWire ())
333 m_stats[face].get<1> ().m_inInterests += interest->GetWire ()->GetSize ();
338 L3AggregateTracer::DropInterests (Ptr<const Interest> interest, Ptr<const Face> face)
340 m_stats[face].get<0> ().m_dropInterests ++;
341 if (interest->GetWire ())
343 m_stats[face].get<1> ().m_dropInterests += interest->GetWire ()->GetSize ();
348 L3AggregateTracer::OutNacks (Ptr<const Interest> nack, Ptr<const Face> face)
350 m_stats[face].get<0> ().m_outNacks ++;
351 if (nack->GetWire ())
353 m_stats[face].get<1> ().m_outNacks += nack->GetWire ()->GetSize ();
358 L3AggregateTracer::InNacks (Ptr<const Interest> nack, Ptr<const Face> face)
360 m_stats[face].get<0> ().m_inNacks ++;
361 if (nack->GetWire ())
363 m_stats[face].get<1> ().m_inNacks += nack->GetWire ()->GetSize ();
368 L3AggregateTracer::DropNacks (Ptr<const Interest> nack, Ptr<const Face> face)
370 m_stats[face].get<0> ().m_dropNacks ++;
371 if (nack->GetWire ())
373 m_stats[face].get<1> ().m_dropNacks += nack->GetWire ()->GetSize ();
378 L3AggregateTracer::OutData (Ptr<const Data> data,
379 bool fromCache, Ptr<const Face> face)
381 m_stats[face].get<0> ().m_outData ++;
382 if (data->GetWire ())
384 m_stats[face].get<1> ().m_outData += data->GetWire ()->GetSize ();
389 L3AggregateTracer::InData (Ptr<const Data> data,
390 Ptr<const Face> face)
392 m_stats[face].get<0> ().m_inData ++;
393 if (data->GetWire ())
395 m_stats[face].get<1> ().m_inData += data->GetWire ()->GetSize ();
400 L3AggregateTracer::DropData (Ptr<const Data> data,
401 Ptr<const Face> face)
403 m_stats[face].get<0> ().m_dropData ++;
404 if (data->GetWire ())
406 m_stats[face].get<1> ().m_dropData += data->GetWire ()->GetSize ();
411 L3AggregateTracer::SatisfiedInterests (Ptr<const pit::Entry>)
413 m_stats[0].get<0> ().m_satisfiedInterests ++;
418 L3AggregateTracer::TimedOutInterests (Ptr<const pit::Entry>)
420 m_stats[0].get<0> ().m_timedOutInterests ++;
virtual void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
L3AggregateTracer(boost::shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to the node using node pointer.
static void Install(const NodeContainer &nodes, const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on the selected simulation nodes.
static void InstallAll(const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on all simulation nodes.
Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack...
virtual ~L3AggregateTracer()
Destructor.
virtual void Print(std::ostream &os) const
Print current trace data.
static void Destroy()
Explicit request to remove all statically created tracers.