blob: 37136bce9a58b24299d29f098ae772094c8e08a7 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Vince12e49462014-06-09 13:29:32 -05003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Vince12e49462014-06-09 13:29:32 -050024 */
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070025
26#ifndef NFD_RIB_RIB_HPP
27#define NFD_RIB_RIB_HPP
28
29#include "common.hpp"
Vince12e49462014-06-09 13:29:32 -050030#include "rib-entry.hpp"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070031#include <ndn-cxx/management/nfd-control-command.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070032
33namespace nfd {
34namespace rib {
35
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070036/** \brief represents the RIB
37 */
Alexander Afanasyev20d31442014-04-19 17:00:53 -070038class Rib : noncopyable
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070039{
40public:
Vince12e49462014-06-09 13:29:32 -050041 typedef std::list<shared_ptr<RibEntry> > RibEntryList;
42 typedef std::map<Name, shared_ptr<RibEntry> > RibTable;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070043 typedef RibTable::const_iterator const_iterator;
Vince12e49462014-06-09 13:29:32 -050044 typedef std::map<uint64_t, std::list<shared_ptr<RibEntry> > > FaceLookupTable;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070045
46 Rib();
47
48 ~Rib();
49
50 const_iterator
Vince12e49462014-06-09 13:29:32 -050051 find(const Name& prefix) const;
52
53 shared_ptr<FaceEntry>
54 find(const Name& prefix, const FaceEntry& face) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070055
56 void
Vince12e49462014-06-09 13:29:32 -050057 insert(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070058
59 void
Vince12e49462014-06-09 13:29:32 -050060 erase(const Name& prefix, const FaceEntry& face);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070061
62 void
Vince12e49462014-06-09 13:29:32 -050063 erase(const uint64_t faceId);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070064
65 const_iterator
66 begin() const;
67
68 const_iterator
69 end() const;
70
71 size_t
72 size() const;
73
Vince12e49462014-06-09 13:29:32 -050074 bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070075 empty() const;
76
Vince12e49462014-06-09 13:29:32 -050077
78 shared_ptr<RibEntry>
79 findParent(const Name& prefix) const;
80
81 /** \brief finds namespaces under the passed prefix
82 * \return{ a list of entries which are under the passed prefix }
83 */
84 std::list<shared_ptr<RibEntry> >
85 findDescendants(const Name& prefix) const;
86
87 RibTable::iterator
88 eraseEntry(RibTable::iterator it);
89
90 void
91 eraseEntry(const Name& name);
92
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070093private:
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070094 RibTable m_rib;
Vince12e49462014-06-09 13:29:32 -050095 FaceLookupTable m_faceMap;
96 size_t m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070097};
98
99inline Rib::const_iterator
100Rib::begin() const
101{
102 return m_rib.begin();
103}
104
105inline Rib::const_iterator
106Rib::end() const
107{
108 return m_rib.end();
109}
110
111inline size_t
112Rib::size() const
113{
Vince12e49462014-06-09 13:29:32 -0500114 return m_nItems;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700115}
116
Vince12e49462014-06-09 13:29:32 -0500117inline bool
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700118Rib::empty() const
119{
120 return m_rib.empty();
121}
122
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700123std::ostream&
Vince12e49462014-06-09 13:29:32 -0500124operator<<(std::ostream& os, const FaceEntry& entry);
125
126std::ostream&
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700127operator<<(std::ostream& os, const RibEntry& entry);
128
Vince12e49462014-06-09 13:29:32 -0500129std::ostream&
130operator<<(std::ostream& os, const Rib& rib);
131
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700132} // namespace rib
133} // namespace nfd
134
135#endif // NFD_RIB_RIB_HPP