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_RIB_ENTRY_HPP |
| 23 | #define NDN_MGMT_NFD_RIB_ENTRY_HPP |
| 24 | |
Davide Pesavento | d1a415c | 2017-02-20 00:41:42 -0500 | [diff] [blame] | 25 | #include "route-flags-traits.hpp" |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 26 | #include "../../encoding/block.hpp" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 27 | #include "../../name.hpp" |
| 28 | #include "../../util/time.hpp" |
| 29 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 30 | namespace ndn { |
| 31 | namespace nfd { |
| 32 | |
| 33 | /** |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 34 | * \ingroup management |
| 35 | * \brief represents a route in a RibEntry |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 36 | * |
| 37 | * A route indicates the availability of content via a certain face and |
| 38 | * provides meta-information about the face. |
| 39 | * |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 40 | * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Route |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 41 | */ |
Davide Pesavento | d1a415c | 2017-02-20 00:41:42 -0500 | [diff] [blame] | 42 | class Route : public RouteFlagsTraits<Route> |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 43 | { |
| 44 | public: |
| 45 | class Error : public tlv::Error |
| 46 | { |
| 47 | public: |
Junxiao Shi | 68b5385 | 2018-07-25 13:56:38 -0600 | [diff] [blame] | 48 | using tlv::Error::Error; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | Route(); |
| 52 | |
| 53 | explicit |
| 54 | Route(const Block& block); |
| 55 | |
| 56 | uint64_t |
| 57 | getFaceId() const |
| 58 | { |
| 59 | return m_faceId; |
| 60 | } |
| 61 | |
| 62 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 63 | setFaceId(uint64_t faceId); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 64 | |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 65 | RouteOrigin |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 66 | getOrigin() const |
| 67 | { |
| 68 | return m_origin; |
| 69 | } |
| 70 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 71 | Route& |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 72 | setOrigin(RouteOrigin origin); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 73 | |
| 74 | uint64_t |
| 75 | getCost() const |
| 76 | { |
| 77 | return m_cost; |
| 78 | } |
| 79 | |
| 80 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 81 | setCost(uint64_t cost); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 82 | |
| 83 | uint64_t |
| 84 | getFlags() const |
| 85 | { |
| 86 | return m_flags; |
| 87 | } |
| 88 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 89 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 90 | setFlags(uint64_t flags); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 91 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 92 | bool |
| 93 | hasExpirationPeriod() const |
| 94 | { |
| 95 | return !!m_expirationPeriod; |
| 96 | } |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 97 | |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 98 | time::milliseconds |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 99 | getExpirationPeriod() const |
| 100 | { |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 101 | return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 105 | setExpirationPeriod(time::milliseconds expirationPeriod); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 106 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 107 | Route& |
| 108 | unsetExpirationPeriod(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 109 | |
| 110 | template<encoding::Tag TAG> |
| 111 | size_t |
| 112 | wireEncode(EncodingImpl<TAG>& block) const; |
| 113 | |
| 114 | const Block& |
| 115 | wireEncode() const; |
| 116 | |
| 117 | void |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 118 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 119 | |
| 120 | private: |
| 121 | uint64_t m_faceId; |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 122 | RouteOrigin m_origin; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 123 | uint64_t m_cost; |
| 124 | uint64_t m_flags; |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 125 | optional<time::milliseconds> m_expirationPeriod; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 126 | |
| 127 | mutable Block m_wire; |
| 128 | }; |
| 129 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 130 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Route); |
| 131 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 132 | bool |
| 133 | operator==(const Route& a, const Route& b); |
| 134 | |
| 135 | inline bool |
| 136 | operator!=(const Route& a, const Route& b) |
| 137 | { |
| 138 | return !(a == b); |
| 139 | } |
| 140 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 141 | std::ostream& |
| 142 | operator<<(std::ostream& os, const Route& route); |
| 143 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 144 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 145 | /** |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 146 | * \ingroup management |
| 147 | * \brief represents an item in NFD RIB dataset |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 148 | * |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 149 | * A RIB entry contains one or more routes for a name prefix |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 150 | * |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 151 | * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 152 | */ |
| 153 | class RibEntry |
| 154 | { |
| 155 | public: |
| 156 | class Error : public tlv::Error |
| 157 | { |
| 158 | public: |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 159 | explicit |
| 160 | Error(const std::string& what) |
| 161 | : tlv::Error(what) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 162 | { |
| 163 | } |
| 164 | }; |
| 165 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 166 | RibEntry(); |
| 167 | |
| 168 | explicit |
| 169 | RibEntry(const Block& block); |
| 170 | |
| 171 | const Name& |
| 172 | getName() const |
| 173 | { |
| 174 | return m_prefix; |
| 175 | } |
| 176 | |
| 177 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 178 | setName(const Name& prefix); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 179 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 180 | const std::vector<Route>& |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 181 | getRoutes() const |
| 182 | { |
| 183 | return m_routes; |
| 184 | } |
| 185 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 186 | template<typename InputIt> |
| 187 | RibEntry& |
| 188 | setRoutes(InputIt first, InputIt last) |
| 189 | { |
| 190 | m_routes.assign(first, last); |
| 191 | m_wire.reset(); |
| 192 | return *this; |
| 193 | } |
| 194 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 195 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 196 | addRoute(const Route& route); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 197 | |
| 198 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 199 | clearRoutes(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 200 | |
| 201 | template<encoding::Tag TAG> |
| 202 | size_t |
| 203 | wireEncode(EncodingImpl<TAG>& block) const; |
| 204 | |
| 205 | const Block& |
| 206 | wireEncode() const; |
| 207 | |
| 208 | void |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 209 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 210 | |
| 211 | private: |
| 212 | Name m_prefix; |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 213 | std::vector<Route> m_routes; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 214 | |
| 215 | mutable Block m_wire; |
| 216 | }; |
| 217 | |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 218 | NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RibEntry); |
| 219 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 220 | bool |
| 221 | operator==(const RibEntry& a, const RibEntry& b); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 222 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 223 | inline bool |
| 224 | operator!=(const RibEntry& a, const RibEntry& b) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 225 | { |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 226 | return !(a == b); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | std::ostream& |
| 230 | operator<<(std::ostream& os, const RibEntry& entry); |
| 231 | |
| 232 | } // namespace nfd |
| 233 | } // namespace ndn |
| 234 | |
| 235 | #endif // NDN_MGMT_NFD_RIB_ENTRY_HPP |