blob: 2e5dec70b9f8596021f2c4737dae122d2f424da1 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, 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/>.
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
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
140std::ostream&
141operator<<(std::ostream& os, const Adjacency& adjacency);
142
143} // namespace tlv
144} // namespace nlsr
145
146#endif // NLSR_TLV_ADJACENCY_HPP