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" |
| 28 | |
| 29 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 30 | #include <boost/shared_ptr.hpp> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 31 | #include <map> |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 32 | #include <list> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 33 | |
| 34 | namespace ns3 { |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 35 | namespace ndn { |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 38 | * @ingroup ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 39 | * @brief CCNx network-layer rate tracer |
| 40 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 41 | class L3RateTracer : public L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 42 | { |
| 43 | public: |
| 44 | /** |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 45 | * @brief Trace constructor that attaches to the node using node pointer |
| 46 | * @param os reference to the output stream |
| 47 | * @param node pointer to the node |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 48 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 49 | L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * @brief Trace constructor that attaches to the node using node name |
| 53 | * @param os reference to the output stream |
| 54 | * @param nodeName name of the node registered using Names::Add |
| 55 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 56 | L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * @brief Destructor |
| 60 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 61 | virtual ~L3RateTracer (); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 63 | /** |
| 64 | * @brief Helper method to install tracers on all simulation nodes |
| 65 | * |
| 66 | * @param file File to which traces will be written |
| 67 | * @param averagingPeriod Defines averaging period for the rate calculation, |
| 68 | * as well as how often data will be written into the trace file (default, every half second) |
| 69 | * |
| 70 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 71 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 72 | * |
| 73 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 74 | static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > > |
| 75 | InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5)); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 76 | |
| 77 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 78 | virtual void |
| 79 | PrintHeader (std::ostream &os) const; |
| 80 | |
| 81 | virtual void |
| 82 | Print (std::ostream &os) const; |
| 83 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 84 | protected: |
| 85 | // from L3Tracer |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 86 | virtual void |
| 87 | OutInterests (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 88 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 89 | |
| 90 | virtual void |
| 91 | InInterests (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 92 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 93 | |
| 94 | virtual void |
| 95 | DropInterests (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 96 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 97 | |
| 98 | virtual void |
| 99 | OutNacks (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 100 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 101 | |
| 102 | virtual void |
| 103 | InNacks (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 104 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 105 | |
| 106 | virtual void |
| 107 | DropNacks (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 108 | Ptr<const Interest>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 109 | |
| 110 | virtual void |
| 111 | OutData (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 112 | Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 113 | |
| 114 | virtual void |
| 115 | InData (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 116 | Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 117 | |
| 118 | virtual void |
| 119 | DropData (std::string context, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 120 | Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 121 | |
| 122 | private: |
| 123 | void |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 124 | SetAveragingPeriod (const Time &period); |
| 125 | |
| 126 | void |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 127 | PeriodicPrinter (); |
| 128 | |
| 129 | void |
| 130 | Reset (); |
| 131 | |
| 132 | private: |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 133 | boost::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 134 | Time m_period; |
| 135 | EventId m_printEvent; |
| 136 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 137 | 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] | 138 | }; |
| 139 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 140 | } // namespace ndn |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 141 | } // namespace ns3 |
| 142 | |
| 143 | #endif // CCNX_RATE_L3_TRACER_H |