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> 33 #include <boost/make_shared.hpp> 37 NS_LOG_COMPONENT_DEFINE(
"ndn.AppDelayTracer");
42 static std::list<std::tuple<shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer>>>>
54 using namespace boost;
57 std::list<Ptr<AppDelayTracer>> tracers;
58 shared_ptr<std::ostream> outputStream;
60 shared_ptr<std::ofstream> os(
new std::ofstream());
61 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
64 NS_LOG_ERROR(
"File " << file <<
" cannot be opened for writing. Tracing disabled");
71 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
74 for (NodeList::Iterator node = NodeList::Begin(); node != NodeList::End(); node++) {
75 Ptr<AppDelayTracer> trace =
Install(*node, outputStream);
76 tracers.push_back(trace);
79 if (tracers.size() > 0) {
81 tracers.front()->PrintHeader(*outputStream);
82 *outputStream <<
"\n";
85 g_tracers.push_back(std::make_tuple(outputStream, tracers));
91 using namespace boost;
94 std::list<Ptr<AppDelayTracer>> tracers;
95 shared_ptr<std::ostream> outputStream;
97 shared_ptr<std::ofstream> os(
new std::ofstream());
98 os->open(file.c_str(), std::ios_base::out | std::ios_base::trunc);
100 if (!os->is_open()) {
101 NS_LOG_ERROR(
"File " << file <<
" cannot be opened for writing. Tracing disabled");
108 outputStream = shared_ptr<std::ostream>(&std::cout, std::bind([]{}));
111 for (NodeContainer::Iterator node = nodes.Begin(); node != nodes.End(); node++) {
112 Ptr<AppDelayTracer> trace =
Install(*node, outputStream);
113 tracers.push_back(trace);
116 if (tracers.size() > 0) {
118 tracers.front()->PrintHeader(*outputStream);
119 *outputStream <<
"\n";
122 g_tracers.push_back(std::make_tuple(outputStream, tracers));
128 using namespace boost;
131 std::list<Ptr<AppDelayTracer>> 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<AppDelayTracer> trace =
Install(node, outputStream);
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));
163 NS_LOG_DEBUG(
"Node: " << node->GetId());
165 Ptr<AppDelayTracer> trace = Create<AppDelayTracer>(outputStream, node);
178 m_node = boost::lexical_cast<std::string>(m_nodePtr->GetId());
182 std::string
name = Names::FindName(node);
198 AppDelayTracer::Connect()
200 Config::ConnectWithoutContext(
"/NodeList/" + m_node
201 +
"/ApplicationList/*/LastRetransmittedInterestDataDelay",
202 MakeCallback(&AppDelayTracer::LastRetransmittedInterestDataDelay,
205 Config::ConnectWithoutContext(
"/NodeList/" + m_node +
"/ApplicationList/*/FirstInterestDataDelay",
206 MakeCallback(&AppDelayTracer::FirstInterestDataDelay,
this));
234 AppDelayTracer::LastRetransmittedInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay,
237 *m_os << Simulator::Now().ToDouble(Time::S) <<
"\t" << m_node <<
"\t" << app->GetId() <<
"\t" 240 <<
"\t" << delay.ToDouble(Time::S) <<
"\t" << delay.ToDouble(Time::US) <<
"\t" << 1 <<
"\t" 245 AppDelayTracer::FirstInterestDataDelay(Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount,
248 *m_os << Simulator::Now().ToDouble(Time::S) <<
"\t" << m_node <<
"\t" << app->GetId() <<
"\t" 251 <<
"\t" << delay.ToDouble(Time::S) <<
"\t" << delay.ToDouble(Time::US) <<
"\t" << retxCount
252 <<
"\t" << hopCount <<
"\n";
Copyright (c) 2011-2015 Regents of the University of California.
static void Install(const NodeContainer &nodes, const std::string &file)
Helper method to install tracers on the selected simulation nodes.
Copyright (c) 2013-2015 Regents of the University of California.
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.
static void Destroy()
Explicit request to remove all statically created tracers.
AppDelayTracer(shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to all applications on the node using node's pointer.
static void InstallAll(const std::string &file)
Helper method to install tracers on all simulation nodes.
void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
~AppDelayTracer()
Destructor.