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