blob: de0e2606bccb858be5f9d9cb4907edac7b6c1058 [file] [log] [blame]
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -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_L3_AGGREGATE_TRACER_H
22#define NDN_L3_AGGREGATE_TRACER_H
23
24#include "ndn-l3-tracer.h"
25
26#include <ns3/nstime.h>
27#include <ns3/event-id.h>
Alexander Afanasyeva68783a2013-06-27 13:39:04 -070028#include <ns3/node-container.h>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080029
Alexander Afanasyev59314802012-11-26 14:56:04 -080030#include <boost/tuple/tuple.hpp>
31#include <boost/shared_ptr.hpp>
32#include <map>
33#include <list>
34
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080035namespace ns3 {
36namespace ndn {
37
Alexander Afanasyev59314802012-11-26 14:56:04 -080038/**
39 * @ingroup ndn
40 * @brief CCNx network-layer tracer for aggregate packet counts
41 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080042class L3AggregateTracer : public L3Tracer
43{
44public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080045 /**
46 * @brief Trace constructor that attaches to the node using node pointer
47 * @param os reference to the output stream
48 * @param node pointer to the node
49 */
50 L3AggregateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070051
Alexander Afanasyev59314802012-11-26 14:56:04 -080052 /**
53 * @brief Trace constructor that attaches to the node using node name
54 * @param os reference to the output stream
55 * @param nodeName name of the node registered using Names::Add
56 */
57 L3AggregateTracer (boost::shared_ptr<std::ostream> os, const std::string &nodeName);
58
59 /**
60 * @brief Destructor
61 */
62 virtual ~L3AggregateTracer ();
63
64 /**
65 * @brief Helper method to install tracers on all simulation nodes
66 *
67 * @param file File to which traces will be written
68 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
69 *
70 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
71 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070072 *
Alexander Afanasyev59314802012-11-26 14:56:04 -080073 */
74 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > >
75 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
76
Alexander Afanasyeva68783a2013-06-27 13:39:04 -070077 /**
78 * @brief Helper method to install tracers on the selected simulation nodes
79 *
80 * @param nodes Nodes on which to install tracer
81 * @param file File to which traces will be written
82 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
83 *
84 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
85 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
86 *
87 */
88 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > >
89 Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
90
91 /**
92 * @brief Helper method to install tracers on a specific simulation node
93 *
94 * @param nodes Nodes on which to install tracer
95 * @param file File to which traces will be written
96 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
97 *
98 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
99 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
100 *
101 */
102 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > >
103 Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
104
105private:
106 static Ptr<L3AggregateTracer>
107 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
108
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700109protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800110 // from L3Tracer
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800111 virtual void
112 PrintHeader (std::ostream &os) const;
113
114 virtual void
115 Print (std::ostream &os) const;
116
117 virtual void
118 OutInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700119 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800120
121 virtual void
122 InInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700123 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800124
125 virtual void
126 DropInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700127 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700128
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800129 virtual void
130 OutNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700131 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800132
133 virtual void
134 InNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700135 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800136
137 virtual void
138 DropNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700139 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700140
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800141 virtual void
142 OutData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700143 Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800144
145 virtual void
146 InData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700147 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800148
149 virtual void
150 DropData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700151 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800152
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700153
154 virtual void
155 SatisfiedInterests (Ptr<const pit::Entry>);
156
157 virtual void
158 TimedOutInterests (Ptr<const pit::Entry>);
159
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800160protected:
161 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800162 SetAveragingPeriod (const Time &period);
163
164 void
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800165 Reset ();
166
167 void
168 PeriodicPrinter ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700169
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800170protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800171 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800172
173 Time m_period;
174 EventId m_printEvent;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700175
Alexander Afanasyev59314802012-11-26 14:56:04 -0800176 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800177};
178
179} // namespace ndn
180} // namespace ns3
181
182#endif // NDN_L3_AGGREGATE_TRACER_H