blob: 0536fc5c8303f9f4ec1dced46766e169c3f31b3a [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 -070033class NameTree;
34namespace name_tree {
35class Entry;
Junxiao Shib184e532016-05-26 18:09:57 +000036} // namespace name_tree
Junxiao Shiefceadc2014-03-09 18:52:57 -070037
Junxiao Shic1e12362014-01-24 20:03:26 -070038namespace fib {
39
40/** \class NextHopList
41 * \brief represents a collection of nexthops
Junxiao Shi56a21bf2014-11-02 21:11:50 -070042 *
43 * This type has these methods as public API:
Junxiao Shic1e12362014-01-24 20:03:26 -070044 * iterator<NextHop> begin()
45 * iterator<NextHop> end()
46 * size_t size()
47 */
48typedef std::vector<fib::NextHop> NextHopList;
49
50/** \class Entry
51 * \brief represents a FIB entry
52 */
Junxiao Shi05cc50a2016-07-11 22:38:21 +000053class Entry : public enable_shared_from_this<Entry>, noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070054{
55public:
Junxiao Shi408a7002014-02-12 17:53:47 -070056 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070057 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070058
Junxiao Shic1e12362014-01-24 20:03:26 -070059 const Name&
60 getPrefix() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070061
Junxiao Shic1e12362014-01-24 20:03:26 -070062 const NextHopList&
63 getNextHops() const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070064
Junxiao Shi56a21bf2014-11-02 21:11:50 -070065 /** \return whether this Entry has any NextHop record
66 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070067 bool
68 hasNextHops() const;
69
Junxiao Shi56a21bf2014-11-02 21:11:50 -070070 /** \return whether there is a NextHop record for face
71 *
72 * \todo change parameter type to Face&
73 */
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070074 bool
75 hasNextHop(shared_ptr<Face> face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070076
Junxiao Shi56a21bf2014-11-02 21:11:50 -070077 /** \brief adds a NextHop record
78 *
79 * If a NextHop record for face already exists, its cost is updated.
80 * \note shared_ptr is passed by value because this function will take shared ownership
81 */
Junxiao Shic1e12362014-01-24 20:03:26 -070082 void
Alexander Afanasyev11b9f3f2014-04-10 00:01:15 -070083 addNextHop(shared_ptr<Face> face, uint64_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070084
Junxiao Shi56a21bf2014-11-02 21:11:50 -070085 /** \brief removes a NextHop record
86 *
87 * If no NextHop record for face exists, do nothing.
88 *
89 * \todo change parameter type to Face&
90 */
Junxiao Shic1e12362014-01-24 20:03:26 -070091 void
92 removeNextHop(shared_ptr<Face> face);
93
94private:
Junxiao Shi56a21bf2014-11-02 21:11:50 -070095 /** @note This method is non-const because normal iterator is needed by callers.
96 */
97 NextHopList::iterator
98 findNextHop(Face& face);
99
Junxiao Shic1e12362014-01-24 20:03:26 -0700100 /// sorts the nexthop list
101 void
102 sortNextHops();
103
104private:
105 Name m_prefix;
106 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700107
Junxiao Shib184e532016-05-26 18:09:57 +0000108 weak_ptr<name_tree::Entry> m_nameTreeEntry;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700109 friend class nfd::NameTree;
110 friend class nfd::name_tree::Entry;
Junxiao Shic1e12362014-01-24 20:03:26 -0700111};
112
113
114inline const Name&
115Entry::getPrefix() const
116{
117 return m_prefix;
118}
119
120inline const NextHopList&
121Entry::getNextHops() const
122{
123 return m_nextHops;
124}
125
Junxiao Shiefceadc2014-03-09 18:52:57 -0700126inline bool
127Entry::hasNextHops() const
128{
129 return !m_nextHops.empty();
130}
131
Junxiao Shic1e12362014-01-24 20:03:26 -0700132} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800133} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -0700134
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700135#endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP