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 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame^] | 29 | #include <tuple> |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 30 | #include <map> |
| 31 | |
| 32 | namespace ns3 { |
| 33 | |
| 34 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 35 | * @ingroup ndn-tracers |
| 36 | * @brief Tracer to collect link-layer rate information about links |
| 37 | * |
| 38 | * @todo Finish implementation |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 39 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | class L2RateTracer : public L2Tracer { |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 41 | public: |
| 42 | /** |
| 43 | * @brief Network layer tracer constructor |
| 44 | */ |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame^] | 45 | L2RateTracer(std::shared_ptr<std::ostream> os, Ptr<Node> node); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | virtual ~L2RateTracer(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * @brief Helper method to install tracers on all simulation nodes |
| 50 | * |
| 51 | * @param file File to which traces will be written |
| 52 | * @param averagingPeriod Defines averaging period for the rate calculation, |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | * as well as how often data will be written into the trace file (default, every half |
| 54 | *second) |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 55 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This |
| 57 | *tuple needs to be preserved |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 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 | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5)); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 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 |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | Destroy(); |
Alexander Afanasyev | db5f3b6 | 2013-08-09 17:42:12 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 73 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | SetAveragingPeriod(const Time& period); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 75 | |
| 76 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 77 | PrintHeader(std::ostream& os) const; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 78 | |
| 79 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | Print(std::ostream& os) const; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 81 | |
| 82 | virtual void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | Drop(Ptr<const Packet>); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 84 | |
| 85 | private: |
| 86 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | PeriodicPrinter(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 88 | |
| 89 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | Reset(); |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 91 | |
| 92 | private: |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame^] | 93 | std::shared_ptr<std::ostream> m_os; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 94 | Time m_period; |
| 95 | EventId m_printEvent; |
| 96 | |
Spyridon Mastorakis | da904f2 | 2014-11-05 16:23:33 -0800 | [diff] [blame^] | 97 | mutable std::tuple<Stats, Stats, Stats, Stats> m_stats; |
Alexander Afanasyev | c759762 | 2013-02-28 10:58:52 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace ns3 |
| 101 | |
| 102 | #endif // L2_RATE_TRACER_H |