blob: 3bdb9ecdf5360c465db1234a5f1d34690517505b [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
24#include "content-store-impl.h"
25
26#include "../../utils/trie/multi-policy.h"
Alexander Afanasyev7456b702013-02-01 22:41:48 -080027#include "custom-policies/lifetime-stats-policy.h"
Alexander Afanasyev8566f452012-12-10 15:21:51 -080028
29namespace ns3 {
30namespace ndn {
31namespace cs {
32
33template<class Policy>
34class ContentStoreWithStats :
35 public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > >
36{
37public:
38 typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super;
39
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070040 typedef typename super::policy_container::template index<1>::type lifetime_stats_container;
41
Alexander Afanasyev8566f452012-12-10 15:21:51 -080042 ContentStoreWithStats ()
43 {
44 // connect traceback to the policy
45 super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry);
46 }
Alexander Afanasyev7456b702013-02-01 22:41:48 -080047
Alexander Afanasyev8566f452012-12-10 15:21:51 -080048 static TypeId
49 GetTypeId ();
Alexander Afanasyev7456b702013-02-01 22:41:48 -080050
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070051 virtual inline void
52 Print (std::ostream &os) const;
53
Alexander Afanasyev8566f452012-12-10 15:21:51 -080054private:
55 static LogComponent g_log; ///< @brief Logging variable
56
57 /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how long entry was in the cache
Alexander Afanasyev7456b702013-02-01 22:41:48 -080058 TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry;
Alexander Afanasyev8566f452012-12-10 15:21:51 -080059};
60
61//////////////////////////////////////////
62////////// Implementation ////////////////
63//////////////////////////////////////////
64
65
66template<class Policy>
67LogComponent
68ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ());
69
70
71template<class Policy>
72TypeId
73ContentStoreWithStats< Policy >::GetTypeId ()
74{
75 static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ())
76 .SetGroupName ("Ndn")
77 .SetParent<super> ()
78 .template AddConstructor< ContentStoreWithStats< Policy > > ()
79
80 .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed",
81 MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry))
82
83 // trace stuff here
84 ;
85
86 return tid;
87}
88
Alexander Afanasyevbe82da52013-04-09 05:43:14 -070089template<class Policy>
90void
91ContentStoreWithStats< Policy >::Print (std::ostream &os) const
92{
93 // const freshness_policy_container &freshness = this->getPolicy ().template get<freshness_policy_container> ();
94
95 for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
96 item != this->getPolicy ().end ();
97 item++)
98 {
99 Time alive = lifetime_stats_container::policy_base::get_time (&(*item)) - Simulator::Now ();
100 os << item->payload ()->GetName () << "(alive: " << alive.ToDouble (Time::S) << "s)" << std::endl;
101 }
102}
103
104
Alexander Afanasyev8566f452012-12-10 15:21:51 -0800105
106} // namespace cs
107} // namespace ndn
108} // namespace ns3
109
110#endif // NDN_CONTENT_STORE_IMPL_H_