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 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 24 | #include "l2-tracer.hpp" |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 41 | class L2RateTracer : public L2Tracer { |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 42 | public: |
| 43 | /** |
| 44 | * @brief Network layer tracer constructor |
| 45 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | L2RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node); |
| 47 | virtual ~L2RateTracer(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * @brief Helper method to install tracers on all simulation nodes |
| 51 | * |
| 52 | * @param file File to which traces will be written |
| 53 | * @param averagingPeriod Defines averaging period for the rate calculation, |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | * as well as how often data will be written into the trace file (default, every half |
| 55 | *second) |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 56 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 58 | *tuple needs to be preserved |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 59 | * for the lifetime of simulation, otherwise SEGFAULTs are inevitable |
| 60 | * |
| 61 | */ |
Alexander Afanasyev | 3fe94dc | 2013-08-09 17:12:12 -0700 | [diff] [blame] | 62 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5)); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 65 | /** |
| 66 | * @brief Explicit request to remove all statically created tracers |
| 67 | * |
| 68 | * This method can be helpful if simulation scenario contains several independent run, |
| 69 | * or if it is desired to do a postprocessing of the resulting data |
| 70 | */ |
| 71 | static void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 72 | Destroy(); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 74 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | SetAveragingPeriod(const Time& period); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 76 | |
| 77 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | PrintHeader(std::ostream& os) const; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 79 | |
| 80 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | Print(std::ostream& os) const; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 82 | |
| 83 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | Drop(Ptr<const Packet>); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | PeriodicPrinter(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 89 | |
| 90 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | Reset(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 92 | |
| 93 | private: |
| 94 | boost::shared_ptr<std::ostream> m_os; |
| 95 | Time m_period; |
| 96 | EventId m_printEvent; |
| 97 | |
| 98 | mutable boost::tuple<Stats, Stats, Stats, Stats> m_stats; |
| 99 | }; |
| 100 | |
| 101 | } // namespace ns3 |
| 102 | |
| 103 | #endif // L2_RATE_TRACER_H |