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 | 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: |
| 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 | |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 69 | RouteOrigin |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 70 | getOrigin() const |
| 71 | { |
| 72 | return m_origin; |
| 73 | } |
| 74 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 75 | Route& |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 76 | setOrigin(RouteOrigin origin); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 77 | |
| 78 | uint64_t |
| 79 | getCost() const |
| 80 | { |
| 81 | return m_cost; |
| 82 | } |
| 83 | |
| 84 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 85 | setCost(uint64_t cost); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 86 | |
| 87 | uint64_t |
| 88 | getFlags() const |
| 89 | { |
| 90 | return m_flags; |
| 91 | } |
| 92 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 93 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 94 | setFlags(uint64_t flags); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 95 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 96 | bool |
| 97 | hasExpirationPeriod() const |
| 98 | { |
| 99 | return !!m_expirationPeriod; |
| 100 | } |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 101 | |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 102 | time::milliseconds |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 103 | getExpirationPeriod() const |
| 104 | { |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 105 | return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 109 | setExpirationPeriod(time::milliseconds expirationPeriod); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 110 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 111 | Route& |
| 112 | unsetExpirationPeriod(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 113 | |
| 114 | template<encoding::Tag TAG> |
| 115 | size_t |
| 116 | wireEncode(EncodingImpl<TAG>& block) const; |
| 117 | |
| 118 | const Block& |
| 119 | wireEncode() const; |
| 120 | |
| 121 | void |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 122 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 123 | |
| 124 | private: |
| 125 | uint64_t m_faceId; |
Davide Pesavento | e8e48c2 | 2017-04-13 00:35:33 -0400 | [diff] [blame] | 126 | RouteOrigin m_origin; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 127 | uint64_t m_cost; |
| 128 | uint64_t m_flags; |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 129 | optional<time::milliseconds> m_expirationPeriod; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 130 | |
| 131 | mutable Block m_wire; |
| 132 | }; |
| 133 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 134 | bool |
| 135 | operator==(const Route& a, const Route& b); |
| 136 | |
| 137 | inline bool |
| 138 | operator!=(const Route& a, const Route& b) |
| 139 | { |
| 140 | return !(a == b); |
| 141 | } |
| 142 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 143 | std::ostream& |
| 144 | operator<<(std::ostream& os, const Route& route); |
| 145 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 146 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 147 | /** |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 148 | * \ingroup management |
| 149 | * \brief represents an item in NFD RIB dataset |
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 | * A RIB entry contains one or more routes for a name prefix |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 152 | * |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 153 | * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 154 | */ |
| 155 | class RibEntry |
| 156 | { |
| 157 | public: |
| 158 | class Error : public tlv::Error |
| 159 | { |
| 160 | public: |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 161 | explicit |
| 162 | Error(const std::string& what) |
| 163 | : tlv::Error(what) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 164 | { |
| 165 | } |
| 166 | }; |
| 167 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 168 | RibEntry(); |
| 169 | |
| 170 | explicit |
| 171 | RibEntry(const Block& block); |
| 172 | |
| 173 | const Name& |
| 174 | getName() const |
| 175 | { |
| 176 | return m_prefix; |
| 177 | } |
| 178 | |
| 179 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 180 | setName(const Name& prefix); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 181 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 182 | const std::vector<Route>& |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 183 | getRoutes() const |
| 184 | { |
| 185 | return m_routes; |
| 186 | } |
| 187 | |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 188 | template<typename InputIt> |
| 189 | RibEntry& |
| 190 | setRoutes(InputIt first, InputIt last) |
| 191 | { |
| 192 | m_routes.assign(first, last); |
| 193 | m_wire.reset(); |
| 194 | return *this; |
| 195 | } |
| 196 | |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 197 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 198 | addRoute(const Route& route); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 199 | |
| 200 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame] | 201 | clearRoutes(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 202 | |
| 203 | template<encoding::Tag TAG> |
| 204 | size_t |
| 205 | wireEncode(EncodingImpl<TAG>& block) const; |
| 206 | |
| 207 | const Block& |
| 208 | wireEncode() const; |
| 209 | |
| 210 | void |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 211 | wireDecode(const Block& block); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 212 | |
| 213 | private: |
| 214 | Name m_prefix; |
Davide Pesavento | 484bbe5 | 2017-02-15 00:03:46 -0500 | [diff] [blame] | 215 | std::vector<Route> m_routes; |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 216 | |
| 217 | mutable Block m_wire; |
| 218 | }; |
| 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 |