blob: 79f16c4c41d61f7ec67fe3af94e0cf7bc501efc5 [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
29#include <boost/tuple/tuple.hpp>
30#include <boost/shared_ptr.hpp>
31#include <map>
32
33namespace ns3 {
34
35/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070036 * @ingroup ndn-tracers
37 * @brief Tracer to collect link-layer rate information about links
38 *
39 * @todo Finish implementation
Alexander Afanasyevc7597622013-02-28 10:58:52 -080040 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041class L2RateTracer : public L2Tracer {
Alexander Afanasyevc7597622013-02-28 10:58:52 -080042public:
43 /**
44 * @brief Network layer tracer constructor
45 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 L2RateTracer(boost::shared_ptr<std::ostream> os, Ptr<Node> node);
47 virtual ~L2RateTracer();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080048
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 Afanasyevbe55cf62014-12-20 17:51:09 -080054 * as well as how often data will be written into the trace file (default, every half
55 *second)
Alexander Afanasyevc7597622013-02-28 10:58:52 -080056 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This
58 *tuple needs to be preserved
Alexander Afanasyevc7597622013-02-28 10:58:52 -080059 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
60 *
61 */
Alexander Afanasyev3fe94dc2013-08-09 17:12:12 -070062 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 InstallAll(const std::string& file, Time averagingPeriod = Seconds(0.5));
Alexander Afanasyevc7597622013-02-28 10:58:52 -080064
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070065 /**
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 Afanasyevbe55cf62014-12-20 17:51:09 -080072 Destroy();
Alexander Afanasyevdb5f3b62013-08-09 17:42:12 -070073
Alexander Afanasyevc7597622013-02-28 10:58:52 -080074 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 SetAveragingPeriod(const Time& period);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080076
77 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 PrintHeader(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080079
80 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 Print(std::ostream& os) const;
Alexander Afanasyevc7597622013-02-28 10:58:52 -080082
83 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Drop(Ptr<const Packet>);
Alexander Afanasyevc7597622013-02-28 10:58:52 -080085
86private:
87 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 PeriodicPrinter();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080089
90 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080091 Reset();
Alexander Afanasyevc7597622013-02-28 10:58:52 -080092
93private:
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