blob: bca0022854562327901121d77977800f47d2def1 [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
27namespace ns3 {
28
29class Node;
30class Packet;
31
32namespace ndn {
33
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070034namespace pit {
35class Entry;
36}
37
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080038class Face;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070039
40class Interest;
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070041class ContentObject;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080042
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080043/**
44 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
45 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080046class L3Tracer : public SimpleRefCount<L3Tracer>
47{
48public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080049 /**
50 * @brief Trace constructor that attaches to the node using node pointer
51 * @param node pointer to the node
52 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080053 L3Tracer (Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080054
55 /**
56 * @brief Trace constructor that attaches to the node using node name
57 * @param nodeName name of the node registered using Names::Add
58 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080059 L3Tracer (const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080060
61 /**
62 * @brief Destructor
63 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080064 virtual ~L3Tracer ();
65
Alexander Afanasyev59314802012-11-26 14:56:04 -080066 /**
67 * @brief Print head of the trace (e.g., for post-processing)
68 *
69 * @param os reference to output stream
70 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080071 virtual void
72 PrintHeader (std::ostream &os) const = 0;
73
Alexander Afanasyev59314802012-11-26 14:56:04 -080074 /**
75 * @brief Print current trace data
76 *
77 * @param os reference to output stream
78 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080079 virtual void
80 Print (std::ostream &os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070081
Alexander Afanasyev59314802012-11-26 14:56:04 -080082protected:
83 void
84 Connect ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070085
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080086 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070087 OutInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080088
89 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070090 InInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080091
92 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070093 DropInterests (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070094
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080095 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -070096 OutNacks (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 InNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800100
101 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700102 DropNacks (Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800103
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700104
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800105 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700106 OutData (Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800107
108 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700109 InData (Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800110
111 virtual void
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700112 DropData (Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800113
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700114 virtual void
115 SatisfiedInterests (Ptr<const pit::Entry>) = 0;
116
117 virtual void
118 TimedOutInterests (Ptr<const pit::Entry>) = 0;
119
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800120protected:
121 std::string m_node;
122 Ptr<Node> m_nodePtr;
123
124 struct Stats
125 {
126 inline void Reset ()
127 {
128 m_inInterests = 0;
129 m_outInterests = 0;
130 m_dropInterests = 0;
131 m_inNacks = 0;
132 m_outNacks = 0;
133 m_dropNacks = 0;
134 m_inData = 0;
135 m_outData = 0;
136 m_dropData = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700137 m_satisfiedInterests = 0;
138 m_timedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700140
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800141 double m_inInterests;
142 double m_outInterests;
143 double m_dropInterests;
144 double m_inNacks;
145 double m_outNacks;
146 double m_dropNacks;
147 double m_inData;
148 double m_outData;
149 double m_dropData;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700150 double m_satisfiedInterests;
151 double m_timedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800152 };
153};
154
Alexander Afanasyev59314802012-11-26 14:56:04 -0800155/**
156 * @brief Helper to dump the trace to an output stream
157 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800158inline std::ostream&
159operator << (std::ostream &os, const L3Tracer &tracer)
160{
161 os << "# ";
162 tracer.PrintHeader (os);
163 os << "\n";
164 tracer.Print (os);
165 return os;
166}
167
168} // namespace ndn
169} // namespace ns3
170
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700171#endif // NDN_L3_TRACER_H