blob: 6b0fafe97f6f2f891f1c3d0beea720aad7dabf1a [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"
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -070024#include "ns3/ndnSIM/NFD/daemon/table/pit-entry.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070025
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080026#include "ns3/ptr.h"
27#include "ns3/simple-ref-count.h"
28
29namespace ns3 {
30
31class Node;
32class Packet;
33
34namespace ndn {
35
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080036/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070037 * @ingroup ndn-tracers
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080038 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
39 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040class L3Tracer : public SimpleRefCount<L3Tracer> {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080041public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080042 /**
43 * @brief Trace constructor that attaches to the node using node pointer
44 * @param node pointer to the node
45 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 L3Tracer(Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080047
48 /**
49 * @brief Trace constructor that attaches to the node using node name
50 * @param nodeName name of the node registered using Names::Add
51 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 L3Tracer(const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080053
54 /**
55 * @brief Destructor
56 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 virtual ~L3Tracer();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080058
Alexander Afanasyev59314802012-11-26 14:56:04 -080059 /**
60 * @brief Print head of the trace (e.g., for post-processing)
61 *
62 * @param os reference to output stream
63 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080064 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080066
Alexander Afanasyev59314802012-11-26 14:56:04 -080067 /**
68 * @brief Print current trace data
69 *
70 * @param os reference to output stream
71 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080072 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 Print(std::ostream& os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070074
Alexander Afanasyev59314802012-11-26 14:56:04 -080075protected:
76 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 Connect();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070078
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080079 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080080 OutInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080081
82 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080083 InInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080084
85 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080086 OutData(const Data&, const Face&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070087
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080088 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080089 InData(const Data&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080090
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080091 virtual void
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -080092 OutNack(const lp::Nack& nack, const Face&) = 0;
93
94 virtual void
95 InNack(const lp::Nack&, const Face&) = 0;
96
97 virtual void
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -080098 SatisfiedInterests(const nfd::pit::Entry&, const Face&, const Data&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070099
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800100 virtual void
101 TimedOutInterests(const nfd::pit::Entry&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700102
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800103protected:
104 std::string m_node;
105 Ptr<Node> m_nodePtr;
106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 struct Stats {
108 inline void
109 Reset()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800110 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 m_inInterests = 0;
112 m_outInterests = 0;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800113 m_inData = 0;
114 m_outData = 0;
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800115 m_inNack = 0;
116 m_outNack = 0;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800117 m_satisfiedInterests = 0;
118 m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700119
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800120 m_outSatisfiedInterests = 0;
121 m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800122 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700123
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800124 double m_inInterests;
125 double m_outInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800126 double m_inData;
127 double m_outData;
Spyridon Mastorakis8a74d0c2016-12-07 14:34:07 -0800128 double m_inNack;
129 double m_outNack;
Alexander Afanasyevdc6fae82015-01-08 21:44:15 -0800130 double m_satisfiedInterests;
131 double m_timedOutInterests;
132 double m_outSatisfiedInterests;
133 double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800134 };
135};
136
Alexander Afanasyev59314802012-11-26 14:56:04 -0800137/**
138 * @brief Helper to dump the trace to an output stream
139 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800140inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800141operator<<(std::ostream& os, const L3Tracer& tracer)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800142{
143 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800144 tracer.PrintHeader(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800145 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 tracer.Print(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800147 return os;
148}
149
150} // namespace ndn
151} // namespace ns3
152
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700153#endif // NDN_L3_TRACER_H