model: Generalizing content store implementation
diff --git a/model/cs/content-store-impl.cc b/model/cs/content-store-impl.cc
index 0bb9dd2..3a219fa 100644
--- a/model/cs/content-store-impl.cc
+++ b/model/cs/content-store-impl.cc
@@ -19,9 +19,6 @@
  */
 
 #include "content-store-impl.h"
-#include "ns3/log.h"
-#include "ns3/uinteger.h"
-#include "ns3/string.h"
 
 #include "../../utils/trie/random-policy.h"
 #include "../../utils/trie/lru-policy.h"
@@ -45,204 +42,6 @@
 
 namespace cs {
 
-
-template<>
-TypeId
-ContentStoreImpl< lru_policy_traits >::GetTypeId ()
-{
-  static TypeId tid = TypeId ("ns3::ndn::cs::Lru")
-    .SetGroupName ("Ndn")
-    .SetParent<ContentStore> ()
-    .AddConstructor< ContentStoreImpl< lru_policy_traits > > ()
-    .AddAttribute ("MaxSize",
-                   "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
-                   StringValue ("100"),
-                   MakeUintegerAccessor (&ContentStoreImpl< lru_policy_traits >::GetMaxSize,
-                                         &ContentStoreImpl< lru_policy_traits >::SetMaxSize),
-                   MakeUintegerChecker<uint32_t> ())
-    ;
-
-  return tid;
-}
-
-template<>
-TypeId
-ContentStoreImpl< random_policy_traits >::GetTypeId ()
-{
-  static TypeId tid = TypeId ("ns3::ndn::cs::Random")
-    .SetGroupName ("Ndn")
-    .SetParent<ContentStore> ()
-    .AddConstructor< ContentStoreImpl< random_policy_traits > > ()
-    .AddAttribute ("MaxSize",
-                   "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
-                   StringValue ("100"),
-                   MakeUintegerAccessor (&ContentStoreImpl< random_policy_traits >::GetMaxSize,
-                                         &ContentStoreImpl< random_policy_traits >::SetMaxSize),
-                   MakeUintegerChecker<uint32_t> ())
-    ;
-
-  return tid;
-}
-
-template<>
-TypeId
-ContentStoreImpl< fifo_policy_traits >::GetTypeId ()
-{
-  static TypeId tid = TypeId ("ns3::ndn::cs::Fifo")
-    .SetGroupName ("Ndn")
-    .SetParent<ContentStore> ()
-    .AddConstructor< ContentStoreImpl< fifo_policy_traits > > ()
-    .AddAttribute ("MaxSize",
-                   "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
-                   StringValue ("100"),
-                   MakeUintegerAccessor (&ContentStoreImpl< fifo_policy_traits >::GetMaxSize,
-                                         &ContentStoreImpl< fifo_policy_traits >::SetMaxSize),
-                   MakeUintegerChecker<uint32_t> ())
-    ;
-
-  return tid;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////////////
-
-template<class Policy>
-boost::tuple<Ptr<Packet>, Ptr<const ContentObjectHeader>, Ptr<const Packet> >
-ContentStoreImpl<Policy>::Lookup (Ptr<const InterestHeader> interest)
-{
-  // NS_LOG_FUNCTION (this << interest->GetName ());
-
-  /// @todo Change to search with predicate
-  typename super::const_iterator node = this->deepest_prefix_match (interest->GetName ());
-  
-  if (node != this->end ())
-    {
-      this->m_cacheHitsTrace (interest, node->payload ()->GetHeader ());
-
-      // NS_LOG_DEBUG ("cache hit with " << node->payload ()->GetHeader ()->GetName ());
-      return boost::make_tuple (node->payload ()->GetFullyFormedNdnPacket (),
-                                node->payload ()->GetHeader (),
-                                node->payload ()->GetPacket ());
-    }
-  else
-    {
-      // NS_LOG_DEBUG ("cache miss for " << interest->GetName ());
-      this->m_cacheMissesTrace (interest);
-      return boost::tuple<Ptr<Packet>, Ptr<ContentObjectHeader>, Ptr<Packet> > (0, 0, 0);
-    }
-}   
-    
-template<class Policy>
-bool 
-ContentStoreImpl<Policy>::Add (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet)
-{
-  // NS_LOG_FUNCTION (this << header->GetName ());
-
-  Ptr< entry > newEntry = Create< entry > (header, packet);
-  std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
-
-  if (result.first != super::end ())
-    {
-      if (result.second)
-        {
-          newEntry->SetTrie (result.first);
-          return newEntry;
-        }
-      else
-        {
-          // should we do anything?
-          // update payload? add new payload?
-          return false;
-        }
-    }
-  else
-    return false; // cannot insert entry
-}
-
-template<class Policy>
-void 
-ContentStoreImpl<Policy>::Print (std::ostream &os) const
-{
-  for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
-       item != this->getPolicy ().end ();
-       item++)
-  // BOOST_FOREACH (const typename super::parent_trie &item, this->getPolicy ())
-    {
-      os << item->payload ()->GetName () << std::endl;
-    }
-}
-
-template<class Policy>
-void 
-ContentStoreImpl<Policy>::SetMaxSize (uint32_t maxSize)
-{
-  this->getPolicy ().set_max_size (maxSize);
-}
-
-template<class Policy>
-uint32_t
-ContentStoreImpl<Policy>::GetMaxSize () const
-{
-  return this->getPolicy ().get_max_size ();
-}
-
-template<class Policy>
-uint32_t
-ContentStoreImpl<Policy>::GetSize () const
-{
-  return this->getPolicy ().size ();
-}
-
-template<class Policy>
-Ptr<Entry>
-ContentStoreImpl<Policy>::Begin ()
-{
-  typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
-  for (; item != end; item++)
-    {
-      if (item->payload () == 0) continue;
-      break;
-    }
-
-  if (item == end)
-    return End ();
-  else
-    return item->payload ();
-}
-
-template<class Policy>
-Ptr<Entry>
-ContentStoreImpl<Policy>::End ()
-{
-  return 0;
-}
-
-template<class Policy>
-Ptr<Entry>
-ContentStoreImpl<Policy>::Next (Ptr<Entry> from)
-{
-  if (from == 0) return 0;
-  
-  typename super::parent_trie::recursive_iterator
-    item (*StaticCast< entry > (from)->to_iterator ()),
-    end (0);
-  
-  for (item++; item != end; item++)
-    {
-      if (item->payload () == 0) continue;
-      break;
-    }
-
-  if (item == end)
-    return End ();
-  else
-    return item->payload ();
-}
-
-
-////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////
-
 // explicit instantiation and registering
 /**
  * @brief ContentStore with LRU cache replacement policy
diff --git a/model/cs/content-store-impl.h b/model/cs/content-store-impl.h
index 1281495..a168636 100644
--- a/model/cs/content-store-impl.h
+++ b/model/cs/content-store-impl.h
@@ -27,6 +27,10 @@
 #include "ns3/ndn-content-object.h"
 #include <boost/foreach.hpp>
 
+#include "ns3/log.h"
+#include "ns3/uinteger.h"
+#include "ns3/string.h"
+
 #include "../../utils/trie/trie-with-policy.h"
 
 namespace ns3 {
@@ -109,8 +113,172 @@
 
   uint32_t
   GetMaxSize () const;
+
+private:
+  static LogComponent g_log; ///< @brief Logging variable
 };
 
+//////////////////////////////////////////
+////////// Implementation ////////////////
+//////////////////////////////////////////
+
+
+template<class Policy>
+LogComponent ContentStoreImpl< Policy >::g_log = LogComponent (("ndn.cs." + Policy::GetName ()).c_str ());
+
+
+template<class Policy>
+TypeId
+ContentStoreImpl< Policy >::GetTypeId ()
+{
+  static TypeId tid = TypeId (("ns3::ndn::cs::"+Policy::GetName ()).c_str ())
+    .SetGroupName ("Ndn")
+    .SetParent<ContentStore> ()
+    .AddConstructor< ContentStoreImpl< Policy > > ()
+    .AddAttribute ("MaxSize",
+                   "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
+                   StringValue ("100"),
+                   MakeUintegerAccessor (&ContentStoreImpl< Policy >::GetMaxSize,
+                                         &ContentStoreImpl< Policy >::SetMaxSize),
+                   MakeUintegerChecker<uint32_t> ())
+    ;
+
+  return tid;
+}
+
+template<class Policy>
+boost::tuple<Ptr<Packet>, Ptr<const ContentObjectHeader>, Ptr<const Packet> >
+ContentStoreImpl<Policy>::Lookup (Ptr<const InterestHeader> interest)
+{
+  NS_LOG_FUNCTION (this << interest->GetName ());
+
+  /// @todo Change to search with predicate
+  typename super::const_iterator node = this->deepest_prefix_match (interest->GetName ());
+  
+  if (node != this->end ())
+    {
+      this->m_cacheHitsTrace (interest, node->payload ()->GetHeader ());
+
+      // NS_LOG_DEBUG ("cache hit with " << node->payload ()->GetHeader ()->GetName ());
+      return boost::make_tuple (node->payload ()->GetFullyFormedNdnPacket (),
+                                node->payload ()->GetHeader (),
+                                node->payload ()->GetPacket ());
+    }
+  else
+    {
+      // NS_LOG_DEBUG ("cache miss for " << interest->GetName ());
+      this->m_cacheMissesTrace (interest);
+      return boost::tuple<Ptr<Packet>, Ptr<ContentObjectHeader>, Ptr<Packet> > (0, 0, 0);
+    }
+}   
+    
+template<class Policy>
+bool 
+ContentStoreImpl<Policy>::Add (Ptr<const ContentObjectHeader> header, Ptr<const Packet> packet)
+{
+  NS_LOG_FUNCTION (this << header->GetName ());
+
+  Ptr< entry > newEntry = Create< entry > (header, packet);
+  std::pair< typename super::iterator, bool > result = super::insert (header->GetName (), newEntry);
+
+  if (result.first != super::end ())
+    {
+      if (result.second)
+        {
+          newEntry->SetTrie (result.first);
+          return newEntry;
+        }
+      else
+        {
+          // should we do anything?
+          // update payload? add new payload?
+          return false;
+        }
+    }
+  else
+    return false; // cannot insert entry
+}
+
+template<class Policy>
+void 
+ContentStoreImpl<Policy>::Print (std::ostream &os) const
+{
+  for (typename super::policy_container::const_iterator item = this->getPolicy ().begin ();
+       item != this->getPolicy ().end ();
+       item++)
+    {
+      os << item->payload ()->GetName () << std::endl;
+    }
+}
+
+template<class Policy>
+void 
+ContentStoreImpl<Policy>::SetMaxSize (uint32_t maxSize)
+{
+  this->getPolicy ().set_max_size (maxSize);
+}
+
+template<class Policy>
+uint32_t
+ContentStoreImpl<Policy>::GetMaxSize () const
+{
+  return this->getPolicy ().get_max_size ();
+}
+
+template<class Policy>
+uint32_t
+ContentStoreImpl<Policy>::GetSize () const
+{
+  return this->getPolicy ().size ();
+}
+
+template<class Policy>
+Ptr<Entry>
+ContentStoreImpl<Policy>::Begin ()
+{
+  typename super::parent_trie::recursive_iterator item (super::getTrie ()), end (0);
+  for (; item != end; item++)
+    {
+      if (item->payload () == 0) continue;
+      break;
+    }
+
+  if (item == end)
+    return End ();
+  else
+    return item->payload ();
+}
+
+template<class Policy>
+Ptr<Entry>
+ContentStoreImpl<Policy>::End ()
+{
+  return 0;
+}
+
+template<class Policy>
+Ptr<Entry>
+ContentStoreImpl<Policy>::Next (Ptr<Entry> from)
+{
+  if (from == 0) return 0;
+  
+  typename super::parent_trie::recursive_iterator
+    item (*StaticCast< entry > (from)->to_iterator ()),
+    end (0);
+  
+  for (item++; item != end; item++)
+    {
+      if (item->payload () == 0) continue;
+      break;
+    }
+
+  if (item == end)
+    return End ();
+  else
+    return item->payload ();
+}
+
+
 } // namespace cs
 } // namespace ndn
 } // namespace ns3
diff --git a/utils/trie/counting-policy.h b/utils/trie/counting-policy.h
index ffa2d1a..2c8656c 100644
--- a/utils/trie/counting-policy.h
+++ b/utils/trie/counting-policy.h
@@ -34,6 +34,9 @@
  */
 struct counting_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return "Counting"; }
