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