NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-cs-tracer.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef CCNX_CS_TRACER_H
21 #define CCNX_CS_TRACER_H
22 
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
24 
25 #include "ns3/ptr.h"
26 #include "ns3/simple-ref-count.h"
27 #include <ns3/nstime.h>
28 #include <ns3/event-id.h>
29 #include <ns3/node-container.h>
30 
31 #include <tuple>
32 #include <map>
33 #include <list>
34 
35 namespace ns3 {
36 
37 class Node;
38 class Packet;
39 
40 namespace ndn {
41 
42 namespace cs {
43 
45 struct Stats {
46  inline void
47  Reset()
48  {
49  m_cacheHits = 0;
50  m_cacheMisses = 0;
51  }
52  double m_cacheHits;
53  double m_cacheMisses;
54 };
56 }
57 
62 class CsTracer : public SimpleRefCount<CsTracer> {
63 public:
76  static void
77  InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
78 
92  static void
93  Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
94 
108  static void
109  Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
110 
123  static Ptr<CsTracer>
124  Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream,
125  Time averagingPeriod = Seconds(0.5));
126 
133  static void
134  Destroy();
135 
141  CsTracer(shared_ptr<std::ostream> os, Ptr<Node> node);
142 
148  CsTracer(shared_ptr<std::ostream> os, const std::string& node);
149 
153  ~CsTracer();
154 
160  void
161  PrintHeader(std::ostream& os) const;
162 
168  void
169  Print(std::ostream& os) const;
170 
171 private:
172  void
173  Connect();
174 
175  void
176  CacheHits(shared_ptr<const Interest>, shared_ptr<const Data>);
177 
178  void
179  CacheMisses(shared_ptr<const Interest>);
180 
181 private:
182  void
183  SetAveragingPeriod(const Time& period);
184 
185  void
186  Reset();
187 
188  void
189  PeriodicPrinter();
190 
191 private:
192  std::string m_node;
193  Ptr<Node> m_nodePtr;
194 
195  shared_ptr<std::ostream> m_os;
196 
197  Time m_period;
198  EventId m_printEvent;
199  cs::Stats m_stats;
200 };
201 
205 inline std::ostream&
206 operator<<(std::ostream& os, const CsTracer& tracer)
207 {
208  os << "# ";
209  tracer.PrintHeader(os);
210  os << "\n";
211  tracer.Print(os);
212  return os;
213 }
214 
215 } // namespace ndn
216 } // namespace ns3
217 
218 #endif // CCNX_CS_TRACER_H
ns3::ndn::operator<<
std::ostream & operator<<(std::ostream &os, const AbstractFib &fib)
Definition: abstract-fib.cpp:175
ns3::ndn::CsTracer
NDN tracer for cache performance (hits and misses)
Definition: ndn-cs-tracer.hpp:62
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ns3::ndn::CsTracer::PrintHeader
void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
Definition: ndn-cs-tracer.cpp:228
ns3::ndn::CsTracer::CsTracer
CsTracer(shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to the node using node pointer.
Definition: ndn-cs-tracer.cpp:176
ns3::ndn::CsTracer::~CsTracer
~CsTracer()
Destructor.
Definition: ndn-cs-tracer.cpp:197
ns3::ndn::CsTracer::InstallAll
static void InstallAll(const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on all simulation nodes.
Definition: ndn-cs-tracer.cpp:50
ns3::ndn::CsTracer::Print
void Print(std::ostream &os) const
Print current trace data.
Definition: ndn-cs-tracer.cpp:253
ns3::ndn::CsTracer::Install
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.
Definition: ndn-cs-tracer.cpp:87
ns3::ndn::CsTracer::Destroy
static void Destroy()
Explicit request to remove all statically created tracers.
Definition: ndn-cs-tracer.cpp:44
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34