blob: 94f2331ca7e8e02f258905aaa1785c632b205142 [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shib184e532016-05-26 18:09:57 +00003 * Copyright (c) 2014-2016, 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 Afanasyev9bcbc7c2014-04-06 19:37:37 -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/>.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070024 */
Junxiao Shic1e12362014-01-24 20:03:26 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_FIB_ENTRY_HPP
27#define NFD_DAEMON_TABLE_FIB_ENTRY_HPP
Junxiao Shic1e12362014-01-24 20:03:26 -070028
29#include "fib-nexthop.hpp"
30
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shidbe71732014-02-21 22:23:28 -070032
Junxiao Shiefceadc2014-03-09 18:52:57 -070033namespace name_tree {
Junxiao Shi2570f3e2016-07-27 02:48:29 +000034class NameTree;
Junxiao Shiefceadc2014-03-09 18:52:57 -070035class Entry;
Junxiao Shib184e532016-05-26 18:09:57 +000036} // namespace name_tree
Junxiao Shi2570f3e2016-07-27 02:48:29 +000037using name_tree::NameTree;
Junxiao Shiefceadc2014-03-09 18:52:57 -070038
Junxiao Shic1e12362014-01-24 20:03:26 -070039namespace fib {
40
41/** \class NextHopList
42 * \brief represents a collection of nexthops
Junxiao Shi56a21bf2014-11-02 21:11:50 -070043 *
44 * This type has these methods as public API:
Junxiao Shic1e12362014-01-24 20:03:26 -070045 * iterator<NextHop> begin()
46 * iterator<NextHop> end()
47 * size_t size()
48 */
49typedef std::vector<fib::NextHop> NextHopList;
50
51/** \class Entry
52 * \brief represents a FIB entry
53 */
Junxiao Shi8d843142016-07-11 22:42:42 +000054class Entry : noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070055{
56public:
Junxiao Shi408a7002014-02-12 17:53:47 -070057 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070058 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070059
Junxiao Shic1e12362014-01-24 20:03:26 -070060 const Name&
61 getPrefix() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070062
Junxiao Shic1e12362014-01-24 20:03:26 -070063 const NextHopList&
64 getNextHops() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070065
Junxiao Shi56a21bf2014-11-02 21:11:50 -070066 /** \return whether this Entry has any NextHop record
67 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070068 bool
69 hasNextHops() const;
70
Junxiao Shia6de4292016-07-12 02:08:10 +000071 /** \return whether there is a NextHop record for \p face
Junxiao Shi56a21bf2014-11-02 21:11:50 -070072 */
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070073 bool
Junxiao Shia6de4292016-07-12 02:08:10 +000074 hasNextHop(const Face& face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070075
Junxiao Shi56a21bf2014-11-02 21:11:50 -070076 /** \brief adds a NextHop record
77 *
Junxiao Shia6de4292016-07-12 02:08:10 +000078 * If a NextHop record for \p face already exists, its cost is updated.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070079 */
Junxiao Shic1e12362014-01-24 20:03:26 -070080 void
Junxiao Shia6de4292016-07-12 02:08:10 +000081 addNextHop(Face& face, uint64_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070082
Junxiao Shi56a21bf2014-11-02 21:11:50 -070083 /** \brief removes a NextHop record
84 *
85 * If no NextHop record for face exists, do nothing.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070086 */
Junxiao Shic1e12362014-01-24 20:03:26 -070087 void
Junxiao Shia6de4292016-07-12 02:08:10 +000088 removeNextHop(const Face& face);
Junxiao Shic1e12362014-01-24 20:03:26 -070089
90private:
Junxiao Shia6de4292016-07-12 02:08:10 +000091 /** \note This method is non-const because mutable iterators are needed by callers.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070092 */
93 NextHopList::iterator
Junxiao Shia6de4292016-07-12 02:08:10 +000094 findNextHop(const Face& face);
Junxiao Shi56a21bf2014-11-02 21:11:50 -070095
Junxiao Shia6de4292016-07-12 02:08:10 +000096 /** \brief sorts the nexthop list
97 */
Junxiao Shic1e12362014-01-24 20:03:26 -070098 void
99 sortNextHops();
100
101private:
102 Name m_prefix;
103 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700104
Junxiao Shib184e532016-05-26 18:09:57 +0000105 weak_ptr<name_tree::Entry> m_nameTreeEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700106 friend class nfd::NameTree;
107 friend class nfd::name_tree::Entry;
Junxiao Shic1e12362014-01-24 20:03:26 -0700108};
109
110
111inline const Name&
112Entry::getPrefix() const
113{
114 return m_prefix;
115}
116
117inline const NextHopList&
118Entry::getNextHops() const
119{
120 return m_nextHops;
121}
122
Junxiao Shiefceadc2014-03-09 18:52:57 -0700123inline bool
124Entry::hasNextHops() const
125{
126 return !m_nextHops.empty();
127}
128
Junxiao Shic1e12362014-01-24 20:03:26 -0700129} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800130} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -0700131
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700132#endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP