Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 1 | /* -*- 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 Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 24 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 25 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 26 | #include "ndn-l3-tracer.hpp" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 27 | |
| 28 | #include "ns3/nstime.h" |
| 29 | #include "ns3/event-id.h" |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 30 | #include <ns3/node-container.h> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 31 | |
| 32 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 33 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 34 | #include <map> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 35 | #include <list> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 36 | |
| 37 | namespace ns3 { |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 38 | namespace ndn { |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 41 | * @ingroup ndn-tracers |
| 42 | * @brief NDN network-layer rate tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 43 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | class L3RateTracer : public L3Tracer { |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 45 | public: |
| 46 | /** |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 47 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | * as well as how often data will be written into the trace file (default, every half |
| 52 | *second) |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 53 | */ |
| 54 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 55 | InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5)); |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 56 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 63 | *second) |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 64 | */ |
| 65 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | Install(const NodeContainer& nodes, const std::string& file, Time averagingPeriod = Seconds(0.5)); |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 67 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 74 | *second) |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 75 | */ |
| 76 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | Install(Ptr<Node> node, const std::string& file, Time averagingPeriod = Seconds(0.5)); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 78 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | Destroy(); |
| 87 | |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 88 | /** |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 89 | * @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 Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 92 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | L3RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 94 | |
| 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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | L3RateTracer(boost::shared_ptr<std::ostream> os, const std::string& node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * @brief Destructor |
| 104 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | virtual ~L3RateTracer(); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 107 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 108 | * @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 Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 112 | * @param averagingPeriod How often data will be written into the trace file (default, every half |
| 113 | *second) |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 114 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 116 | *tuple needs to be preserved |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 117 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 118 | */ |
| 119 | static Ptr<L3RateTracer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 120 | Install(Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, |
| 121 | Time averagingPeriod = Seconds(0.5)); |
| 122 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 123 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 124 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 125 | PrintHeader(std::ostream& os) const; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 126 | |
| 127 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | Print(std::ostream& os) const; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 130 | protected: |
| 131 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 132 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 133 | OutInterests(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 134 | |
| 135 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 136 | InInterests(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 137 | |
| 138 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 139 | DropInterests(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 141 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 142 | OutNacks(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 143 | |
| 144 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 145 | InNacks(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 146 | |
| 147 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 148 | DropNacks(shared_ptr<const Interest>, shared_ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 149 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 150 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 151 | OutData(shared_ptr<const Data>, bool fromCache, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 152 | |
| 153 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 154 | InData(shared_ptr<const Data>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 155 | |
| 156 | virtual void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 157 | DropData(shared_ptr<const Data>, shared_ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 158 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 159 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | SatisfiedInterests(Ptr<const pit::Entry>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 161 | |
| 162 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 163 | TimedOutInterests(Ptr<const pit::Entry>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 164 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 165 | private: |
| 166 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 167 | SetAveragingPeriod(const Time& period); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 168 | |
| 169 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 170 | PeriodicPrinter(); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 171 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 172 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 173 | Reset(); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 174 | |
| 175 | private: |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 176 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 177 | Time m_period; |
| 178 | EventId m_printEvent; |
| 179 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 180 | mutable std::map<shared_ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats>> m_stats; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 181 | }; |
| 182 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 183 | } // namespace ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 184 | } // namespace ns3 |
| 185 | |
| 186 | #endif // CCNX_RATE_L3_TRACER_H |