blob: e1e5c5a02ae3f1209de554637f372bcf6beed093 [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
Steve DiBenedettod030cfc2014-03-10 20:04:47 -060058 void
59 erase(const fib::Entry& entry);
60
Junxiao Shic1e12362014-01-24 20:03:26 -070061 /** \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
HangZhangad4afd12014-03-01 11:03:08 +080068 size_t
69 size() const;
70
Junxiao Shic1e12362014-01-24 20:03:26 -070071private:
HangZhangcb4fc832014-03-11 16:57:11 +080072 shared_ptr<fib::Entry>
73 findLongestPrefixMatch(shared_ptr<name_tree::Entry> nameTreeEntry) const;
74
Junxiao Shiefceadc2014-03-09 18:52:57 -070075private:
HangZhangad4afd12014-03-01 11:03:08 +080076 NameTree& m_nameTree;
Junxiao Shi40631842014-03-01 13:52:37 -070077 size_t m_nItems;
Junxiao Shiefceadc2014-03-09 18:52:57 -070078
Junxiao Shi40631842014-03-01 13:52:37 -070079 /** \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.
HangZhangcb4fc832014-03-11 16:57:11 +080085 static const shared_ptr<fib::Entry> s_emptyEntry;
Junxiao Shic1e12362014-01-24 20:03:26 -070086};
87
HangZhangad4afd12014-03-01 11:03:08 +080088inline size_t
89Fib::size() const
90{
91 return m_nItems;
92}
93
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080094} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -070095
96#endif // NFD_TABLE_FIB_HPP