Checkpoint
diff --git a/model/fw/ndn-fw-tag.h b/model/fw/ndn-fw-tag.h
new file mode 100644
index 0000000..3407a07
--- /dev/null
+++ b/model/fw/ndn-fw-tag.h
@@ -0,0 +1,43 @@
+/* -*- 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 NDNSIM_FW_TAG_H
+#define NDNSIM_FW_TAG_H
+
+namespace ns3 {
+namespace ndn {
+namespace fw {
+
+/**
+ * \ingroup ndn
+ * \brief Abstract class for the forwarding strategy tag, which can be added to PIT entries
+ */
+class Tag
+{
+public:
+ virtual ~Tag () { };
+};
+
+} // namespace fw
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDNSIM_FW_TAG_H
diff --git a/model/pit/ndn-pit-entry.h b/model/pit/ndn-pit-entry.h
index d08c09e..d95d338 100644
--- a/model/pit/ndn-pit-entry.h
+++ b/model/pit/ndn-pit-entry.h
@@ -37,12 +37,15 @@
#include <boost/multi_index/member.hpp>
// #include <boost/multi_index/mem_fun.hpp>
#include <set>
+#include <boost/shared_ptr.hpp>
namespace ns3 {
namespace ndn {
class Pit;
+namespace fw { class Tag; }
+
namespace pit {
/// @cond include_hidden
@@ -249,6 +252,26 @@
const out_container &
GetOutgoing () const;
+ /**
+ * @brief Add new forwarding strategy tag
+ */
+ inline void
+ AddFwTag (boost::shared_ptr< fw::Tag > tag);
+
+ /**
+ * @brief Get forwarding strategy tag (tag is not removed)
+ */
+ template<class T>
+ inline boost::shared_ptr< T >
+ GetFwTag ();
+
+ /**
+ * @brief Remove the forwarding strategy tag
+ */
+ template<class T>
+ inline void
+ RemoveFwTag ();
+
private:
friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
@@ -266,10 +289,78 @@
Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
+
+ std::list< boost::shared_ptr<fw::Tag> > m_fwTags; ///< @brief Forwarding strategy tags
};
std::ostream& operator<< (std::ostream& os, const Entry &entry);
+inline void
+Entry::AddFwTag (boost::shared_ptr< fw::Tag > tag)
+{
+ m_fwTags.push_back (tag);
+}
+
+/**
+ * @brief Get and remove forwarding strategy tag
+ */
+template<class T>
+inline boost::shared_ptr< T >
+Entry::GetFwTag ()
+{
+ for (std::list< boost::shared_ptr<fw::Tag> >::iterator item = m_fwTags.begin ();
+ item != m_fwTags.end ();
+ item ++)
+ {
+ boost::shared_ptr< T > retPtr = boost::dynamic_pointer_cast<T> (*item);
+ if (retPtr != 0)
+ {
+ return retPtr;
+ }
+ }
+
+ return 0;
+}
+
+// /**
+// * @brief Peek the forwarding strategy tag
+// */
+// template<class T>
+// inline boost::shared_ptr< const T >
+// Entry::PeekFwTag () const
+// {
+// for (std::list< boost::shared_ptr<fw::Tag> >::const_iterator item = m_fwTags.begin ();
+// item != m_fwTags.end ();
+// item ++)
+// {
+// boost::shared_ptr< const T > retPtr = boost::dynamic_pointer_cast<const T> (*item);
+// if (retPtr != 0)
+// {
+// return retPtr;
+// }
+// }
+
+// return 0;
+// }
+
+template<class T>
+inline void
+Entry::RemoveFwTag ()
+{
+ for (std::list< boost::shared_ptr<fw::Tag> >::iterator item = m_fwTags.begin ();
+ item != m_fwTags.end ();
+ item ++)
+ {
+ boost::shared_ptr< T > retPtr = boost::dynamic_pointer_cast< T > (*item);
+ if (retPtr != 0)
+ {
+ m_fwTags.erase (item);
+ return;
+ }
+ }
+}
+
+
} // namespace pit
} // namespace ndn
} // namespace ns3
diff --git a/utils/ndn-pit-queue.cc b/utils/ndn-pit-queue.cc
index 3486d6d..4d6c064 100644
--- a/utils/ndn-pit-queue.cc
+++ b/utils/ndn-pit-queue.cc
@@ -53,11 +53,19 @@
PitQueue::Enqueue (Ptr<Face> inFace,
Ptr<pit::Entry> pitEntry)
{
- Queue &queue = m_queues [inFace]; // either lookup or create
- if (queue.size () >= m_maxQueueSize)
+ PerInFaceQueue::iterator queue = m_queues.find (inFace);
+ if (queue == m_queues.end ())
+ {
+ pair<PerInFaceQueue::iterator, bool> itemPair = m_queues.insert (make_pair (inFace, boost::make_shared<Queue> ()));
+ NS_ASSERT (itemPair.second == true);
+
+ queue = itemPair.first;
+ }
+
+ if (queue->second->size () >= m_maxQueueSize)
return false;
- queue.push_back (pitEntry);
+ queue->second->push_back (pitEntry);
return true;
}
@@ -66,7 +74,7 @@
{
PerInFaceQueue::iterator queue = m_lastQueue;
- while (queue != m_queues.end () && queue->second.size () == 0) // advance iterator
+ while (queue != m_queues.end () && queue->second->size () == 0) // advance iterator
{
queue ++;
}
@@ -74,7 +82,7 @@
if (queue == m_queues.end ())
queue = m_queues.begin (); // circle to the beginning
- while (queue != m_queues.end () && queue->second.size () == 0) // advance iterator
+ while (queue != m_queues.end () && queue->second->size () == 0) // advance iterator
{
queue ++;
}
@@ -82,10 +90,10 @@
if (queue == m_queues.end ()) // e.g., begin () == end ()
return 0;
- NS_ASSERT_MSG (queue->second.size () != 0, "Logic error");
+ NS_ASSERT_MSG (queue->second->size () != 0, "Logic error");
- Ptr<pit::Entry> entry = *queue->second.begin ();
- queue->second.pop_front ();
+ Ptr<pit::Entry> entry = *queue->second->begin ();
+ queue->second->pop_front ();
m_lastQueue = queue;
return entry;
diff --git a/utils/ndn-pit-queue.h b/utils/ndn-pit-queue.h
index de30713..34987db 100644
--- a/utils/ndn-pit-queue.h
+++ b/utils/ndn-pit-queue.h
@@ -25,6 +25,11 @@
#include <list>
#include "ns3/ptr.h"
+#include "ns3/ndn-fw-tag.h"
+
+#include <boost/tuple/tuple.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
namespace ns3 {
namespace ndn {
@@ -57,18 +62,31 @@
void
Remove (Ptr<pit::Entry> entry);
-
-private:
+public:
typedef std::list< Ptr<pit::Entry> > Queue;
- typedef std::map< Ptr<Face>, Queue > PerInFaceQueue;
+ typedef std::map< Ptr<Face>, boost::shared_ptr<Queue> > PerInFaceQueue;
- uint32_t m_maxQueueSize;
-
- PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken
+private:
+ uint32_t m_maxQueueSize;
+ PerInFaceQueue::iterator m_lastQueue; // last queue from which interest was taken
PerInFaceQueue m_queues;
};
+namespace fw {
+
+class PitQueueTag :
+ public Tag
+{
+public:
+ virtual
+ ~PitQueueTag () { };
+
+ typedef boost::tuple< boost::shared_ptr<PitQueue::Queue>, PitQueue::Queue::iterator > Item;
+};
+
+} // namespace fw
+
} // namespace ndn
} // namespace ns3
diff --git a/wscript b/wscript
index 8f2e59f..7bb4838 100644
--- a/wscript
+++ b/wscript
@@ -90,6 +90,7 @@
"model/pit/ndn-pit-entry-outgoing-face.h",
"model/fw/ndn-forwarding-strategy.h",
+ "model/fw/ndn-fw-tag.h",
"utils/batches.h",
"utils/ndn-limits.h",