model: (Re-)Implementing ability to keep PIT records after Interest is getting satisfied
Default behavior remained the same.
As part of this commit, a small extension (and bug fix) in trie data
structure, allowing search with predicates (e.g., used to lookup a
non-empty PIT entry during Lookup on ContentObject header).
diff --git a/model/pit/ndn-pit-entry.cc b/model/pit/ndn-pit-entry.cc
index 77c7578..accfcf1 100644
--- a/model/pit/ndn-pit-entry.cc
+++ b/model/pit/ndn-pit-entry.cc
@@ -62,12 +62,12 @@
Entry::UpdateLifetime (const Time &offsetTime)
{
NS_LOG_FUNCTION (offsetTime.ToDouble (Time::S));
-
+
Time newExpireTime = Simulator::Now () + offsetTime;
if (newExpireTime > m_expireTime)
m_expireTime = newExpireTime;
-
- NS_LOG_INFO ("Updated lifetime to " << m_expireTime.ToDouble (Time::S));
+
+ NS_LOG_INFO (this->GetPrefix () << ", Updated lifetime to " << m_expireTime.ToDouble (Time::S) << "s, " << (m_expireTime-Simulator::Now ()).ToDouble (Time::S) << "s left");
}
void
@@ -78,7 +78,7 @@
{
m_expireTime = Simulator::Now ();
}
- NS_LOG_INFO ("Offsetting lifetime to " << m_expireTime.ToDouble (Time::S));
+ NS_LOG_INFO (this->GetPrefix () << ", Offsetting lifetime to " << m_expireTime.ToDouble (Time::S) << "s, " << (m_expireTime-Simulator::Now ()).ToDouble (Time::S) << "s left");
}
@@ -110,7 +110,7 @@
Entry::in_iterator
Entry::AddIncoming (Ptr<Face> face)
{
- std::pair<in_iterator,bool> ret =
+ std::pair<in_iterator,bool> ret =
m_incoming.insert (IncomingFace (face));
// NS_ASSERT_MSG (ret.second, "Something is wrong");
@@ -277,7 +277,7 @@
os << ",";
else
first = false;
-
+
os << *face.m_face;
}
@@ -289,7 +289,7 @@
os << ",";
else
first = false;
-
+
os << *face.m_face;
}
os << "\nNonces: ";
@@ -300,7 +300,7 @@
os << ",";
else
first = false;
-
+
os << nonce;
}
diff --git a/model/pit/ndn-pit-entry.h b/model/pit/ndn-pit-entry.h
index 259af75..9680ac2 100644
--- a/model/pit/ndn-pit-entry.h
+++ b/model/pit/ndn-pit-entry.h
@@ -75,7 +75,7 @@
// // boost::multi_index::ordered_non_unique<
// // boost::multi_index::tag<i_retx>,
// // boost::multi_index::member<OutgoingFace, uint32_t, &OutgoingFace::m_retxCount>
-// // >
+// // >
// >
// > type;
// /// @endcond
@@ -99,7 +99,7 @@
typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces
typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type
-
+
/**
* \brief PIT entry constructor
* \param prefix Prefix of the PIT entry
@@ -112,33 +112,34 @@
* @brief Virtual destructor
*/
virtual ~Entry ();
-
+
/**
* @brief Update lifetime of PIT entry
*
- * This function will update PIT entry lifetime to the maximum of the current lifetime and
- * the lifetime Simulator::Now () + offsetTime
+ * @param lifetime desired lifetime of the pit entry (relative to the Simulator::Now ())
*
- * @param lifetime Relative time to the current moment, representing PIT entry lifetime
+ * This function will update PIT entry lifetime to the maximum of the current lifetime and
+ * the lifetime Simulator::Now () + lifetime
*/
virtual void
UpdateLifetime (const Time &lifetime);
/**
* @brief Offset the currently set PIT lifetime (allowed both negative and positive offsets)
+ *
* @param offsetTime positive or negative offset for the PIT lifetime.
*
* If PIT expire time becomes less than Simulator::Now, then it is adjusted to Simulator::Now.
*/
virtual void
OffsetLifetime (const Time &offsetTime);
-
+
/**
* @brief Get prefix of the PIT entry
*/
const NameComponents &
GetPrefix () const;
-
+
/**
* @brief Get current expiration time of the record
*
@@ -146,7 +147,7 @@
*/
const Time &
GetExpireTime () const;
-
+
/**
* @brief Check if nonce `nonce` for the same prefix has already been seen
*
@@ -154,7 +155,7 @@
*/
bool
IsNonceSeen (uint32_t nonce) const;
-
+
/**
* @brief Add `nonce` to the list of seen nonces
*
@@ -164,7 +165,7 @@
*/
virtual void
AddSeenNonce (uint32_t nonce);
-
+
/**
* @brief Add `face` to the list of incoming faces
*
@@ -200,10 +201,10 @@
*/
virtual void
ClearOutgoing ();
-
+
/**
* @brief Remove all references to face.
- *
+ *
* This method should be called before face is completely removed from the stack.
* Face is removed from the lists of incoming and outgoing faces
*/
@@ -217,7 +218,7 @@
// SetWaitingInVain (out_iterator face);
virtual void
SetWaitingInVain (Ptr<Face> face);
-
+
/**
* @brief Check if all outgoing faces are NACKed
*/
@@ -266,7 +267,7 @@
*/
uint32_t
GetOutgoingCount () const;
-
+
/**
* @brief Add new forwarding strategy tag
*/
@@ -295,14 +296,14 @@
private:
friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
-
+
protected:
Pit &m_container; ///< @brief Reference to the container (to rearrange indexes, if necessary)
Ptr<const InterestHeader> m_interest; ///< \brief Interest of the PIT entry (if several interests are received, then nonce is from the first Interest)
Ptr<fib::Entry> m_fibEntry; ///< \brief FIB entry related to this prefix
-
- nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
+
+ nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
in_container m_incoming; ///< \brief container for incoming interests
out_container m_outgoing; ///< \brief container for outgoing interests
@@ -314,6 +315,15 @@
std::list< boost::shared_ptr<fw::Tag> > m_fwTags; ///< @brief Forwarding strategy tags
};
+struct EntryIsNotEmpty
+{
+ bool
+ operator () (Ptr<Entry> entry)
+ {
+ return !entry->GetIncoming ().empty ();
+ }
+};
+
std::ostream& operator<< (std::ostream& os, const Entry &entry);
inline void
diff --git a/model/pit/ndn-pit-impl.cc b/model/pit/ndn-pit-impl.cc
index 3b693f8..27fcab2 100644
--- a/model/pit/ndn-pit-impl.cc
+++ b/model/pit/ndn-pit-impl.cc
@@ -185,7 +185,7 @@
PitImpl<Policy>::Lookup (const ContentObjectHeader &header)
{
/// @todo use predicate to search with exclude filters
- typename super::iterator item = super::longest_prefix_match (header.GetName ());
+ typename super::iterator item = super::longest_prefix_match_if (header.GetName (), EntryIsNotEmpty ());
if (item == super::end ())
return 0;
@@ -249,8 +249,14 @@
void
PitImpl<Policy>::MarkErased (Ptr<Entry> item)
{
- // entry->SetExpireTime (Simulator::Now () + m_PitEntryPruningTimout);
- super::erase (StaticCast< entry > (item)->to_iterator ());
+ if (this->m_PitEntryPruningTimout.IsZero ())
+ {
+ super::erase (StaticCast< entry > (item)->to_iterator ());
+ }
+ else
+ {
+ item->OffsetLifetime (this->m_PitEntryPruningTimout - item->GetExpireTime () + Simulator::Now ());
+ }
}
diff --git a/model/pit/ndn-pit.cc b/model/pit/ndn-pit.cc
index ad8f4a2..224e013 100644
--- a/model/pit/ndn-pit.cc
+++ b/model/pit/ndn-pit.cc
@@ -24,7 +24,7 @@
#include "ns3/ndn-content-object.h"
#include "ns3/log.h"
-#include "ns3/string.h"
+#include "ns3/nstime.h"
#include "ns3/uinteger.h"
#include "ns3/simulator.h"
@@ -44,10 +44,10 @@
static TypeId tid = TypeId ("ns3::ndn::Pit")
.SetGroupName ("Ndn")
.SetParent<Object> ()
-
+
.AddAttribute ("PitEntryPruningTimout",
"Timeout for PIT entry to live after being satisfied. To make sure recently satisfied interest will not be satisfied again",
- StringValue ("100ms"),
+ TimeValue (), // by default, PIT entries are removed instantly
MakeTimeAccessor (&Pit::m_PitEntryPruningTimout),
MakeTimeChecker ())
;