blob: e2371eb8ac056a1bb1a1a427dfbe582db509c839 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * 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
10 *
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/>.
24 **/
25
26#ifndef NFD_RIB_RIB_HPP
27#define NFD_RIB_RIB_HPP
28
29#include "common.hpp"
Alexander Afanasyev20d31442014-04-19 17:00:53 -070030#include <ndn-cpp-dev/management/nfd-control-command.hpp>
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070031
32namespace nfd {
33namespace rib {
34
Alexander Afanasyev20d31442014-04-19 17:00:53 -070035class RibEntry
36{
37public:
38 RibEntry()
39 : faceId(0)
40 , origin(0)
41 , flags(0)
42 , cost(0)
43 , expires(time::steady_clock::TimePoint::min())
44 {
45 }
46
47public:
48 Name name;
49 uint64_t faceId;
50 uint64_t origin;
51 uint64_t flags;
52 uint64_t cost;
53 time::steady_clock::TimePoint expires;
54};
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070055
56/** \brief represents the RIB
57 */
Alexander Afanasyev20d31442014-04-19 17:00:53 -070058class Rib : noncopyable
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070059{
60public:
Alexander Afanasyev20d31442014-04-19 17:00:53 -070061 typedef std::list<RibEntry> RibTable;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070062 typedef RibTable::const_iterator const_iterator;
63
64 Rib();
65
66 ~Rib();
67
68 const_iterator
Alexander Afanasyev20d31442014-04-19 17:00:53 -070069 find(const RibEntry& entry) const;
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070070
71 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070072 insert(const RibEntry& entry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070073
74 void
Alexander Afanasyev20d31442014-04-19 17:00:53 -070075 erase(const RibEntry& entry);
Alexander Afanasyev3ecec502014-04-16 13:42:44 -070076
77 void
78 erase(uint64_t faceId);
79
80 const_iterator
81 begin() const;
82
83 const_iterator
84 end() const;
85
86 size_t
87 size() const;
88
89 size_t
90 empty() const;
91
92private:
93 // Note: Taking a list right now. A Trie will be used later to store
94 // prefixes
95 RibTable m_rib;
96};
97
98inline Rib::const_iterator
99Rib::begin() const
100{
101 return m_rib.begin();
102}
103
104inline Rib::const_iterator
105Rib::end() const
106{
107 return m_rib.end();
108}
109
110inline size_t
111Rib::size() const
112{
113 return m_rib.size();
114}
115
116inline size_t
117Rib::empty() const
118{
119 return m_rib.empty();
120}
121
Alexander Afanasyev20d31442014-04-19 17:00:53 -0700122std::ostream&
123operator<<(std::ostream& os, const RibEntry& entry);
124
Alexander Afanasyev3ecec502014-04-16 13:42:44 -0700125} // namespace rib
126} // namespace nfd
127
128#endif // NFD_RIB_RIB_HPP