laqinfan | 3573185 | 2017-08-08 06:17:39 -0500 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2018, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | **/ |
| 21 | |
| 22 | #ifndef NLSR_TLV_NEXTHOP_HPP |
| 23 | #define NLSR_TLV_NEXTHOP_HPP |
| 24 | |
| 25 | #include <ndn-cxx/util/time.hpp> |
| 26 | #include <ndn-cxx/encoding/block.hpp> |
| 27 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 28 | #include <ndn-cxx/encoding/tlv.hpp> |
| 29 | #include <ndn-cxx/name.hpp> |
| 30 | #include <boost/throw_exception.hpp> |
| 31 | |
| 32 | namespace nlsr { |
| 33 | namespace tlv { |
| 34 | |
| 35 | /*! \brief Data abstraction for Nexthop |
| 36 | * |
| 37 | * NextHop := NEXTHOP-TYPE TLV-LENGTH |
| 38 | * Uri |
| 39 | * Cost |
| 40 | * |
| 41 | * \sa https://redmine.named-data.net/projects/nlsr/wiki/Routing_Table_Dataset |
| 42 | */ |
| 43 | class NextHop |
| 44 | { |
| 45 | public: |
| 46 | class Error : public ndn::tlv::Error |
| 47 | { |
| 48 | public: |
| 49 | explicit |
| 50 | Error(const std::string& what) |
| 51 | : ndn::tlv::Error(what) |
| 52 | { |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | NextHop(); |
| 57 | |
| 58 | explicit |
| 59 | NextHop(const ndn::Block& block); |
| 60 | |
| 61 | const std::string& |
| 62 | getUri() const |
| 63 | { |
| 64 | return m_uri; |
| 65 | } |
| 66 | |
| 67 | NextHop& |
| 68 | setUri(const std::string& uri) |
| 69 | { |
| 70 | m_uri = uri; |
| 71 | m_wire.reset(); |
| 72 | return *this; |
| 73 | } |
| 74 | |
| 75 | double |
| 76 | getCost() const |
| 77 | { |
| 78 | return m_cost; |
| 79 | } |
| 80 | |
| 81 | NextHop& |
| 82 | setCost(double cost) |
| 83 | { |
| 84 | m_cost = cost; |
| 85 | m_wire.reset(); |
| 86 | return *this; |
| 87 | } |
| 88 | |
| 89 | template<ndn::encoding::Tag TAG> |
| 90 | size_t |
| 91 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 92 | |
| 93 | const ndn::Block& |
| 94 | wireEncode() const; |
| 95 | |
| 96 | void |
| 97 | wireDecode(const ndn::Block& wire); |
| 98 | |
| 99 | private: |
| 100 | std::string m_uri; |
| 101 | double m_cost; |
| 102 | |
| 103 | mutable ndn::Block m_wire; |
| 104 | }; |
| 105 | |
| 106 | std::ostream& |
| 107 | operator<<(std::ostream& os, const NextHop& nexthop); |
| 108 | |
| 109 | } // namespace tlv |
| 110 | } // namespace nlsr |
| 111 | |
| 112 | #endif // NLSR_TLV_NEXTHOP_HPP |