Implementing new cache replacement strategies: Random and FIFO
diff --git a/model/ccnx-content-store-impl.h b/model/ccnx-content-store-impl.h
new file mode 100644
index 0000000..e2ee632
--- /dev/null
+++ b/model/ccnx-content-store-impl.h
@@ -0,0 +1,104 @@
+/* -*- 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>
+ */
+
+#ifndef CCNX_CONTENT_STORE_IMPL_H_
+#define CCNX_CONTENT_STORE_IMPL_H_
+
+#include "ccnx-content-store.h"
+#include "ns3/packet.h"
+#include "ns3/ccnx-interest-header.h"
+#include "ns3/ccnx-content-object-header.h"
+#include <boost/foreach.hpp>
+
+namespace ns3
+{
+
+template<class Container>
+class CcnxContentStoreImpl : public CcnxContentStore,
+ protected Container
+{
+public:
+ // from CcnxContentStore
+
+ virtual inline boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
+ Lookup (Ptr<const CcnxInterestHeader> interest);
+
+ virtual inline bool
+ Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
+
+ // virtual bool
+ // Remove (Ptr<CcnxInterestHeader> header);
+
+ virtual inline void
+ Print (std::ostream &os) const;
+};
+
+
+template<class Container>
+boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
+CcnxContentStoreImpl<Container>::Lookup (Ptr<const CcnxInterestHeader> interest)
+{
+ // NS_LOG_FUNCTION (this << interest->GetName ());
+
+ /// @todo Change to search with predicate
+ typename Container::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 ()->GetFullyFormedCcnxPacket (),
+ 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<CcnxContentObjectHeader>, Ptr<Packet> > (0, 0, 0);
+ }
+}
+
+template<class Container>
+bool
+CcnxContentStoreImpl<Container>::Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
+{
+ // NS_LOG_FUNCTION (this << header->GetName ());
+
+ return
+ this->insert (header->GetName (), Create<CcnxContentStoreEntry> (header, packet))
+ .second;
+}
+
+template<class Container>
+void
+CcnxContentStoreImpl<Container>::Print (std::ostream &os) const
+{
+ BOOST_FOREACH (const typename Container::parent_trie &item, this->getPolicy ())
+ {
+ os << item.payload ()->GetName () << std::endl;
+ }
+}
+
+
+} // namespace ns3
+
+#endif // CCNX_CONTENT_STORE_IMPL_H_