blob: 69a8c0f3e52bce0e1da227c94df8079fcca08ffb [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080019
20#ifndef CCNX_RATE_L3_TRACER_H
21#define CCNX_RATE_L3_TRACER_H
22
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyev0c395372014-12-20 15:54:02 -080025#include "ndn-l3-tracer.hpp"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080026
27#include "ns3/nstime.h"
28#include "ns3/event-id.h"
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080029#include "ns3/node-container.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080030
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080031#include <tuple>
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 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080091 L3RateTracer(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 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080098 L3RateTracer(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>
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800118 Install(Ptr<Node> node, shared_ptr<std::ostream> outputStream,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 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
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800131 OutInterests(const Interest& interest, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800132
133 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800134 InInterests(const Interest& interest, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800135
136 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800137 OutData(const Data& data, const Face& face);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700138
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800139 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800140 InData(const Data& data, const Face& face);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800141
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800142 // virtual void
143 // SatisfiedInterests(Ptr<const pit::Entry>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800144
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800145 // virtual void
146 // TimedOutInterests(Ptr<const pit::Entry>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700147
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800148private:
149 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800150 SetAveragingPeriod(const Time& period);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800151
152 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800153 PeriodicPrinter();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700154
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800155 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800156 Reset();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800157
158private:
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800159 shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800160 Time m_period;
161 EventId m_printEvent;
162
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800163 mutable std::map<shared_ptr<const Face>, std::tuple<Stats, Stats, Stats, Stats>> m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800164};
165
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800166} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800167} // namespace ns3
168
169#endif // CCNX_RATE_L3_TRACER_H