blob: 2f3a3a7e1839cbe346044ffded6bdf51443abd37 [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"
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080025#include "ns3/ndnSIM/model/ndn-face.hpp"
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070026
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080027#include "ns3/ptr.h"
28#include "ns3/simple-ref-count.h"
29
30namespace ns3 {
31
32class Node;
33class Packet;
34
35namespace ndn {
36
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080037/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070038 * @ingroup ndn-tracers
Alexander Afanasyev0b9e3bd2012-12-10 15:27:09 -080039 * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack
40 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041class L3Tracer : public SimpleRefCount<L3Tracer> {
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080042public:
Alexander Afanasyev59314802012-11-26 14:56:04 -080043 /**
44 * @brief Trace constructor that attaches to the node using node pointer
45 * @param node pointer to the node
46 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 L3Tracer(Ptr<Node> node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080048
49 /**
50 * @brief Trace constructor that attaches to the node using node name
51 * @param nodeName name of the node registered using Names::Add
52 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 L3Tracer(const std::string& node);
Alexander Afanasyev59314802012-11-26 14:56:04 -080054
55 /**
56 * @brief Destructor
57 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 virtual ~L3Tracer();
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080059
Alexander Afanasyev59314802012-11-26 14:56:04 -080060 /**
61 * @brief Print head of the trace (e.g., for post-processing)
62 *
63 * @param os reference to output stream
64 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080065 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 PrintHeader(std::ostream& os) const = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080067
Alexander Afanasyev59314802012-11-26 14:56:04 -080068 /**
69 * @brief Print current trace data
70 *
71 * @param os reference to output stream
72 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080073 virtual void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 Print(std::ostream& os) const = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070075
Alexander Afanasyev59314802012-11-26 14:56:04 -080076protected:
77 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 Connect();
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070079
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080080 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080081 OutInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080082
83 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080084 InInterests(const Interest&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080085
86 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080087 OutData(const Data&, const Face&) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070088
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080089 virtual void
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080090 InData(const Data&, const Face&) = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080091
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080092 // virtual void
93 // SatisfiedInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070094
Spyridon Mastorakisda904f22014-11-05 16:23:33 -080095 // virtual void
96 // TimedOutInterests(Ptr<const pit::Entry>) = 0;
Alexander Afanasyev37b84c52013-04-26 13:38:52 -070097
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -080098protected:
99 std::string m_node;
100 Ptr<Node> m_nodePtr;
101
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800102 struct Stats {
103 inline void
104 Reset()
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800105 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 m_inInterests = 0;
107 m_outInterests = 0;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 m_inData = 0;
109 m_outData = 0;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800110 // m_satisfiedInterests = 0;
111 // m_timedOutInterests = 0;
Alexander Afanasyevbf939292013-07-15 10:10:01 -0700112
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800113 // m_outSatisfiedInterests = 0;
114 // m_outTimedOutInterests = 0;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800115 }
Alexander Afanasyev37b84c52013-04-26 13:38:52 -0700116
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800117 double m_inInterests;
118 double m_outInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800119 double m_inData;
120 double m_outData;
Spyridon Mastorakisda904f22014-11-05 16:23:33 -0800121 // double m_satisfiedInterests;
122 // double m_timedOutInterests;
123 // double m_outSatisfiedInterests;
124 // double m_outTimedOutInterests;
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800125 };
126};
127
Alexander Afanasyev59314802012-11-26 14:56:04 -0800128/**
129 * @brief Helper to dump the trace to an output stream
130 */
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800131inline std::ostream&
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800132operator<<(std::ostream& os, const L3Tracer& tracer)
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800133{
134 os << "# ";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800135 tracer.PrintHeader(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800136 os << "\n";
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800137 tracer.Print(os);
Alexander Afanasyevc9d5c1a2012-11-21 18:00:26 -0800138 return os;
139}
140
141} // namespace ndn
142} // namespace ns3
143
Alexander Afanasyev5352af32013-07-15 09:51:28 -0700144#endif // NDN_L3_TRACER_H