New implementation of FIB seems to be working now
diff --git a/model/ccnx-fib-impl.cc b/model/ccnx-fib-impl.cc
index 18d07ad..ba970fd 100644
--- a/model/ccnx-fib-impl.cc
+++ b/model/ccnx-fib-impl.cc
@@ -91,10 +91,12 @@
CcnxFib::iterator
CcnxFibImpl::Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric)
{
- NS_LOG_FUNCTION(this->GetObject<Node> ()->GetId () << boost::cref(*prefix) << boost::cref(*face) << metric);
+ NS_LOG_FUNCTION (this);
+ // NS_LOG_FUNCTION(this->GetObject<Node> ()->GetId () << boost::cref(*prefix) << boost::cref(*face) << metric);
// will add entry if doesn't exists, or just return an iterator to the existing entry
- std::pair< super::iterator, bool > result = super::insert (*prefix, Create<CcnxFibEntry> (prefix));
+ Ptr<CcnxFibEntry> newEntry = Create<CcnxFibEntry> (prefix);
+ std::pair< super::iterator, bool > result = super::insert (*prefix, newEntry);
NS_ASSERT_MSG (face != NULL, "Trying to modify NULL face");
@@ -112,68 +114,83 @@
super::erase (*prefix);
}
-void
-CcnxFibImpl::Invalidate (const Ptr<const CcnxNameComponents> &prefix)
-{
- NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix));
+// void
+// CcnxFibImpl::Invalidate (const Ptr<const CcnxNameComponents> &prefix)
+// {
+// NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix));
- super::iterator foundItem, lastItem;
- bool reachLast;
- boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (*prefix);
+// super::iterator foundItem, lastItem;
+// bool reachLast;
+// boost::tie (foundItem, reachLast, lastItem) = super::getTrie ().find (*prefix);
- if (!reachLast || lastItem->payload () == 0)
- return; // nothing to invalidate
+// if (!reachLast || lastItem->payload () == 0)
+// return; // nothing to invalidate
- super::modify (lastItem,
- ll::bind (&CcnxFibEntry::Invalidate, ll::_1));
-}
+// super::modify (lastItem,
+// ll::bind (&CcnxFibEntry::Invalidate, ll::_1));
+// }
void
CcnxFibImpl::InvalidateAll ()
{
- // NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId ());
+ NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId ());
- // for (super::iterator entry = m_fib.begin ();
- // entry != m_fib.end ();
- // entry ++)
- // {
- // m_fib.modify (entry,
- // ll::bind (&CcnxFibEntry::Invalidate, ll::_1));
- // }
+ super::parent_trie::recursive_iterator item (super::getTrie ());
+ super::parent_trie::recursive_iterator end (0);
+ for (; item != end; item++)
+ {
+ if (item->payload () == 0) continue;
+
+ super::modify (&(*item),
+ ll::bind (&CcnxFibEntry::Invalidate, ll::_1));
+ }
}
void
-CcnxFibImpl::Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face)
+CcnxFibImpl::Remove (super::parent_trie &item, Ptr<CcnxFace> face)
{
- // NS_LOG_FUNCTION (this);
+ if (item.payload () == 0) return;
+ NS_LOG_FUNCTION (this);
- // m_fib.modify (m_fib.iterator_to (entry),
- // ll::bind (&CcnxFibEntry::RemoveFace, ll::_1, face));
- // if (entry.m_faces.size () == 0)
- // {
- // m_fib.erase (m_fib.iterator_to (entry));
- // }
+ super::modify (&item,
+ ll::bind (&CcnxFibEntry::RemoveFace, ll::_1, face));
}
void
CcnxFibImpl::RemoveFromAll (Ptr<CcnxFace> face)
{
- // NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION (this);
- // for_each (m_fib.begin (), m_fib.end (),
- // ll::bind (static_cast< void (CcnxFib::*) (const CcnxFibEntry &, Ptr<CcnxFace>) > (&CcnxFib::Remove),
- // this, ll::_1, face));
+ std::for_each (super::parent_trie::recursive_iterator (super::getTrie ()),
+ super::parent_trie::recursive_iterator (0),
+ ll::bind (static_cast< void (CcnxFib::*) (super::parent_trie &, Ptr<CcnxFace>) > (&CcnxFibImpl::Remove),
+ this, ll::_1, face));
+
+ super::parent_trie::recursive_iterator trieNode (super::getTrie ());
+ super::parent_trie::recursive_iterator end (0);
+ for (; trieNode != end; trieNode++)
+ {
+ if (trieNode->payload () == 0) continue;
+
+ if (trieNode->payload ()->m_faces.size () == 0)
+ {
+ trieNode = super::parent_trie::recursive_iterator (trieNode->erase ());
+ }
+ }
}
void
CcnxFibImpl::Print (std::ostream &os) const
{
- // for (super::iterator entry = fib.m_fib.begin ();
- // entry != fib.m_fib.end ();
- // entry++)
- // {
- // os << entry->GetPrefix () << "\t" << *entry << "\n";
- // }
+ // !!! unordered_set imposes "random" order of item in the same level !!!
+ super::parent_trie::const_recursive_iterator item (super::getTrie ());
+ super::parent_trie::const_recursive_iterator end (0);
+ for (; item != end; item++)
+ {
+ if (item->payload () == 0) continue;
+
+ os << item->payload ()->GetPrefix () << "\t" << *item->payload () << "\n";
+ }
}
} // namespace ns3
diff --git a/model/ccnx-fib-impl.h b/model/ccnx-fib-impl.h
index b10d558..5ef9610 100644
--- a/model/ccnx-fib-impl.h
+++ b/model/ccnx-fib-impl.h
@@ -110,14 +110,14 @@
void
Remove (const Ptr<const CcnxNameComponents> &prefix);
- /**
- * @brief Invalidate FIB entry ("Safe" version of Remove)
- *
- * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
- * @param name Smart pointer to prefix
- */
- void
- Invalidate (const Ptr<const CcnxNameComponents> &prefix);
+ // /**
+ // * @brief Invalidate FIB entry ("Safe" version of Remove)
+ // *
+ // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
+ // * @param name Smart pointer to prefix
+ // */
+ // void
+ // Invalidate (const Ptr<const CcnxNameComponents> &prefix);
/**
* @brief Invalidate all FIB entries
@@ -126,13 +126,6 @@
InvalidateAll ();
/**
- * @brief Remove reference to a face from the entry. If entry had only this face, the whole
- * entry will be removed
- */
- void
- Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face);
-
- /**
* @brief Remove all references to a face from FIB. If for some enty that face was the only element,
* this FIB entry will be removed.
*/
@@ -149,13 +142,27 @@
bool
modify (CcnxFib::iterator position, Modifier mod)
{
- return this->modify (position, mod);
+ mod (*position);
+
+ return true;
+ // somehow we need to obtain trie iterator from the payload...
+ // super::getPolicy ().
+ // return super::modify (position, mod);
}
protected:
// inherited from Object class
virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
virtual void DoDispose (); ///< @brief Perform cleanup
+
+private:
+ /**
+ * @brief Remove reference to a face from the entry. If entry had only this face, the whole
+ * entry will be removed
+ */
+ void
+ Remove (super::parent_trie &item, Ptr<CcnxFace> face);
+
private:
Ptr<Node> m_node;
diff --git a/model/ccnx-fib.cc b/model/ccnx-fib.cc
index 5bbbc15..c8153fc 100644
--- a/model/ccnx-fib.cc
+++ b/model/ccnx-fib.cc
@@ -39,6 +39,12 @@
using namespace __ccnx_private;
+TypeId
+CcnxFib::GetTypeId (void)
+{
+ return CcnxFibImpl::GetTypeId ();
+}
+
std::ostream& operator<< (std::ostream& os, const CcnxFib &fib)
{
os << "Node " << Names::FindName (fib.GetObject<Node>()) << "\n";
diff --git a/model/ccnx-fib.h b/model/ccnx-fib.h
index 31fd2d8..4d4c7f7 100644
--- a/model/ccnx-fib.h
+++ b/model/ccnx-fib.h
@@ -41,6 +41,12 @@
typedef ns3::Ptr<CcnxFibEntry> const_iterator;
/**
+ * \brief Interface ID
+ *
+ * \return interface ID
+ */
+ static TypeId GetTypeId ();
+ /**
* @brief Default constructor
*/
CcnxFib () {}
@@ -100,14 +106,14 @@
virtual void
Remove (const Ptr<const CcnxNameComponents> &prefix) = 0;
- /**
- * @brief Invalidate FIB entry ("Safe" version of Remove)
- *
- * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
- * @param name Smart pointer to prefix
- */
- virtual void
- Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0;
+ // /**
+ // * @brief Invalidate FIB entry ("Safe" version of Remove)
+ // *
+ // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
+ // * @param name Smart pointer to prefix
+ // */
+ // virtual void
+ // Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0;
/**
* @brief Invalidate all FIB entries
@@ -116,13 +122,6 @@
InvalidateAll () = 0;
/**
- * @brief Remove reference to a face from the entry. If entry had only this face, the whole
- * entry will be removed
- */
- virtual void
- Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face) = 0;
-
- /**
* @brief Remove all references to a face from FIB. If for some enty that face was the only element,
* this FIB entry will be removed.
*/