blob: 2f132bdabc4dd17177e3f0f2105519dea7e99e75 [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-2012 University of California, Los Angeles
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
Alexander Afanasyev5352af32013-07-15 09:51:28 -070021#ifndef NDN_L3_TRACER_H
22#define NDN_L3_TRACER_H
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080023
24#include "ns3/ptr.h"
25#include "ns3/simple-ref-count.h"
26
Alexander Afanasyev79206512013-07-27 16:49:12 -070027/**
28 * @ingroup ndn-helpers
29 * @defgroup ndn-tracers Helpers to simplify metric collection
30 */
31
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080032namespace ns3 {
33
34class Node;
35class Packet;
36
37namespace ndn {
38
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070039namespace pit {
40class Entry;
41}
42
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080043class Face;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070044
45class Interest;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070046class Data;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080047
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080048/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070049 * @ingroup ndn-tracers
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080050 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
51 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080052class L3Tracer : public SimpleRefCount<L3Tracer>
53{
54public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080055 /**
56 * @brief Trace constructor that attaches to the node using node pointer
57 * @param node pointer to the node
58 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080059 L3Tracer (Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080060
61 /**
62 * @brief Trace constructor that attaches to the node using node name
63 * @param nodeName name of the node registered using Names::Add
64 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080065 L3Tracer (const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080066
67 /**
68 * @brief Destructor
69 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080070 virtual ~L3Tracer ();
71
Alexander Afanasyev59314802012-11-26 14:56:04 -080072 /**
73 * @brief Print head of the trace (e.g., for post-processing)
74 *
75 * @param os reference to output stream
76 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080077 virtual void
78 PrintHeader (std::ostream &os) const = 0;
79
Alexander Afanasyev59314802012-11-26 14:56:04 -080080 /**
81 * @brief Print current trace data
82 *
83 * @param os reference to output stream
84 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080085 virtual void
86 Print (std::ostream &os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070087
Alexander Afanasyev59314802012-11-26 14:56:04 -080088protected:
89 void
90 Connect ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070091
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080092 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070093 OutInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080094
95 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070096 InInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080097
98 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070099 DropInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700100
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800101 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700102 OutNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800103
104 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700105 InNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800106
107 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700108 DropNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800109
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700110
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800111 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700112 OutData (Ptr<const Data>, bool fromCache, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800113
114 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700115 InData (Ptr<const Data>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800116
117 virtual void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700118 DropData (Ptr<const Data>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800119
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700120 virtual void
121 SatisfiedInterests (Ptr<const pit::Entry>) = 0;
122
123 virtual void
124 TimedOutInterests (Ptr<const pit::Entry>) = 0;
125
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800126protected:
127 std::string m_node;
128 Ptr<Node> m_nodePtr;
129
130 struct Stats
131 {
132 inline void Reset ()
133 {
134 m_inInterests = 0;
135 m_outInterests = 0;
136 m_dropInterests = 0;
137 m_inNacks = 0;
138 m_outNacks = 0;
139 m_dropNacks = 0;
140 m_inData = 0;
141 m_outData = 0;
142 m_dropData = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700143 m_satisfiedInterests = 0;
144 m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700145
146 m_outSatisfiedInterests = 0;
147 m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800148 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700149
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800150 double m_inInterests;
151 double m_outInterests;
152 double m_dropInterests;
153 double m_inNacks;
154 double m_outNacks;
155 double m_dropNacks;
156 double m_inData;
157 double m_outData;
158 double m_dropData;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700159 double m_satisfiedInterests;
160 double m_timedOutInterests;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700161 double m_outSatisfiedInterests;
162 double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800163 };
164};
165
Alexander Afanasyev59314802012-11-26 14:56:04 -0800166/**
167 * @brief Helper to dump the trace to an output stream
168 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800169inline std::ostream&
170operator << (std::ostream &os, const L3Tracer &tracer)
171{
172 os << "# ";
173 tracer.PrintHeader (os);
174 os << "\n";
175 tracer.Print (os);
176 return os;
177}
178
179} // namespace ndn
180} // namespace ns3
181
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700182#endif // NDN_L3_TRACER_H