NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-cs-tracer.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2 /*
3  * Copyright (c) 2011-2012 University of California, Los Angeles
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Xiaoyan Hu <x......u@gmail.com>
19  * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20  */
21 
22 #ifndef CCNX_CS_TRACER_H
23 #define CCNX_CS_TRACER_H
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 <boost/tuple/tuple.hpp>
32 #include <boost/shared_ptr.hpp>
33 #include <map>
34 #include <list>
35 
36 namespace ns3 {
37 
38 class Node;
39 class Packet;
40 
41 namespace ndn {
42 
43 class Interest;
44 class Data;
45 
46 typedef Interest InterestHeader;
47 typedef Data DataHeader;
48 
49 namespace cs {
50 
52 struct Stats
53 {
54  inline void Reset ()
55  {
56  m_cacheHits = 0;
57  m_cacheMisses = 0;
58  }
59  double m_cacheHits;
60  double m_cacheMisses;
61 };
63 
64 }
65 
70 class CsTracer : public SimpleRefCount<CsTracer>
71 {
72 public:
83  static void
84  InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
85 
97  static void
98  Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
99 
111  static void
112  Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
113 
124  static Ptr<CsTracer>
125  Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
126 
133  static void
134  Destroy ();
135 
141  CsTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
142 
148  CsTracer (boost::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 (Ptr<const Interest>, Ptr<const Data>);
177 
178  void
179  CacheMisses (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  boost::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)
Definition: ndn-cs-tracer.h:70
void Print(std::ostream &os) const
Print current trace data.
static void InstallAll(const std::string &file, Time averagingPeriod=Seconds(0.5))
Helper method to install tracers on all simulation nodes.
~CsTracer()
Destructor.
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.
void PrintHeader(std::ostream &os) const
Print head of the trace (e.g., for post-processing)
static void Destroy()
Explicit request to remove all statically created tracers.
CsTracer(boost::shared_ptr< std::ostream > os, Ptr< Node > node)
Trace constructor that attaches to the node using node pointer.