Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 3 | * 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 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 { |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 34 | class NameTree; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 35 | class Entry; |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 36 | } // namespace name_tree |
Junxiao Shi | 2570f3e | 2016-07-27 02:48:29 +0000 | [diff] [blame] | 37 | using name_tree::NameTree; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 38 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 39 | namespace fib { |
| 40 | |
| 41 | /** \class NextHopList |
| 42 | * \brief represents a collection of nexthops |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 43 | * |
| 44 | * This type has these methods as public API: |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 45 | * iterator<NextHop> begin() |
| 46 | * iterator<NextHop> end() |
| 47 | * size_t size() |
| 48 | */ |
| 49 | typedef std::vector<fib::NextHop> NextHopList; |
| 50 | |
| 51 | /** \class Entry |
| 52 | * \brief represents a FIB entry |
| 53 | */ |
Junxiao Shi | 8d84314 | 2016-07-11 22:42:42 +0000 | [diff] [blame] | 54 | class Entry : noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 55 | { |
| 56 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 57 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 58 | Entry(const Name& prefix); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 59 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 60 | const Name& |
| 61 | getPrefix() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 62 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 63 | const NextHopList& |
| 64 | getNextHops() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 65 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 66 | /** \return whether this Entry has any NextHop record |
| 67 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 68 | bool |
| 69 | hasNextHops() const; |
| 70 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 71 | /** \return whether there is a NextHop record for \p face |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 72 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 73 | bool |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 74 | hasNextHop(const Face& face) const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 75 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 76 | /** \brief adds a NextHop record |
| 77 | * |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 78 | * If a NextHop record for \p face already exists, its cost is updated. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 79 | */ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 80 | void |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 81 | addNextHop(Face& face, uint64_t cost); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 82 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 83 | /** \brief removes a NextHop record |
| 84 | * |
| 85 | * If no NextHop record for face exists, do nothing. |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 86 | */ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 87 | void |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 88 | removeNextHop(const Face& face); |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 89 | |
| 90 | private: |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 91 | /** \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] | 92 | */ |
| 93 | NextHopList::iterator |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 94 | findNextHop(const Face& face); |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 95 | |
Junxiao Shi | a6de429 | 2016-07-12 02:08:10 +0000 | [diff] [blame] | 96 | /** \brief sorts the nexthop list |
| 97 | */ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 98 | void |
| 99 | sortNextHops(); |
| 100 | |
| 101 | private: |
| 102 | Name m_prefix; |
| 103 | NextHopList m_nextHops; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 104 | |
Junxiao Shi | b184e53 | 2016-05-26 18:09:57 +0000 | [diff] [blame] | 105 | weak_ptr<name_tree::Entry> m_nameTreeEntry; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 106 | friend class nfd::NameTree; |
| 107 | friend class nfd::name_tree::Entry; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
| 111 | inline const Name& |
| 112 | Entry::getPrefix() const |
| 113 | { |
| 114 | return m_prefix; |
| 115 | } |
| 116 | |
| 117 | inline const NextHopList& |
| 118 | Entry::getNextHops() const |
| 119 | { |
| 120 | return m_nextHops; |
| 121 | } |
| 122 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 123 | inline bool |
| 124 | Entry::hasNextHops() const |
| 125 | { |
| 126 | return !m_nextHops.empty(); |
| 127 | } |
| 128 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 129 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 130 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 132 | #endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP |