Alexander Afanasyev | 8628799 | 2012-12-10 16:11:50 -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: Xiaoyan Hu <x......u@gmail.com> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #ifndef CCNX_CS_TRACER_H |
| 23 | #define CCNX_CS_TRACER_H |
| 24 | |
| 25 | #include "ns3/ptr.h" |
| 26 | #include "ns3/simple-ref-count.h" |
| 27 | |
| 28 | namespace ns3 { |
| 29 | |
| 30 | class Node; |
| 31 | class Packet; |
| 32 | |
| 33 | namespace ndn { |
| 34 | |
| 35 | class InterestHeader; |
| 36 | class ContentObjectHeader; |
| 37 | |
| 38 | /** |
| 39 | * @brief Base class for content store tracers (CacheHits and CacheMisses) |
| 40 | */ |
| 41 | class CsTracer : public SimpleRefCount<CsTracer> |
| 42 | { |
| 43 | public: |
| 44 | /** |
| 45 | * @brief Trace constructor that attaches to the node using node pointer |
| 46 | * @param node pointer to the node |
| 47 | */ |
| 48 | CsTracer (Ptr<Node> node); |
| 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 | */ |
| 54 | CsTracer (const std::string &node); |
| 55 | |
| 56 | /** |
| 57 | * @brief Destructor |
| 58 | */ |
| 59 | virtual ~CsTracer (); |
| 60 | |
| 61 | /** |
| 62 | * @brief Print head of the trace (e.g., for post-processing) |
| 63 | * |
| 64 | * @param os reference to output stream |
| 65 | */ |
| 66 | virtual void |
| 67 | PrintHeader (std::ostream &os) const = 0; |
| 68 | |
| 69 | /** |
| 70 | * @brief Print current trace data |
| 71 | * |
| 72 | * @param os reference to output stream |
| 73 | */ |
| 74 | virtual void |
| 75 | Print (std::ostream &os) const = 0; |
| 76 | |
| 77 | protected: |
| 78 | void |
| 79 | Connect (); |
| 80 | |
| 81 | virtual void |
| 82 | CacheHits (std::string context, |
| 83 | Ptr<const InterestHeader>, Ptr<const ContentObjectHeader>) = 0; |
| 84 | |
| 85 | virtual void |
| 86 | CacheMisses (std::string context, |
| 87 | Ptr<const InterestHeader>) = 0; |
| 88 | |
| 89 | protected: |
| 90 | std::string m_node; |
| 91 | Ptr<Node> m_nodePtr; |
| 92 | |
| 93 | struct Stats |
| 94 | { |
| 95 | inline void Reset () |
| 96 | { |
| 97 | m_cacheHits = 0; |
| 98 | m_cacheMisses = 0; |
| 99 | } |
| 100 | double m_cacheHits; |
| 101 | double m_cacheMisses; |
| 102 | }; |
| 103 | }; |
| 104 | |
| 105 | /** |
| 106 | * @brief Helper to dump the trace to an output stream |
| 107 | */ |
| 108 | inline std::ostream& |
| 109 | operator << (std::ostream &os, const CsTracer &tracer) |
| 110 | { |
| 111 | os << "# "; |
| 112 | tracer.PrintHeader (os); |
| 113 | os << "\n"; |
| 114 | tracer.Print (os); |
| 115 | return os; |
| 116 | } |
| 117 | |
| 118 | } // namespace ndn |
| 119 | } // namespace ns3 |
| 120 | |
| 121 | #endif // CCNX_CS_TRACER_H |