blob: 4db4e70a4e053158643daf2d3fc38448b325820c [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
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070072 *
Alexander Afanasyev59314802012-11-26 14:56:04 -080073 */
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 Afanasyeveae83ee2013-03-15 15:01:10 -070088 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080089
90 virtual void
91 InInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070092 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080093
94 virtual void
95 DropInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070096 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070097
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080098 virtual void
99 OutNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700100 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800101
102 virtual void
103 InNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700104 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800105
106 virtual void
107 DropNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700108 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700109
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800110 virtual void
111 OutData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700112 Ptr<const ContentObject>, 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 Afanasyeveae83ee2013-03-15 15:01:10 -0700116 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800117
118 virtual void
119 DropData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700120 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800121
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700122 virtual void
123 SatisfiedInterests (Ptr<const pit::Entry>);
124
125 virtual void
126 TimedOutInterests (Ptr<const pit::Entry>);
127
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800128private:
129 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800130 SetAveragingPeriod (const Time &period);
131
132 void
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800133 PeriodicPrinter ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700134
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800135 void
136 Reset ();
137
138private:
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800140 Time m_period;
141 EventId m_printEvent;
142
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800143 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats, Stats, Stats> > m_stats;
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800144};
145
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800146} // namespace ndn
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800147} // namespace ns3
148
149#endif // CCNX_RATE_L3_TRACER_H