blob: aa5d82fde363dbf51d4a99c80e6156ad2e2ff56c [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyev0c395372014-12-20 15:54:02 -080026#include "ndn-l3-tracer.hpp"
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080027
28#include <ns3/nstime.h>
29#include <ns3/event-id.h>
Alexander Afanasyeva68783a2013-06-27 13:39:04 -070030#include <ns3/node-container.h>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080031
Alexander Afanasyev59314802012-11-26 14:56:04 -080032#include <boost/tuple/tuple.hpp>
33#include <boost/shared_ptr.hpp>
34#include <map>
35#include <list>
36
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080037namespace ns3 {
38namespace ndn {
39
Alexander Afanasyev59314802012-11-26 14:56:04 -080040/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070041 * @ingroup ndn-tracers
42 * @brief NDN network-layer tracer for aggregate packet counts
Alexander Afanasyev59314802012-11-26 14:56:04 -080043 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044class L3AggregateTracer : public L3Tracer {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080045public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080046 /**
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070047 * @brief Helper method to install tracers on all simulation nodes
48 *
49 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 * @param averagingPeriod How often data will be written into the trace file (default, every half
51 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070052 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
54 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070055 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
56 *
57 */
58 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070060
61 /**
62 * @brief Helper method to install tracers on the selected simulation nodes
63 *
64 * @param nodes Nodes on which to install tracer
65 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 * @param averagingPeriod How often data will be written into the trace file (default, every half
67 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070068 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
70 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070071 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
72 *
73 */
74 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070076
77 /**
78 * @brief Helper method to install tracers on a specific simulation node
79 *
80 * @param nodes Nodes on which to install tracer
81 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 * @param averagingPeriod How often data will be written into the trace file (default, every half
83 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070084 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
86 *tuple needs to be preserved
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070087 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
88 *
89 */
90 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070092
93 /**
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070094 * @brief Explicit request to remove all statically created tracers
95 *
96 * This method can be helpful if simulation scenario contains several independent run,
97 * or if it is desired to do a postprocessing of the resulting data
98 */
99 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 Destroy();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -0700101
102 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -0800103 * @brief Trace constructor that attaches to the node using node pointer
104 * @param os reference to the output stream
105 * @param node pointer to the node
106 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 L3AggregateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700108
Alexander Afanasyev59314802012-11-26 14:56:04 -0800109 /**
110 * @brief Trace constructor that attaches to the node using node name
111 * @param os reference to the output stream
112 * @param nodeName name of the node registered using Names::Add
113 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 L3AggregateTracer(boost::shared_ptr<std::ostream> os, const std::string& nodeName);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800115
116 /**
117 * @brief Destructor
118 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 virtual ~L3AggregateTracer();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800120
121 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700122 * @brief Helper method to install tracers on a specific simulation node
123 *
124 * @param nodes Nodes on which to install tracer
125 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 * @param averagingPeriod How often data will be written into the trace file (default, every half
127 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700128 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
130 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700131 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
132 */
Alexander Afanasyeva68783a2013-06-27 13:39:04 -0700133 static Ptr<L3AggregateTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
135 Time averagingPeriod = Seconds(0.5));
Alexander Afanasyeva68783a2013-06-27 13:39:04 -0700136
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700137protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800138 // from L3Tracer
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140 PrintHeader(std::ostream& os) const;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800141
142 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800143 Print(std::ostream& os) const;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800144
145 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700146 OutInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800147
148 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700149 InInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800150
151 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700152 DropInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700153
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800154 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700155 OutNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800156
157 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700158 InNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800159
160 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700161 DropNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700162
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800163 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700164 OutData(shared_ptr<const Data>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800165
166 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700167 InData(shared_ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800168
169 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700170 DropData(shared_ptr<const Data>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700171
172 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173 SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700174
175 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800176 TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700177
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800178protected:
179 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800180 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800181
182 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800183 Reset();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800184
185 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800186 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700187
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800188protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800189 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800190
191 Time m_period;
192 EventId m_printEvent;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700193
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800194 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats>> m_stats;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800195};
196
197} // namespace ndn
198} // namespace ns3
199
200#endif // NDN_L3_AGGREGATE_TRACER_H