21 #include "ndn-fib-impl.h"
23 #include "ns3/ndn-face.h"
24 #include "ns3/ndn-interest.h"
25 #include "ns3/ndn-forwarding-strategy.h"
28 #include "ns3/assert.h"
29 #include "ns3/names.h"
32 #include <boost/ref.hpp>
33 #include <boost/lambda/lambda.hpp>
34 #include <boost/lambda/bind.hpp>
35 namespace ll = boost::lambda;
37 NS_LOG_COMPONENT_DEFINE (
"ndn.fib.FibImpl");
43 NS_OBJECT_ENSURE_REGISTERED (FibImpl);
48 static TypeId tid = TypeId (
"ns3::ndn::fib::Default")
63 Object::NotifyNewAggregate ();
80 if (item == super::end ())
83 return item->payload ();
91 if (item == super::end ())
94 return item->payload ();
101 return Add (Create<Name> (prefix), face, metric);
105 FibImpl::Add (
const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric)
107 NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix) << boost::cref(*face) << metric);
110 std::pair< super::iterator, bool > result = super::insert (*prefix, 0);
111 if (result.first != super::end ())
115 Ptr<EntryImpl> newEntry = Create<EntryImpl> (
this, prefix);
116 newEntry->SetTrie (result.first);
117 result.first->set_payload (newEntry);
120 super::modify (result.first,
126 NS_ASSERT (this->GetObject<ForwardingStrategy> () != 0);
127 this->GetObject<ForwardingStrategy> ()->DidAddFibEntry (result.first->payload ());
130 return result.first->payload ();
139 NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId () << boost::cref(*prefix));
142 if (fibEntry != super::end ())
145 NS_ASSERT (this->GetObject<ForwardingStrategy> () != 0);
146 this->GetObject<ForwardingStrategy> ()->WillRemoveFibEntry (fibEntry->payload ());
148 super::erase (fibEntry);
172 NS_LOG_FUNCTION (this->GetObject<Node> ()->GetId ());
174 super::parent_trie::recursive_iterator item (super::getTrie ());
175 super::parent_trie::recursive_iterator end (0);
176 for (; item != end; item++)
178 if (item->payload () == 0)
continue;
180 super::modify (&(*item),
186 FibImpl::RemoveFace (super::parent_trie &item, Ptr<Face> face)
188 if (item.payload () == 0)
return;
189 NS_LOG_FUNCTION (
this);
191 super::modify (&item,
198 NS_LOG_FUNCTION (
this);
200 Ptr<Entry> entry =
Begin ();
201 while (entry !=
End ())
203 entry->RemoveFace (face);
204 if (entry->m_faces.size () == 0)
206 Ptr<Entry> nextEntry = Next (entry);
209 NS_ASSERT (this->GetObject<ForwardingStrategy> () != 0);
210 this->GetObject<ForwardingStrategy> ()->WillRemoveFibEntry (entry);
212 super::erase (StaticCast<EntryImpl> (entry)->to_iterator ());
217 entry = Next (entry);
226 super::parent_trie::const_recursive_iterator item (super::getTrie ());
227 super::parent_trie::const_recursive_iterator end (0);
228 for (; item != end; item++)
230 if (item->payload () == 0)
continue;
232 os << item->payload ()->GetPrefix () <<
"\t" << *item->payload () <<
"\n";
239 return super::getPolicy ().size ();
245 super::parent_trie::const_recursive_iterator item (super::getTrie ());
246 super::parent_trie::const_recursive_iterator end (0);
247 for (; item != end; item++)
249 if (item->payload () == 0)
continue;
256 return item->payload ();
266 FibImpl::Next (Ptr<const Entry> from)
const
268 if (from == 0)
return 0;
270 super::parent_trie::const_recursive_iterator item (*StaticCast<const EntryImpl> (from)->to_iterator ());
271 super::parent_trie::const_recursive_iterator end (0);
272 for (item++; item != end; item++)
274 if (item->payload () == 0)
continue;
281 return item->payload ();
287 super::parent_trie::recursive_iterator item (super::getTrie ());
288 super::parent_trie::recursive_iterator end (0);
289 for (; item != end; item++)
291 if (item->payload () == 0)
continue;
298 return item->payload ();
308 FibImpl::Next (Ptr<Entry> from)
310 if (from == 0)
return 0;
312 super::parent_trie::recursive_iterator item (*StaticCast<EntryImpl> (from)->to_iterator ());
313 super::parent_trie::recursive_iterator end (0);
314 for (item++; item != end; item++)
316 if (item->payload () == 0)
continue;
323 return item->payload ();
virtual void DoDispose()
Perform cleanup.
virtual Ptr< Entry > LongestPrefixMatch(const Interest &interest)
Perform longest prefix match.
Class implementing FIB functionality.
virtual Ptr< const Entry > Begin() const
Return first element of FIB (no order guaranteed)
virtual void InvalidateAll()
Invalidate all FIB entries.
virtual void NotifyNewAggregate()
Notify when object is aggregated.
virtual Ptr< fib::Entry > Find(const Name &prefix)
Get FIB entry for the prefix (exact match)
const Name & GetName() const
Get interest name.
iterator longest_prefix_match(const Name &key)
Find a node that has the longest common prefix with key (FIB/PIT lookup)
virtual Ptr< Entry > Add(const Name &prefix, Ptr< Face > face, int32_t metric)
Add or update FIB entry.
virtual uint32_t GetSize() const
Get number of entries in FIB.
static TypeId GetTypeId()
Interface ID.
void AddOrUpdateRoutingMetric(Ptr< Face > face, int32_t metric)
Add or update routing metric of FIB next hop.
void Invalidate()
Invalidate face.
virtual void Print(std::ostream &os) const
Print out entries in FIB.
Class implementing FIB functionality.
virtual void RemoveFromAll(Ptr< Face > face)
Remove all references to a face from FIB.
NDN Interest (wire formats are defined in wire)
virtual Ptr< const Entry > End() const
Return item next after last (no order guaranteed)
virtual void Remove(const Ptr< const Name > &prefix)
Remove FIB entry.
iterator find_exact(const Name &key)
Find a node that has the exact match with the key.
void RemoveFace(const Ptr< Face > &face)
Remove record associated with face