model: Adding "new" content store with ability to track lifetime of entries
Available options for ndnStackHelper.SetContentStore:
- ns3::ndn::cs::Stats::Lru
- ns3::ndn::cs::Stats::Random
- ns3::ndn::cs::Stats::Fifo
Tracked events include 0-lifetime entries, i.e., when entries are not stored at all.
Config::ConnectWithoutContext ("/NodeList/1/$ns3::ndn::cs::Stats::Random/WillRemoveEntry", MakeCallback (CacheEntryRemoved));
Prototype for the callback is: void (*)(Ptr<const ndn::cs::Entry> entry, Time lifetime)
diff --git a/model/cs/content-store-impl.cc b/model/cs/content-store-impl.cc
index 3a219fa..aa7a234 100644
--- a/model/cs/content-store-impl.cc
+++ b/model/cs/content-store-impl.cc
@@ -24,8 +24,6 @@
#include "../../utils/trie/lru-policy.h"
#include "../../utils/trie/fifo-policy.h"
-NS_LOG_COMPONENT_DEFINE ("ndn.cs.ContentStoreImpl");
-
#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
static struct X ## type ## templ ## RegistrationClass \
{ \
diff --git a/model/cs/content-store-impl.h b/model/cs/content-store-impl.h
index a168636..6ebd865 100644
--- a/model/cs/content-store-impl.h
+++ b/model/cs/content-store-impl.h
@@ -41,6 +41,9 @@
class EntryImpl : public Entry
{
public:
+ typedef Entry base_type;
+
+public:
EntryImpl (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet)
: Entry (header, packet)
, item_ (0)
@@ -65,12 +68,12 @@
template<class Policy>
class ContentStoreImpl : public ContentStore,
protected ndnSIM::trie_with_policy< NameComponents,
- ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >,
+ ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > >, Entry >,
Policy >
{
public:
typedef ndnSIM::trie_with_policy< NameComponents,
- ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > > >,
+ ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > >, Entry >,
Policy > super;
typedef EntryImpl< ContentStoreImpl< Policy > > entry;
diff --git a/model/cs/content-store-with-stats.cc b/model/cs/content-store-with-stats.cc
new file mode 100644
index 0000000..1e39255
--- /dev/null
+++ b/model/cs/content-store-with-stats.cc
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "content-store-with-stats.h"
+
+#include "../../utils/trie/random-policy.h"
+#include "../../utils/trie/lru-policy.h"
+#include "../../utils/trie/fifo-policy.h"
+
+#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \
+ static struct X ## type ## templ ## RegistrationClass \
+ { \
+ X ## type ## templ ## RegistrationClass () { \
+ ns3::TypeId tid = type<templ>::GetTypeId (); \
+ tid.GetParent (); \
+ } \
+ } x_ ## type ## templ ## RegistrationVariable
+
+namespace ns3 {
+namespace ndn {
+
+using namespace ndnSIM;
+
+namespace cs {
+
+// explicit instantiation and registering
+/**
+ * @brief ContentStore with stats and LRU cache replacement policy
+ **/
+template class ContentStoreWithStats<lru_policy_traits>;
+
+/**
+ * @brief ContentStore with stats and random cache replacement policy
+ **/
+template class ContentStoreWithStats<random_policy_traits>;
+
+/**
+ * @brief ContentStore with stats and FIFO cache replacement policy
+ **/
+template class ContentStoreWithStats<fifo_policy_traits>;
+
+NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, lru_policy_traits);
+NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, random_policy_traits);
+NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, fifo_policy_traits);
+
+
+#ifdef DOXYGEN
+// /**
+// * \brief Content Store implementing LRU cache replacement policy
+// */
+class Stats::Lru : public ContentStoreWithStats<lru_policy_traits> { };
+
+/**
+ * \brief Content Store implementing FIFO cache replacement policy
+ */
+class Stats::Fifo : public ContentStoreWithStats<fifo_policy_traits> { };
+
+/**
+ * \brief Content Store implementing Random cache replacement policy
+ */
+class Stats::Random : public ContentStoreWithStats<random_policy_traits> { };
+
+#endif
+
+
+} // namespace cs
+} // namespace ndn
+} // namespace ns3
diff --git a/model/cs/content-store-with-stats.h b/model/cs/content-store-with-stats.h
new file mode 100644
index 0000000..02ffec0
--- /dev/null
+++ b/model/cs/content-store-with-stats.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_CONTENT_STORE_WITH_STATS_H_
+#define NDN_CONTENT_STORE_WITH_STATS_H_
+
+#include "content-store-impl.h"
+
+#include "../../utils/trie/multi-policy.h"
+#include "../../utils/trie/lifetime-stats-policy.h"
+
+namespace ns3 {
+namespace ndn {
+namespace cs {
+
+template<class Policy>
+class ContentStoreWithStats :
+ public ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > >
+{
+public:
+ typedef ContentStoreImpl< ndnSIM::multi_policy_traits< boost::mpl::vector2< Policy, ndnSIM::lifetime_stats_policy_traits > > > super;
+
+ ContentStoreWithStats ()
+ {
+ // connect traceback to the policy
+ super::getPolicy ().template get<1> ().set_traced_callback (&m_willRemoveEntry);
+ }
+
+ static TypeId
+ GetTypeId ();
+
+private:
+ static LogComponent g_log; ///< @brief Logging variable
+
+ /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how long entry was in the cache
+ TracedCallback< Ptr<const Entry>, Time > m_willRemoveEntry;
+};
+
+//////////////////////////////////////////
+////////// Implementation ////////////////
+//////////////////////////////////////////
+
+
+template<class Policy>
+LogComponent
+ContentStoreWithStats< Policy >::g_log = LogComponent (("ndn.cs.Stats." + Policy::GetName ()).c_str ());
+
+
+template<class Policy>
+TypeId
+ContentStoreWithStats< Policy >::GetTypeId ()
+{
+ static TypeId tid = TypeId (("ns3::ndn::cs::Stats::"+Policy::GetName ()).c_str ())
+ .SetGroupName ("Ndn")
+ .SetParent<super> ()
+ .template AddConstructor< ContentStoreWithStats< Policy > > ()
+
+ .AddTraceSource ("WillRemoveEntry", "Trace called just before content store entry will be removed",
+ MakeTraceSourceAccessor (&ContentStoreWithStats< Policy >::m_willRemoveEntry))
+
+ // trace stuff here
+ ;
+
+ return tid;
+}
+
+
+} // namespace cs
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_CONTENT_STORE_IMPL_H_