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" |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 26 | #include "../../name.hpp" |
| 27 | #include "../../util/time.hpp" |
| 28 | |
| 29 | #include <list> |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace nfd { |
| 33 | |
| 34 | /** |
| 35 | * @ingroup management |
| 36 | * |
| 37 | * @brief Data abstraction for Route |
| 38 | * |
| 39 | * A route indicates the availability of content via a certain face and |
| 40 | * provides meta-information about the face. |
| 41 | * |
| 42 | * Route := ROUTE-TYPE TLV-LENGTH |
| 43 | * FaceId |
| 44 | * Origin |
| 45 | * Cost |
| 46 | * Flags |
| 47 | * ExpirationPeriod? |
| 48 | * |
| 49 | * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt |
| 50 | */ |
| 51 | class Route : public RibFlagsTraits<Route> |
| 52 | { |
| 53 | public: |
| 54 | class Error : public tlv::Error |
| 55 | { |
| 56 | public: |
| 57 | explicit |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 58 | Error(const std::string& what) |
| 59 | : tlv::Error(what) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 60 | { |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | Route(); |
| 65 | |
| 66 | explicit |
| 67 | Route(const Block& block); |
| 68 | |
| 69 | uint64_t |
| 70 | getFaceId() const |
| 71 | { |
| 72 | return m_faceId; |
| 73 | } |
| 74 | |
| 75 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 76 | setFaceId(uint64_t faceId); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 77 | |
| 78 | uint64_t |
| 79 | getOrigin() const |
| 80 | { |
| 81 | return m_origin; |
| 82 | } |
| 83 | |
| 84 | /** @brief set Origin |
| 85 | * @param origin a code defined in ndn::nfd::RouteOrigin |
| 86 | */ |
| 87 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 88 | setOrigin(uint64_t origin); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 89 | |
| 90 | uint64_t |
| 91 | getCost() const |
| 92 | { |
| 93 | return m_cost; |
| 94 | } |
| 95 | |
| 96 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 97 | setCost(uint64_t cost); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 98 | |
| 99 | uint64_t |
| 100 | getFlags() const |
| 101 | { |
| 102 | return m_flags; |
| 103 | } |
| 104 | |
| 105 | /** @brief set route inheritance flags |
| 106 | * @param flags a bitwise OR'ed code from ndn::nfd::RouteFlags |
| 107 | */ |
| 108 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 109 | setFlags(uint64_t flags); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 110 | |
| 111 | static const time::milliseconds INFINITE_EXPIRATION_PERIOD; |
| 112 | |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 113 | time::milliseconds |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 114 | getExpirationPeriod() const |
| 115 | { |
| 116 | return m_expirationPeriod; |
| 117 | } |
| 118 | |
| 119 | Route& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 120 | setExpirationPeriod(time::milliseconds expirationPeriod); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 121 | |
| 122 | bool |
| 123 | hasInfiniteExpirationPeriod() const |
| 124 | { |
| 125 | return m_hasInfiniteExpirationPeriod; |
| 126 | } |
| 127 | |
| 128 | template<encoding::Tag TAG> |
| 129 | size_t |
| 130 | wireEncode(EncodingImpl<TAG>& block) const; |
| 131 | |
| 132 | const Block& |
| 133 | wireEncode() const; |
| 134 | |
| 135 | void |
| 136 | wireDecode(const Block& wire); |
| 137 | |
| 138 | private: |
| 139 | uint64_t m_faceId; |
| 140 | uint64_t m_origin; |
| 141 | uint64_t m_cost; |
| 142 | uint64_t m_flags; |
| 143 | time::milliseconds m_expirationPeriod; |
| 144 | bool m_hasInfiniteExpirationPeriod; |
| 145 | |
| 146 | mutable Block m_wire; |
| 147 | }; |
| 148 | |
| 149 | std::ostream& |
| 150 | operator<<(std::ostream& os, const Route& route); |
| 151 | |
| 152 | /** |
| 153 | * @ingroup management |
| 154 | * |
| 155 | * @brief Data abstraction for RIB entry |
| 156 | * |
| 157 | * A RIB entry contains one or more routes for the name prefix |
| 158 | * |
| 159 | * RibEntry := RIB-ENTRY-TYPE TLV-LENGTH |
| 160 | * Name |
| 161 | * Route+ |
| 162 | * |
| 163 | * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt |
| 164 | */ |
| 165 | class RibEntry |
| 166 | { |
| 167 | public: |
| 168 | class Error : public tlv::Error |
| 169 | { |
| 170 | public: |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 171 | explicit |
| 172 | Error(const std::string& what) |
| 173 | : tlv::Error(what) |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 174 | { |
| 175 | } |
| 176 | }; |
| 177 | |
| 178 | typedef std::list<Route> RouteList; |
| 179 | typedef RouteList::const_iterator iterator; |
| 180 | |
| 181 | RibEntry(); |
| 182 | |
| 183 | explicit |
| 184 | RibEntry(const Block& block); |
| 185 | |
| 186 | const Name& |
| 187 | getName() const |
| 188 | { |
| 189 | return m_prefix; |
| 190 | } |
| 191 | |
| 192 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 193 | setName(const Name& prefix); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 194 | |
| 195 | const std::list<Route>& |
| 196 | getRoutes() const |
| 197 | { |
| 198 | return m_routes; |
| 199 | } |
| 200 | |
| 201 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 202 | addRoute(const Route& route); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 203 | |
| 204 | RibEntry& |
Davide Pesavento | 6ad3d53 | 2017-02-17 01:43:57 -0500 | [diff] [blame^] | 205 | clearRoutes(); |
Junxiao Shi | 7357ef2 | 2016-09-07 02:39:37 +0000 | [diff] [blame] | 206 | |
| 207 | template<encoding::Tag TAG> |
| 208 | size_t |
| 209 | wireEncode(EncodingImpl<TAG>& block) const; |
| 210 | |
| 211 | const Block& |
| 212 | wireEncode() const; |
| 213 | |
| 214 | void |
| 215 | wireDecode(const Block& wire); |
| 216 | |
| 217 | iterator |
| 218 | begin() const; |
| 219 | |
| 220 | iterator |
| 221 | end() const; |
| 222 | |
| 223 | private: |
| 224 | Name m_prefix; |
| 225 | RouteList m_routes; |
| 226 | |
| 227 | mutable Block m_wire; |
| 228 | }; |
| 229 | |
| 230 | inline RibEntry::iterator |
| 231 | RibEntry::begin() const |
| 232 | { |
| 233 | return m_routes.begin(); |
| 234 | } |
| 235 | |
| 236 | inline RibEntry::iterator |
| 237 | RibEntry::end() const |
| 238 | { |
| 239 | return m_routes.end(); |
| 240 | } |
| 241 | |
| 242 | std::ostream& |
| 243 | operator<<(std::ostream& os, const RibEntry& entry); |
| 244 | |
| 245 | } // namespace nfd |
| 246 | } // namespace ndn |
| 247 | |
| 248 | #endif // NDN_MGMT_NFD_RIB_ENTRY_HPP |