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