blob: bc9c48de771f074bb4ea72923597c4e50860a69e [file] [log] [blame]
Alexander Afanasyev86287992012-12-10 16:11:50 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 UCLA
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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#ifndef NDN_CS_IMP_TRACER_H
22#define NDN_CS_IMP_TRACER_H
23
24#include "ndn-cs-tracer.h"
25
26#include <ns3/nstime.h>
27#include <ns3/event-id.h>
28
29#include <boost/tuple/tuple.hpp>
30#include <boost/shared_ptr.hpp>
31#include <map>
32#include <list>
33
34namespace ns3 {
35namespace ndn {
36
37/**
38 * @ingroup ndn
39 * @brief CCNx network-layer tracer for aggregate packet counts
40 */
41class CsImpTracer : public CsTracer
42{
43public:
44 /**
45 * @brief Trace constructor that attaches to the node using node pointer
46 * @param os reference to the output stream
47 * @param node pointer to the node
48 */
49 CsImpTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
50
51 /**
52 * @brief Trace constructor that attaches to the node using node name
53 * @param os reference to the output stream
54 * @param nodeName name of the node registered using Names::Add
55 */
56 CsImpTracer (boost::shared_ptr<std::ostream> os, const std::string &nodeName);
57
58 /**
59 * @brief Destructor
60 */
61 virtual ~CsImpTracer ();
62
63 /**
64 * @brief Helper method to install tracers on all simulation nodes
65 *
66 * @param file File to which traces will be written
67 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
68 *
69 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
70 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
71 *
72 */
73 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<CsImpTracer> > >
74 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
75
76protected:
77 // from CsTracer
78 virtual void
79 PrintHeader (std::ostream &os) const;
80
81 virtual void
82 Print (std::ostream &os) const;
83
84 virtual void
85 CacheHits (std::string context,
86 Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>);
87
88 virtual void
89 CacheMisses (std::string context,
90 Ptr<const InterestHeader>);
91
92protected:
93 void
94 SetAveragingPeriod (const Time &period);
95
96 void
97 Reset ();
98
99 void
100 PeriodicPrinter ();
101
102protected:
103 boost::shared_ptr<std::ostream> m_os;
104
105 Time m_period;
106 EventId m_printEvent;
107 Stats m_stats;
108
109// mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
110};
111
112} // namespace ndn
113} // namespace ns3
114
115#endif // NDN_CS_IMP_TRACER_H