blob: 979a5e5e4799c7875d22588aec74a6b6b510fa76 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev8566f452012-12-10 15:21:51 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev8566f452012-12-10 15:21:51 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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 Afanasyev8566f452012-12-10 15:21:51 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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 Afanasyev8566f452012-12-10 15:21:51 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 Afanasyev8566f452012-12-10 15:21:51 -080019
20#ifndef NDN_CONTENT_STORE_WITH_STATS_H_
21#define NDN_CONTENT_STORE_WITH_STATS_H_
22
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
Alexander Afanasyev8566f452012-12-10 15:21:51 -080024
Alexander Afanasyev0c395372014-12-20 15:54:02 -080025#include "content-store-impl.hpp"
26
27#include "../../utils/trie/multi-policy.hpp"
28#include "custom-policies/lifetime-stats-policy.hpp"
Alexander Afanasyev8566f452012-12-10 15:21:51 -080029
30namespace ns3 {
31namespace ndn {
32namespace cs {
33
Alexander Afanasyev79206512013-07-27 16:49:12 -070034/**
35 * @ingroup ndn-cs
36 * @brief Special content store realization that provides ability to track stats of CS operations
37 */
Alexander Afanasyev8566f452012-12-10 15:21:51 -080038template<class Policy>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039class ContentStoreWithStats
40 : public ContentStoreImpl<ndnSIM::
41 multi_policy_traits<boost::mpl::
42 vector2<Policy,
43 ndnSIM::
44 lifetime_stats_policy_traits>>> {
Alexander Afanasyev8566f452012-12-10 15:21:51 -080045public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 typedef ContentStoreImpl<ndnSIM::
47 multi_policy_traits<boost::mpl::
48 vector2<Policy,
49 ndnSIM::lifetime_stats_policy_traits>>>
50 super;
Alexander Afanasyev8566f452012-12-10 15:21:51 -080051
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070052 typedef typename super::policy_container::template index<1>::type lifetime_stats_container;
53
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 ContentStoreWithStats()
Alexander Afanasyev8566f452012-12-10 15:21:51 -080055 {
56 // connect traceback to the policy
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry);
Alexander Afanasyev8566f452012-12-10 15:21:51 -080058 }
Alexander Afanasyev7456b702013-02-01 22:41:48 -080059
Alexander Afanasyev8566f452012-12-10 15:21:51 -080060 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 GetTypeId();
Alexander Afanasyev7456b702013-02-01 22:41:48 -080062
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070063 virtual inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 Print(std::ostream& os) const;
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070065
Alexander Afanasyev8566f452012-12-10 15:21:51 -080066private:
67 static LogComponent g_log; ///< @brief Logging variable
68
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080069 /// @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 Afanasyev8566f452012-12-10 15:21:51 -080072};
73
74//////////////////////////////////////////
75////////// Implementation ////////////////
76//////////////////////////////////////////
77
Alexander Afanasyev8566f452012-12-10 15:21:51 -080078template<class Policy>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats."
80 + Policy::GetName()).c_str());
Alexander Afanasyev8566f452012-12-10 15:21:51 -080081
82template<class Policy>
83TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084ContentStoreWithStats<Policy>::GetTypeId()
Alexander Afanasyev8566f452012-12-10 15:21:51 -080085{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 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 Afanasyev8566f452012-12-10 15:21:51 -080091
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 .AddTraceSource("WillRemoveEntry",
93 "Trace called just before content store entry will be removed",
94 MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry))
Alexander Afanasyev8566f452012-12-10 15:21:51 -080095
96 // trace stuff here
97 ;
98
99 return tid;
100}
101
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700102template<class Policy>
103void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104ContentStoreWithStats<Policy>::Print(std::ostream& os) const
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700105{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 // const freshness_policy_container &freshness = this->getPolicy ().template
107 // get<freshness_policy_container> ();
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700108
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 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 Afanasyevbe82da52013-04-09 05:43:14 -0700114}
115
Alexander Afanasyev8566f452012-12-10 15:21:51 -0800116} // namespace cs
117} // namespace ndn
118} // namespace ns3
119
120#endif // NDN_CONTENT_STORE_IMPL_H_