Modularize ContentStore
diff --git a/helper/ccnx-stack-helper.cc b/helper/ccnx-stack-helper.cc
index a40e39a..34010e4 100644
--- a/helper/ccnx-stack-helper.cc
+++ b/helper/ccnx-stack-helper.cc
@@ -61,6 +61,7 @@
, m_needSetDefaultRoutes (false)
{
m_strategyFactory.SetTypeId ("ns3::CcnxFloodingStrategy");
+ m_contentStoreFactory.SetTypeId ("ns3::CcnxContentStoreLru");
}
CcnxStackHelper::~CcnxStackHelper ()
@@ -68,11 +69,16 @@
}
void
-CcnxStackHelper::SetForwardingStrategy (std::string strategy)
+CcnxStackHelper::SetForwardingStrategy (const std::string &strategy)
{
m_strategyFactory.SetTypeId (strategy);
}
+void
+CcnxStackHelper::SetContentStore (const std::string &contentStore)
+{
+ m_contentStoreFactory.SetTypeId (contentStore);
+}
void
CcnxStackHelper::SetDefaultRoutes (bool needSet)
diff --git a/helper/ccnx-stack-helper.h b/helper/ccnx-stack-helper.h
index f7ebd62..afd797b 100644
--- a/helper/ccnx-stack-helper.h
+++ b/helper/ccnx-stack-helper.h
@@ -68,19 +68,24 @@
virtual ~CcnxStackHelper ();
/**
- * @brief Set forwarding strategy helper
+ * @brief Set forwarding strategy class
+ * @param forwardingStrategy string containing name of the forwarding strategy class
*
- * \param forwarding a new forwarding helper
+ * Valid options are "ns3::CcnxFloodingStrategy" (default) and "ns3::CcnxBestRouteStrategy"
*
- * Set the forwarding helper to use during Install. The forwarding helper is
- * really an object factory which is used to create an object of type
- * ns3::CcnxL3Protocol per node. This forwarding object is then associated to
- * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
+ * Other strategies can be implemented, inheriting ns3::CcnxForwardingStrategy class
*/
void
- SetForwardingStrategy (std::string forwardingStrategy);
+ SetForwardingStrategy (const std::string &forwardingStrategy);
/**
+ * @brief Set content store class
+ * @param contentStore string, representing class of the content store
+ */
+ void
+ SetContentStore (const std::string &contentStore);
+
+ /**
* @brief Enable Interest limits (disabled by default)
*
* @param enable Enable or disable limits
@@ -177,6 +182,7 @@
private:
ObjectFactory m_strategyFactory;
+ ObjectFactory m_contentStoreFactory;
bool m_limitsEnabled;
Time m_avgRtt;
uint32_t m_avgContentObjectSize;
diff --git a/model/ccnx-content-object-header.cc b/model/ccnx-content-object-header.cc
index 070c366..0dba3cb 100644
--- a/model/ccnx-content-object-header.cc
+++ b/model/ccnx-content-object-header.cc
@@ -462,10 +462,10 @@
Buffer::Iterator i = start;
i.Prev (2); // Trailer interface requires us to go backwards
- uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
+ uint8_t closing_tag_content = i.ReadU8 ();
NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
- uint8_t __attribute__ ((unused)) closing_tag_content_object = i.ReadU8 ();
+ uint8_t closing_tag_content_object = i.ReadU8 ();
NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
return 2;
diff --git a/model/ccnx-content-store-lru.cc b/model/ccnx-content-store-lru.cc
new file mode 100644
index 0000000..bb35c1b
--- /dev/null
+++ b/model/ccnx-content-store-lru.cc
@@ -0,0 +1,173 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * 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");
+
+namespace ns3
+{
+
+NS_OBJECT_ENSURE_REGISTERED (CcnxContentStoreLru);
+
+using namespace __ccnx_private;
+
+TypeId
+CcnxContentStoreLru::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::CcnxContentStoreLru")
+ .SetGroupName ("Ccnx")
+ .SetParent<CcnxContentStore> ()
+ .AddConstructor<CcnxContentStoreLru> ()
+ .AddAttribute ("Size",
+ "Maximum number of packets that content storage can hold",
+ UintegerValue (100),
+ MakeUintegerAccessor (&CcnxContentStoreLru::SetMaxSize,
+ &CcnxContentStoreLru::GetMaxSize),
+ MakeUintegerChecker<uint32_t> ())
+ ;
+
+ return tid;
+}
+
+void
+CcnxContentStoreLru::SetMaxSize (uint32_t maxSize)
+{
+ m_maxSize = maxSize;
+}
+
+uint32_t
+CcnxContentStoreLru::GetMaxSize () const
+{
+ return m_maxSize;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+// Helper classes
+//////////////////////////////////////////////////////////////////////
+/**
+ * \ingroup ccnx
+ * \brief Typedef for hash index of content store container
+ */
+struct CcnxContentStoreByPrefix
+{
+ typedef
+ CcnxContentStoreLruContainer::type::index<i_prefix>::type
+ type;
+};
+
+/**
+ * \ingroup ccnx
+ * \brief Typedef for MRU index of content store container
+ */
+struct CcnxContentStoreByMru
+{
+ typedef
+ CcnxContentStoreLruContainer::type::index<i_mru>::type
+ type;
+};
+
+#ifdef _DEBUG
+#define DUMP_INDEX_TAG i_ordered
+#define DUMP_INDEX CcnxContentStoreOrderedPrefix
+/**
+ * \ingroup ccnx
+ * \brief Typedef for ordered index of content store container
+ */
+struct CcnxContentStoreOrderedPrefix
+{
+ typedef
+ CcnxContentStoreLruContainer::type::index<i_ordered>::type
+ type;
+};
+#else
+#define DUMP_INDEX_TAG i_mru
+#define DUMP_INDEX CcnxContentStoreByMru
+#endif
+
+
+
+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 ());
+ CcnxContentStoreLruContainer::type::iterator it = m_contentStore.get<i_prefix> ().find (interest->GetName ());
+ if (it != m_contentStore.end ())
+ {
+ // promote entry to the top
+ m_contentStore.get<i_mru> ().relocate (m_contentStore.get<i_mru> ().begin (),
+ m_contentStore.project<i_mru> (it));
+
+ // return fully formed CCNx packet
+ return boost::make_tuple (it->GetFullyFormedCcnxPacket (), it->GetHeader (), it->GetPacket ());
+ }
+ 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 ());
+ CcnxContentStoreLruContainer::type::iterator it = m_contentStore.get<i_prefix> ().find (header->GetName ());
+ if (it == m_contentStore.end ())
+ { // add entry to the top
+ m_contentStore.get<i_mru> ().push_front (CcnxContentStoreEntry (header, packet));
+ if (m_contentStore.size () > m_maxSize)
+ m_contentStore.get<i_mru> ().pop_back ();
+ return false;
+ }
+ else
+ {
+ /// @todo Wrong!!! Record should be updated and relocated, not just relocated
+ // promote entry to the top
+ m_contentStore.get<i_mru> ().relocate (m_contentStore.get<i_mru> ().begin (),
+ m_contentStore.project<i_mru> (it));
+ return true;
+ }
+}
+
+void
+CcnxContentStoreLru::Print() const
+{
+ for( DUMP_INDEX::type::iterator it=m_contentStore.get<DUMP_INDEX_TAG> ().begin ();
+ it != m_contentStore.get<DUMP_INDEX_TAG> ().end ();
+ it++
+ )
+ {
+ NS_LOG_INFO (it->GetName ());
+ }
+}
+
+} // namespace ns3
diff --git a/model/ccnx-content-store-lru.h b/model/ccnx-content-store-lru.h
new file mode 100644
index 0000000..66a81a2
--- /dev/null
+++ b/model/ccnx-content-store-lru.h
@@ -0,0 +1,138 @@
+/* -*- 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#ifndef CCNX_CONTENT_STORE_LRU_H
+#define CCNX_CONTENT_STORE_LRU_H
+
+#include "ccnx-content-store.h"
+
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/tag.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+#include <boost/tuple/tuple.hpp>
+
+#include "ccnx.h"
+#include "ccnx-name-components-hash-helper.h"
+// #include "ccnx-content-object-header.h"
+// #include "ccnx-interest-header.h"
+// #include "ccnx-name-components.h"
+
+namespace ns3
+{
+/**
+ * \ingroup ccnx
+ * \brief Typedef for content store container implemented as a Boost.MultiIndex container
+ *
+ * - First index (tag<prefix>) is a unique hash index based on NDN prefix of the stored content.
+ * - Second index (tag<mru>) is a sequential index used to maintain up to m_maxSize most recent used (MRU) entries in the content store
+ * - Third index (tag<ordered>) is just a helper to provide stored prefixes in ordered way. Should be disabled in production build
+ *
+ * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
+ */
+struct CcnxContentStoreLruContainer
+{
+ /// @cond include_hidden
+ typedef
+ boost::multi_index::multi_index_container<
+ CcnxContentStoreEntry,
+ boost::multi_index::indexed_by<
+ boost::multi_index::hashed_unique<
+ boost::multi_index::tag<__ccnx_private::i_prefix>,
+ boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
+ const CcnxNameComponents&,
+ &CcnxContentStoreEntry::GetName>,
+ CcnxPrefixHash>,
+ boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::i_mru> >
+#ifdef _DEBUG
+ ,
+ boost::multi_index::ordered_unique<
+ boost::multi_index::tag<__ccnx_private::i_ordered>,
+ boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
+ const CcnxNameComponents&,
+ &CcnxContentStoreEntry::GetName>
+ >
+#endif
+ >
+ > type;
+ /// @endcond
+};
+
+/**
+ * \ingroup ccnx
+ * \brief NDN content store entry
+ */
+class CcnxContentStoreLru : public CcnxContentStore
+{
+public:
+ /**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
+ static TypeId GetTypeId ();
+
+ /**
+ * Default constructor
+ */
+ CcnxContentStoreLru ();
+ virtual ~CcnxContentStoreLru ();
+
+ /**
+ * \brief Set maximum size of content store
+ *
+ * \param size size in packets
+ */
+ void
+ SetMaxSize (uint32_t maxSize);
+
+ /**
+ * \brief Get maximum size of content store
+ *
+ * \returns size in packets
+ */
+ uint32_t
+ GetMaxSize () const;
+
+ // from CcnxContentStore
+ virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
+ Lookup (Ptr<const CcnxInterestHeader> interest);
+
+ virtual bool
+ Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
+
+ virtual void
+ Print () const;
+
+private:
+ size_t m_maxSize; ///< \brief maximum number of entries in cache
+
+ /**
+ * \brief Content store implemented as a Boost.MultiIndex container
+ * \internal
+ */
+ CcnxContentStoreLruContainer::type m_contentStore;
+};
+
+} //namespace ns3
+
+#endif // CCNX_CONTENT_STORE_LRU_H
diff --git a/model/ccnx-content-store.cc b/model/ccnx-content-store.cc
index f21841a..986405f 100644
--- a/model/ccnx-content-store.cc
+++ b/model/ccnx-content-store.cc
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2011 University of California, Los Angeles
+ * 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
@@ -15,16 +15,17 @@
* 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>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ *
*/
#include "ccnx-content-store.h"
#include "ns3/log.h"
#include "ns3/packet.h"
+#include "ns3/ccnx-name-components.h"
#include "ns3/ccnx-interest-header.h"
#include "ns3/ccnx-content-object-header.h"
-#include "ns3/uinteger.h"
NS_LOG_COMPONENT_DEFINE ("CcnxContentStore");
@@ -33,79 +34,28 @@
NS_OBJECT_ENSURE_REGISTERED (CcnxContentStore);
-using namespace __ccnx_private;
-
TypeId
CcnxContentStore::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::CcnxContentStore")
.SetGroupName ("Ccnx")
.SetParent<Object> ()
- .AddConstructor<CcnxContentStore> ()
- .AddAttribute ("Size",
- "Maximum number of packets that content storage can hold",
- UintegerValue (100),
- MakeUintegerAccessor (&CcnxContentStore::SetMaxSize,
- &CcnxContentStore::GetMaxSize),
- MakeUintegerChecker<uint32_t> ())
;
return tid;
}
-//////////////////////////////////////////////////////////////////////
-// Helper classes
-//////////////////////////////////////////////////////////////////////
-/**
- * \ingroup ccnx
- * \brief Typedef for hash index of content store container
- */
-struct CcnxContentStoreByPrefix
-{
- typedef
- CcnxContentStoreContainer::type::index<i_prefix>::type
- type;
-};
-/**
- * \ingroup ccnx
- * \brief Typedef for MRU index of content store container
- */
-struct CcnxContentStoreByMru
+CcnxContentStore::~CcnxContentStore ()
{
- typedef
- CcnxContentStoreContainer::type::index<i_mru>::type
- type;
-};
-
-#ifdef _DEBUG
-#define DUMP_INDEX_TAG i_ordered
-#define DUMP_INDEX CcnxContentStoreOrderedPrefix
-/**
- * \ingroup ccnx
- * \brief Typedef for ordered index of content store container
- */
-struct CcnxContentStoreOrderedPrefix
-{
- typedef
- CcnxContentStoreContainer::type::index<i_ordered>::type
- type;
-};
-#else
-#define DUMP_INDEX_TAG i_mru
-#define DUMP_INDEX CcnxContentStoreByMru
-#endif
+}
//////////////////////////////////////////////////////////////////////
CcnxContentStoreEntry::CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
: m_header (header)
+ , m_packet (packet->Copy ())
{
- static CcnxContentObjectTail tail; ///< \internal for optimization purposes
-
- m_packet = packet->Copy ();
- //m_packet->RemoveHeader (*header);//causes bug
- //m_packet->RemoveTrailer (tail);
}
Ptr<Packet>
@@ -119,83 +69,22 @@
return packet;
}
-// /// Disabled copy constructor
-// CcnxContentStoreEntry::CcnxContentStoreEntry (const CcnxContentStoreEntry &o)
-// {
-// }
-
-// /// Disables copy operator
-// CcnxContentStoreEntry& CcnxContentStoreEntry::operator= (const CcnxContentStoreEntry &o)
-// {
-// return *this;
-// }
-
-
-
-CcnxContentStore::CcnxContentStore( )
- : m_maxSize(100) { } // this value shouldn't matter, NS-3 should call SetSize with default value specified in AddAttribute earlier
-
-CcnxContentStore::~CcnxContentStore( )
-{ }
-
-/// Disabled copy constructor
-CcnxContentStore::CcnxContentStore (const CcnxContentStore &o)
+const CcnxNameComponents&
+CcnxContentStoreEntry::GetName () const
{
+ return m_header->GetName ();
}
-/// Disables copy operator
-CcnxContentStore& CcnxContentStore::operator= (const CcnxContentStore &o)
+Ptr<const CcnxContentObjectHeader>
+CcnxContentStoreEntry::GetHeader () const
{
- return *this;
+ return m_header;
}
-
-boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
-CcnxContentStore::Lookup (Ptr<const CcnxInterestHeader> interest)
+Ptr<const Packet>
+CcnxContentStoreEntry::GetPacket () const
{
- NS_LOG_FUNCTION (this << interest->GetName ());
- CcnxContentStoreContainer::type::iterator it = m_contentStore.get<i_prefix> ().find (interest->GetName ());
- if (it != m_contentStore.end ())
- {
- // promote entry to the top
- m_contentStore.get<i_mru> ().relocate (m_contentStore.get<i_mru> ().begin (),
- m_contentStore.project<i_mru> (it));
-
- // return fully formed CCNx packet
- return boost::make_tuple (it->GetFullyFormedCcnxPacket (), it->GetHeader (), it->GetPacket ());
- }
- return boost::tuple<Ptr<Packet>, Ptr<CcnxContentObjectHeader>, Ptr<Packet> > (0, 0, 0);
-}
-
-void
-CcnxContentStore::Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet)
-{
- NS_LOG_FUNCTION (this << header->GetName ());
- CcnxContentStoreContainer::type::iterator it = m_contentStore.get<i_prefix> ().find (header->GetName ());
- if (it == m_contentStore.end ())
- { // add entry to the top
- m_contentStore.get<i_mru> ().push_front (CcnxContentStoreEntry (header, packet));
- if (m_contentStore.size () > m_maxSize)
- m_contentStore.get<i_mru> ().pop_back ();
- }
- else
- {
- // promote entry to the top
- m_contentStore.get<i_mru> ().relocate (m_contentStore.get<i_mru> ().begin (),
- m_contentStore.project<i_mru> (it));
- }
-}
-
-void
-CcnxContentStore::Print() const
-{
- for( DUMP_INDEX::type::iterator it=m_contentStore.get<DUMP_INDEX_TAG> ().begin ();
- it != m_contentStore.get<DUMP_INDEX_TAG> ().end ();
- it++
- )
- {
- NS_LOG_INFO (it->GetName ());
- }
+ return m_packet;
}
} // namespace ns3
diff --git a/model/ccnx-content-store.h b/model/ccnx-content-store.h
index 6c0e876..dd56867 100644
--- a/model/ccnx-content-store.h
+++ b/model/ccnx-content-store.h
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2011 University of California, Los Angeles
+ * 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
@@ -15,7 +15,8 @@
* 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>
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
*/
#ifndef CCNX_CONTENT_STORE_H
@@ -23,28 +24,16 @@
#include "ns3/object.h"
#include "ns3/ptr.h"
-#include "ns3/packet.h"
-
-#include <list>
-#include <string>
-#include <iostream>
-
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/tag.hpp>
-#include <boost/multi_index/ordered_index.hpp>
-#include <boost/multi_index/sequenced_index.hpp>
-#include <boost/multi_index/hashed_index.hpp>
-#include <boost/multi_index/mem_fun.hpp>
#include <boost/tuple/tuple.hpp>
-#include "ccnx.h"
-#include "ccnx-name-components-hash-helper.h"
-#include "ccnx-content-object-header.h"
-#include "ccnx-interest-header.h"
-#include "ccnx-name-components.h"
-
namespace ns3
{
+
+class Packet;
+class CcnxContentObjectHeader;
+class CcnxInterestHeader;
+class CcnxNameComponents;
+
/**
* \ingroup ccnx
* \brief NDN content store entry
@@ -74,21 +63,21 @@
* \brief Get prefix of the stored entry
* \returns prefix of the stored entry
*/
- inline const CcnxNameComponents&
+ const CcnxNameComponents&
GetName () const;
/**
* \brief Get CcnxContentObjectHeader of the stored entry
* \returns CcnxContentObjectHeader of the stored entry
*/
- inline Ptr<const CcnxContentObjectHeader>
+ Ptr<const CcnxContentObjectHeader>
GetHeader () const;
/**
* \brief Get content of the stored entry
* \returns content of the stored entry
*/
- inline Ptr<const Packet>
+ Ptr<const Packet>
GetPacket () const;
/**
@@ -98,58 +87,17 @@
Ptr<Packet>
GetFullyFormedCcnxPacket () const;
-// Copy constructor is required by the container. Though, we're
-// storing only two pointers, so shouldn't be a problem
-// private:
-// CcnxContentStoreEntry (const CcnxContentStoreEntry &); ///< disabled copy constructor
-// CcnxContentStoreEntry& operator= (const CcnxContentStoreEntry&); ///< disabled copy operator
-
private:
Ptr<CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader
Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet
};
-/**
- * \ingroup ccnx
- * \brief Typedef for content store container implemented as a Boost.MultiIndex container
- *
- * - First index (tag<prefix>) is a unique hash index based on NDN prefix of the stored content.
- * - Second index (tag<mru>) is a sequential index used to maintain up to m_maxSize most recent used (MRU) entries in the content store
- * - Third index (tag<ordered>) is just a helper to provide stored prefixes in ordered way. Should be disabled in production build
- *
- * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
- */
-struct CcnxContentStoreContainer
-{
- /// @cond include_hidden
- typedef
- boost::multi_index::multi_index_container<
- CcnxContentStoreEntry,
- boost::multi_index::indexed_by<
- boost::multi_index::hashed_unique<
- boost::multi_index::tag<__ccnx_private::i_prefix>,
- boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
- const CcnxNameComponents&,
- &CcnxContentStoreEntry::GetName>,
- CcnxPrefixHash>,
- boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::i_mru> >
-#ifdef _DEBUG
- ,
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<__ccnx_private::i_ordered>,
- boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
- const CcnxNameComponents&,
- &CcnxContentStoreEntry::GetName>
- >
-#endif
- >
- > type;
- /// @endcond
-};
/**
* \ingroup ccnx
- * \brief NDN content store entry
+ * \brief Base class for NDN content store
+ *
+ * Particular implementations should implement Lookup, Add, and Print methods
*/
class CcnxContentStore : public Object
{
@@ -159,13 +107,13 @@
*
* \return interface ID
*/
- static TypeId GetTypeId ();
+ static
+ TypeId GetTypeId ();
/**
- * Default constructor
+ * @brief Virtual destructor
*/
- CcnxContentStore( );
- virtual ~CcnxContentStore( );
+ virtual ~CcnxContentStore ();
/**
* \brief Find corresponding CS entry for the given interest
@@ -176,8 +124,8 @@
* If an entry is found, it is promoted to the top of most recent
* used entries index, \see m_contentStore
*/
- boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
- Lookup (Ptr<const CcnxInterestHeader> interest);
+ virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
+ Lookup (Ptr<const CcnxInterestHeader> interest) = 0;
/**
* \brief Add a new content to the content store.
@@ -185,28 +133,19 @@
* \param header Fully parsed CcnxContentObjectHeader
* \param packet Fully formed CCNx packet to add to content store
* (will be copied and stripped down of headers)
- *
- * If entry with the same prefix exists, the old entry will be
- * promoted to the top of the MRU hash
+ * @returns true if an existing entry was updated, false otherwise
*/
- void
- Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
+ virtual bool
+ Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet) = 0;
- /**
- * \brief Set maximum size of content store
- *
- * \param size size in packets
- */
- inline void
- SetMaxSize (uint32_t maxSize);
-
- /**
- * \brief Get maximum size of content store
- *
- * \returns size in packets
- */
- inline uint32_t
- GetMaxSize () const;
+ // /**
+ // * \brief Add a new content to the content store.
+ // *
+ // * \param header Interest header for which an entry should be removed
+ // * @returns true if an existing entry was removed, false otherwise
+ // */
+ // virtual bool
+ // Remove (Ptr<CcnxInterestHeader> header) = 0;
/**
* \brief Print out content store entries
@@ -216,21 +155,8 @@
*
* Release build dumps everything in MRU order
*/
- void Print () const;
-
-private:
- CcnxContentStore (const CcnxContentStore &o); ///< Disabled copy constructor
- CcnxContentStore& operator= (const CcnxContentStore &o); ///< Disabled copy operator
-
-private:
- size_t m_maxSize; ///< \brief maximum number of entries in cache \internal
- // string_key_hash_t<CsEntry> m_contentStore; ///< \brief actual content store \internal
-
- /**
- * \brief Content store implemented as a Boost.MultiIndex container
- * \internal
- */
- CcnxContentStoreContainer::type m_contentStore;
+ virtual void
+ Print () const = 0;
};
inline std::ostream&
@@ -240,37 +166,6 @@
return os;
}
-const CcnxNameComponents&
-CcnxContentStoreEntry::GetName () const
-{
- return m_header->GetName ();
-}
-
-Ptr<const CcnxContentObjectHeader>
-CcnxContentStoreEntry::GetHeader () const
-{
- return m_header;
-}
-
-Ptr<const Packet>
-CcnxContentStoreEntry::GetPacket () const
-{
- return m_packet;
-}
-
-
-inline void
-CcnxContentStore::SetMaxSize (uint32_t maxSize)
-{
- m_maxSize = maxSize;
-}
-
-inline uint32_t
-CcnxContentStore::GetMaxSize () const
-{
- return m_maxSize;
-}
-
-} //namespace ns3
+} // namespace ns3
#endif // CCNX_CONTENT_STORE_H
diff --git a/model/ccnx-interest-header.cc b/model/ccnx-interest-header.cc
index 06777e3..554cded 100644
--- a/model/ccnx-interest-header.cc
+++ b/model/ccnx-interest-header.cc
@@ -26,6 +26,7 @@
#include "ccnx-interest-header.h"
#include "ns3/log.h"
+#include "ns3/unused.h"
#include "../helper/ccnx-encoding-helper.h"
#include "../helper/ccnx-decoding-helper.h"
@@ -198,8 +199,8 @@
void
CcnxInterestHeader::Serialize (Buffer::Iterator start) const
{
- size_t size __attribute__ ((__unused__)) = CcnxEncodingHelper::Serialize (start, *this);
-
+ size_t size = CcnxEncodingHelper::Serialize (start, *this);
+ NS_UNUSED (size);
NS_LOG_INFO ("Serialize size = " << size);
}
diff --git a/model/ccnx-l3-protocol.cc b/model/ccnx-l3-protocol.cc
index 83ab9d2..013a2ee 100644
--- a/model/ccnx-l3-protocol.cc
+++ b/model/ccnx-l3-protocol.cc
@@ -98,7 +98,6 @@
NS_LOG_FUNCTION (this);
m_pit = CreateObject<CcnxPit> ();
- m_contentStore = CreateObject<CcnxContentStore> ();
}
CcnxL3Protocol::~CcnxL3Protocol ()
@@ -125,7 +124,7 @@
{
if (m_node == 0)
{
- Ptr<Node>node = this->GetObject<Node>();
+ Ptr<Node> node = this->GetObject<Node>();
// verify that it's a valid node and that
// the node has not been set before
if (node != 0)
@@ -133,6 +132,11 @@
this->SetNode (node);
}
}
+ if (m_contentStore == 0)
+ {
+ m_contentStore = this->GetObject<CcnxContentStore> ();
+ }
+
Object::NotifyNewAggregate ();
}