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