blob: cf372ac8ae1c2d4a383490bd6d8a5e1095d2ba9f [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 {
34class Entry;
Junxiao Shib184e532016-05-26 18:09:57 +000035} // namespace name_tree
Junxiao Shiefceadc2014-03-09 18:52:57 -070036
Junxiao Shic1e12362014-01-24 20:03:26 -070037namespace fib {
38
39/** \class NextHopList
40 * \brief represents a collection of nexthops
Junxiao Shi56a21bf2014-11-02 21:11:50 -070041 *
42 * This type has these methods as public API:
Junxiao Shic1e12362014-01-24 20:03:26 -070043 * iterator<NextHop> begin()
44 * iterator<NextHop> end()
45 * size_t size()
46 */
47typedef std::vector<fib::NextHop> NextHopList;
48
Junxiao Shi340d5532016-08-13 04:00:35 +000049/** \brief represents a FIB entry
Junxiao Shic1e12362014-01-24 20:03:26 -070050 */
Junxiao Shi8d843142016-07-11 22:42:42 +000051class Entry : noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070052{
53public:
Junxiao Shi408a7002014-02-12 17:53:47 -070054 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070055 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070056
Junxiao Shic1e12362014-01-24 20:03:26 -070057 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000058 getPrefix() const
59 {
60 return m_prefix;
61 }
Junxiao Shi7bb01512014-03-05 21:34:09 -070062
Junxiao Shic1e12362014-01-24 20:03:26 -070063 const NextHopList&
Junxiao Shi340d5532016-08-13 04:00:35 +000064 getNextHops() const
65 {
66 return m_nextHops;
67 }
Junxiao Shi7bb01512014-03-05 21:34:09 -070068
Junxiao Shi56a21bf2014-11-02 21:11:50 -070069 /** \return whether this Entry has any NextHop record
70 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070071 bool
Junxiao Shi340d5532016-08-13 04:00:35 +000072 hasNextHops() const
73 {
74 return !m_nextHops.empty();
75 }
Junxiao Shiefceadc2014-03-09 18:52:57 -070076
Junxiao Shia6de4292016-07-12 02:08:10 +000077 /** \return whether there is a NextHop record for \p face
Junxiao Shi56a21bf2014-11-02 21:11:50 -070078 */
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070079 bool
Junxiao Shia6de4292016-07-12 02:08:10 +000080 hasNextHop(const Face& face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070081
Junxiao Shi56a21bf2014-11-02 21:11:50 -070082 /** \brief adds a NextHop record
83 *
Junxiao Shia6de4292016-07-12 02:08:10 +000084 * If a NextHop record for \p face already exists, its cost is updated.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070085 */
Junxiao Shic1e12362014-01-24 20:03:26 -070086 void
Junxiao Shia6de4292016-07-12 02:08:10 +000087 addNextHop(Face& face, uint64_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070088
Junxiao Shi56a21bf2014-11-02 21:11:50 -070089 /** \brief removes a NextHop record
90 *
91 * If no NextHop record for face exists, do nothing.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070092 */
Junxiao Shic1e12362014-01-24 20:03:26 -070093 void
Junxiao Shia6de4292016-07-12 02:08:10 +000094 removeNextHop(const Face& face);
Junxiao Shic1e12362014-01-24 20:03:26 -070095
96private:
Junxiao Shia6de4292016-07-12 02:08:10 +000097 /** \note This method is non-const because mutable iterators are needed by callers.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070098 */
99 NextHopList::iterator
Junxiao Shia6de4292016-07-12 02:08:10 +0000100 findNextHop(const Face& face);
Junxiao Shi56a21bf2014-11-02 21:11:50 -0700101
Junxiao Shia6de4292016-07-12 02:08:10 +0000102 /** \brief sorts the nexthop list
103 */
Junxiao Shic1e12362014-01-24 20:03:26 -0700104 void
105 sortNextHops();
106
107private:
108 Name m_prefix;
109 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700110
Junxiao Shi340d5532016-08-13 04:00:35 +0000111 name_tree::Entry* m_nameTreeEntry;
112
113 friend class name_tree::Entry;
Junxiao Shic1e12362014-01-24 20:03:26 -0700114};
115
Junxiao Shic1e12362014-01-24 20:03:26 -0700116} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800117} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -0700118
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700119#endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP