/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** * Copyright (C) 2014 Named Data Networking Project * See COPYING for copyright and distribution information. */ #ifndef NFD_TABLE_FIB_HPP #define NFD_TABLE_FIB_HPP #include "fib-entry.hpp" #include "name-tree.hpp" namespace nfd { namespace measurements { class Entry; } namespace pit { class Entry; } /** \class Fib * \brief represents the FIB */ class Fib : noncopyable { public: class const_iterator; explicit Fib(NameTree& nameTree); ~Fib(); /** \brief inserts a FIB entry for prefix * If an entry for exact same prefix exists, that entry is returned. * \return{ the entry, and true for new entry, false for existing entry } */ std::pair, bool> insert(const Name& prefix); /// performs a longest prefix match shared_ptr findLongestPrefixMatch(const Name& prefix) const; /// performs a longest prefix match shared_ptr findLongestPrefixMatch(const pit::Entry& pitEntry) const; /// performs a longest prefix match shared_ptr findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const; shared_ptr findExactMatch(const Name& prefix) const; void erase(const Name& prefix); void erase(const fib::Entry& entry); /** \brief removes the NextHop record for face in all entrites * This is usually invoked when face goes away. * Removing all NextHops in a FIB entry will not remove the FIB entry. */ void removeNextHopFromAllEntries(shared_ptr face); size_t size() const; const_iterator begin() const; const_iterator end() const; class const_iterator : public std::iterator { public: explicit const_iterator(const NameTree::const_iterator& it); ~const_iterator(); const fib::Entry& operator*() const; shared_ptr operator->() const; const_iterator& operator++(); const_iterator operator++(int); bool operator==(const const_iterator& other) const; bool operator!=(const const_iterator& other) const; private: NameTree::const_iterator m_nameTreeIterator; }; private: shared_ptr findLongestPrefixMatch(shared_ptr nameTreeEntry) const; private: NameTree& m_nameTree; size_t m_nItems; /** \brief The empty FIB entry. * * This entry has no nexthops. * It is returned by findLongestPrefixMatch if nothing is matched. */ // Returning empty entry instead of nullptr makes forwarding and strategy implementation easier. static const shared_ptr s_emptyEntry; }; inline size_t Fib::size() const { return m_nItems; } inline Fib::const_iterator Fib::end() const { return const_iterator(m_nameTree.end()); } inline Fib::const_iterator::const_iterator(const NameTree::const_iterator& it) : m_nameTreeIterator(it) { } inline Fib::const_iterator::~const_iterator() { } inline Fib::const_iterator Fib::const_iterator::operator++(int) { Fib::const_iterator temp(*this); ++(*this); return temp; } inline Fib::const_iterator& Fib::const_iterator::operator++() { ++m_nameTreeIterator; return *this; } inline const fib::Entry& Fib::const_iterator::operator*() const { return *(m_nameTreeIterator->getFibEntry()); } inline shared_ptr Fib::const_iterator::operator->() const { return m_nameTreeIterator->getFibEntry(); } inline bool Fib::const_iterator::operator==(const Fib::const_iterator& other) const { return m_nameTreeIterator == other.m_nameTreeIterator; } inline bool Fib::const_iterator::operator!=(const Fib::const_iterator& other) const { return m_nameTreeIterator != other.m_nameTreeIterator; } } // namespace nfd #endif // NFD_TABLE_FIB_HPP