Now everything suppose to work, but testing is necessary to determine how well it works.
diff --git a/model/ccnx-pit-entry-impl.h b/model/ccnx-pit-entry-impl.h
new file mode 100644
index 0000000..c707cd6
--- /dev/null
+++ b/model/ccnx-pit-entry-impl.h
@@ -0,0 +1,91 @@
+/* -*- 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_PIT_ENTRY_IMPL_H_
+#define _CCNX_PIT_ENTRY_IMPL_H_
+
+namespace ns3 {
+
+class CcnxPit;
+class CcnxInterestHeader;
+class CcnxFibEntry;
+
+template<class Pit>
+class CcnxPitEntryImpl : public CcnxPitEntry
+{
+ typedef CcnxPitEntry super;
+ #define CONTAINER static_cast<Pit&> (m_container)
+
+public:
+ CcnxPitEntryImpl (CcnxPit &pit,
+ Ptr<const CcnxInterestHeader> header,
+ Ptr<CcnxFibEntry> fibEntry)
+ : CcnxPitEntry (pit, header, fibEntry)
+ , item_ (0)
+ {
+ CONTAINER.i_time.insert (*this);
+ CONTAINER.RescheduleCleaning ();
+ }
+
+ virtual ~CcnxPitEntryImpl ()
+ {
+ CONTAINER.i_time.erase (*this);
+
+ CONTAINER.RescheduleCleaning ();
+ }
+
+ virtual void
+ UpdateLifetime (const Time &offsetTime)
+ {
+ CONTAINER.i_time.erase (*this);
+ super::UpdateLifetime (offsetTime);
+ CONTAINER.i_time.insert (*this);
+
+ CONTAINER.RescheduleCleaning ();
+ }
+
+
+ // to make sure policies work
+ void
+ SetTrie (typename Pit::super::iterator item) { item_ = item; }
+
+ typename Pit::super::iterator to_iterator () { return item_; }
+ typename Pit::super::const_iterator to_iterator () const { return item_; }
+
+public:
+ boost::intrusive::set_member_hook<> time_hook_;
+
+private:
+ typename Pit::super::iterator item_;
+};
+
+template<class T>
+struct TimestampIndex
+{
+ bool
+ operator () (const T &a, const T &b) const
+ {
+ return a.GetExpireTime () < b.GetExpireTime ();
+ }
+};
+
+} // ns3
+
+#endif
diff --git a/model/ccnx-pit-entry.cc b/model/ccnx-pit-entry.cc
index 3d3e5d7..dde19e7 100644
--- a/model/ccnx-pit-entry.cc
+++ b/model/ccnx-pit-entry.cc
@@ -49,13 +49,6 @@
}
void
-CcnxPitEntry::SetExpireTime (const Time &expireTime)
-{
- NS_LOG_FUNCTION (expireTime.ToDouble (Time::S));
- m_expireTime = expireTime;
-}
-
-void
CcnxPitEntry::UpdateLifetime (const Time &offsetTime)
{
NS_LOG_FUNCTION (offsetTime.ToDouble (Time::S));
diff --git a/model/ccnx-pit-entry.h b/model/ccnx-pit-entry.h
index 5d85c94..beda5bb 100644
--- a/model/ccnx-pit-entry.h
+++ b/model/ccnx-pit-entry.h
@@ -136,14 +136,6 @@
{ return m_expireTime; }
/**
- * @brief Set expiration time on record as `expireTime` (absolute time)
- *
- * @param expireTime absolute simulation time of when the record should expire
- */
- virtual void
- SetExpireTime (const Time &expireTime);
-
- /**
* @brief Check if nonce `nonce` for the same prefix has already been seen
*
* @param nonce Nonce to check
diff --git a/model/ccnx-pit-impl.cc b/model/ccnx-pit-impl.cc
index e5179d3..0dcfef2 100644
--- a/model/ccnx-pit-impl.cc
+++ b/model/ccnx-pit-impl.cc
@@ -103,28 +103,39 @@
void
CcnxPitImpl::DoDispose ()
{
- clear ();
+ super::clear ();
+}
+
+void CcnxPitImpl::RescheduleCleaning ()
+{
+ m_cleanEvent.Cancel ();
+ if (i_time.empty ())
+ return;
+
+ m_cleanEvent = Simulator::Schedule (i_time.begin ()->GetExpireTime (),
+ &CcnxPitImpl::CleanExpired, this);
}
void
-CcnxPitImpl::DoCleanExpired ()
+CcnxPitImpl::CleanExpired ()
{
- // NS_LOG_LOGIC ("Cleaning PIT. Total: " << size ());
+ NS_LOG_LOGIC ("Cleaning PIT. Total: " << i_time.size ());
Time now = Simulator::Now ();
- NS_LOG_ERROR ("Need to be repaired");
- // // uint32_t count = 0;
- // while (!empty ())
- // {
- // CcnxPit::index<i_timestamp>::type::iterator entry = get<i_timestamp> ().begin ();
- // if (entry->GetExpireTime () <= now) // is the record stale?
- // {
- // get<i_timestamp> ().erase (entry);
- // // count ++;
- // }
- // else
- // break; // nothing else to do. All later records will not be stale
- // }
+ // uint32_t count = 0;
+ while (!i_time.empty ())
+ {
+ time_index::iterator entry = i_time.begin ();
+ if (entry->GetExpireTime () <= now) // is the record stale?
+ {
+ super::erase (entry->to_iterator ());
+ // // count ++;
+ }
+ else
+ break; // nothing else to do. All later records will not be stale
+ }
+
+ RescheduleCleaning ();
}
Ptr<CcnxPitEntry>
diff --git a/model/ccnx-pit-impl.h b/model/ccnx-pit-impl.h
index 9dfd62b..d03134c 100644
--- a/model/ccnx-pit-impl.h
+++ b/model/ccnx-pit-impl.h
@@ -25,55 +25,13 @@
#include "../utils/trie-with-policy.h"
#include "../utils/empty-policy.h"
#include "../utils/persistent-policy.h"
+
+#include "ccnx-pit-entry-impl.h"
+
#include "ns3/ccnx-name-components.h"
namespace ns3 {
-template<class Pit>
-class CcnxPitEntryImpl : public CcnxPitEntry
-{
-public:
- CcnxPitEntryImpl (CcnxPit &pit,
- Ptr<const CcnxInterestHeader> header,
- Ptr<CcnxFibEntry> fibEntry)
- : CcnxPitEntry (pit, header, fibEntry)
- , item_ (0)
- {
- static_cast<Pit&> (m_container).i_time.insert (*this);
- }
-
- virtual ~CcnxPitEntryImpl ()
- {
- static_cast<Pit&> (m_container).i_time.erase (*this);
- }
-
- // to make sure policies work
- void
- SetTrie (typename Pit::super::iterator item) { item_ = item; }
-
- typename Pit::super::iterator to_iterator () { return item_; }
- typename Pit::super::const_iterator to_iterator () const { return item_; }
-
-public:
- boost::intrusive::set_member_hook<> time_hook_;
-
-private:
- typename Pit::super::iterator item_;
-};
-
-template<class T>
-struct TimestampIndex
-{
- bool
- operator () (const T &a, const T &b) const
- {
- return a.GetExpireTime () < b.GetExpireTime ();
- }
-};
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
/**
* \ingroup ccnx
* \brief Class implementing Pending Interests Table
@@ -91,8 +49,6 @@
> super;
typedef CcnxPitEntryImpl< CcnxPitImpl > entry;
- // typedef CcnxPitEntryImpl::trie super;
-
/**
* \brief Interface ID
*
@@ -136,8 +92,8 @@
Next (Ptr<CcnxPitEntry>);
protected:
- // inherited from CcnxPit
- virtual void DoCleanExpired ();
+ void RescheduleCleaning ();
+ void CleanExpired ();
// inherited from Object class
virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
@@ -151,6 +107,7 @@
SetMaxSize (uint32_t maxSize);
private:
+ EventId m_cleanEvent;
Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table
// indexes
@@ -160,8 +117,8 @@
boost::intrusive::member_hook< entry,
boost::intrusive::set_member_hook<>,
&entry::time_hook_>
- > expireTimeIndexType;
- expireTimeIndexType i_time;
+ > time_index;
+ time_index i_time;
friend class CcnxPitEntryImpl< CcnxPitImpl >;
};
diff --git a/model/ccnx-pit.cc b/model/ccnx-pit.cc
index a6328fd..00b892d 100644
--- a/model/ccnx-pit.cc
+++ b/model/ccnx-pit.cc
@@ -43,11 +43,11 @@
static TypeId tid = TypeId ("ns3::private::CcnxPit")
.SetGroupName ("Ccnx")
.SetParent<Object> ()
- .AddAttribute ("CleanupTimeout",
- "Timeout defining how frequent RIT should be cleaned up",
- StringValue ("1s"),
- MakeTimeAccessor (&CcnxPit::GetCleanupTimeout, &CcnxPit::SetCleanupTimeout),
- MakeTimeChecker ())
+ // .AddAttribute ("CleanupTimeout",
+ // "Timeout defining how frequent RIT should be cleaned up",
+ // StringValue ("1s"),
+ // MakeTimeAccessor (&CcnxPit::GetCleanupTimeout, &CcnxPit::SetCleanupTimeout),
+ // MakeTimeChecker ())
.AddAttribute ("PitEntryPruningTimout",
"Timeout for PIT entry to live after being satisfied. To make sure recently satisfied interest will not be satisfied again",
@@ -67,32 +67,32 @@
{
}
-void CcnxPit::CleanExpired ()
-{
- DoCleanExpired ();
+// void CcnxPit::CleanExpired ()
+// {
+// DoCleanExpired ();
- // schedule next event
- m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
- &CcnxPit::CleanExpired, this);
-}
+// // schedule next event
+// m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
+// &CcnxPit::CleanExpired, this);
+// }
-void
-CcnxPit::SetCleanupTimeout (const Time &timeout)
-{
- m_cleanupTimeout = timeout;
- if (m_cleanupEvent.IsRunning ())
- m_cleanupEvent.Cancel (); // cancel any scheduled cleanup events
+// void
+// CcnxPit::SetCleanupTimeout (const Time &timeout)
+// {
+// m_cleanupTimeout = timeout;
+// if (m_cleanupEvent.IsRunning ())
+// m_cleanupEvent.Cancel (); // cancel any scheduled cleanup events
- // schedule even with new timeout
- m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
- &CcnxPit::CleanExpired, this);
-}
+// // schedule even with new timeout
+// m_cleanupEvent = Simulator::Schedule (m_cleanupTimeout,
+// &CcnxPit::CleanExpired, this);
+// }
-Time
-CcnxPit::GetCleanupTimeout () const
-{
- return m_cleanupTimeout;
-}
+// Time
+// CcnxPit::GetCleanupTimeout () const
+// {
+// return m_cleanupTimeout;
+// }
} // namespace ns3
diff --git a/model/ccnx-pit.h b/model/ccnx-pit.h
index 0597863..0ae3968 100644
--- a/model/ccnx-pit.h
+++ b/model/ccnx-pit.h
@@ -159,39 +159,32 @@
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
-protected:
- virtual void
- DoCleanExpired () = 0;
-
private:
- /**
- * @brief Remove expired records from PIT
- */
- void
- CleanExpired ();
+ // /**
+ // * @brief Remove expired records from PIT
+ // */
+ // void
+ // CleanExpired ();
- /**
- * \brief Set cleanup timeout
- *
- * Side effect: current clean up even (if any) will be cancelled and a new event started
- *
- * \param timeout cleanup timeout
- */
- void
- SetCleanupTimeout (const Time &timeout);
+ // /**
+ // * \brief Set cleanup timeout
+ // *
+ // * Side effect: current clean up even (if any) will be cancelled and a new event started
+ // *
+ // * \param timeout cleanup timeout
+ // */
+ // void
+ // SetCleanupTimeout (const Time &timeout);
- /**
- * \brief Get cleanup timeout
- *
- * \returns cleanup timeout
- */
- Time
- GetCleanupTimeout () const;
+ // /**
+ // * \brief Get cleanup timeout
+ // *
+ // * \returns cleanup timeout
+ // */
+ // Time
+ // GetCleanupTimeout () const;
protected:
- Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
- EventId m_cleanupEvent; ///< \brief Cleanup event
-
// configuration variables. Check implementation of GetTypeId for more details
Time m_PitEntryPruningTimout;
};