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