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