+
   struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
 
   template<class Container>
diff --git a/utils/trie/empty-policy.h b/utils/trie/empty-policy.h
index a50b9e8..c610717 100644
--- a/utils/trie/empty-policy.h
+++ b/utils/trie/empty-policy.h
@@ -30,6 +30,9 @@
  */
 struct empty_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return ""; }
+
   typedef void* policy_hook_type;
 
   template<class Container> struct container_hook { typedef void* type; };
diff --git a/utils/trie/fifo-policy.h b/utils/trie/fifo-policy.h
index 77d4ce2..7ab4ec7 100644
--- a/utils/trie/fifo-policy.h
+++ b/utils/trie/fifo-policy.h
@@ -33,6 +33,9 @@
  */
 struct fifo_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return "Fifo"; }
+
   struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
 
   template<class Container>
diff --git a/utils/trie/lru-policy.h b/utils/trie/lru-policy.h
index 15b482f..a248117 100644
--- a/utils/trie/lru-policy.h
+++ b/utils/trie/lru-policy.h
@@ -33,6 +33,9 @@
  */
 struct lru_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return "Lru"; }
+  
   struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
 
   template<class Container>
diff --git a/utils/trie/persistent-policy.h b/utils/trie/persistent-policy.h
index 95c7d8f..9b706b0 100644
--- a/utils/trie/persistent-policy.h
+++ b/utils/trie/persistent-policy.h
@@ -36,6 +36,9 @@
  */
 struct persistent_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return "Persistent"; }
+
   struct policy_hook_type : public boost::intrusive::list_member_hook<> {};
 
   template<class Container>
diff --git a/utils/trie/random-policy.h b/utils/trie/random-policy.h
index 9e0dde6..1800f95 100644
--- a/utils/trie/random-policy.h
+++ b/utils/trie/random-policy.h
@@ -35,6 +35,9 @@
  */
 struct random_policy_traits
 {
+  /// @brief Name that can be used to identify the policy (for NS-3 object model and logging)
+  static std::string GetName () { return "Random"; }
+
   struct policy_hook_type : public boost::intrusive::set_member_hook<> { uint32_t randomOrder; };
 
   template<class Container>