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