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 | |
| 40 | ContentStoreWithStats () |
| 41 | { |
| 42 | // connect traceback to the policy |
| 43 | super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry); |
| 44 | } |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 46 | static TypeId |
| 47 | GetTypeId (); |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 48 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 49 | private: |
| 50 | static LogComponent g_log; ///< @brief Logging variable |
| 51 | |
| 52 | /// @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] | 53 | TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry; |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | ////////////////////////////////////////// |
| 57 | ////////// Implementation //////////////// |
| 58 | ////////////////////////////////////////// |
| 59 | |
| 60 | |
| 61 | template<class Policy> |
| 62 | LogComponent |
| 63 | ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ()); |
| 64 | |
| 65 | |
| 66 | template<class Policy> |
| 67 | TypeId |
| 68 | ContentStoreWithStats< Policy >::GetTypeId () |
| 69 | { |
| 70 | static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ()) |
| 71 | .SetGroupName ("Ndn") |
| 72 | .SetParent<super> () |
| 73 | .template AddConstructor< ContentStoreWithStats< Policy > > () |
| 74 | |
| 75 | .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed", |
| 76 | MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry)) |
| 77 | |
| 78 | // trace stuff here |
| 79 | ; |
| 80 | |
| 81 | return tid; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | } // namespace cs |
| 86 | } // namespace ndn |
| 87 | } // namespace ns3 |
| 88 | |
| 89 | #endif // NDN_CONTENT_STORE_IMPL_H_ |