blob: 4b2cc5aced29e0bbdc19272875171e0bc229bbad [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
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
25
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080026#include "ns3/ptr.h"
27#include "ns3/simple-ref-count.h"
28
Alexander Afanasyev79206512013-07-27 16:49:12 -070029/**
30 * @ingroup ndn-helpers
31 * @defgroup ndn-tracers Helpers to simplify metric collection
32 */
33
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080034namespace ns3 {
35
36class Node;
37class Packet;
38
39namespace ndn {
40
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070041namespace pit {
42class Entry;
43}
44
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080045class Face;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070046
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080047/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070048 * @ingroup ndn-tracers
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080049 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
50 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051class L3Tracer : public SimpleRefCount<L3Tracer> {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080052public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080053 /**
54 * @brief Trace constructor that attaches to the node using node pointer
55 * @param node pointer to the node
56 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 L3Tracer(Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080058
59 /**
60 * @brief Trace constructor that attaches to the node using node name
61 * @param nodeName name of the node registered using Names::Add
62 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 L3Tracer(const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080064
65 /**
66 * @brief Destructor
67 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 virtual ~L3Tracer();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080069
Alexander Afanasyev59314802012-11-26 14:56:04 -080070 /**
71 * @brief Print head of the trace (e.g., for post-processing)
72 *
73 * @param os reference to output stream
74 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080075 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080077
Alexander Afanasyev59314802012-11-26 14:56:04 -080078 /**
79 * @brief Print current trace data
80 *
81 * @param os reference to output stream
82 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080083 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Print(std::ostream& os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070085
Alexander Afanasyev59314802012-11-26 14:56:04 -080086protected:
87 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 Connect();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070089
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080090 virtual void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070091 OutInterests(shared_ptr<const Interest>, shared_ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080092
93 virtual void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070094 InInterests(shared_ptr<const Interest>, shared_ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080095
96 virtual void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070097 OutData(shared_ptr<const Data>, bool fromCache, shared_ptr<const Face>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070098
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080099 virtual void
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -0700100 InData(shared_ptr<const Data>, shared_ptr<const Face>) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800101
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700102 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 SatisfiedInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700104
105 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 TimedOutInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700107
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800108protected:
109 std::string m_node;
110 Ptr<Node> m_nodePtr;
111
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 struct Stats {
113 inline void
114 Reset()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800115 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800116 m_inInterests = 0;
117 m_outInterests = 0;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 m_inData = 0;
119 m_outData = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700120 m_satisfiedInterests = 0;
121 m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700122
123 m_outSatisfiedInterests = 0;
124 m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800125 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700126
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800127 double m_inInterests;
128 double m_outInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800129 double m_inData;
130 double m_outData;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700131 double m_satisfiedInterests;
132 double m_timedOutInterests;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700133 double m_outSatisfiedInterests;
134 double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800135 };
136};
137
Alexander Afanasyev59314802012-11-26 14:56:04 -0800138/**
139 * @brief Helper to dump the trace to an output stream
140 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800141inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142operator<<(std::ostream& os, const L3Tracer& tracer)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800143{
144 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800145 tracer.PrintHeader(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800146 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 tracer.Print(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800148 return os;
149}
150
151} // namespace ndn
152} // namespace ns3
153
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700154#endif // NDN_L3_TRACER_H