| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2013-2014 Regents of the University of California. |
| * |
| * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| * |
| * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| * terms of the GNU Lesser General Public License as published by the Free Software |
| * Foundation, either version 3 of the License, or (at your option) any later version. |
| * |
| * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| * |
| * You should have received copies of the GNU General Public License and GNU Lesser |
| * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| * <http://www.gnu.org/licenses/>. |
| * |
| * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| */ |
| |
| #ifndef NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP |
| #define NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP |
| |
| #include "../encoding/block.hpp" |
| #include "../encoding/encoding-buffer.hpp" |
| #include "../encoding/tlv-nfd.hpp" |
| #include "../name.hpp" |
| |
| #include <list> |
| |
| namespace ndn { |
| namespace nfd { |
| |
| /** |
| * @ingroup management |
| * |
| * @brief Data abstraction for Route |
| * |
| * A route indicates the availability of content via a certain face and |
| * provides meta-information about the face. |
| * |
| * Route := ROUTE-TYPE TLV-LENGTH |
| * FaceId |
| * Origin |
| * Cost |
| * Flags |
| * ExpirationPeriod? |
| * |
| * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt |
| */ |
| class Route |
| { |
| public: |
| class Error : public tlv::Error |
| { |
| public: |
| explicit |
| Error(const std::string& what) : tlv::Error(what) |
| { |
| } |
| }; |
| |
| Route(); |
| |
| explicit |
| Route(const Block& block); |
| |
| uint64_t |
| getFaceId() const |
| { |
| return m_faceId; |
| } |
| |
| Route& |
| setFaceId(uint64_t faceId) |
| { |
| m_faceId = faceId; |
| m_wire.reset(); |
| return *this; |
| } |
| |
| uint64_t |
| getOrigin() const |
| { |
| return m_origin; |
| } |
| |
| Route& |
| setOrigin(uint64_t origin) |
| { |
| m_origin = origin; |
| m_wire.reset(); |
| return *this; |
| } |
| |
| uint64_t |
| getCost() const |
| { |
| return m_cost; |
| } |
| |
| Route& |
| setCost(uint64_t cost) |
| { |
| m_cost = cost; |
| m_wire.reset(); |
| return *this; |
| } |
| |
| uint64_t |
| getFlags() const |
| { |
| return m_flags; |
| } |
| |
| Route& |
| setFlags(uint64_t flags) |
| { |
| m_flags = flags; |
| m_wire.reset(); |
| return *this; |
| } |
| |
| static const time::milliseconds INFINITE_EXPIRATION_PERIOD; |
| |
| const time::milliseconds& |
| getExpirationPeriod() const |
| { |
| return m_expirationPeriod; |
| } |
| |
| Route& |
| setExpirationPeriod(const time::milliseconds& expirationPeriod) |
| { |
| m_expirationPeriod = expirationPeriod; |
| |
| m_hasInfiniteExpirationPeriod = m_expirationPeriod == INFINITE_EXPIRATION_PERIOD; |
| |
| m_wire.reset(); |
| return *this; |
| } |
| |
| bool |
| hasInfiniteExpirationPeriod() const |
| { |
| return m_hasInfiniteExpirationPeriod; |
| } |
| |
| template<bool T> |
| size_t |
| wireEncode(EncodingImpl<T>& block) const; |
| |
| const Block& |
| wireEncode() const; |
| |
| void |
| wireDecode(const Block& wire); |
| |
| private: |
| uint64_t m_faceId; |
| uint64_t m_origin; |
| uint64_t m_cost; |
| uint64_t m_flags; |
| time::milliseconds m_expirationPeriod; |
| bool m_hasInfiniteExpirationPeriod; |
| |
| mutable Block m_wire; |
| }; |
| |
| std::ostream& |
| operator<<(std::ostream& os, const Route& route); |
| |
| /** |
| * @ingroup management |
| * |
| * @brief Data abstraction for RIB entry |
| * |
| * A RIB entry contains one or more routes for the name prefix |
| * |
| * RibEntry := RIB-ENTRY-TYPE TLV-LENGTH |
| * Name |
| * Route+ |
| * |
| * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt |
| */ |
| class RibEntry |
| { |
| public: |
| class Error : public tlv::Error |
| { |
| public: |
| Error(const std::string& what) : tlv::Error(what) |
| { |
| } |
| }; |
| |
| typedef std::list<Route> RouteList; |
| typedef RouteList::const_iterator iterator; |
| |
| RibEntry(); |
| |
| explicit |
| RibEntry(const Block& block); |
| |
| const Name& |
| getName() const |
| { |
| return m_prefix; |
| } |
| |
| RibEntry& |
| setName(const Name& prefix) |
| { |
| m_prefix = prefix; |
| m_wire.reset(); |
| return *this; |
| } |
| |
| const std::list<Route>& |
| getRoutes() const |
| { |
| return m_routes; |
| } |
| |
| RibEntry& |
| addRoute(const Route& route) |
| { |
| m_routes.push_back(route); |
| m_wire.reset(); |
| return *this; |
| } |
| |
| RibEntry& |
| clearRoutes() |
| { |
| m_routes.clear(); |
| return *this; |
| } |
| |
| template<bool T> |
| size_t |
| wireEncode(EncodingImpl<T>& block) const; |
| |
| const Block& |
| wireEncode() const; |
| |
| void |
| wireDecode(const Block& wire); |
| |
| iterator |
| begin() const; |
| |
| iterator |
| end() const; |
| |
| private: |
| Name m_prefix; |
| RouteList m_routes; |
| |
| mutable Block m_wire; |
| }; |
| |
| inline RibEntry::iterator |
| RibEntry::begin() const |
| { |
| return m_routes.begin(); |
| } |
| |
| inline RibEntry::iterator |
| RibEntry::end() const |
| { |
| return m_routes.end(); |
| } |
| |
| std::ostream& |
| operator<<(std::ostream& os, const RibEntry& entry); |
| |
| } // namespace nfd |
| } // namespace ndn |
| |
| #endif // NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP |