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