Implementing new cache replacement strategies: Random and FIFO
diff --git a/model/ccnx-content-store-lru.cc b/model/ccnx-content-store-lru.cc
index 5546d84..a8d00b6 100644
--- a/model/ccnx-content-store-lru.cc
+++ b/model/ccnx-content-store-lru.cc
@@ -15,22 +15,24 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
- *         Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
  */
 
 #include "ccnx-content-store-lru.h"
 #include "ns3/log.h"
-#include "ns3/packet.h"
-#include "ns3/ccnx-interest-header.h"
-#include "ns3/ccnx-content-object-header.h"
 #include "ns3/uinteger.h"
 
-NS_LOG_COMPONENT_DEFINE ("CcnxContentStoreLru");
+NS_LOG_COMPONENT_DEFINE ("CcnxContentStorePolicies");
 
 namespace ns3
 {
 
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+// LRU policy
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+
 NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreLru);
 
 TypeId 
@@ -38,7 +40,7 @@
 {
   static TypeId tid = TypeId ("ns3::CcnxContentStoreLru")
     .SetGroupName ("Ccnx")
-    .SetParent<CcnxContentStore> ()
+    .SetParent< CcnxContentStore > ()
     .AddConstructor<CcnxContentStoreLru> ()
     .AddAttribute ("Size",
                    "Maximum number of packets that content storage can hold",
@@ -54,77 +56,118 @@
 void
 CcnxContentStoreLru::SetMaxSize (uint32_t maxSize)
 {
-  m_maxSize = maxSize;
-  m_contentStore.getPolicy ().set_max_size (maxSize);
+  getPolicy ().set_max_size (maxSize);
 }
 
 uint32_t
 CcnxContentStoreLru::GetMaxSize () const
 {
-  return m_maxSize;
+  return getPolicy ().get_max_size ();
 }
 
-
-//////////////////////////////////////////////////////////////////////
-// Helper classes
-//////////////////////////////////////////////////////////////////////
-/**
- * \ingroup ccnx
- * \brief Typedef for hash index of content store container
- */
-
 CcnxContentStoreLru::CcnxContentStoreLru ()
-  : m_maxSize (100)
-{ } // this value shouldn't matter, NS-3 should call SetSize with default value specified in AddAttribute earlier
+{
+}
         
 CcnxContentStoreLru::~CcnxContentStoreLru () 
-{ }
-
-
-boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
-CcnxContentStoreLru::Lookup (Ptr<const CcnxInterestHeader> interest)
 {
-  NS_LOG_FUNCTION (this << interest->GetName ());
-
-  /// @todo Change to search with predicate
-  CcnxContentStoreLruContainer::iterator node =
-    m_contentStore.deepest_prefix_match (interest->GetName ());
-  
-  if (node != m_contentStore.end ())
-    {
-      m_cacheHitsTrace (interest, node->payload ()->GetHeader ());
-
-      NS_LOG_DEBUG ("cache hit with " << node->payload ()->GetHeader ()->GetName ());
-      return boost::make_tuple (node->payload ()->GetFullyFormedCcnxPacket (),
-                                node->payload ()->GetHeader (),
-                                node->payload ()->GetPacket ());
-    }
-  else
-    {
-      NS_LOG_DEBUG ("cache miss for " << interest->GetName ());
-      m_cacheMissesTrace (interest);
-      return boost::tuple<Ptr<Packet>, Ptr<CcnxContentObjectHeader>, Ptr<Packet> > (0, 0, 0);
-    }
-}   
-    
-bool 
-CcnxContentStoreLru::Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
-{
-  NS_LOG_FUNCTION (this << header->GetName ());
-
-  return
-    m_contentStore
-    .insert (header->GetName (), Create<CcnxContentStoreEntry> (header, packet))
-    .second;
 }
-    
-void 
-CcnxContentStoreLru::Print () const
+
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+// RANDOM policy
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreRandom);
+
+TypeId 
+CcnxContentStoreRandom::GetTypeId (void)
 {
-  BOOST_FOREACH (const CcnxContentStoreLruContainer::parent_trie &item, m_contentStore.getPolicy ())
-    {
-      NS_LOG_INFO (item.payload ()->GetName ());
-    }
+  static TypeId tid = TypeId ("ns3::CcnxContentStoreRandom")
+    .SetGroupName ("Ccnx")
+    .SetParent< CcnxContentStore > ()
+    .AddConstructor<CcnxContentStoreRandom> ()
+    
+    .AddAttribute ("Size",
+                   "Maximum number of packets that content storage can hold",
+                   UintegerValue (100),
+                   MakeUintegerAccessor (&CcnxContentStoreRandom::SetMaxSize,
+                                         &CcnxContentStoreRandom::GetMaxSize),
+                   MakeUintegerChecker<uint32_t> ())
+    ;
+
+  return tid;
 }
 
+void
+CcnxContentStoreRandom::SetMaxSize (uint32_t maxSize)
+{
+  getPolicy ().set_max_size (maxSize);
+}
+
+uint32_t
+CcnxContentStoreRandom::GetMaxSize () const
+{
+  return getPolicy ().get_max_size ();
+}
+
+CcnxContentStoreRandom::CcnxContentStoreRandom ()
+{
+}
+        
+CcnxContentStoreRandom::~CcnxContentStoreRandom () 
+{
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+// FIFO policy
+////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreFifo);
+
+TypeId 
+CcnxContentStoreFifo::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::CcnxContentStoreFifo")
+    .SetGroupName ("Ccnx")
+    .SetParent< CcnxContentStore > ()
+    .AddConstructor<CcnxContentStoreFifo> ()
+    
+    .AddAttribute ("Size",
+                   "Maximum number of packets that content storage can hold",
+                   UintegerValue (100),
+                   MakeUintegerAccessor (&CcnxContentStoreFifo::SetMaxSize,
+                                         &CcnxContentStoreFifo::GetMaxSize),
+                   MakeUintegerChecker<uint32_t> ())
+    ;
+
+  return tid;
+}
+
+void
+CcnxContentStoreFifo::SetMaxSize (uint32_t maxSize)
+{
+  getPolicy ().set_max_size (maxSize);
+}
+
+uint32_t
+CcnxContentStoreFifo::GetMaxSize () const
+{
+  return getPolicy ().get_max_size ();
+}
+
+CcnxContentStoreFifo::CcnxContentStoreFifo ()
+{
+}
+        
+CcnxContentStoreFifo::~CcnxContentStoreFifo () 
+{
+}
+
+
 } // namespace ns3
+