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 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 58 | /** \brief removes the NextHop record for face in all entrites |
| 59 | * This is usually invoked when face goes away. |
| 60 | * Removing all NextHops in a FIB entry will not remove the FIB entry. |
| 61 | */ |
| 62 | void |
| 63 | removeNextHopFromAllEntries(shared_ptr<Face> face); |
| 64 | |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame^] | 65 | size_t |
| 66 | size() const; |
| 67 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 68 | private: |
| 69 | shared_ptr<fib::Entry> m_rootEntry; |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame^] | 70 | NameTree& m_nameTree; |
| 71 | size_t m_nItems; // Number of items being stored |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
HangZhang | ad4afd1 | 2014-03-01 11:03:08 +0800 | [diff] [blame^] | 74 | inline size_t |
| 75 | Fib::size() const |
| 76 | { |
| 77 | return m_nItems; |
| 78 | } |
| 79 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 80 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 81 | |
| 82 | #endif // NFD_TABLE_FIB_HPP |