Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 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 L2_RATE_TRACER_H |
| 22 | #define L2_RATE_TRACER_H |
| 23 | |
| 24 | #include "l2-tracer.h" |
| 25 | |
| 26 | #include "ns3/nstime.h" |
| 27 | #include "ns3/event-id.h" |
| 28 | |
| 29 | #include <boost/tuple/tuple.hpp> |
| 30 | #include <boost/shared_ptr.hpp> |
| 31 | #include <map> |
| 32 | |
| 33 | namespace ns3 { |
| 34 | |
| 35 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 36 | * @ingroup ndn-tracers |
| 37 | * @brief Tracer to collect link-layer rate information about links |
| 38 | * |
| 39 | * @todo Finish implementation |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 40 | */ |
| 41 | class L2RateTracer : public L2Tracer |
| 42 | { |
| 43 | public: |
| 44 | /** |
| 45 | * @brief Network layer tracer constructor |
| 46 | */ |
| 47 | L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
| 48 | virtual ~L2RateTracer (); |
| 49 | |
| 50 | /** |
| 51 | * @brief Helper method to install tracers on all simulation nodes |
| 52 | * |
| 53 | * @param file File to which traces will be written |
| 54 | * @param averagingPeriod Defines averaging period for the rate calculation, |
| 55 | * as well as how often data will be written into the trace file (default, every half second) |
| 56 | * |
| 57 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved |
| 58 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 59 | * |
| 60 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 61 | static void |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 62 | InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5)); |
| 63 | |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 64 | /** |
| 65 | * @brief Explicit request to remove all statically created tracers |
| 66 | * |
| 67 | * This method can be helpful if simulation scenario contains several independent run, |
| 68 | * or if it is desired to do a postprocessing of the resulting data |
| 69 | */ |
| 70 | static void |
| 71 | Destroy (); |
| 72 | |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 73 | void |
| 74 | SetAveragingPeriod (const Time &period); |
| 75 | |
| 76 | virtual void |
| 77 | PrintHeader (std::ostream &os) const; |
| 78 | |
| 79 | virtual void |
| 80 | Print (std::ostream &os) const; |
| 81 | |
| 82 | virtual void |
| 83 | Drop (Ptr<const Packet>); |
| 84 | |
| 85 | private: |
| 86 | void |
| 87 | PeriodicPrinter (); |
| 88 | |
| 89 | void |
| 90 | Reset (); |
| 91 | |
| 92 | private: |
| 93 | boost::shared_ptr<std::ostream> m_os; |
| 94 | Time m_period; |
| 95 | EventId m_printEvent; |
| 96 | |
| 97 | mutable boost::tuple<Stats, Stats, Stats, Stats> m_stats; |
| 98 | }; |
| 99 | |
| 100 | } // namespace ns3 |
| 101 | |
| 102 | #endif // L2_RATE_TRACER_H |