blob: c1a5372bb9297c9c4314975bf643b2e427c99cde [file] [log] [blame]
Alexander Afanasyevc7597622013-02-28 10:58:52 -08001/* -*- 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 Afanasyev0c395372014-12-20 15:54:02 -080024#include "l2-tracer.hpp"
Alexander Afanasyevc7597622013-02-28 10:58:52 -080025
26#include "ns3/nstime.h"
27#include "ns3/event-id.h"
28
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080029#include <tuple>
Alexander Afanasyevc7597622013-02-28 10:58:52 -080030#include <map>
31
32namespace ns3 {
33
34/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070035 * @ingroup ndn-tracers
36 * @brief Tracer to collect link-layer rate information about links
37 *
38 * @todo Finish implementation
Alexander Afanasyevc7597622013-02-28 10:58:52 -080039 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040class L2RateTracer : public L2Tracer {
Alexander Afanasyevc7597622013-02-28 10:58:52 -080041public:
42 /**
43 * @brief Network layer tracer constructor
44 */
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080045 L2RateTracer(std::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 virtual ~L2RateTracer();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080047
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 Afanasyevbe55cf62014-12-20 17:51:09 -080053 * as well as how often data will be written into the trace file (default, every half
54 *second)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080055 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
57 *tuple needs to be preserved
Alexander Afanasyevc7597622013-02-28 10:58:52 -080058 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
59 *
60 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070061 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevc7597622013-02-28 10:58:52 -080063
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070064 /**
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 Afanasyevbe55cf62014-12-20 17:51:09 -080071 Destroy();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070072
Alexander Afanasyevc7597622013-02-28 10:58:52 -080073 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 SetAveragingPeriod(const Time& period);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080075
76 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 PrintHeader(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080078
79 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080 Print(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080081
82 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 Drop(Ptr<const Packet>);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080084
85private:
86 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 PeriodicPrinter();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080088
89 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 Reset();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080091
92private:
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080093 std::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080094 Time m_period;
95 EventId m_printEvent;
96
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080097 mutable std::tuple<Stats, Stats, Stats, Stats> m_stats;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080098};
99
100} // namespace ns3
101
102#endif // L2_RATE_TRACER_H