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 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 24 | #include "ndn-l3-tracer.h" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 25 | |
| 26 | #include "ns3/nstime.h" |
| 27 | #include "ns3/event-id.h" |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 28 | #include <ns3/node-container.h> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 29 | |
| 30 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 31 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 32 | #include <map> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 33 | #include <list> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 34 | |
| 35 | namespace ns3 { |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 36 | namespace ndn { |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 39 | * @ingroup ndn-tracers |
| 40 | * @brief NDN network-layer rate tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 41 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 42 | class L3RateTracer : public L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | /** |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 46 | * @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)); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * @brief Explicit request to remove all statically created tracers |
| 77 | * |
| 78 | * This method can be helpful if simulation scenario contains several independent run, |
| 79 | * or if it is desired to do a postprocessing of the resulting data |
| 80 | */ |
| 81 | static void |
| 82 | Destroy (); |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 85 | * @brief Trace constructor that attaches to the node using node pointer |
| 86 | * @param os reference to the output stream |
| 87 | * @param node pointer to the node |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 88 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 89 | L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * @brief Trace constructor that attaches to the node using node name |
| 93 | * @param os reference to the output stream |
| 94 | * @param nodeName name of the node registered using Names::Add |
| 95 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 96 | L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * @brief Destructor |
| 100 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 101 | virtual ~L3RateTracer (); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 103 | /** |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 104 | * @brief Helper method to install tracers on a specific simulation node |
| 105 | * |
| 106 | * @param nodes Nodes on which to install tracer |
| 107 | * @param outputStream Smart pointer to a stream |
| 108 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 109 | * |
| 110 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 111 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 112 | */ |
| 113 | static Ptr<L3RateTracer> |
| 114 | Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5)); |
| 115 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 116 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 117 | virtual void |
| 118 | PrintHeader (std::ostream &os) const; |
| 119 | |
| 120 | virtual void |
| 121 | Print (std::ostream &os) const; |
| 122 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 123 | protected: |
| 124 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 125 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 126 | OutInterests (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 127 | |
| 128 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 129 | InInterests (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 130 | |
| 131 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 132 | DropInterests (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 133 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 134 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 135 | OutNacks (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 136 | |
| 137 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 138 | InNacks (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 139 | |
| 140 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 141 | DropNacks (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 142 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 143 | virtual void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 144 | OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 145 | |
| 146 | virtual void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 147 | InData (Ptr<const Data>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 148 | |
| 149 | virtual void |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 150 | DropData (Ptr<const Data>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 151 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 152 | virtual void |
| 153 | SatisfiedInterests (Ptr<const pit::Entry>); |
| 154 | |
| 155 | virtual void |
| 156 | TimedOutInterests (Ptr<const pit::Entry>); |
| 157 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 158 | private: |
| 159 | void |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 160 | SetAveragingPeriod (const Time &period); |
| 161 | |
| 162 | void |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 163 | PeriodicPrinter (); |
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 | void |
| 166 | Reset (); |
| 167 | |
| 168 | private: |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 169 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 170 | Time m_period; |
| 171 | EventId m_printEvent; |
| 172 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 173 | mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 174 | }; |
| 175 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 176 | } // namespace ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 177 | } // namespace ns3 |
| 178 | |
| 179 | #endif // CCNX_RATE_L3_TRACER_H |