blob: 9df79b1f512c38322367682cd8b3886af01c4a33 [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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080024#include "ndn-l3-tracer.h"
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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080042class L3RateTracer : public L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080043{
44public:
45 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080046 * @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
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080049 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080050 L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080051
52 /**
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 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080057 L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080058
59 /**
60 * @brief Destructor
61 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080062 virtual ~L3RateTracer ();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080063
Alexander Afanasyev59314802012-11-26 14:56:04 -080064 /**
65 * @brief Helper method to install tracers on all simulation nodes
66 *
Alexander Afanasyev5352af32013-07-15 09:51:28 -070067 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyev59314802012-11-26 14:56:04 -080068 * @param averagingPeriod Defines averaging period for the rate calculation,
69 * as well as how often data will be written into the trace file (default, every half second)
70 *
71 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
72 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070073 *
Alexander Afanasyev59314802012-11-26 14:56:04 -080074 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080075 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
76 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
Alexander Afanasyev59314802012-11-26 14:56:04 -080077
Alexander Afanasyev5352af32013-07-15 09:51:28 -070078 /**
79 * @brief Helper method to install tracers on the selected simulation nodes
80 *
81 * @param nodes Nodes on which to install tracer
82 * @param file File to which traces will be written. If filename is -, then std::out is used
83 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
84 *
85 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
86 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
87 *
88 */
89 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
90 Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
91
92 /**
93 * @brief Helper method to install tracers on a specific simulation node
94 *
95 * @param nodes Nodes on which to install tracer
96 * @param file File to which traces will be written. If filename is -, then std::out is used
97 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
98 *
99 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
100 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
101 *
102 */
103 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
104 Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
105
106 /**
107 * @brief Helper method to install tracers on a specific simulation node
108 *
109 * @param nodes Nodes on which to install tracer
110 * @param outputStream Smart pointer to a stream
111 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
112 *
113 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
114 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
115 */
116 static Ptr<L3RateTracer>
117 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
118
Alexander Afanasyev59314802012-11-26 14:56:04 -0800119 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800120 virtual void
121 PrintHeader (std::ostream &os) const;
122
123 virtual void
124 Print (std::ostream &os) const;
125
Alexander Afanasyev59314802012-11-26 14:56:04 -0800126protected:
127 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800128 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700129 OutInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800130
131 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700132 InInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800133
134 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700135 DropInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700136
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800137 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700138 OutNacks (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800139
140 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700141 InNacks (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800142
143 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700144 DropNacks (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700145
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800146 virtual void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700147 OutData (Ptr<const ContentObject>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800148
149 virtual void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700150 InData (Ptr<const ContentObject>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800151
152 virtual void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700153 DropData (Ptr<const ContentObject>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800154
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700155 virtual void
156 SatisfiedInterests (Ptr<const pit::Entry>);
157
158 virtual void
159 TimedOutInterests (Ptr<const pit::Entry>);
160
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800161private:
162 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800163 SetAveragingPeriod (const Time &period);
164
165 void
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800166 PeriodicPrinter ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700167
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800168 void
169 Reset ();
170
171private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800172 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800173 Time m_period;
174 EventId m_printEvent;
175
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800176 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800177};
178
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800179} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800180} // namespace ns3
181
182#endif // CCNX_RATE_L3_TRACER_H