blob: c433a17b5f8ae44a43d48411139e6b5957267e2d [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"
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080030#include "ns3/node-container.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080031
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080032#include <tuple>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080033#include <map>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080034#include <list>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080035
36namespace ns3 {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080037namespace ndn {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080038
39/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070040 * @ingroup ndn-tracers
41 * @brief NDN network-layer rate tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080042 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043class L3RateTracer : public L3Tracer {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080044public:
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,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 * as well as how often data will be written into the trace file (default, every half
51 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070052 */
53 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070055
56 /**
57 * @brief Helper method to install tracers on the selected simulation nodes
58 *
59 * @param nodes Nodes on which to install tracer
60 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 * @param averagingPeriod How often data will be written into the trace file (default, every half
62 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070063 */
64 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070066
67 /**
68 * @brief Helper method to install tracers on a specific simulation node
69 *
70 * @param nodes Nodes on which to install tracer
71 * @param file File to which traces will be written. If filename is -, then std::out is used
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 * @param averagingPeriod How often data will be written into the trace file (default, every half
73 *second)
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070074 */
75 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070077
78 /**
79 * @brief Explicit request to remove all statically created tracers
80 *
81 * This method can be helpful if simulation scenario contains several independent run,
82 * or if it is desired to do a postprocessing of the resulting data
83 */
84 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 Destroy();
86
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070087 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080088 * @brief Trace constructor that attaches to the node using node pointer
89 * @param os reference to the output stream
90 * @param node pointer to the node
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080091 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080092 L3RateTracer(shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080093
94 /**
95 * @brief Trace constructor that attaches to the node using node name
96 * @param os reference to the output stream
97 * @param nodeName name of the node registered using Names::Add
98 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080099 L3RateTracer(shared_ptr<std::ostream> os, const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800100
101 /**
102 * @brief Destructor
103 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 virtual ~L3RateTracer();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800105
Alexander Afanasyev59314802012-11-26 14:56:04 -0800106 /**
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700107 * @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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 * @param averagingPeriod How often data will be written into the trace file (default, every half
112 *second)
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700113 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
115 *tuple needs to be preserved
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700116 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
117 */
118 static Ptr<L3RateTracer>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800119 Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800120 Time averagingPeriod = Seconds(0.5));
121
Alexander Afanasyev59314802012-11-26 14:56:04 -0800122 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800123 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800124 PrintHeader(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800125
126 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800127 Print(std::ostream& os) const;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800128
Alexander Afanasyev59314802012-11-26 14:56:04 -0800129protected:
130 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800131 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800132 OutInterests(const Interest& interest, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800133
134 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800135 InInterests(const Interest& interest, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800136
137 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800138 OutData(const Data& data, const Face& face);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700139
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800140 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800141 InData(const Data& data, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800142
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800143 // virtual void
144 // SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800145
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800146 // virtual void
147 // TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700148
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800149private:
150 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800151 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800152
153 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800154 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700155
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800156 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800157 Reset();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800158
159private:
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800160 shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800161 Time m_period;
162 EventId m_printEvent;
163
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800164 mutable std::map<shared_ptr<const Face>, std::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