NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
content-store-with-stats.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #ifndef NDN_CONTENT_STORE_WITH_STATS_H_
21 #define NDN_CONTENT_STORE_WITH_STATS_H_
22 
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
24 
25 #include "content-store-impl.hpp"
26 
27 #include "../../utils/trie/multi-policy.hpp"
29 
30 namespace ns3 {
31 namespace ndn {
32 namespace cs {
33 
38 template<class Policy>
40  : public ContentStoreImpl<ndnSIM::
41  multi_policy_traits<boost::mpl::
42  vector2<Policy,
43  ndnSIM::
44  lifetime_stats_policy_traits>>> {
45 public:
46  typedef ContentStoreImpl<ndnSIM::
47  multi_policy_traits<boost::mpl::
48  vector2<Policy,
49  ndnSIM::lifetime_stats_policy_traits>>>
51 
52  typedef typename super::policy_container::template index<1>::type lifetime_stats_container;
53 
55  {
56  // connect traceback to the policy
57  super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry);
58  }
59 
60  static TypeId
61  GetTypeId();
62 
63  virtual inline void
64  Print(std::ostream& os) const;
65 
66 private:
67  static LogComponent g_log;
68 
71  TracedCallback<Ptr<const Entry>, Time> m_willRemoveEntry;
72 };
73 
77 
78 template<class Policy>
79 LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats."
80  + Policy::GetName()).c_str());
81 
82 template<class Policy>
83 TypeId
85 {
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>>()
91 
92  .AddTraceSource("WillRemoveEntry",
93  "Trace called just before content store entry will be removed",
94  MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry))
95 
96  // trace stuff here
97  ;
98 
99  return tid;
100 }
101 
102 template<class Policy>
103 void
105 {
106  // const freshness_policy_container &freshness = this->getPolicy ().template
107  // get<freshness_policy_container> ();
108 
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  }
114 }
115 
116 } // namespace cs
117 } // namespace ndn
118 } // namespace ns3
119 
120 #endif // NDN_CONTENT_STORE_IMPL_H_
virtual void Print(std::ostream &os) const
Print out content store entries.
super::policy_container::template index< 1 >::type lifetime_stats_container
Special content store realization that provides ability to track stats of CS operations.
ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super
Base implementation of NDN content store.