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 | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 39 | * @ingroup ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 40 | * @brief CCNx network-layer rate tracer |
| 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 | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 46 | * @brief Trace constructor that attaches to the node using node pointer |
| 47 | * @param os reference to the output stream |
| 48 | * @param node pointer to the node |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 49 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 50 | L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * @brief Trace constructor that attaches to the node using node name |
| 54 | * @param os reference to the output stream |
| 55 | * @param nodeName name of the node registered using Names::Add |
| 56 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 57 | L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * @brief Destructor |
| 61 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 62 | virtual ~L3RateTracer (); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 64 | /** |
| 65 | * @brief Helper method to install tracers on all simulation nodes |
| 66 | * |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 67 | * @param file File to which traces will be written. If filename is -, then std::out is used |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 68 | * @param averagingPeriod Defines averaging period for the rate calculation, |
| 69 | * as well as how often data will be written into the trace file (default, every half second) |
| 70 | * |
| 71 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 72 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 73 | * |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 75 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > |
| 76 | InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5)); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 78 | /** |
| 79 | * @brief Helper method to install tracers on the selected simulation nodes |
| 80 | * |
| 81 | * @param nodes Nodes on which to install tracer |
| 82 | * @param file File to which traces will be written. If filename is -, then std::out is used |
| 83 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 84 | * |
| 85 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 86 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 87 | * |
| 88 | */ |
| 89 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > |
| 90 | Install (const NodeContainer &nodes, const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 91 | |
| 92 | /** |
| 93 | * @brief Helper method to install tracers on a specific simulation node |
| 94 | * |
| 95 | * @param nodes Nodes on which to install tracer |
| 96 | * @param file File to which traces will be written. If filename is -, then std::out is used |
| 97 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 98 | * |
| 99 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 100 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 101 | * |
| 102 | */ |
| 103 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > |
| 104 | Install (Ptr<Node> node, const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 105 | |
| 106 | /** |
| 107 | * @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 |
| 111 | * @param averagingPeriod How often data will be written into the trace file (default, every half second) |
| 112 | * |
| 113 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 114 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 115 | */ |
| 116 | static Ptr<L3RateTracer> |
| 117 | Install (Ptr<Node> node, boost::shared_ptr<std::ostream> outputStream, Time averagingPeriod = Seconds (0.5)); |
| 118 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 119 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 120 | virtual void |
| 121 | PrintHeader (std::ostream &os) const; |
| 122 | |
| 123 | virtual void |
| 124 | Print (std::ostream &os) const; |
| 125 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 126 | protected: |
| 127 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 128 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 129 | OutInterests (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 | InInterests (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 133 | |
| 134 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 135 | DropInterests (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 137 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 138 | OutNacks (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 | InNacks (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 142 | |
| 143 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 144 | DropNacks (Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 145 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 146 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 147 | OutData (Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 148 | |
| 149 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 150 | InData (Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 151 | |
| 152 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 153 | DropData (Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 154 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 155 | virtual void |
| 156 | SatisfiedInterests (Ptr<const pit::Entry>); |
| 157 | |
| 158 | virtual void |
| 159 | TimedOutInterests (Ptr<const pit::Entry>); |
| 160 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 161 | private: |
| 162 | void |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 163 | SetAveragingPeriod (const Time &period); |
| 164 | |
| 165 | void |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 166 | PeriodicPrinter (); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 167 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 168 | void |
| 169 | Reset (); |
| 170 | |
| 171 | private: |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 172 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 173 | Time m_period; |
| 174 | EventId m_printEvent; |
| 175 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 176 | 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] | 177 | }; |
| 178 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 179 | } // namespace ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 180 | } // namespace ns3 |
| 181 | |
| 182 | #endif // CCNX_RATE_L3_TRACER_H |