blob: facf24856eae6b8bb875da430a5657482e8b1ddd [file] [log] [blame]
Junxiao Shic1e12362014-01-24 20:03:26 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento1cb619e2018-04-10 17:13:53 -04002/*
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Junxiao Shib184e532016-05-26 18:09:57 +00004 * 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
Ju Pand8315bf2019-07-31 06:59:07 +000039class Fib;
40
Davide Pesavento1cb619e2018-04-10 17:13:53 -040041/** \class nfd::fib::NextHopList
42 * \brief Represents a collection of nexthops.
Junxiao Shi56a21bf2014-11-02 21:11:50 -070043 *
Davide Pesavento1cb619e2018-04-10 17:13:53 -040044 * This type has the following member functions:
45 * - `iterator<NextHop> begin()`
46 * - `iterator<NextHop> end()`
47 * - `size_t size()`
Junxiao Shic1e12362014-01-24 20:03:26 -070048 */
Davide Pesavento1cb619e2018-04-10 17:13:53 -040049using NextHopList = std::vector<NextHop>;
Junxiao Shic1e12362014-01-24 20:03:26 -070050
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -040051/**
52 * \brief Represents an entry in the FIB.
53 * \sa Fib
Junxiao Shic1e12362014-01-24 20:03:26 -070054 */
Junxiao Shi8d843142016-07-11 22:42:42 +000055class Entry : noncopyable
Junxiao Shic1e12362014-01-24 20:03:26 -070056{
57public:
Junxiao Shi408a7002014-02-12 17:53:47 -070058 explicit
Junxiao Shic1e12362014-01-24 20:03:26 -070059 Entry(const Name& prefix);
Junxiao Shi7bb01512014-03-05 21:34:09 -070060
Junxiao Shic1e12362014-01-24 20:03:26 -070061 const Name&
Junxiao Shi340d5532016-08-13 04:00:35 +000062 getPrefix() const
63 {
64 return m_prefix;
65 }
Junxiao Shi7bb01512014-03-05 21:34:09 -070066
Junxiao Shic1e12362014-01-24 20:03:26 -070067 const NextHopList&
Junxiao Shi340d5532016-08-13 04:00:35 +000068 getNextHops() const
69 {
70 return m_nextHops;
71 }
Junxiao Shi7bb01512014-03-05 21:34:09 -070072
Junxiao Shi56a21bf2014-11-02 21:11:50 -070073 /** \return whether this Entry has any NextHop record
74 */
Junxiao Shiefceadc2014-03-09 18:52:57 -070075 bool
Junxiao Shi340d5532016-08-13 04:00:35 +000076 hasNextHops() const
77 {
78 return !m_nextHops.empty();
79 }
Junxiao Shiefceadc2014-03-09 18:52:57 -070080
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000081 /** \return whether there is a NextHop record for \p face
Junxiao Shi56a21bf2014-11-02 21:11:50 -070082 */
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070083 bool
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000084 hasNextHop(const Face& face) const;
Junxiao Shi7bb01512014-03-05 21:34:09 -070085
Ju Pand8315bf2019-07-31 06:59:07 +000086private:
87 /** \brief adds a NextHop record to the entry
Junxiao Shi56a21bf2014-11-02 21:11:50 -070088 *
Ju Pand8315bf2019-07-31 06:59:07 +000089 * If a NextHop record for \p face already exists in the entry, its cost is set to \p cost.
90 *
91 * \return the iterator to the new or updated NextHop and a bool indicating whether a new
92 * NextHop was inserted
Junxiao Shi56a21bf2014-11-02 21:11:50 -070093 */
Ju Pand8315bf2019-07-31 06:59:07 +000094 std::pair<NextHopList::iterator, bool>
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000095 addOrUpdateNextHop(Face& face, uint64_t cost);
Junxiao Shi7bb01512014-03-05 21:34:09 -070096
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +000097 /** \brief removes a NextHop record
98 *
99 * If no NextHop record for face exists, do nothing.
Junxiao Shi56a21bf2014-11-02 21:11:50 -0700100 */
Ju Pand8315bf2019-07-31 06:59:07 +0000101 bool
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000102 removeNextHop(const Face& face);
Junxiao Shic1e12362014-01-24 20:03:26 -0700103
Junxiao Shia6de4292016-07-12 02:08:10 +0000104 /** \note This method is non-const because mutable iterators are needed by callers.
Junxiao Shi56a21bf2014-11-02 21:11:50 -0700105 */
106 NextHopList::iterator
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000107 findNextHop(const Face& face);
Junxiao Shi56a21bf2014-11-02 21:11:50 -0700108
Md Ashiqur Rahman6be93872019-08-07 01:25:31 +0000109 /** \brief sorts the nexthop list
Junxiao Shia6de4292016-07-12 02:08:10 +0000110 */
Junxiao Shic1e12362014-01-24 20:03:26 -0700111 void
112 sortNextHops();
113
114private:
115 Name m_prefix;
116 NextHopList m_nextHops;
Junxiao Shiefceadc2014-03-09 18:52:57 -0700117
Davide Pesavento50a6af32019-02-21 00:04:40 -0500118 name_tree::Entry* m_nameTreeEntry = nullptr;
Junxiao Shi340d5532016-08-13 04:00:35 +0000119
Davide Pesaventoa3a7a4e2022-05-29 16:06:22 -0400120 friend name_tree::Entry;
121 friend Fib;
Junxiao Shic1e12362014-01-24 20:03:26 -0700122};
123
Junxiao Shic1e12362014-01-24 20:03:26 -0700124} // namespace fib
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800125} // namespace nfd
Junxiao Shic1e12362014-01-24 20:03:26 -0700126
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700127#endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP