Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP |
| 23 | #define NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP |
| 24 | |
| 25 | #include "../encoding/block.hpp" |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 26 | #include "../name.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 27 | #include <list> |
| 28 | |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 29 | namespace ndn { |
| 30 | namespace nfd { |
| 31 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 32 | /** @ingroup management |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 33 | */ |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 34 | class NextHopRecord |
| 35 | { |
| 36 | public: |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 37 | class Error : public tlv::Error |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 38 | { |
| 39 | public: |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 40 | explicit |
| 41 | Error(const std::string& what) |
| 42 | : tlv::Error(what) |
| 43 | { |
| 44 | } |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 45 | }; |
| 46 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 47 | NextHopRecord(); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 48 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 49 | explicit |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 50 | NextHopRecord(const Block& block); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 51 | |
| 52 | uint64_t |
| 53 | getFaceId() const |
| 54 | { |
| 55 | return m_faceId; |
| 56 | } |
| 57 | |
| 58 | NextHopRecord& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 59 | setFaceId(uint64_t faceId); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 60 | |
| 61 | uint64_t |
| 62 | getCost() const |
| 63 | { |
| 64 | return m_cost; |
| 65 | } |
| 66 | |
| 67 | NextHopRecord& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 68 | setCost(uint64_t cost); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 69 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 70 | template<encoding::Tag TAG> |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 71 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 72 | wireEncode(EncodingImpl<TAG>& block) const; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 73 | |
| 74 | const Block& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 75 | wireEncode() const; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 76 | |
| 77 | void |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 78 | wireDecode(const Block& wire); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 79 | |
| 80 | private: |
| 81 | uint64_t m_faceId; |
| 82 | uint64_t m_cost; |
| 83 | |
| 84 | mutable Block m_wire; |
| 85 | }; |
| 86 | |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 87 | /** @ingroup management |
Alexander Afanasyev | 4671bf7 | 2014-05-19 09:01:37 -0400 | [diff] [blame] | 88 | */ |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 89 | class FibEntry |
| 90 | { |
| 91 | public: |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 92 | class Error : public tlv::Error |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 93 | { |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 94 | public: |
| 95 | explicit |
| 96 | Error(const std::string& what) |
| 97 | : tlv::Error(what) |
| 98 | { |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | FibEntry(); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 103 | |
Alexander Afanasyev | 44b438a | 2014-03-19 12:51:49 -0700 | [diff] [blame] | 104 | explicit |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 105 | FibEntry(const Block& block); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 106 | |
| 107 | const Name& |
| 108 | getPrefix() const |
| 109 | { |
| 110 | return m_prefix; |
| 111 | } |
| 112 | |
| 113 | FibEntry& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 114 | setPrefix(const Name& prefix); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 115 | |
| 116 | const std::list<NextHopRecord>& |
| 117 | getNextHopRecords() const |
| 118 | { |
| 119 | return m_nextHopRecords; |
| 120 | } |
| 121 | |
| 122 | FibEntry& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 123 | addNextHopRecord(const NextHopRecord& nextHopRecord); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 124 | |
| 125 | template<typename T> |
| 126 | FibEntry& |
| 127 | setNextHopRecords(const T& begin, const T& end) |
| 128 | { |
| 129 | m_nextHopRecords.clear(); |
| 130 | m_nextHopRecords.assign(begin, end); |
| 131 | m_wire.reset(); |
| 132 | return *this; |
| 133 | } |
| 134 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 135 | template<encoding::Tag TAG> |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 136 | size_t |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame^] | 137 | wireEncode(EncodingImpl<TAG>& block) const; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 138 | |
| 139 | const Block& |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 140 | wireEncode() const; |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 141 | |
| 142 | void |
Junxiao Shi | 65f1a71 | 2014-11-20 14:59:36 -0700 | [diff] [blame] | 143 | wireDecode(const Block& wire); |
Steve DiBenedetto | 6d792d7 | 2014-03-15 19:01:36 -0600 | [diff] [blame] | 144 | |
| 145 | private: |
| 146 | Name m_prefix; |
| 147 | std::list<NextHopRecord> m_nextHopRecords; |
| 148 | |
| 149 | mutable Block m_wire; |
| 150 | }; |
| 151 | |
| 152 | } // namespace nfd |
| 153 | } // namespace ndn |
| 154 | |
| 155 | #endif // NDN_MANAGEMENT_NFD_FIB_ENTRY_HPP |