model: New trivial implementation of ContentStore (ns3::ndn::cs::Nocache)
This implementation completely disables all caching (this trivial implementation
is more efficient than content store with custom no-caching policy)
diff --git a/examples/ndn-simple-with-cs-lfu.cc b/examples/ndn-simple-with-cs-lfu.cc
index 83cef07..59c9a46 100644
--- a/examples/ndn-simple-with-cs-lfu.cc
+++ b/examples/ndn-simple-with-cs-lfu.cc
@@ -114,12 +114,18 @@
// Install CCNx stack on all nodes
ndn::StackHelper ccnxHelper;
ccnxHelper.SetDefaultRoutes (true);
- ccnxHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lfu"); // don't set up max size here, will use default value = 100
- ccnxHelper.InstallAll ();
- // set up max sizes, after NDN stack is installed
- Config::Set ("/NodeList/0/$ns3::ndn::ContentStore/MaxSize", UintegerValue (1)); // number after nodeList is global ID of the node (= node->GetId ())
- Config::Set ("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue (2));
+ // node 0: disable cache completely
+ ccnxHelper.SetContentStore ("ns3::ndn::cs::Nocache"); // disable cache
+ ccnxHelper.Install (nodes.Get (0));
+
+ // node 1 and 2: set cache with Lfu policy
+ ccnxHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lfu", "MaxSize", "2"); // can set cache size this way
+ ccnxHelper.Install (nodes.Get (1));
+ ccnxHelper.Install (nodes.Get (2));
+
+ // alternative way to configure cache size
+ // [number after nodeList is global ID of the node (= node->GetId ())]
Config::Set ("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue (100000));
// Installing applications
diff --git a/model/cs/content-store-nocache.cc b/model/cs/content-store-nocache.cc
new file mode 100644
index 0000000..8814c13
--- /dev/null
+++ b/model/cs/content-store-nocache.cc
@@ -0,0 +1,102 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011,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>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ *
+ */
+
+#include "content-store-nocache.h"
+#include "ns3/log.h"
+#include "ns3/packet.h"
+#include "ns3/ndn-name.h"
+#include "ns3/ndn-interest.h"
+#include "ns3/ndn-content-object.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.cs.Nocache");
+
+namespace ns3 {
+namespace ndn {
+namespace cs {
+
+NS_OBJECT_ENSURE_REGISTERED (Nocache);
+
+TypeId
+Nocache::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndn::cs::Nocache")
+ .SetGroupName ("Ndn")
+ .SetParent<ContentStore> ()
+ .AddConstructor< Nocache > ()
+ ;
+
+ return tid;
+}
+
+Nocache::Nocache ()
+{
+}
+
+Nocache::~Nocache ()
+{
+}
+
+boost::tuple<Ptr<Packet>, Ptr<const ContentObject>, Ptr<const Packet> >
+Nocache::Lookup (Ptr<const Interest> interest)
+{
+ this->m_cacheMissesTrace (interest);
+ return boost::tuple<Ptr<Packet>, Ptr<const ContentObject>, Ptr<const Packet> > (0, 0, 0);
+}
+
+bool
+Nocache::Add (Ptr<const ContentObject> header, Ptr<const Packet> packet)
+{
+ return false;
+}
+
+void
+Nocache::Print (std::ostream &os) const
+{
+}
+
+uint32_t
+Nocache::GetSize () const
+{
+ return 0;
+}
+
+Ptr<cs::Entry>
+Nocache::Begin ()
+{
+ return 0;
+}
+
+Ptr<cs::Entry>
+Nocache::End ()
+{
+ return 0;
+}
+
+Ptr<cs::Entry>
+Nocache::Next (Ptr<cs::Entry>)
+{
+ return 0;
+}
+
+} // namespace cs
+} // namespace ndn
+} // namespace ns3
diff --git a/model/cs/content-store-nocache.h b/model/cs/content-store-nocache.h
new file mode 100644
index 0000000..6d38f40
--- /dev/null
+++ b/model/cs/content-store-nocache.h
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Alexander Afanasyev
+ *
+ * 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_NOCACHE_H
+#define NDN_CONTENT_STORE_NOCACHE_H
+
+#include "ns3/ndn-content-store.h"
+
+namespace ns3 {
+namespace ndn {
+namespace cs {
+
+/**
+ * \ingroup ndn
+ * \brief Implementation of ContentStore that completely disables caching
+ */
+class Nocache : public ContentStore
+{
+public:
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
+ static
+ TypeId GetTypeId ();
+
+ /**
+ * @brief Default constructor
+ */
+ Nocache ();
+
+ /**
+ * @brief Virtual destructor
+ */
+ virtual
+ ~Nocache ();
+
+ virtual boost::tuple<Ptr<Packet>, Ptr<const ContentObject>, Ptr<const Packet> >
+ Lookup (Ptr<const Interest> interest);
+
+ virtual bool
+ Add (Ptr<const ContentObject> header, Ptr<const Packet> packet);
+
+ virtual void
+ Print (std::ostream &os) const;
+
+ virtual uint32_t
+ GetSize () const;
+
+ virtual Ptr<cs::Entry>
+ Begin ();
+
+ virtual Ptr<cs::Entry>
+ End ();
+
+ virtual Ptr<cs::Entry>
+ Next (Ptr<cs::Entry>);
+
+};
+
+} // namespace cs
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_CONTENT_STORE_NOCACHE_H