Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 21 | #ifndef NDN_L3_TRACER_H |
| 22 | #define NDN_L3_TRACER_H |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ns3/ptr.h" |
| 25 | #include "ns3/simple-ref-count.h" |
| 26 | |
| 27 | namespace ns3 { |
| 28 | |
| 29 | class Node; |
| 30 | class Packet; |
| 31 | |
| 32 | namespace ndn { |
| 33 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 34 | namespace pit { |
| 35 | class Entry; |
| 36 | } |
| 37 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 38 | class Face; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 39 | |
| 40 | class Interest; |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 41 | class ContentObject; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | 0b9e3bd | 2012-12-10 15:27:09 -0800 | [diff] [blame] | 43 | /** |
| 44 | * @brief Base class for network-layer (incoming/outgoing Interests and Data) tracing of NDN stack |
| 45 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 46 | class L3Tracer : public SimpleRefCount<L3Tracer> |
| 47 | { |
| 48 | public: |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 49 | /** |
| 50 | * @brief Trace constructor that attaches to the node using node pointer |
| 51 | * @param node pointer to the node |
| 52 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 53 | L3Tracer (Ptr<Node> node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @brief Trace constructor that attaches to the node using node name |
| 57 | * @param nodeName name of the node registered using Names::Add |
| 58 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 59 | L3Tracer (const std::string &node); |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * @brief Destructor |
| 63 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 64 | virtual ~L3Tracer (); |
| 65 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 66 | /** |
| 67 | * @brief Print head of the trace (e.g., for post-processing) |
| 68 | * |
| 69 | * @param os reference to output stream |
| 70 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 71 | virtual void |
| 72 | PrintHeader (std::ostream &os) const = 0; |
| 73 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 74 | /** |
| 75 | * @brief Print current trace data |
| 76 | * |
| 77 | * @param os reference to output stream |
| 78 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 79 | virtual void |
| 80 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 82 | protected: |
| 83 | void |
| 84 | Connect (); |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 86 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 87 | OutInterests (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 88 | |
| 89 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 90 | InInterests (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 91 | |
| 92 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 93 | DropInterests (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 95 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 96 | OutNacks (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 97 | |
| 98 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 99 | InNacks (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 100 | |
| 101 | virtual void |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 102 | DropNacks (Ptr<const Interest>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 105 | virtual void |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 106 | OutData (Ptr<const ContentObject>, bool fromCache, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 107 | |
| 108 | virtual void |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 109 | InData (Ptr<const ContentObject>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 110 | |
| 111 | virtual void |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 112 | DropData (Ptr<const ContentObject>, Ptr<const Face>) = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 114 | virtual void |
| 115 | SatisfiedInterests (Ptr<const pit::Entry>) = 0; |
| 116 | |
| 117 | virtual void |
| 118 | TimedOutInterests (Ptr<const pit::Entry>) = 0; |
| 119 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 120 | protected: |
| 121 | std::string m_node; |
| 122 | Ptr<Node> m_nodePtr; |
| 123 | |
| 124 | struct Stats |
| 125 | { |
| 126 | inline void Reset () |
| 127 | { |
| 128 | m_inInterests = 0; |
| 129 | m_outInterests = 0; |
| 130 | m_dropInterests = 0; |
| 131 | m_inNacks = 0; |
| 132 | m_outNacks = 0; |
| 133 | m_dropNacks = 0; |
| 134 | m_inData = 0; |
| 135 | m_outData = 0; |
| 136 | m_dropData = 0; |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 137 | m_satisfiedInterests = 0; |
| 138 | m_timedOutInterests = 0; |
Alexander Afanasyev | bf93929 | 2013-07-15 10:10:01 -0700 | [diff] [blame] | 139 | |
| 140 | m_outSatisfiedInterests = 0; |
| 141 | m_outTimedOutInterests = 0; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 142 | } |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 143 | |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 144 | double m_inInterests; |
| 145 | double m_outInterests; |
| 146 | double m_dropInterests; |
| 147 | double m_inNacks; |
| 148 | double m_outNacks; |
| 149 | double m_dropNacks; |
| 150 | double m_inData; |
| 151 | double m_outData; |
| 152 | double m_dropData; |
Alexander Afanasyev | 37b84c5 | 2013-04-26 13:38:52 -0700 | [diff] [blame] | 153 | double m_satisfiedInterests; |
| 154 | double m_timedOutInterests; |
Alexander Afanasyev | bf93929 | 2013-07-15 10:10:01 -0700 | [diff] [blame] | 155 | double m_outSatisfiedInterests; |
| 156 | double m_outTimedOutInterests; |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 157 | }; |
| 158 | }; |
| 159 | |
Alexander Afanasyev | 5931480 | 2012-11-26 14:56:04 -0800 | [diff] [blame] | 160 | /** |
| 161 | * @brief Helper to dump the trace to an output stream |
| 162 | */ |
Alexander Afanasyev | c9d5c1a | 2012-11-21 18:00:26 -0800 | [diff] [blame] | 163 | inline std::ostream& |
| 164 | operator << (std::ostream &os, const L3Tracer &tracer) |
| 165 | { |
| 166 | os << "# "; |
| 167 | tracer.PrintHeader (os); |
| 168 | os << "\n"; |
| 169 | tracer.Print (os); |
| 170 | return os; |
| 171 | } |
| 172 | |
| 173 | } // namespace ndn |
| 174 | } // namespace ns3 |
| 175 | |
Alexander Afanasyev | 5352af3 | 2013-07-15 09:51:28 -0700 | [diff] [blame] | 176 | #endif // NDN_L3_TRACER_H |