blob: e624c3d1d243f443483784d9386d18c2a3754ca3 [file] [log] [blame]
Alexander Afanasyev7e71c752012-01-25 21:40:39 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 UCLA
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 IPV4_RATE_L3_TRACER_H
22#define IPV4_RATE_L3_TRACER_H
23
24#include "ipv4-l3-tracer.h"
25
26#include "ns3/nstime.h"
27#include "ns3/event-id.h"
28
29#include <boost/tuple/tuple.hpp>
Alexander Afanasyev49165862013-01-31 00:38:20 -080030#include <boost/shared_ptr.hpp>
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080031#include <map>
32
33namespace ns3 {
34
35/**
36 * @ingroup ccnx
37 * @brief CCNx network-layer rate tracer
38 */
39class Ipv4RateL3Tracer : public Ipv4L3Tracer
40{
41public:
42 /**
43 * @brief Network layer tracer constructor
44 */
Alexander Afanasyev49165862013-01-31 00:38:20 -080045 Ipv4RateL3Tracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080046 virtual ~Ipv4RateL3Tracer ();
47
Alexander Afanasyev49165862013-01-31 00:38:20 -080048 /**
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,
53 * as well as how often data will be written into the trace file (default, every half second)
54 *
55 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
56 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
57 *
58 */
59 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<Ipv4RateL3Tracer> > >
60 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
61
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080062 void
63 SetAveragingPeriod (const Time &period);
Alexander Afanasyev49165862013-01-31 00:38:20 -080064
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080065 virtual void
66 PrintHeader (std::ostream &os) const;
67
68 virtual void
69 Print (std::ostream &os) const;
70
71 virtual void
72 Rx (std::string context,
73 Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
74
75 virtual void
76 Tx (std::string context,
77 Ptr<const Packet>, Ptr<Ipv4>, uint32_t);
78
79 virtual void
80 Drop (std::string context,
81 const Ipv4Header &, Ptr<const Packet>, Ipv4L3Protocol::DropReason, Ptr<Ipv4>, uint32_t);
82
83private:
84 void
85 PeriodicPrinter ();
Alexander Afanasyev49165862013-01-31 00:38:20 -080086
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080087 void
88 Reset ();
89
90private:
Alexander Afanasyev49165862013-01-31 00:38:20 -080091 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080092 Time m_period;
93 EventId m_printEvent;
94
95 mutable std::map<uint32_t, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
96};
97
98} // namespace ns3
99
100#endif // IPV4_RATE_L3_TRACER_H