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_ADJACENCY_HPP |
| 23 | #define NLSR_TLV_ADJACENCY_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 | |
| 31 | namespace nlsr { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 32 | namespace tlv { |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 33 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 34 | /*! |
| 35 | \brief Data abstraction for Adjacency |
| 36 | |
| 37 | Adjacency := ADJACENCY-TYPE TLV-LENGTH |
| 38 | Name |
| 39 | Uri |
| 40 | Cost |
| 41 | |
| 42 | \sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 43 | */ |
| 44 | class Adjacency |
| 45 | { |
| 46 | public: |
| 47 | class Error : public ndn::tlv::Error |
| 48 | { |
| 49 | public: |
| 50 | explicit |
| 51 | Error(const std::string& what) |
| 52 | : ndn::tlv::Error(what) |
| 53 | { |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | Adjacency(); |
| 58 | |
| 59 | explicit |
| 60 | Adjacency(const ndn::Block& block); |
| 61 | |
| 62 | const ndn::Name& |
| 63 | getName() const |
| 64 | { |
| 65 | return m_name; |
| 66 | } |
| 67 | |
| 68 | Adjacency& |
| 69 | setName(const ndn::Name& name) |
| 70 | { |
| 71 | m_name = name; |
| 72 | m_wire.reset(); |
| 73 | return *this; |
| 74 | } |
| 75 | |
| 76 | const std::string& |
| 77 | getUri() const |
| 78 | { |
| 79 | return m_uri; |
| 80 | } |
| 81 | |
| 82 | Adjacency& |
| 83 | setUri(const std::string& uri) |
| 84 | { |
| 85 | m_uri = uri; |
| 86 | m_wire.reset(); |
| 87 | return *this; |
| 88 | } |
| 89 | |
| 90 | uint64_t |
| 91 | getCost() const |
| 92 | { |
| 93 | return m_cost; |
| 94 | } |
| 95 | |
| 96 | Adjacency& |
| 97 | setCost(uint64_t cost) |
| 98 | { |
| 99 | m_cost = cost; |
| 100 | m_wire.reset(); |
| 101 | return *this; |
| 102 | } |
| 103 | |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 104 | template<ndn::encoding::Tag TAG> |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 105 | size_t |
Alexander Afanasyev | f9f3910 | 2015-12-01 17:43:40 -0800 | [diff] [blame] | 106 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
Jiewen Tan | 7a56d1c | 2015-01-26 23:26:51 -0800 | [diff] [blame] | 107 | |
| 108 | const ndn::Block& |
| 109 | wireEncode() const; |
| 110 | |
| 111 | void |
| 112 | wireDecode(const ndn::Block& wire); |
| 113 | |
| 114 | private: |
| 115 | ndn::Name m_name; |
| 116 | std::string m_uri; |
| 117 | uint64_t m_cost; |
| 118 | |
| 119 | mutable ndn::Block m_wire; |
| 120 | }; |
| 121 | |
| 122 | std::ostream& |
| 123 | operator<<(std::ostream& os, const Adjacency& adjacency); |
| 124 | |
| 125 | } // namespace tlv |
| 126 | } // namespace nlsr |
| 127 | |
| 128 | #endif // NLSR_TLV_ADJACENCY_HPP |