blob: d3534fa0fd648d2dd5799a4b96ecedc7412e08b9 [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 Afanasyevbe55cf62014-12-20 17:51:09 -080052class L3Tracer : public SimpleRefCount<L3Tracer> {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080053public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080054 /**
55 * @brief Trace constructor that attaches to the node using node pointer
56 * @param node pointer to the node
57 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 L3Tracer(Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080059
60 /**
61 * @brief Trace constructor that attaches to the node using node name
62 * @param nodeName name of the node registered using Names::Add
63 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 L3Tracer(const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080065
66 /**
67 * @brief Destructor
68 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 virtual ~L3Tracer();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080070
Alexander Afanasyev59314802012-11-26 14:56:04 -080071 /**
72 * @brief Print head of the trace (e.g., for post-processing)
73 *
74 * @param os reference to output stream
75 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080076 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080078
Alexander Afanasyev59314802012-11-26 14:56:04 -080079 /**
80 * @brief Print current trace data
81 *
82 * @param os reference to output stream
83 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080084 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085 Print(std::ostream& os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070086
Alexander Afanasyev59314802012-11-26 14:56:04 -080087protected:
88 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 Connect();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070090
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080091 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 OutInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080093
94 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 InInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080096
97 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 DropInterests(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070099
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800100 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 OutNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800102
103 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 InNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800105
106 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 DropNacks(Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700108
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800109 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 OutData(Ptr<const Data>, bool fromCache, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800111
112 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 InData(Ptr<const Data>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800114
115 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 DropData(Ptr<const Data>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800117
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700118 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800119 SatisfiedInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700120
121 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800122 TimedOutInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700123
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800124protected:
125 std::string m_node;
126 Ptr<Node> m_nodePtr;
127
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 struct Stats {
129 inline void
130 Reset()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800131 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132 m_inInterests = 0;
133 m_outInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800134 m_dropInterests = 0;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 m_inNacks = 0;
136 m_outNacks = 0;
137 m_dropNacks = 0;
138 m_inData = 0;
139 m_outData = 0;
140 m_dropData = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700141 m_satisfiedInterests = 0;
142 m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700143
144 m_outSatisfiedInterests = 0;
145 m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800146 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700147
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800148 double m_inInterests;
149 double m_outInterests;
150 double m_dropInterests;
151 double m_inNacks;
152 double m_outNacks;
153 double m_dropNacks;
154 double m_inData;
155 double m_outData;
156 double m_dropData;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700157 double m_satisfiedInterests;
158 double m_timedOutInterests;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700159 double m_outSatisfiedInterests;
160 double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800161 };
162};
163
Alexander Afanasyev59314802012-11-26 14:56:04 -0800164/**
165 * @brief Helper to dump the trace to an output stream
166 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800167inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800168operator<<(std::ostream& os, const L3Tracer& tracer)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800169{
170 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800171 tracer.PrintHeader(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800172 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800173 tracer.Print(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800174 return os;
175}
176
177} // namespace ndn
178} // namespace ns3
179
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700180#endif // NDN_L3_TRACER_H