NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
NDN tracer for cache performance (hits and misses)
static void InstallAll(const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on all simulation nodes.
std::ostream & operator<<(std::ostream &os, const ContentStore &cs)
void Print(std::ostream &os) const
Print current trace data.
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.
Opaque type (shared_ptr) representing ID of a scheduled event.
static void Destroy()
Explicit request to remove all statically created tracers.
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.
~CsTracer()
Destructor.