Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 19 | |
| 20 | #ifndef NDN_CONTENT_STORE_WITH_STATS_H_ |
| 21 | #define NDN_CONTENT_STORE_WITH_STATS_H_ |
| 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 24 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 25 | #include "content-store-impl.hpp" |
| 26 | |
| 27 | #include "../../utils/trie/multi-policy.hpp" |
| 28 | #include "custom-policies/lifetime-stats-policy.hpp" |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 29 | |
| 30 | namespace ns3 { |
| 31 | namespace ndn { |
| 32 | namespace cs { |
| 33 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 34 | /** |
| 35 | * @ingroup ndn-cs |
| 36 | * @brief Special content store realization that provides ability to track stats of CS operations |
| 37 | */ |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 38 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | class ContentStoreWithStats |
| 40 | : public ContentStoreImpl<ndnSIM:: |
| 41 | multi_policy_traits<boost::mpl:: |
| 42 | vector2<Policy, |
| 43 | ndnSIM:: |
| 44 | lifetime_stats_policy_traits>>> { |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 45 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | typedef ContentStoreImpl<ndnSIM:: |
| 47 | multi_policy_traits<boost::mpl:: |
| 48 | vector2<Policy, |
| 49 | ndnSIM::lifetime_stats_policy_traits>>> |
| 50 | super; |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 51 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 52 | typedef typename super::policy_container::template index<1>::type lifetime_stats_container; |
| 53 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | ContentStoreWithStats() |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 55 | { |
| 56 | // connect traceback to the policy |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry); |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 58 | } |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 60 | static TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | GetTypeId(); |
Alexander Afanasyev | 7456b70 | 2013-02-01 22:41:48 -0800 | [diff] [blame] | 62 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 63 | virtual inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 64 | Print(std::ostream& os) const; |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 66 | private: |
| 67 | static LogComponent g_log; ///< @brief Logging variable |
| 68 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how |
| 70 | /// long entry was in the cache |
| 71 | TracedCallback<Ptr<const Entry>, Time> m_willRemoveEntry; |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | ////////////////////////////////////////// |
| 75 | ////////// Implementation //////////////// |
| 76 | ////////////////////////////////////////// |
| 77 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 78 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 79 | LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats." |
| 80 | + Policy::GetName()).c_str()); |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 81 | |
| 82 | template<class Policy> |
| 83 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 84 | ContentStoreWithStats<Policy>::GetTypeId() |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 85 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | static TypeId tid = |
| 87 | TypeId(("ns3::ndn::cs::Stats::" + Policy::GetName()).c_str()) |
| 88 | .SetGroupName("Ndn") |
| 89 | .SetParent<super>() |
| 90 | .template AddConstructor<ContentStoreWithStats<Policy>>() |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | .AddTraceSource("WillRemoveEntry", |
| 93 | "Trace called just before content store entry will be removed", |
| 94 | MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry)) |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 95 | |
| 96 | // trace stuff here |
| 97 | ; |
| 98 | |
| 99 | return tid; |
| 100 | } |
| 101 | |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 102 | template<class Policy> |
| 103 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | ContentStoreWithStats<Policy>::Print(std::ostream& os) const |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 105 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | // const freshness_policy_container &freshness = this->getPolicy ().template |
| 107 | // get<freshness_policy_container> (); |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 109 | for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); |
| 110 | item != this->getPolicy().end(); item++) { |
| 111 | Time alive = lifetime_stats_container::policy_base::get_time(&(*item)) - Simulator::Now(); |
| 112 | os << item->payload()->GetName() << "(alive: " << alive.ToDouble(Time::S) << "s)" << std::endl; |
| 113 | } |
Alexander Afanasyev | be82da5 | 2013-04-09 05:43:14 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 116 | } // namespace cs |
| 117 | } // namespace ndn |
| 118 | } // namespace ns3 |
| 119 | |
| 120 | #endif // NDN_CONTENT_STORE_IMPL_H_ |