blob: e2931d9f237cf80f63c2c14501bbf824693cc61f [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 Afanasyev3fe94dc2013-08-09 17:12:12 -070046 * @brief Helper method to install tracers on all simulation nodes
47 *
48 * @param file File to which traces will be written. If filename is -, then std::out is used
49 * @param averagingPeriod Defines averaging period for the rate calculation,
50 * as well as how often data will be written into the trace file (default, every half second)
51 */
52 static void
53 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
54
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
60 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
61 */
62 static void
63 Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5));
64
65 /**
66 * @brief Helper method to install tracers on a specific simulation node
67 *
68 * @param nodes Nodes on which to install tracer
69 * @param file File to which traces will be written. If filename is -, then std::out is used
70 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
71 */
72 static void
73 Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5));
74
75 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080076 * @brief Trace constructor that attaches to the node using node pointer
77 * @param os reference to the output stream
78 * @param node pointer to the node
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080079 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080080 L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080081
82 /**
83 * @brief Trace constructor that attaches to the node using node name
84 * @param os reference to the output stream
85 * @param nodeName name of the node registered using Names::Add
86 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080087 L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080088
89 /**
90 * @brief Destructor
91 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080092 virtual ~L3RateTracer ();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080093
Alexander Afanasyev59314802012-11-26 14:56:04 -080094 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -070095 * @brief Helper method to install tracers on a specific simulation node
96 *
97 * @param nodes Nodes on which to install tracer
98 * @param outputStream Smart pointer to a stream
99 * @param averagingPeriod How often data will be written into the trace file (default, every half second)
100 *
101 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
102 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
103 */
104 static Ptr<L3RateTracer>
105 Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5));
106
Alexander Afanasyev59314802012-11-26 14:56:04 -0800107 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800108 virtual void
109 PrintHeader (std::ostream &os) const;
110
111 virtual void
112 Print (std::ostream &os) const;
113
Alexander Afanasyev59314802012-11-26 14:56:04 -0800114protected:
115 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800116 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700117 OutInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800118
119 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700120 InInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800121
122 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700123 DropInterests (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700124
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800125 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700126 OutNacks (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800127
128 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700129 InNacks (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 DropNacks (Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700133
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800134 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700135 OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800136
137 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700138 InData (Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800139
140 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700141 DropData (Ptr<const Data>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800142
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700143 virtual void
144 SatisfiedInterests (Ptr<const pit::Entry>);
145
146 virtual void
147 TimedOutInterests (Ptr<const pit::Entry>);
148
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800149private:
150 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800151 SetAveragingPeriod (const Time &period);
152
153 void
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800154 PeriodicPrinter ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700155
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800156 void
157 Reset ();
158
159private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800160 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800161 Time m_period;
162 EventId m_printEvent;
163
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800164 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800165};
166
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800167} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800168} // namespace ns3
169
170#endif // CCNX_RATE_L3_TRACER_H