Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 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 NDN_CONTENT_STORE_WITH_STATS_H_ |
| 22 | #define NDN_CONTENT_STORE_WITH_STATS_H_ |
| 23 | |
| 24 | #include "content-store-impl.h" |
| 25 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame^] | 26 | #include "content-store-impl.hpp" |
| 27 | |
| 28 | #include "../../utils/trie/multi-policy.hpp" |
| 29 | #include "custom-policies/lifetime-stats-policy.hpp" |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 30 | |
| 31 | namespace ns3 { |
| 32 | namespace ndn { |
| 33 | namespace cs { |
| 34 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 35 | /** |
| 36 | * @ingroup ndn-cs |
| 37 | * @brief Special content store realization that provides ability to track stats of CS operations |
| 38 | */ |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 39 | template<class Policy> |
| 40 | class ContentStoreWithStats : |
| 41 | public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > |
| 42 | { |
| 43 | public: |
| 44 | typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super; |
| 45 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 46 | typedef typename super::policy_container::template index<1>::type lifetime_stats_container; |
| 47 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 48 | ContentStoreWithStats () |
| 49 | { |
| 50 | // connect traceback to the policy |
| 51 | super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry); |
| 52 | } |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 54 | static TypeId |
| 55 | GetTypeId (); |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 57 | virtual inline void |
| 58 | Print (std::ostream &os) const; |
| 59 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 60 | private: |
| 61 | static LogComponent g_log; ///< @brief Logging variable |
| 62 | |
| 63 | /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how long entry was in the cache |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 64 | TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry; |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | ////////////////////////////////////////// |
| 68 | ////////// Implementation //////////////// |
| 69 | ////////////////////////////////////////// |
| 70 | |
| 71 | |
| 72 | template<class Policy> |
| 73 | LogComponent |
| 74 | ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ()); |
| 75 | |
| 76 | |
| 77 | template<class Policy> |
| 78 | TypeId |
| 79 | ContentStoreWithStats< Policy >::GetTypeId () |
| 80 | { |
| 81 | static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ()) |
| 82 | .SetGroupName ("Ndn") |
| 83 | .SetParent<super> () |
| 84 | .template AddConstructor< ContentStoreWithStats< Policy > > () |
| 85 | |
| 86 | .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed", |
| 87 | MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry)) |
| 88 | |
| 89 | // trace stuff here |
| 90 | ; |
| 91 | |
| 92 | return tid; |
| 93 | } |
| 94 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 95 | template<class Policy> |
| 96 | void |
| 97 | ContentStoreWithStats< Policy >::Print (std::ostream &os) const |
| 98 | { |
| 99 | // const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> (); |
| 100 | |
| 101 | for (typename super::policy_container::const_iterator item = this->getPolicy ().begin (); |
| 102 | item != this->getPolicy ().end (); |
| 103 | item++) |
| 104 | { |
| 105 | Time alive = lifetime_stats_container::policy_base::get_time (&(*item)) - Simulator::Now (); |
| 106 | os << item->payload ()->GetName () << "(alive: " << alive.ToDouble (Time::S) << "s)" << std::endl; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 111 | |
| 112 | } // namespace cs |
| 113 | } // namespace ndn |
| 114 | } // namespace ns3 |
| 115 | |
| 116 | #endif // NDN_CONTENT_STORE_IMPL_H_ |