Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_TABLE_FIB_ENTRY_HPP |
| 26 | #define NFD_TABLE_FIB_ENTRY_HPP |
| 27 | |
| 28 | #include "fib-nexthop.hpp" |
| 29 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 30 | namespace nfd { |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 31 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 32 | class NameTree; |
| 33 | namespace name_tree { |
| 34 | class Entry; |
| 35 | } |
| 36 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 37 | namespace fib { |
| 38 | |
| 39 | /** \class NextHopList |
| 40 | * \brief represents a collection of nexthops |
| 41 | * This type has these methods: |
| 42 | * iterator<NextHop> begin() |
| 43 | * iterator<NextHop> end() |
| 44 | * size_t size() |
| 45 | */ |
| 46 | typedef std::vector<fib::NextHop> NextHopList; |
| 47 | |
| 48 | /** \class Entry |
| 49 | * \brief represents a FIB entry |
| 50 | */ |
Junxiao Shi | e349ea1 | 2014-03-12 01:32:42 -0700 | [diff] [blame] | 51 | class Entry : noncopyable |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 52 | { |
| 53 | public: |
Junxiao Shi | 408a700 | 2014-02-12 17:53:47 -0700 | [diff] [blame] | 54 | explicit |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 55 | Entry(const Name& prefix); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 56 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 57 | const Name& |
| 58 | getPrefix() const; |
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 NextHopList& |
| 61 | getNextHops() const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 62 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 63 | /// whether this Entry has any nexthop |
| 64 | bool |
| 65 | hasNextHops() const; |
| 66 | |
Junxiao Shi | 0b5fbbb | 2014-02-20 15:54:03 -0700 | [diff] [blame] | 67 | bool |
| 68 | hasNextHop(shared_ptr<Face> face) const; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 70 | /// adds a nexthop |
| 71 | void |
Alexander Afanasyev | 11b9f3f | 2014-04-10 00:01:15 -0700 | [diff] [blame] | 72 | addNextHop(shared_ptr<Face> face, uint64_t cost); |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 73 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 74 | /// removes a nexthop |
| 75 | void |
| 76 | removeNextHop(shared_ptr<Face> face); |
| 77 | |
| 78 | private: |
| 79 | /// sorts the nexthop list |
| 80 | void |
| 81 | sortNextHops(); |
| 82 | |
| 83 | private: |
| 84 | Name m_prefix; |
| 85 | NextHopList m_nextHops; |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 86 | |
| 87 | shared_ptr<name_tree::Entry> m_nameTreeEntry; |
| 88 | friend class nfd::NameTree; |
| 89 | friend class nfd::name_tree::Entry; |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | |
| 93 | inline const Name& |
| 94 | Entry::getPrefix() const |
| 95 | { |
| 96 | return m_prefix; |
| 97 | } |
| 98 | |
| 99 | inline const NextHopList& |
| 100 | Entry::getNextHops() const |
| 101 | { |
| 102 | return m_nextHops; |
| 103 | } |
| 104 | |
Junxiao Shi | efceadc | 2014-03-09 18:52:57 -0700 | [diff] [blame] | 105 | inline bool |
| 106 | Entry::hasNextHops() const |
| 107 | { |
| 108 | return !m_nextHops.empty(); |
| 109 | } |
| 110 | |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 111 | } // namespace fib |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 112 | } // namespace nfd |
Junxiao Shi | c1e1236 | 2014-01-24 20:03:26 -0700 | [diff] [blame] | 113 | |
| 114 | #endif // NFD_TABLE_FIB_ENTRY_HPP |