blob: f1ba5b29046041e2b178e11f2e4f1e26f5a2945d [file] [log] [blame]
Alexander Afanasyev8566f452012-12-10 15:21:51 -08001/* -*- 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 Mastorakis53e922f2014-10-17 17:29:26 -070024#include "ns3/ndnSIM/model/ndn-common.hpp"
Alexander Afanasyev8566f452012-12-10 15:21:51 -080025
Alexander Afanasyev0c395372014-12-20 15:54:02 -080026#include "content-store-impl.hpp"
27
28#include "../../utils/trie/multi-policy.hpp"
29#include "custom-policies/lifetime-stats-policy.hpp"
Alexander Afanasyev8566f452012-12-10 15:21:51 -080030
31namespace ns3 {
32namespace ndn {
33namespace cs {
34
Alexander Afanasyev79206512013-07-27 16:49:12 -070035/**
36 * @ingroup ndn-cs
37 * @brief Special content store realization that provides ability to track stats of CS operations
38 */
Alexander Afanasyev8566f452012-12-10 15:21:51 -080039template<class Policy>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080040class ContentStoreWithStats
41 : public ContentStoreImpl<ndnSIM::
42 multi_policy_traits<boost::mpl::
43 vector2<Policy,
44 ndnSIM::
45 lifetime_stats_policy_traits>>> {
Alexander Afanasyev8566f452012-12-10 15:21:51 -080046public:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 typedef ContentStoreImpl<ndnSIM::
48 multi_policy_traits<boost::mpl::
49 vector2<Policy,
50 ndnSIM::lifetime_stats_policy_traits>>>
51 super;
Alexander Afanasyev8566f452012-12-10 15:21:51 -080052
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070053 typedef typename super::policy_container::template index<1>::type lifetime_stats_container;
54
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 ContentStoreWithStats()
Alexander Afanasyev8566f452012-12-10 15:21:51 -080056 {
57 // connect traceback to the policy
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry);
Alexander Afanasyev8566f452012-12-10 15:21:51 -080059 }
Alexander Afanasyev7456b702013-02-01 22:41:48 -080060
Alexander Afanasyev8566f452012-12-10 15:21:51 -080061 static TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 GetTypeId();
Alexander Afanasyev7456b702013-02-01 22:41:48 -080063
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070064 virtual inline void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 Print(std::ostream& os) const;
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070066
Alexander Afanasyev8566f452012-12-10 15:21:51 -080067private:
68 static LogComponent g_log; ///< @brief Logging variable
69
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 /// @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 Afanasyev8566f452012-12-10 15:21:51 -080073};
74
75//////////////////////////////////////////
76////////// Implementation ////////////////
77//////////////////////////////////////////
78
Alexander Afanasyev8566f452012-12-10 15:21:51 -080079template<class Policy>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080080LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats."
81 + Policy::GetName()).c_str());
Alexander Afanasyev8566f452012-12-10 15:21:51 -080082
83template<class Policy>
84TypeId
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080085ContentStoreWithStats<Policy>::GetTypeId()
Alexander Afanasyev8566f452012-12-10 15:21:51 -080086{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 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 Afanasyev8566f452012-12-10 15:21:51 -080092
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 .AddTraceSource("WillRemoveEntry",
94 "Trace called just before content store entry will be removed",
95 MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry))
Alexander Afanasyev8566f452012-12-10 15:21:51 -080096
97 // trace stuff here
98 ;
99
100 return tid;
101}
102
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700103template<class Policy>
104void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105ContentStoreWithStats<Policy>::Print(std::ostream& os) const
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700106{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 // const freshness_policy_container &freshness = this->getPolicy ().template
108 // get<freshness_policy_container> ();
Alexander Afanasyevbe82da52013-04-09 05:43:14 -0700109
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 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 Afanasyevbe82da52013-04-09 05:43:14 -0700115}
116
Alexander Afanasyev8566f452012-12-10 15:21:51 -0800117} // namespace cs
118} // namespace ndn
119} // namespace ns3
120
121#endif // NDN_CONTENT_STORE_IMPL_H_