Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | c6a8522 | 2017-01-03 16:54:34 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 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_COORDINATE_LSA_HPP |
| 23 | #define NLSR_TLV_COORDINATE_LSA_HPP |
| 24 | |
| 25 | #include "lsa-info.hpp" |
| 26 | |
| 27 | #include <ndn-cxx/util/time.hpp> |
| 28 | #include <ndn-cxx/encoding/block.hpp> |
| 29 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 30 | #include <ndn-cxx/encoding/tlv.hpp> |
| 31 | #include <ndn-cxx/name.hpp> |
| 32 | |
| 33 | namespace nlsr { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 34 | namespace tlv { |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 35 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 36 | /*! |
| 37 | \brief Data abstraction for CoordinateLsa |
| 38 | |
| 39 | CoordinateLsa := COORDINATE-LSA-TYPE TLV-LENGTH |
| 40 | LsaInfo |
| 41 | HyperbolicRadius |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 42 | HyperbolicAngle+ |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 43 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 44 | \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 45 | */ |
| 46 | class CoordinateLsa |
| 47 | { |
| 48 | public: |
| 49 | class Error : public ndn::tlv::Error |
| 50 | { |
| 51 | public: |
| 52 | explicit |
| 53 | Error(const std::string& what) |
| 54 | : ndn::tlv::Error(what) |
| 55 | { |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | CoordinateLsa(); |
| 60 | |
| 61 | explicit |
| 62 | CoordinateLsa(const ndn::Block& block); |
| 63 | |
| 64 | const LsaInfo& |
| 65 | getLsaInfo() const |
| 66 | { |
| 67 | return m_lsaInfo; |
| 68 | } |
| 69 | |
| 70 | CoordinateLsa& |
| 71 | setLsaInfo(const LsaInfo& lsaInfo) |
| 72 | { |
| 73 | m_lsaInfo = lsaInfo; |
| 74 | m_wire.reset(); |
| 75 | return *this; |
| 76 | } |
| 77 | |
| 78 | double |
| 79 | getHyperbolicRadius() const |
| 80 | { |
| 81 | return m_hyperbolicRadius; |
| 82 | } |
| 83 | |
| 84 | CoordinateLsa& |
| 85 | setHyperbolicRadius(double hyperbolicRadius) |
| 86 | { |
| 87 | m_hyperbolicRadius = hyperbolicRadius; |
| 88 | m_wire.reset(); |
| 89 | return *this; |
| 90 | } |
| 91 | |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 92 | const std::vector<double> |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 93 | getHyperbolicAngle() const |
| 94 | { |
| 95 | return m_hyperbolicAngle; |
| 96 | } |
| 97 | |
| 98 | CoordinateLsa& |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 99 | setHyperbolicAngle(const std::vector<double>& hyperbolicAngle) |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 100 | { |
| 101 | m_hyperbolicAngle = hyperbolicAngle; |
| 102 | m_wire.reset(); |
| 103 | return *this; |
| 104 | } |
| 105 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame^] | 106 | /*! \brief Encodes the hyperbolic coordinates and some info using the method in TAG. |
| 107 | * |
| 108 | * This function will TLV-format the hyperbolic coordinates objects and some LSA |
| 109 | * info using the implementation speciifed by TAG. Usually this is |
| 110 | * called with an estimator first to guess how long the buffer needs |
| 111 | * to be, then with an encoder to do the real work. This process is |
| 112 | * automated by the other wireEncode. |
| 113 | * \sa CoordinateLsa::wireEncode() |
| 114 | */ |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 115 | template<ndn::encoding::Tag TAG> |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 116 | size_t |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 117 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 118 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame^] | 119 | /*! \brief Create a TLV encoding of this object. |
| 120 | * |
| 121 | * Create a block containing the TLV encoding of this object. That |
| 122 | * involves two steps: estimating the size that the information will |
| 123 | * take up, and then creating a buffer of that size and encoding the |
| 124 | * information into it. Both steps are accomplished by |
| 125 | * CoordinateLsa::wireEncode(ndn::EncodingImpl<TAG>&) |
| 126 | */ |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 127 | const ndn::Block& |
| 128 | wireEncode() const; |
| 129 | |
Nick Gordon | d0a7df3 | 2017-05-30 16:44:34 -0500 | [diff] [blame^] | 130 | /*! \brief Populate this object by decoding the one contained in the |
| 131 | * given block. |
| 132 | */ |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 133 | void |
| 134 | wireDecode(const ndn::Block& wire); |
| 135 | |
| 136 | private: |
| 137 | LsaInfo m_lsaInfo; |
| 138 | double m_hyperbolicRadius; |
Muktadir R Chowdhury | b00dc2a | 2016-11-05 10:48:58 -0600 | [diff] [blame] | 139 | std::vector<double> m_hyperbolicAngle; |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 140 | |
| 141 | mutable ndn::Block m_wire; |
| 142 | }; |
| 143 | |
| 144 | std::ostream& |
| 145 | operator<<(std::ostream& os, const CoordinateLsa& coordinateLsa); |
| 146 | |
| 147 | } // namespace tlv |
| 148 | } // namespace nlsr |
| 149 | |
| 150 | #endif // NLSR_TLV_COORDINATE_LSA_HPP |