21 #include "ndn-app-delay-tracer.h"
23 #include "ns3/packet.h"
24 #include "ns3/config.h"
25 #include "ns3/names.h"
26 #include "ns3/callback.h"
28 #include "ns3/ndn-app.h"
29 #include "ns3/ndn-interest.h"
30 #include "ns3/ndn-data.h"
31 #include "ns3/simulator.h"
32 #include "ns3/node-list.h"
35 #include <boost/lexical_cast.hpp>
36 #include <boost/make_shared.hpp>
40 NS_LOG_COMPONENT_DEFINE (
"ndn.AppDelayTracer");
47 static std::list< boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<AppDelayTracer> > > > g_tracers;
56 AppDelayTracer::Destroy ()
62 AppDelayTracer::InstallAll (
const std::string &file)
64 using namespace boost;
67 std::list<Ptr<AppDelayTracer> > tracers;
68 boost::shared_ptr<std::ostream> outputStream;
71 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
72 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
76 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
84 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
87 for (NodeList::Iterator node = NodeList::Begin ();
88 node != NodeList::End ();
91 Ptr<AppDelayTracer> trace = Install (*node, outputStream);
92 tracers.push_back (trace);
95 if (tracers.size () > 0)
98 tracers.front ()->PrintHeader (*outputStream);
99 *outputStream <<
"\n";
102 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
106 AppDelayTracer::Install (
const NodeContainer &nodes,
const std::string &file)
108 using namespace boost;
111 std::list<Ptr<AppDelayTracer> > tracers;
112 boost::shared_ptr<std::ostream> outputStream;
115 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
116 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
120 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
128 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
131 for (NodeContainer::Iterator node = nodes.Begin ();
132 node != nodes.End ();
135 Ptr<AppDelayTracer> trace = Install (*node, outputStream);
136 tracers.push_back (trace);
139 if (tracers.size () > 0)
142 tracers.front ()->PrintHeader (*outputStream);
143 *outputStream <<
"\n";
146 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
150 AppDelayTracer::Install (Ptr<Node> node,
const std::string &file)
152 using namespace boost;
155 std::list<Ptr<AppDelayTracer> > tracers;
156 boost::shared_ptr<std::ostream> outputStream;
159 boost::shared_ptr<std::ofstream> os (
new std::ofstream ());
160 os->open (file.c_str (), std::ios_base::out | std::ios_base::trunc);
164 NS_LOG_ERROR (
"File " << file <<
" cannot be opened for writing. Tracing disabled");
172 outputStream = boost::shared_ptr<std::ostream> (&std::cout, NullDeleter<std::ostream>);
175 Ptr<AppDelayTracer> trace = Install (node, outputStream);
176 tracers.push_back (trace);
178 if (tracers.size () > 0)
181 tracers.front ()->PrintHeader (*outputStream);
182 *outputStream <<
"\n";
185 g_tracers.push_back (boost::make_tuple (outputStream, tracers));
190 AppDelayTracer::Install (Ptr<Node> node,
191 boost::shared_ptr<std::ostream> outputStream)
193 NS_LOG_DEBUG (
"Node: " << node->GetId ());
195 Ptr<AppDelayTracer> trace = Create<AppDelayTracer> (outputStream, node);
204 AppDelayTracer::AppDelayTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node)
208 m_node = boost::lexical_cast<
string> (m_nodePtr->GetId ());
212 string name = Names::FindName (node);
232 AppDelayTracer::Connect ()
234 Config::ConnectWithoutContext (
"/NodeList/"+m_node+
"/ApplicationList/*/LastRetransmittedInterestDataDelay",
235 MakeCallback (&AppDelayTracer::LastRetransmittedInterestDataDelay,
this));
237 Config::ConnectWithoutContext (
"/NodeList/"+m_node+
"/ApplicationList/*/FirstInterestDataDelay",
238 MakeCallback (&AppDelayTracer::FirstInterestDataDelay,
this));
252 <<
"RetxCount" <<
"\t"
257 AppDelayTracer::LastRetransmittedInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, int32_t hopCount)
259 *m_os << Simulator::Now ().ToDouble (Time::S) <<
"\t"
261 << app->GetId () <<
"\t"
263 <<
"LastDelay" <<
"\t"
264 << delay.ToDouble (Time::S) <<
"\t"
265 << delay.ToDouble (Time::US) <<
"\t"
271 AppDelayTracer::FirstInterestDataDelay (Ptr<App> app, uint32_t seqno, Time delay, uint32_t retxCount, int32_t hopCount)
273 *m_os << Simulator::Now ().ToDouble (Time::S) <<
"\t"
275 << app->GetId () <<
"\t"
277 <<
"FullDelay" <<
"\t"
278 << delay.ToDouble (Time::S) <<
"\t"
279 << delay.ToDouble (Time::US) <<
"\t"
void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
~AppDelayTracer()
Destructor.
AppDelayTracer(boost::shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to all applications on the node using node's pointer.