blob: 72c4cacb3ecee777489ecfdc26197ad00ec42ee1 [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
34class InterestHeader;
35class Face;
36class ContentObjectHeader;
37
38class L3Tracer : public SimpleRefCount<L3Tracer>
39{
40public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080041 /**
42 * @brief Trace constructor that attaches to the node using node pointer
43 * @param node pointer to the node
44 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080045 L3Tracer (Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080046
47 /**
48 * @brief Trace constructor that attaches to the node using node name
49 * @param nodeName name of the node registered using Names::Add
50 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080051 L3Tracer (const std::string &node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080052
53 /**
54 * @brief Destructor
55 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080056 virtual ~L3Tracer ();
57
Alexander Afanasyev59314802012-11-26 14:56:04 -080058 /**
59 * @brief Print head of the trace (e.g., for post-processing)
60 *
61 * @param os reference to output stream
62 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080063 virtual void
64 PrintHeader (std::ostream &os) const = 0;
65
Alexander Afanasyev59314802012-11-26 14:56:04 -080066 /**
67 * @brief Print current trace data
68 *
69 * @param os reference to output stream
70 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080071 virtual void
72 Print (std::ostream &os) const = 0;
73
Alexander Afanasyev59314802012-11-26 14:56:04 -080074protected:
75 void
76 Connect ();
77
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080078 virtual void
79 OutInterests (std::string context,
80 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
81
82 virtual void
83 InInterests (std::string context,
84 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
85
86 virtual void
87 DropInterests (std::string context,
88 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
89
90 virtual void
91 OutNacks (std::string context,
92 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
93
94 virtual void
95 InNacks (std::string context,
96 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
97
98 virtual void
99 DropNacks (std::string context,
100 Ptr<const InterestHeader>, Ptr<const Face>) = 0;
101
102
103 virtual void
104 OutData (std::string context,
105 Ptr<const ContentObjectHeader>, Ptr<const Packet>, bool fromCache, Ptr<const Face>) = 0;
106
107 virtual void
108 InData (std::string context,
109 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>) = 0;
110
111 virtual void
112 DropData (std::string context,
113 Ptr<const ContentObjectHeader>, Ptr<const Packet>, Ptr<const Face>) = 0;
114
115protected:
116 std::string m_node;
117 Ptr<Node> m_nodePtr;
118
119 struct Stats
120 {
121 inline void Reset ()
122 {
123 m_inInterests = 0;
124 m_outInterests = 0;
125 m_dropInterests = 0;
126 m_inNacks = 0;
127 m_outNacks = 0;
128 m_dropNacks = 0;
129 m_inData = 0;
130 m_outData = 0;
131 m_dropData = 0;
132 }
133
134 double m_inInterests;
135 double m_outInterests;
136 double m_dropInterests;
137 double m_inNacks;
138 double m_outNacks;
139 double m_dropNacks;
140 double m_inData;
141 double m_outData;
142 double m_dropData;
143 };
144};
145
Alexander Afanasyev59314802012-11-26 14:56:04 -0800146/**
147 * @brief Helper to dump the trace to an output stream
148 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800149inline std::ostream&
150operator << (std::ostream &os, const L3Tracer &tracer)
151{
152 os << "# ";
153 tracer.PrintHeader (os);
154 os << "\n";
155 tracer.Print (os);
156 return os;
157}
158
159} // namespace ndn
160} // namespace ns3
161
162#endif // CCNX_L3_TRACER_H