blob: a04df6788649d9484ebbb64559921d5904bfff9f [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,
86 Ptr<const InterestHeader>, Ptr<const Face>);
87
88 virtual void
89 InInterests (std::string context,
90 Ptr<const InterestHeader>, Ptr<const Face>);
91
92 virtual void
93 DropInterests (std::string context,
94 Ptr<const InterestHeader>, Ptr<const Face>);
95
96 virtual void
97 OutNacks (std::string context,
98 Ptr<const InterestHeader>, Ptr<const Face>);
99
100 virtual void
101 InNacks (std::string context,
102 Ptr<const InterestHeader>, Ptr<const Face>);
103
104 virtual void
105 DropNacks (std::string context,
106 Ptr<const InterestHeader>, Ptr<const Face>);
107
108 virtual void
109 OutData (std::string context,
110 Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>);
111
112 virtual void
113 InData (std::string context,
114 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
115
116 virtual void
117 DropData (std::string context,
118 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>);
119
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