blob: 41adf267c0bcb7d846eeedf0b6c49a32d8947d70 [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
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 Afanasyevb3e4b852011-12-23 15:58:20 -080027
28#include "ns3/nstime.h"
29#include "ns3/event-id.h"
Alexander Afanasyev5352af32013-07-15 09:51:28 -070030#include <ns3/node-container.h>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080031
32#include <boost/tuple/tuple.hpp>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080033#include <boost/shared_ptr.hpp>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080034#include <map>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080035#include <list>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080036
37namespace ns3 {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080038namespace ndn {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080039
40/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070041 * @ingroup ndn-tracers
42 * @brief NDN network-layer rate tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080043 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044class L3RateTracer : public L3Tracer {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080045public:
46 /**
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
50 * @param averagingPeriod Defines averaging period for the rate calculation,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 * as well as how often data will be written into the trace file (default, every half
52 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070053 */
54 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070056
57 /**
58 * @brief Helper method to install tracers on the selected simulation nodes
59 *
60 * @param nodes Nodes on which to install tracer
61 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 * @param averagingPeriod How often data will be written into the trace file (default, every half
63 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070064 */
65 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070067
68 /**
69 * @brief Helper method to install tracers on a specific simulation node
70 *
71 * @param nodes Nodes on which to install tracer
72 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 * @param averagingPeriod How often data will be written into the trace file (default, every half
74 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070075 */
76 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070078
79 /**
80 * @brief Explicit request to remove all statically created tracers
81 *
82 * This method can be helpful if simulation scenario contains several independent run,
83 * or if it is desired to do a postprocessing of the resulting data
84 */
85 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 Destroy();
87
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070088 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080089 * @brief Trace constructor that attaches to the node using node pointer
90 * @param os reference to the output stream
91 * @param node pointer to the node
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080092 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 L3RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080094
95 /**
96 * @brief Trace constructor that attaches to the node using node name
97 * @param os reference to the output stream
98 * @param nodeName name of the node registered using Names::Add
99 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 L3RateTracer(boost::shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800101
102 /**
103 * @brief Destructor
104 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 virtual ~L3RateTracer();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800106
Alexander Afanasyev59314802012-11-26 14:56:04 -0800107 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700108 * @brief Helper method to install tracers on a specific simulation node
109 *
110 * @param nodes Nodes on which to install tracer
111 * @param outputStream Smart pointer to a stream
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 * @param averagingPeriod How often data will be written into the trace file (default, every half
113 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700114 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800115 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
116 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700117 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
118 */
119 static Ptr<L3RateTracer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream,
121 Time averagingPeriod = Seconds(0.5));
122
Alexander Afanasyev59314802012-11-26 14:56:04 -0800123 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800124 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800125 PrintHeader(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800126
127 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 Print(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800129
Alexander Afanasyev59314802012-11-26 14:56:04 -0800130protected:
131 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800132 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700133 OutInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800134
135 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700136 InInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800137
138 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700139 DropInterests(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700140
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800141 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700142 OutNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800143
144 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700145 InNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800146
147 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700148 DropNacks(shared_ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700149
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800150 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700151 OutData(shared_ptr<const Data>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800152
153 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700154 InData(shared_ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800155
156 virtual void
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -0700157 DropData(shared_ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800158
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700159 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700161
162 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800163 TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700164
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800165private:
166 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800167 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800168
169 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800170 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700171
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800172 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173 Reset();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800174
175private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800176 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800177 Time m_period;
178 EventId m_printEvent;
179
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800180 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>> m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800181};
182
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800183} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800184} // namespace ns3
185
186#endif // CCNX_RATE_L3_TRACER_H