blob: bedfccc2c300438e12cd384c7be44e040e82190e [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
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ndn-l3-tracer.hpp"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080025
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/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070039 * @ingroup ndn-tracers
40 * @brief NDN network-layer tracer for aggregate packet counts
Alexander Afanasyev59314802012-11-26 14:56:04 -080041 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042class L3AggregateTracer : public L3Tracer {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080043public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080044 /**
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070045 * @brief Helper method to install tracers on all simulation nodes
46 *
47 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048 * @param averagingPeriod How often data will be written into the trace file (default, every half
49 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070050 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
52 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070053 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
54 *
55 */
56 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070058
59 /**
60 * @brief Helper method to install tracers on the selected simulation nodes
61 *
62 * @param nodes Nodes on which to install tracer
63 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 * @param averagingPeriod How often data will be written into the trace file (default, every half
65 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070066 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
68 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070069 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
70 *
71 */
72 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070074
75 /**
76 * @brief Helper method to install tracers on a specific simulation node
77 *
78 * @param nodes Nodes on which to install tracer
79 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 * @param averagingPeriod How often data will be written into the trace file (default, every half
81 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070082 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
84 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070085 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
86 *
87 */
88 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070090
91 /**
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070092 * @brief Explicit request to remove all statically created tracers
93 *
94 * This method can be helpful if simulation scenario contains several independent run,
95 * or if it is desired to do a postprocessing of the resulting data
96 */
97 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 Destroy();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070099
100 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -0800101 * @brief Trace constructor that attaches to the node using node pointer
102 * @param os reference to the output stream
103 * @param node pointer to the node
104 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 L3AggregateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700106
Alexander Afanasyev59314802012-11-26 14:56:04 -0800107 /**
108 * @brief Trace constructor that attaches to the node using node name
109 * @param os reference to the output stream
110 * @param nodeName name of the node registered using Names::Add
111 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 L3AggregateTracer(boost::shared_ptr<std::ostream> os, const std::string& nodeName);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800113
114 /**
115 * @brief Destructor
116 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117 virtual ~L3AggregateTracer();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800118
119 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700120 * @brief Helper method to install tracers on a specific simulation node
121 *
122 * @param nodes Nodes on which to install tracer
123 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800124 * @param averagingPeriod How often data will be written into the trace file (default, every half
125 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700126 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800127 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
128 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700129 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
130 */
Alexander Afanasyeva68783a2013-06-27 13:39:04 -0700131 static Ptr<L3AggregateTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
133 Time averagingPeriod = Seconds(0.5));
Alexander Afanasyeva68783a2013-06-27 13:39:04 -0700134
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700135protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800136 // from L3Tracer
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800137 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 PrintHeader(std::ostream& os) const;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139
140 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141 Print(std::ostream& os) const;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800142
143 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 OutInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800145
146 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 InInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800148
149 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800150 DropInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700151
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800152 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800153 OutNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800154
155 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800156 InNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800157
158 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800159 DropNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700160
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800161 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800162 OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800163
164 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800165 InData(Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800166
167 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 DropData(Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700169
170 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800171 SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700172
173 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800174 TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700175
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800176protected:
177 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800178 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800179
180 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800181 Reset();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800182
183 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800184 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700185
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800186protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800187 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800188
189 Time m_period;
190 EventId m_printEvent;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700191
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800192 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats>> m_stats;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800193};
194
195} // namespace ndn
196} // namespace ns3
197
198#endif // NDN_L3_AGGREGATE_TRACER_H