blob: 45eec7d23fa0ef3b374abf36c28f3f97e5106beb [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 Afanasyevc9d5c1a2012-11-21 18:00:26 -080034class Face;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070035
36class Interest;
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070037class ContentObject;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080038
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070039typedef Interest InterestHeader;
40typedef ContentObject ContentObjectHeader;
41
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080042/**
43 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
44 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080045class L3Tracer : public SimpleRefCount<L3Tracer>
46{
47public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080048 /**
49 * @brief Trace constructor that attaches to the node using node pointer
50 * @param node pointer to the node
51 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080052 L3Tracer (Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080053
54 /**
55 * @brief Trace constructor that attaches to the node using node name
56 * @param nodeName name of the node registered using Names::Add
57 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080058 L3Tracer (const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080059
60 /**
61 * @brief Destructor
62 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080063 virtual ~L3Tracer ();
64
Alexander Afanasyev59314802012-11-26 14:56:04 -080065 /**
66 * @brief Print head of the trace (e.g., for post-processing)
67 *
68 * @param os reference to output stream
69 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080070 virtual void
71 PrintHeader (std::ostream &os) const = 0;
72
Alexander Afanasyev59314802012-11-26 14:56:04 -080073 /**
74 * @brief Print current trace data
75 *
76 * @param os reference to output stream
77 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080078 virtual void
79 Print (std::ostream &os) const = 0;
80
Alexander Afanasyev59314802012-11-26 14:56:04 -080081protected:
82 void
83 Connect ();
84
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080085 virtual void
86 OutInterests (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070087 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080088
89 virtual void
90 InInterests (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 DropInterests (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 OutNacks (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070099 Ptr<const Interest>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800100
101 virtual void
102 InNacks (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 DropNacks (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
110 virtual void
111 OutData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700112 Ptr<const ContentObject>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800113
114 virtual void
115 InData (std::string context,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700116 Ptr<const ContentObject>, Ptr<const Packet>, Ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800117
118 virtual void
119 DropData (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
122protected:
123 std::string m_node;
124 Ptr<Node> m_nodePtr;
125
126 struct Stats
127 {
128 inline void Reset ()
129 {
130 m_inInterests = 0;
131 m_outInterests = 0;
132 m_dropInterests = 0;
133 m_inNacks = 0;
134 m_outNacks = 0;
135 m_dropNacks = 0;
136 m_inData = 0;
137 m_outData = 0;
138 m_dropData = 0;
139 }
140
141 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;
150 };
151};
152
Alexander Afanasyev59314802012-11-26 14:56:04 -0800153/**
154 * @brief Helper to dump the trace to an output stream
155 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800156inline std::ostream&
157operator << (std::ostream &os, const L3Tracer &tracer)
158{
159 os << "# ";
160 tracer.PrintHeader (os);
161 os << "\n";
162 tracer.Print (os);
163 return os;
164}
165
166} // namespace ndn
167} // namespace ns3
168
169#endif // CCNX_L3_TRACER_H