blob: 15dd41fbebdd8668a5f3ef48f170c401871373dc [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080019
Alexander Afanasyev5352af32013-07-15 09:51:28 -070020#ifndef NDN_L3_TRACER_H
21#define NDN_L3_TRACER_H
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080025#include "ns3/ptr.h"
26#include "ns3/simple-ref-count.h"
27
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080028namespace nfd {
29namespace pit {
30class Entry;
31} // namespace pit
32} // namespace nfd
33
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080034namespace ns3 {
35
36class Node;
37class Packet;
38
39namespace ndn {
40
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080041/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070042 * @ingroup ndn-tracers
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080043 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
44 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045class L3Tracer : public SimpleRefCount<L3Tracer> {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080046public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080047 /**
48 * @brief Trace constructor that attaches to the node using node pointer
49 * @param node pointer to the node
50 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 L3Tracer(Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080052
53 /**
54 * @brief Trace constructor that attaches to the node using node name
55 * @param nodeName name of the node registered using Names::Add
56 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 L3Tracer(const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080058
59 /**
60 * @brief Destructor
61 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 virtual ~L3Tracer();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080063
Alexander Afanasyev59314802012-11-26 14:56:04 -080064 /**
65 * @brief Print head of the trace (e.g., for post-processing)
66 *
67 * @param os reference to output stream
68 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080069 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080071
Alexander Afanasyev59314802012-11-26 14:56:04 -080072 /**
73 * @brief Print current trace data
74 *
75 * @param os reference to output stream
76 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080077 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 Print(std::ostream& os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070079
Alexander Afanasyev59314802012-11-26 14:56:04 -080080protected:
81 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 Connect();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070083
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080084 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080085 OutInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080086
87 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080088 InInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080089
90 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080091 OutData(const Data&, const Face&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070092
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080093 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080094 InData(const Data&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080095
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080096 virtual void
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -080097 OutNack(const lp::Nack& nack, const Face&) = 0;
98
99 virtual void
100 InNack(const lp::Nack&, const Face&) = 0;
101
102 virtual void
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800103 SatisfiedInterests(const nfd::pit::Entry&, const Face&, const Data&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700104
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800105 virtual void
106 TimedOutInterests(const nfd::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;
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800120 m_inNack = 0;
121 m_outNack = 0;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800122 m_satisfiedInterests = 0;
123 m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700124
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800125 m_outSatisfiedInterests = 0;
126 m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800127 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700128
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800129 double m_inInterests;
130 double m_outInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800131 double m_inData;
132 double m_outData;
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800133 double m_inNack;
134 double m_outNack;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800135 double m_satisfiedInterests;
136 double m_timedOutInterests;
137 double m_outSatisfiedInterests;
138 double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800139 };
140};
141
Alexander Afanasyev59314802012-11-26 14:56:04 -0800142/**
143 * @brief Helper to dump the trace to an output stream
144 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800145inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146operator<<(std::ostream& os, const L3Tracer& tracer)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800147{
148 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 tracer.PrintHeader(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800150 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800151 tracer.Print(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800152 return os;
153}
154
155} // namespace ndn
156} // namespace ns3
157
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700158#endif // NDN_L3_TRACER_H