NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
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 public:
67  typedef void (*RemoveCsEntryCallback)(Ptr<const Entry>, Time);
68 
69 private:
70  static LogComponent g_log;
71 
74  TracedCallback<Ptr<const Entry>, Time> m_willRemoveEntry;
75 };
76 
80 
81 template<class Policy>
82 LogComponent ContentStoreWithStats<Policy>::g_log = LogComponent(("ndn.cs.Stats."
83  + Policy::GetName()).c_str(), __FILE__);
84 
85 template<class Policy>
86 TypeId
88 {
89  static TypeId tid =
90  TypeId(("ns3::ndn::cs::Stats::" + Policy::GetName()).c_str())
91  .SetGroupName("Ndn")
92  .SetParent<super>()
93  .template AddConstructor<ContentStoreWithStats<Policy>>()
94 
95  .AddTraceSource("WillRemoveEntry",
96  "Trace called just before content store entry will be removed",
97  MakeTraceSourceAccessor(&ContentStoreWithStats<Policy>::m_willRemoveEntry),
98  "ns3::ndn::cs::ContentStoreWithStats::RemoveCsEntryCallback")
99 
100  // trace stuff here
101  ;
102 
103  return tid;
104 }
105 
106 template<class Policy>
107 void
109 {
110  // const freshness_policy_container &freshness = this->getPolicy ().template
111  // get<freshness_policy_container> ();
112 
113  for (typename super::policy_container::const_iterator item = this->getPolicy().begin();
114  item != this->getPolicy().end(); item++) {
115  Time alive = lifetime_stats_container::policy_base::get_time(&(*item)) - Simulator::Now();
116  os << item->payload()->GetName() << "(alive: " << alive.ToDouble(Time::S) << "s)" << std::endl;
117  }
118 }
119 
120 } // namespace cs
121 } // namespace ndn
122 } // namespace ns3
123 
124 #endif // NDN_CONTENT_STORE_IMPL_H_
virtual void Print(std::ostream &os) const
Print out content store entries.
Copyright (c) 2011-2015 Regents of the University of California.
super::policy_container::template index< 1 >::type lifetime_stats_container
Special content store realization that provides ability to track stats of CS operations.
Copyright (c) 2011-2015 Regents of the University of California.
ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super
Base implementation of NDN content store.
void(* RemoveCsEntryCallback)(Ptr< const Entry >, Time)