blob: 21bb06cefbfe811eb5c5c62c0e48a41fd1b98d13 [file] [log] [blame]
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -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 CCNX_RATE_L3_TRACER_H
22#define CCNX_RATE_L3_TRACER_H
23
Alexander Afanasyev0c395372014-12-20 15:54:02 -080024#include "ndn-l3-tracer.hpp"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080025
26#include "ns3/nstime.h"
27#include "ns3/event-id.h"
Alexander Afanasyev5352af32013-07-15 09:51:28 -070028#include <ns3/node-container.h>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080029
30#include <boost/tuple/tuple.hpp>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080031#include <boost/shared_ptr.hpp>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080032#include <map>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080033#include <list>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080034
35namespace ns3 {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080036namespace ndn {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080037
38/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070039 * @ingroup ndn-tracers
40 * @brief NDN network-layer rate tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080041 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042class L3RateTracer : public L3Tracer {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080043public:
44 /**
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
48 * @param averagingPeriod Defines averaging period for the rate calculation,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 * as well as how often data will be written into the trace file (default, every half
50 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070051 */
52 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070054
55 /**
56 * @brief Helper method to install tracers on the selected simulation nodes
57 *
58 * @param nodes Nodes on which to install tracer
59 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 * @param averagingPeriod How often data will be written into the trace file (default, every half
61 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070062 */
63 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070065
66 /**
67 * @brief Helper method to install tracers on a specific simulation node
68 *
69 * @param nodes Nodes on which to install tracer
70 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 * @param averagingPeriod How often data will be written into the trace file (default, every half
72 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070073 */
74 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070076
77 /**
78 * @brief Explicit request to remove all statically created tracers
79 *
80 * This method can be helpful if simulation scenario contains several independent run,
81 * or if it is desired to do a postprocessing of the resulting data
82 */
83 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Destroy();
85
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070086 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080087 * @brief Trace constructor that attaches to the node using node pointer
88 * @param os reference to the output stream
89 * @param node pointer to the node
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080090 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 L3RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080092
93 /**
94 * @brief Trace constructor that attaches to the node using node name
95 * @param os reference to the output stream
96 * @param nodeName name of the node registered using Names::Add
97 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 L3RateTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080099
100 /**
101 * @brief Destructor
102 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 virtual ~L3RateTracer();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800104
Alexander Afanasyev59314802012-11-26 14:56:04 -0800105 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700106 * @brief Helper method to install tracers on a specific simulation node
107 *
108 * @param nodes Nodes on which to install tracer
109 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 * @param averagingPeriod How often data will be written into the trace file (default, every half
111 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700112 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
114 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700115 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
116 */
117 static Ptr<L3RateTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
119 Time averagingPeriod = Seconds(0.5));
120
Alexander Afanasyev59314802012-11-26 14:56:04 -0800121 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800122 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800123 PrintHeader(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800124
125 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800126 Print(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800127
Alexander Afanasyev59314802012-11-26 14:56:04 -0800128protected:
129 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800130 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800131 OutInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800132
133 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800134 InInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800135
136 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 DropInterests(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700138
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800139 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800140 OutNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800141
142 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800143 InNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800144
145 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 DropNacks(Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700147
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800148 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800150
151 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800152 InData(Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800153
154 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800155 DropData(Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800156
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700157 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800158 SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700159
160 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700162
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800163private:
164 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800165 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800166
167 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700169
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800170 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800171 Reset();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800172
173private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800174 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800175 Time m_period;
176 EventId m_printEvent;
177
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800178 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>> m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800179};
180
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800181} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800182} // namespace ns3
183
184#endif // CCNX_RATE_L3_TRACER_H