22 #include "ns3/packet.h" 23 #include "ns3/config.h" 24 #include "ns3/names.h" 25 #include "ns3/callback.h" 28 #include "ns3/simulator.h" 29 #include "ns3/node-list.h" 32 #include <boost/lexical_cast.hpp> 36 NS_LOG_COMPONENT_DEFINE(
"ndn.CsTracer");
41 static std::list<std::tuple<shared_ptr<std::ostream>, std::list<Ptr<CsTracer>>>>
g_tracers;
52 using namespace boost;
55 std::list<Ptr<CsTracer>> tracers;
56 shared_ptr<std::ostream> outputStream;
58 shared_ptr<std::ofstream> os(
new std::ofstream());
59 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
62 NS_LOG_ERROR(
"File " << file <<
" cannot be opened for writing. Tracing disabled");
69 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
72 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
73 Ptr<CsTracer> trace =
Install(*node, outputStream, averagingPeriod);
74 tracers.push_back(trace);
77 if (tracers.size() > 0) {
79 tracers.front()->PrintHeader(*outputStream);
80 *outputStream <<
"\n";
83 g_tracers.push_back(std::make_tuple(outputStream, tracers));
88 Time averagingPeriod )
90 using namespace boost;
93 std::list<Ptr<CsTracer>> tracers;
94 shared_ptr<std::ostream> outputStream;
96 shared_ptr<std::ofstream> os(
new std::ofstream());
97 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
100 NS_LOG_ERROR(
"File " << file <<
" cannot be opened for writing. Tracing disabled");
107 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
110 for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
111 Ptr<CsTracer> trace =
Install(*node, outputStream, averagingPeriod);
112 tracers.push_back(trace);
115 if (tracers.size() > 0) {
117 tracers.front()->PrintHeader(*outputStream);
118 *outputStream <<
"\n";
121 g_tracers.push_back(std::make_tuple(outputStream, tracers));
126 Time averagingPeriod )
128 using namespace boost;
131 std::list<Ptr<CsTracer>> tracers;
132 shared_ptr<std::ostream> outputStream;
134 shared_ptr<std::ofstream> os(
new std::ofstream());
135 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
137 if (!os->is_open()) {
138 NS_LOG_ERROR(
"File " << file <<
" cannot be opened for writing. Tracing disabled");
145 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
148 Ptr<CsTracer> trace =
Install(node, outputStream, averagingPeriod);
149 tracers.push_back(trace);
151 if (tracers.size() > 0) {
153 tracers.front()->PrintHeader(*outputStream);
154 *outputStream <<
"\n";
157 g_tracers.push_back(std::make_tuple(outputStream, tracers));
162 Time averagingPeriod )
164 NS_LOG_DEBUG(
"Node: " << node->GetId());
166 Ptr<CsTracer> trace = Create<CsTracer>(outputStream, node);
167 trace->SetAveragingPeriod(averagingPeriod);
180 m_node = boost::lexical_cast<std::string>(m_nodePtr->GetId());
184 std::string
name = Names::FindName(node);
211 CsTracer::SetAveragingPeriod(
const Time& period)
214 m_printEvent.Cancel();
215 m_printEvent = Simulator::Schedule(m_period, &CsTracer::PeriodicPrinter,
this);
219 CsTracer::PeriodicPrinter()
224 m_printEvent = Simulator::Schedule(m_period, &CsTracer::PeriodicPrinter,
this);
248 #define PRINTER(printName, fieldName) \ 249 os << time.ToDouble(Time::S) << "\t" << m_node << "\t" << printName << "\t" << m_stats.fieldName \ 255 Time
time = Simulator::Now();
257 PRINTER(
"CacheHits", m_cacheHits);
258 PRINTER(
"CacheMisses", m_cacheMisses);
262 CsTracer::CacheHits(shared_ptr<const Interest>, shared_ptr<const Data>)
264 m_stats.m_cacheHits++;
268 CsTracer::CacheMisses(shared_ptr<const Interest>)
270 m_stats.m_cacheMisses++;
Copyright (c) 2011-2015 Regents of the University of California.
static void InstallAll(const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on all simulation nodes.
void Print(std::ostream &os) const
Print current trace data.
#define PRINTER(printName, fieldName)
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 Destroy()
Explicit request to remove all statically created tracers.
static std::list< std::tuple< shared_ptr< std::ostream >, std::list< Ptr< AppDelayTracer > > > > g_tracers
Copyright (c) 2011-2015 Regents of the University of California.
void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
CsTracer(shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to the node using node pointer.