blob: af840f489ced4896fe9e7a5e70ccee9c70816105 [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
21#ifndef CCNX_L3_TRACER_H
22#define CCNX_L3_TRACER_H
23
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 Afanasyev73f06f62013-03-15 15:41:38 -070043typedef Interest InterestHeader;
44typedef ContentObject ContentObjectHeader;
45
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080046/**
47 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
48 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080049class L3Tracer : public SimpleRefCount<L3Tracer>
50{
51public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080052 /**
53 * @brief Trace constructor that attaches to the node using node pointer
54 * @param node pointer to the node
55 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080056 L3Tracer (Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080057
58 /**
59 * @brief Trace constructor that attaches to the node using node name
60 * @param nodeName name of the node registered using Names::Add
61 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080062 L3Tracer (const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080063
64 /**
65 * @brief Destructor
66 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080067 virtual ~L3Tracer ();
68
Alexander Afanasyev59314802012-11-26 14:56:04 -080069 /**
70 * @brief Print head of the trace (e.g., for post-processing)
71 *
72 * @param os reference to output stream
73 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080074 virtual void
75 PrintHeader (std::ostream &os) const = 0;
76
Alexander Afanasyev59314802012-11-26 14:56:04 -080077 /**
78 * @brief Print current trace data
79 *
80 * @param os reference to output stream
81 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080082 virtual void
83 Print (std::ostream &os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070084
Alexander Afanasyev59314802012-11-26 14:56:04 -080085protected:
86 void
87 Connect ();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070088
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080089 virtual void
90 OutInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070091 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080092
93 virtual void
94 InInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070095 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080096
97 virtual void
98 DropInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070099 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
102 OutNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700103 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800104
105 virtual void
106 InNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700107 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800108
109 virtual void
110 DropNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700111 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800112
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700113
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800114 virtual void
115 OutData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700116 Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800117
118 virtual void
119 InData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700120 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800121
122 virtual void
123 DropData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700124 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800125
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700126 virtual void
127 SatisfiedInterests (Ptr<const pit::Entry>) = 0;
128
129 virtual void
130 TimedOutInterests (Ptr<const pit::Entry>) = 0;
131
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800132protected:
133 std::string m_node;
134 Ptr<Node> m_nodePtr;
135
136 struct Stats
137 {
138 inline void Reset ()
139 {
140 m_inInterests = 0;
141 m_outInterests = 0;
142 m_dropInterests = 0;
143 m_inNacks = 0;
144 m_outNacks = 0;
145 m_dropNacks = 0;
146 m_inData = 0;
147 m_outData = 0;
148 m_dropData = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700149 m_satisfiedInterests = 0;
150 m_timedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800151 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700152
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800153 double m_inInterests;
154 double m_outInterests;
155 double m_dropInterests;
156 double m_inNacks;
157 double m_outNacks;
158 double m_dropNacks;
159 double m_inData;
160 double m_outData;
161 double m_dropData;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700162 double m_satisfiedInterests;
163 double m_timedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800164 };
165};
166
Alexander Afanasyev59314802012-11-26 14:56:04 -0800167/**
168 * @brief Helper to dump the trace to an output stream
169 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800170inline std::ostream&
171operator << (std::ostream &os, const L3Tracer &tracer)
172{
173 os << "# ";
174 tracer.PrintHeader (os);
175 os << "\n";
176 tracer.Print (os);
177 return os;
178}
179
180} // namespace ndn
181} // namespace ns3
182
183#endif // CCNX_L3_TRACER_H