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