Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TABLE_FIB_HPP |
| 8 | #define NFD_TABLE_FIB_HPP |
| 9 | |
| 10 | #include "fib-entry.hpp" |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 11 | #include "name-tree.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 13 | namespace nfd { |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 14 | |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 15 | namespace measurements { |
| 16 | class Entry; |
| 17 | } |
| 18 | namespace pit { |
| 19 | class Entry; |
| 20 | } |
| 21 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 22 | /** \class Fib |
| 23 | * \brief represents the FIB |
| 24 | */ |
| 25 | class Fib : noncopyable |
| 26 | { |
| 27 | public: |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 28 | explicit |
| 29 | Fib(NameTree& nameTree); |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 31 | ~Fib(); |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 33 | /** \brief inserts a FIB entry for prefix |
| 34 | * If an entry for exact same prefix exists, that entry is returned. |
| 35 | * \return{ the entry, and true for new entry, false for existing entry } |
| 36 | */ |
| 37 | std::pair<shared_ptr<fib::Entry>, bool> |
| 38 | insert(const Name& prefix); |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 40 | /// performs a longest prefix match |
| 41 | shared_ptr<fib::Entry> |
| 42 | findLongestPrefixMatch(const Name& prefix) const; |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 43 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 44 | /// performs a longest prefix match |
| 45 | shared_ptr<fib::Entry> |
| 46 | findLongestPrefixMatch(const pit::Entry& pitEntry) const; |
| 47 | |
| 48 | /// performs a longest prefix match |
| 49 | shared_ptr<fib::Entry> |
| 50 | findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const; |
| 51 | |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 52 | shared_ptr<fib::Entry> |
| 53 | findExactMatch(const Name& prefix) const; |
| 54 | |
| 55 | void |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 56 | erase(const Name& prefix); |
Steve DiBenedetto | d5f8793 | 2014-02-05 15:11:39 -0700 | [diff] [blame] | 57 | |
Steve DiBenedetto | d030cfc | 2014-03-10 20:04:47 -0600 | [diff] [blame] | 58 | void |
| 59 | erase(const fib::Entry& entry); |
| 60 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 61 | /** \brief removes the NextHop record for face in all entrites |
| 62 | * This is usually invoked when face goes away. |
| 63 | * Removing all NextHops in a FIB entry will not remove the FIB entry. |
| 64 | */ |
| 65 | void |
| 66 | removeNextHopFromAllEntries(shared_ptr<Face> face); |
| 67 | |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 68 | size_t |
| 69 | size() const; |
| 70 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 71 | private: |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 72 | shared_ptr<fib::Entry> |
| 73 | findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const; |
| 74 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 75 | private: |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 76 | NameTree& m_nameTree; |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 77 | size_t m_nItems; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 78 | |
Junxiao Shi | 4063184 | 2014-03-01 13:52:37 -0700 | [diff] [blame] | 79 | /** \brief The empty FIB entry. |
| 80 | * |
| 81 | * This entry has no nexthops. |
| 82 | * It is returned by findLongestPrefixMatch if nothing is matched. |
| 83 | */ |
| 84 | // Returning empty entry instead of nullptr makes forwarding and strategy implementation easier. |
HangZhang | cb4fc83 | 2014-03-11 16:57:11 +0800 | [diff] [blame] | 85 | static const shared_ptr<fib::Entry> s_emptyEntry; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame] | 88 | inline size_t |
| 89 | Fib::size() const |
| 90 | { |
| 91 | return m_nItems; |
| 92 | } |
| 93 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 94 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 95 | |
| 96 | #endif // NFD_TABLE_FIB_HPP |