blob: 8d4a71d8499f538799f91f6aaadb3ca39c044029 [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
40 ContentStoreWithStats ()
41 {
42 // connect traceback to the policy
43 super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry);
44 }
Alexander Afanasyev7456b702013-02-01 22:41:48 -080045
Alexander Afanasyev8566f452012-12-10 15:21:51 -080046 static TypeId
47 GetTypeId ();
Alexander Afanasyev7456b702013-02-01 22:41:48 -080048
Alexander Afanasyev8566f452012-12-10 15:21:51 -080049private:
50 static LogComponent g_log; ///< @brief Logging variable
51
52 /// @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 -080053 TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry;
Alexander Afanasyev8566f452012-12-10 15:21:51 -080054};
55
56//////////////////////////////////////////
57////////// Implementation ////////////////
58//////////////////////////////////////////
59
60
61template<class Policy>
62LogComponent
63ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ());
64
65
66template<class Policy>
67TypeId
68ContentStoreWithStats< Policy >::GetTypeId ()
69{
70 static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ())
71 .SetGroupName ("Ndn")
72 .SetParent<super> ()
73 .template AddConstructor< ContentStoreWithStats< Policy > > ()
74
75 .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed",
76 MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry))
77
78 // trace stuff here
79 ;
80
81 return tid;
82}
83
84
85} // namespace cs
86} // namespace ndn
87} // namespace ns3
88
89#endif // NDN_CONTENT_STORE_IMPL_H_