Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 2 | /* |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #ifndef NDN_MGMT_NFD_FIB_ENTRY_HPP |
| 23 | #define NDN_MGMT_NFD_FIB_ENTRY_HPP |
| 24 | |
| 25 | #include "../../encoding/block.hpp" |
| 26 | #include "../../name.hpp" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | namespace nfd { |
| 30 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 31 | /** \ingroup management |
| 32 | * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 33 | */ |
| 34 | class NextHopRecord |
| 35 | { |
| 36 | public: |
| 37 | class Error : public tlv::Error |
| 38 | { |
| 39 | public: |
| 40 | explicit |
| 41 | Error(const std::string& what) |
| 42 | : tlv::Error(what) |
| 43 | { |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | NextHopRecord(); |
| 48 | |
| 49 | explicit |
| 50 | NextHopRecord(const Block& block); |
| 51 | |
| 52 | uint64_t |
| 53 | getFaceId() const |
| 54 | { |
| 55 | return m_faceId; |
| 56 | } |
| 57 | |
| 58 | NextHopRecord& |
| 59 | setFaceId(uint64_t faceId); |
| 60 | |
| 61 | uint64_t |
| 62 | getCost() const |
| 63 | { |
| 64 | return m_cost; |
| 65 | } |
| 66 | |
| 67 | NextHopRecord& |
| 68 | setCost(uint64_t cost); |
| 69 | |
| 70 | template<encoding::Tag TAG> |
| 71 | size_t |
| 72 | wireEncode(EncodingImpl<TAG>& block) const; |
| 73 | |
| 74 | const Block& |
| 75 | wireEncode() const; |
| 76 | |
| 77 | void |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 78 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 79 | |
| 80 | private: |
| 81 | uint64_t m_faceId; |
| 82 | uint64_t m_cost; |
| 83 | |
| 84 | mutable Block m_wire; |
| 85 | }; |
| 86 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 87 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(NextHopRecord); |
| 88 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 89 | bool |
| 90 | operator==(const NextHopRecord& a, const NextHopRecord& b); |
| 91 | |
| 92 | inline bool |
| 93 | operator!=(const NextHopRecord& a, const NextHopRecord& b) |
| 94 | { |
| 95 | return !(a == b); |
| 96 | } |
| 97 | |
| 98 | std::ostream& |
| 99 | operator<<(std::ostream& os, const NextHopRecord& nh); |
| 100 | |
| 101 | |
| 102 | /** \ingroup management |
| 103 | * \sa https://redmine.named-data.net/projects/nfd/wiki/FibMgmt#FIB-Dataset |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 104 | */ |
| 105 | class FibEntry |
| 106 | { |
| 107 | public: |
| 108 | class Error : public tlv::Error |
| 109 | { |
| 110 | public: |
| 111 | explicit |
| 112 | Error(const std::string& what) |
| 113 | : tlv::Error(what) |
| 114 | { |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | FibEntry(); |
| 119 | |
| 120 | explicit |
| 121 | FibEntry(const Block& block); |
| 122 | |
| 123 | const Name& |
| 124 | getPrefix() const |
| 125 | { |
| 126 | return m_prefix; |
| 127 | } |
| 128 | |
| 129 | FibEntry& |
| 130 | setPrefix(const Name& prefix); |
| 131 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 132 | const std::vector<NextHopRecord>& |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 133 | getNextHopRecords() const |
| 134 | { |
| 135 | return m_nextHopRecords; |
| 136 | } |
| 137 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 138 | template<typename InputIt> |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 139 | FibEntry& |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 140 | setNextHopRecords(InputIt first, InputIt last) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 141 | { |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 142 | m_nextHopRecords.assign(first, last); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 143 | m_wire.reset(); |
| 144 | return *this; |
| 145 | } |
| 146 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 147 | FibEntry& |
| 148 | addNextHopRecord(const NextHopRecord& nh); |
| 149 | |
| 150 | FibEntry& |
| 151 | clearNextHopRecords(); |
| 152 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 153 | template<encoding::Tag TAG> |
| 154 | size_t |
| 155 | wireEncode(EncodingImpl<TAG>& block) const; |
| 156 | |
| 157 | const Block& |
| 158 | wireEncode() const; |
| 159 | |
| 160 | void |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 161 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 162 | |
| 163 | private: |
| 164 | Name m_prefix; |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 165 | std::vector<NextHopRecord> m_nextHopRecords; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 166 | |
| 167 | mutable Block m_wire; |
| 168 | }; |
| 169 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame^] | 170 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(FibEntry); |
| 171 | |
Davide Pesavento | a6f32ca | 2017-02-11 20:08:23 -0500 | [diff] [blame] | 172 | bool |
| 173 | operator==(const FibEntry& a, const FibEntry& b); |
| 174 | |
| 175 | inline bool |
| 176 | operator!=(const FibEntry& a, const FibEntry& b) |
| 177 | { |
| 178 | return !(a == b); |
| 179 | } |
| 180 | |
| 181 | std::ostream& |
| 182 | operator<<(std::ostream& os, const FibEntry& entry); |
| 183 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 184 | } // namespace nfd |
| 185 | } // namespace ndn |
| 186 | |
| 187 | #endif // NDN_MGMT_NFD_FIB_ENTRY_HPP |