blob: b7f6ed3b65d922b5d596ab106e0592b23b3e847b [file] [log] [blame]
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -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 NDN_L3_AGGREGATE_TRACER_H
22#define NDN_L3_AGGREGATE_TRACER_H
23
24#include "ndn-l3-tracer.h"
25
26#include <ns3/nstime.h>
27#include <ns3/event-id.h>
28
Alexander Afanasyev59314802012-11-26 14:56:04 -080029#include <boost/tuple/tuple.hpp>
30#include <boost/shared_ptr.hpp>
31#include <map>
32#include <list>
33
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080034namespace ns3 {
35namespace ndn {
36
Alexander Afanasyev59314802012-11-26 14:56:04 -080037/**
38 * @ingroup ndn
39 * @brief CCNx network-layer tracer for aggregate packet counts
40 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080041class L3AggregateTracer : public L3Tracer
42{
43public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080044 /**
45 * @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
48 */
49 L3AggregateTracer (boost::shared_ptr<std::ostream> os, Ptr<Node> node);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070050
Alexander Afanasyev59314802012-11-26 14:56:04 -080051 /**
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 */
56 L3AggregateTracer (boost::shared_ptr<std::ostream> os, const std::string &nodeName);
57
58 /**
59 * @brief Destructor
60 */
61 virtual ~L3AggregateTracer ();
62
63 /**
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 How often data will be written into the trace file (default, every half second)
68 *
69 * @returns a tuple of reference to output stream and list of tracers. !!! Attention !!! This tuple needs to be preserved
70 * for the lifetime of simulation, otherwise SEGFAULTs are inevitable
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070071 *
Alexander Afanasyev59314802012-11-26 14:56:04 -080072 */
73 static boost::tuple< boost::shared_ptr<std::ostream>, std::list<Ptr<L3AggregateTracer> > >
74 InstallAll (const std::string &file, Time averagingPeriod = Seconds (0.5));
75
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070076protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -080077 // from L3Tracer
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080078 virtual void
79 PrintHeader (std::ostream &os) const;
80
81 virtual void
82 Print (std::ostream &os) const;
83
84 virtual void
85 OutInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070086 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080087
88 virtual void
89 InInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070090 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080091
92 virtual void
93 DropInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070094 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070095
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080096 virtual void
97 OutNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070098 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080099
100 virtual void
101 InNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700102 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800103
104 virtual void
105 DropNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700106 Ptr<const Interest>, Ptr<const Face>);
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700107
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800108 virtual void
109 OutData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700110 Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800111
112 virtual void
113 InData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700114 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800115
116 virtual void
117 DropData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700118 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800119
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700120
121 virtual void
122 SatisfiedInterests (Ptr<const pit::Entry>);
123
124 virtual void
125 TimedOutInterests (Ptr<const pit::Entry>);
126
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800127protected:
128 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800129 SetAveragingPeriod (const Time &period);
130
131 void
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800132 Reset ();
133
134 void
135 PeriodicPrinter ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700136
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800137protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800138 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139
140 Time m_period;
141 EventId m_printEvent;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700142
Alexander Afanasyev59314802012-11-26 14:56:04 -0800143 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800144};
145
146} // namespace ndn
147} // namespace ns3
148
149#endif // NDN_L3_AGGREGATE_TRACER_H