blob: 4046e8f0615cccf16c951a79cc80dab9e4a3cac3 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev67758b12018-03-06 18:36:44 -05002/*
3 * Copyright (c) 2014-2018, The University of Memphis,
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08004 * 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/>.
Alexander Afanasyev67758b12018-03-06 18:36:44 -050020 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080021
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
31namespace nlsr {
Nick G97e34942016-07-11 14:46:27 -050032namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080033
Nick G97e34942016-07-11 14:46:27 -050034/*!
35 \brief Data abstraction for Adjacency
36
37 Adjacency := ADJACENCY-TYPE TLV-LENGTH
38 Name
39 Uri
40 Cost
41
Nick Gordond0a7df32017-05-30 16:44:34 -050042 \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080043 */
44class Adjacency
45{
46public:
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
Nick Gordond0a7df32017-05-30 16:44:34 -0500104 /*! \brief TLV-encode this object using the implementation in from TAG.
105 *
106 * This method TLV-encodes this Adjacency object using the
107 * implementation given by TAG. Usually two implementations are
108 * provided: a size estimator and a real encoder, which are used in
109 * sequence to allocate the necessary block size and then encode it.
110 * \sa Adjacency::wireEncode()
111 */
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800112 template<ndn::encoding::Tag TAG>
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800113 size_t
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800114 wireEncode(ndn::EncodingImpl<TAG>& block) const;
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800115
Nick Gordond0a7df32017-05-30 16:44:34 -0500116 /*! \brief Create a TLV encoding of this object.
117 *
118 * This function automates the process of guessing the necessary
119 * size of a block containing this object, and then creating a block
120 * and putting the TLV encoding into it.
121 * \sa Adjacency::wireEncode(ndn::EncodingImpl<TAG>&)
122 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800123 const ndn::Block&
124 wireEncode() const;
125
Nick Gordond0a7df32017-05-30 16:44:34 -0500126 /*! \brief Populate this object by decoding the object contained in
127 * the given block.
128 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800129 void
130 wireDecode(const ndn::Block& wire);
131
132private:
133 ndn::Name m_name;
134 std::string m_uri;
135 uint64_t m_cost;
136
137 mutable ndn::Block m_wire;
138};
139
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500140NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Adjacency);
141
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800142std::ostream&
143operator<<(std::ostream& os, const Adjacency& adjacency);
144
145} // namespace tlv
146} // namespace nlsr
147
148#endif // NLSR_TLV_ADJACENCY_HPP