blob: c3f437b8f3c2b69bd818f18a57fa78869d249dd4 [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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080050
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
71 *
72 */
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
76protected:
77 // 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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080095
96 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 Afanasyevc9d5c1a2012-11-21 18:00:26 -0800107
108 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
120protected:
121 void
Alexander Afanasyev59314802012-11-26 14:56:04 -0800122 SetAveragingPeriod (const Time &period);
123
124 void
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800125 Reset ();
126
127 void
128 PeriodicPrinter ();
129
130protected:
Alexander Afanasyev59314802012-11-26 14:56:04 -0800131 boost::shared_ptr<std::ostream> m_os;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800132
133 Time m_period;
134 EventId m_printEvent;
Alexander Afanasyev59314802012-11-26 14:56:04 -0800135
136 mutable std::map<Ptr<const Face>, boost::tuple<Stats, Stats> > m_stats;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800137};
138
139} // namespace ndn
140} // namespace ns3
141
142#endif // NDN_L3_AGGREGATE_TRACER_H