blob: 166eb1b7d4045db57aa2839857159f08ee9066a8 [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- 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"
HangZhangad4afd12014-03-01 11:03:08 +080011#include "name-tree.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070012
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080013namespace nfd {
Junxiao Shic1e12362014-01-24 20:03:26 -070014
HangZhangad4afd12014-03-01 11:03:08 +080015namespace measurements {
16class Entry;
17}
18namespace pit {
19class Entry;
20}
21
Junxiao Shic1e12362014-01-24 20:03:26 -070022/** \class Fib
23 * \brief represents the FIB
24 */
25class Fib : noncopyable
26{
27public:
HangZhangad4afd12014-03-01 11:03:08 +080028 explicit
29 Fib(NameTree& nameTree);
Steve DiBenedettod5f87932014-02-05 15:11:39 -070030
Junxiao Shic1e12362014-01-24 20:03:26 -070031 ~Fib();
Steve DiBenedettod5f87932014-02-05 15:11:39 -070032
Junxiao Shic1e12362014-01-24 20:03:26 -070033 /** \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 DiBenedettod5f87932014-02-05 15:11:39 -070039
Junxiao Shic1e12362014-01-24 20:03:26 -070040 /// performs a longest prefix match
41 shared_ptr<fib::Entry>
42 findLongestPrefixMatch(const Name& prefix) const;
Steve DiBenedettod5f87932014-02-05 15:11:39 -070043
Junxiao Shidbe71732014-02-21 22:23:28 -070044 /// 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 DiBenedettod5f87932014-02-05 15:11:39 -070052 shared_ptr<fib::Entry>
53 findExactMatch(const Name& prefix) const;
54
55 void
HangZhangad4afd12014-03-01 11:03:08 +080056 erase(const Name& prefix);
Steve DiBenedettod5f87932014-02-05 15:11:39 -070057
Junxiao Shic1e12362014-01-24 20:03:26 -070058 /** \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
HangZhangad4afd12014-03-01 11:03:08 +080065 size_t
66 size() const;
67
Junxiao Shic1e12362014-01-24 20:03:26 -070068private:
69 shared_ptr<fib::Entry> m_rootEntry;
HangZhangad4afd12014-03-01 11:03:08 +080070 NameTree& m_nameTree;
71 size_t m_nItems; // Number of items being stored
Junxiao Shic1e12362014-01-24 20:03:26 -070072};
73
HangZhangad4afd12014-03-01 11:03:08 +080074inline size_t
75Fib::size() const
76{
77 return m_nItems;
78}
79
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080080} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -070081
82#endif // NFD_TABLE_FIB_HPP