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 | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, 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 | class NameTree; |
| 34 | namespace name_tree { |
| 35 | class Entry; |
| 36 | } |
| 37 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 38 | namespace fib { |
| 39 | |
| 40 | /** \class NextHopList |
| 41 | * \brief represents a collection of nexthops |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 42 | * |
| 43 | * This type has these methods as public API: |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 44 | * iterator<NextHop> begin() |
| 45 | * iterator<NextHop> end() |
| 46 | * size_t size() |
| 47 | */ |
| 48 | typedef std::vector<fib::NextHop> NextHopList; |
| 49 | |
| 50 | /** \class Entry |
| 51 | * \brief represents a FIB entry |
| 52 | */ |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 53 | class Entry : noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 54 | { |
| 55 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 56 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 57 | Entry(const Name& prefix); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 59 | const Name& |
| 60 | getPrefix() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 62 | const NextHopList& |
| 63 | getNextHops() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 64 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 65 | /** \return whether this Entry has any NextHop record |
| 66 | */ |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 67 | bool |
| 68 | hasNextHops() const; |
| 69 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 70 | /** \return whether there is a NextHop record for face |
| 71 | * |
| 72 | * \todo change parameter type to Face& |
| 73 | */ |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 74 | bool |
| 75 | hasNextHop(shared_ptr<Face> face) const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 76 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 77 | /** \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 Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 82 | void |
Alexander Afanasyev | 11b9f3f | 2014-04-10 00:01:15 -0700 | [diff] [blame] | 83 | addNextHop(shared_ptr<Face> face, uint64_t cost); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 84 | |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 85 | /** \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 Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 91 | void |
| 92 | removeNextHop(shared_ptr<Face> face); |
| 93 | |
| 94 | private: |
Junxiao Shi | 56a21bf | 2014-11-02 21:11:50 -0700 | [diff] [blame] | 95 | /** @note This method is non-const because normal iterator is needed by callers. |
| 96 | */ |
| 97 | NextHopList::iterator |
| 98 | findNextHop(Face& face); |
| 99 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 100 | /// sorts the nexthop list |
| 101 | void |
| 102 | sortNextHops(); |
| 103 | |
| 104 | private: |
| 105 | Name m_prefix; |
| 106 | NextHopList m_nextHops; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 107 | |
| 108 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 109 | friend class nfd::NameTree; |
| 110 | friend class nfd::name_tree::Entry; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | |
| 114 | inline const Name& |
| 115 | Entry::getPrefix() const |
| 116 | { |
| 117 | return m_prefix; |
| 118 | } |
| 119 | |
| 120 | inline const NextHopList& |
| 121 | Entry::getNextHops() const |
| 122 | { |
| 123 | return m_nextHops; |
| 124 | } |
| 125 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 126 | inline bool |
| 127 | Entry::hasNextHops() const |
| 128 | { |
| 129 | return !m_nextHops.empty(); |
| 130 | } |
| 131 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 132 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 133 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 134 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 135 | #endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP |