blob: 2c84a96850d1522ce6b53d3544b3739739328ddf [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevc7597622013-02-28 10:58:52 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc7597622013-02-28 10:58:52 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevc7597622013-02-28 10:58:52 -080019
20#ifndef L2_RATE_TRACER_H
21#define L2_RATE_TRACER_H
22
Alexander Afanasyev0c395372014-12-20 15:54:02 -080023#include "l2-tracer.hpp"
Alexander Afanasyevc7597622013-02-28 10:58:52 -080024
25#include "ns3/nstime.h"
26#include "ns3/event-id.h"
27
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080028#include <tuple>
Alexander Afanasyevc7597622013-02-28 10:58:52 -080029#include <map>
30
31namespace ns3 {
32
33/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070034 * @ingroup ndn-tracers
35 * @brief Tracer to collect link-layer rate information about links
36 *
37 * @todo Finish implementation
Alexander Afanasyevc7597622013-02-28 10:58:52 -080038 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039class L2RateTracer : public L2Tracer {
Alexander Afanasyevc7597622013-02-28 10:58:52 -080040public:
41 /**
42 * @brief Network layer tracer constructor
43 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080044 L2RateTracer(std::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 virtual ~L2RateTracer();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080046
47 /**
48 * @brief Helper method to install tracers on all simulation nodes
49 *
50 * @param file File to which traces will be written
51 * @param averagingPeriod Defines averaging period for the rate calculation,
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 * as well as how often data will be written into the trace file (default, every half
53 *second)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080054 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
56 *tuple needs to be preserved
Alexander Afanasyevc7597622013-02-28 10:58:52 -080057 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
58 *
59 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070060 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevc7597622013-02-28 10:58:52 -080062
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070063 /**
64 * @brief Explicit request to remove all statically created tracers
65 *
66 * This method can be helpful if simulation scenario contains several independent run,
67 * or if it is desired to do a postprocessing of the resulting data
68 */
69 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 Destroy();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070071
Alexander Afanasyevc7597622013-02-28 10:58:52 -080072 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 SetAveragingPeriod(const Time& period);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080074
75 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 PrintHeader(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080077
78 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 Print(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080080
81 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 Drop(Ptr<const Packet>);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080083
84private:
85 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 PeriodicPrinter();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080087
88 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 Reset();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080090
91private:
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080092 std::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080093 Time m_period;
94 EventId m_printEvent;
95
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080096 mutable std::tuple<Stats, Stats, Stats, Stats> m_stats;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080097};
98
99} // namespace ns3
100
101#endif // L2_RATE_TRACER_H