blob: 48105ac42a57c3dec1e92cc1766e58fb4e7d087c [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
24#include "l2-tracer.h"
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
33namespace ns3 {
34
35/**
36 * @ingroup ndn
37 */
38class L2RateTracer : public L2Tracer
39{
40public:
41 /**
42 * @brief Network layer tracer constructor
43 */
44 L2RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
45 virtual ~L2RateTracer ();
46
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,
52 * as well as how often data will be written into the trace file (default, every half second)
53 *
54 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
55 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
56 *
57 */
58 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L2RateTracer> > >
59 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
60
61 void
62 SetAveragingPeriod (const Time &period);
63
64 virtual void
65 PrintHeader (std::ostream &os) const;
66
67 virtual void
68 Print (std::ostream &os) const;
69
70 virtual void
71 Drop (Ptr<const Packet>);
72
73private:
74 void
75 PeriodicPrinter ();
76
77 void
78 Reset ();
79
80private:
81 boost::shared_ptr<std::ostream> m_os;
82 Time m_period;
83 EventId m_printEvent;
84
85 mutable boost::tuple<Stats, Stats, Stats, Stats> m_stats;
86};
87
88} // namespace ns3
89
90#endif // L2_RATE_TRACER_H