blob: 791d9534d591ebfc0627f10d3436f2a38e0cbb9b [file] [log] [blame]
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -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 CCNX_RATE_L3_TRACER_H
22#define CCNX_RATE_L3_TRACER_H
23
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080024#include "ndn-l3-tracer.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080025
26#include "ns3/nstime.h"
27#include "ns3/event-id.h"
28
29#include <boost/tuple/tuple.hpp>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080030#include <boost/shared_ptr.hpp>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080031#include <map>
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080032#include <list>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080033
34namespace ns3 {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080035namespace ndn {
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080036
37/**
Alexander Afanasyev59314802012-11-26 14:56:04 -080038 * @ingroup ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080039 * @brief CCNx network-layer rate tracer
40 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080041class L3RateTracer : public L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080042{
43public:
44 /**
Alexander Afanasyev59314802012-11-26 14:56:04 -080045 * @brief Trace constructor that attaches to the node using node pointer
46 * @param os reference to the output stream
47 * @param node pointer to the node
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080048 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080049 L3RateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080050
51 /**
52 * @brief Trace constructor that attaches to the node using node name
53 * @param os reference to the output stream
54 * @param nodeName name of the node registered using Names::Add
55 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080056 L3RateTracer (boost::shared_ptr<std::ostream> os, const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080057
58 /**
59 * @brief Destructor
60 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080061 virtual ~L3RateTracer ();
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080062
Alexander Afanasyev59314802012-11-26 14:56:04 -080063 /**
64 * @brief Helper method to install tracers on all simulation nodes
65 *
66 * @param file File to which traces will be written
67 * @param averagingPeriod Defines averaging period for the rate calculation,
68 * as well as how often data will be written into the trace file (default, every half second)
69 *
70 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
71 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
72 *
73 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080074 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3RateTracer> > >
75 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
Alexander Afanasyev59314802012-11-26 14:56:04 -080076
77 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080078 virtual void
79 PrintHeader (std::ostream &os) const;
80
81 virtual void
82 Print (std::ostream &os) const;
83
Alexander Afanasyev59314802012-11-26 14:56:04 -080084protected:
85 // from L3Tracer
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080086 virtual void
87 OutInterests (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080088 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080089
90 virtual void
91 InInterests (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080092 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080093
94 virtual void
95 DropInterests (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080096 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080097
98 virtual void
99 OutNacks (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800100 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800101
102 virtual void
103 InNacks (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800104 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800105
106 virtual void
107 DropNacks (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800108 Ptr<const InterestHeader>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800109
110 virtual void
111 OutData (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800112 Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800113
114 virtual void
115 InData (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800116 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800117
118 virtual void
119 DropData (std::string context,
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800120 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800121
122private:
123 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800124 SetAveragingPeriod (const Time &period);
125
126 void
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800127 PeriodicPrinter ();
128
129 void
130 Reset ();
131
132private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800133 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800134 Time m_period;
135 EventId m_printEvent;
136
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800137 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800138};
139
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800140} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800141} // namespace ns3
142
143#endif // CCNX_RATE_L3_TRACER_H