Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 24 | */ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_FIB_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_FIB_ENTRY_HPP |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 28 | |
| 29 | #include "fib-nexthop.hpp" |
| 30 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 31 | namespace nfd { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 33 | namespace name_tree { |
| 34 | class Entry; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 35 | } // namespace name_tree |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 36 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 37 | namespace fib { |
| 38 | |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 39 | class Fib; |
| 40 | |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 41 | /** \class nfd::fib::NextHopList |
| 42 | * \brief Represents a collection of nexthops. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 43 | * |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 44 | * This type has the following member functions: |
| 45 | * - `iterator<NextHop> begin()` |
| 46 | * - `iterator<NextHop> end()` |
| 47 | * - `size_t size()` |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 48 | */ |
Davide Pesavento | 1cb619e | 2018-04-10 17:13:53 -0400 | [diff] [blame] | 49 | using NextHopList = std::vector<NextHop>; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 50 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 51 | /** |
| 52 | * \brief Represents an entry in the FIB. |
| 53 | * \sa Fib |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 54 | */ |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 55 | class Entry : noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 56 | { |
| 57 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 58 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 59 | Entry(const Name& prefix); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 60 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 61 | const Name& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 62 | getPrefix() const |
| 63 | { |
| 64 | return m_prefix; |
| 65 | } |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 66 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 67 | const NextHopList& |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 68 | getNextHops() const |
| 69 | { |
| 70 | return m_nextHops; |
| 71 | } |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 72 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 73 | /** \return whether this Entry has any NextHop record |
| 74 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 75 | bool |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 76 | hasNextHops() const |
| 77 | { |
| 78 | return !m_nextHops.empty(); |
| 79 | } |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 80 | |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 81 | /** \return whether there is a NextHop record for \p face |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 82 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 83 | bool |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 84 | hasNextHop(const Face& face) const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 85 | |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 86 | private: |
| 87 | /** \brief adds a NextHop record to the entry |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 88 | * |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 89 | * 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 Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 93 | */ |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 94 | std::pair<NextHopList::iterator, bool> |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 95 | addOrUpdateNextHop(Face& face, uint64_t cost); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 96 | |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 97 | /** \brief removes a NextHop record |
| 98 | * |
| 99 | * If no NextHop record for face exists, do nothing. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 100 | */ |
Ju Pan | d8315bf | 2019-07-31 06:59:07 +0000 | [diff] [blame] | 101 | bool |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 102 | removeNextHop(const Face& face); |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 103 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 104 | /** \note This method is non-const because mutable iterators are needed by callers. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 105 | */ |
| 106 | NextHopList::iterator |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 107 | findNextHop(const Face& face); |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 108 | |
Md Ashiqur Rahman | 6be9387 | 2019-08-07 01:25:31 +0000 | [diff] [blame] | 109 | /** \brief sorts the nexthop list |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 110 | */ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 111 | void |
| 112 | sortNextHops(); |
| 113 | |
| 114 | private: |
| 115 | Name m_prefix; |
| 116 | NextHopList m_nextHops; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 117 | |
Davide Pesavento | 50a6af3 | 2019-02-21 00:04:40 -0500 | [diff] [blame] | 118 | name_tree::Entry* m_nameTreeEntry = nullptr; |
Junxiao Shi | 340d553 | 2016-08-13 04:00:35 +0000 | [diff] [blame] | 119 | |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame^] | 120 | friend name_tree::Entry; |
| 121 | friend Fib; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 124 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 125 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 127 | #endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP |