blob: fb494e64f2e103f7e1e195f77d3a6d12b7f6998c [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_LSDB_STATUS_HPP
23#define NLSR_TLV_LSDB_STATUS_HPP
24
25#include "adjacency-lsa.hpp"
26#include "coordinate-lsa.hpp"
27#include "name-lsa.hpp"
28
29#include <ndn-cxx/util/time.hpp>
30#include <ndn-cxx/encoding/block.hpp>
31#include <ndn-cxx/encoding/encoding-buffer.hpp>
32#include <ndn-cxx/encoding/tlv.hpp>
33#include <ndn-cxx/name.hpp>
34
35#include <list>
36
37namespace nlsr {
Nick G97e34942016-07-11 14:46:27 -050038namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080039
Nick G97e34942016-07-11 14:46:27 -050040/*!
41 \brief Data abstraction for LsdbStatus
42
43 LsdbStatus := LSDB-STATUS-TYPE TLV-LENGTH
44 AdjacencyLsa*
45 CoordinateLsa*
46 NameLsa*
47
Nick Gordond0a7df32017-05-30 16:44:34 -050048 \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080049 */
50class LsdbStatus
51{
52public:
53 class Error : public ndn::tlv::Error
54 {
55 public:
56 explicit
57 Error(const std::string& what)
58 : ndn::tlv::Error(what)
59 {
60 }
61 };
62
63 typedef std::list<AdjacencyLsa> AdjacencyLsaList;
64 typedef std::list<CoordinateLsa> CoordinateLsaList;
65 typedef std::list<NameLsa> NameLsaList;
66
67 LsdbStatus();
68
69 explicit
70 LsdbStatus(const ndn::Block& block);
71
72 const std::list<AdjacencyLsa>&
73 getAdjacencyLsas() const
74 {
75 return m_adjacencyLsas;
76 }
77
78 LsdbStatus&
79 addAdjacencyLsa(const AdjacencyLsa& adjacencyLsa)
80 {
81 m_adjacencyLsas.push_back(adjacencyLsa);
82 m_wire.reset();
83 m_hasAdjacencyLsas = true;
84 return *this;
85 }
86
87 LsdbStatus&
88 clearAdjacencyLsas()
89 {
90 m_adjacencyLsas.clear();
91 m_hasAdjacencyLsas = false;
92 return *this;
93 }
94
95 bool
96 hasAdjacencyLsas()
97 {
98 return m_hasAdjacencyLsas;
99 }
100
101 const std::list<CoordinateLsa>&
102 getCoordinateLsas() const
103 {
104 return m_coordinateLsas;
105 }
106
107 LsdbStatus&
108 addCoordinateLsa(const CoordinateLsa& coordinateLsa)
109 {
110 m_coordinateLsas.push_back(coordinateLsa);
111 m_wire.reset();
112 m_hasCoordinateLsas = true;
113 return *this;
114 }
115
116 LsdbStatus&
117 clearCoordinateLsas()
118 {
119 m_coordinateLsas.clear();
120 m_hasCoordinateLsas = false;
121 return *this;
122 }
123
124 bool
125 hasCoordinateLsas()
126 {
127 return m_hasCoordinateLsas;
128 }
129
130 const std::list<NameLsa>&
131 getNameLsas() const
132 {
133 return m_nameLsas;
134 }
135
136 LsdbStatus&
137 addNameLsa(const NameLsa& nameLsa)
138 {
139 m_nameLsas.push_back(nameLsa);
140 m_wire.reset();
141 m_hasNameLsas = true;
142 return *this;
143 }
144
145 LsdbStatus&
146 clearNameLsas()
147 {
148 m_nameLsas.clear();
149 m_hasNameLsas = false;
150 return *this;
151 }
152
153 bool
154 hasNameLsas()
155 {
156 return m_hasNameLsas;
157 }
158
Nick Gordond0a7df32017-05-30 16:44:34 -0500159 /*! \brief Encodes the LSA objects and some info for each LSA using
160 * the method in TAG.
161 *
162 * This function will TLV-format the LSA objects and some LSA
163 * info using the implementation specified by TAG. Usually this is
164 * called with an estimator first to guess how long the buffer needs
165 * to be, then with an encoder to do the real work. This process is
166 * automated by the other wireEncode.
167 * \sa LsdbStatus::wireEncode()
168 */
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800169 template<ndn::encoding::Tag TAG>
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800170 size_t
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800171 wireEncode(ndn::EncodingImpl<TAG>& block) const;
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800172
Nick Gordond0a7df32017-05-30 16:44:34 -0500173 /*! \brief Create a TLV encoding of this object.
174 *
175 * Create a block containing the TLV encoding of this object. That
176 * involves two steps: estimating the size that the information will
177 * take up, and then creating a buffer of that size and encoding the
178 * information into it. Both steps are accomplished by
179 * LsdbStatus::wireEncode(ndn::EncodingImpl<TAG>&)
180 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800181 const ndn::Block&
182 wireEncode() const;
183
Nick Gordond0a7df32017-05-30 16:44:34 -0500184 /*! \brief Populate this object by decoding the one contained in the
185 * given block.
186 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800187 void
188 wireDecode(const ndn::Block& wire);
189
190private:
191 AdjacencyLsaList m_adjacencyLsas;
192 CoordinateLsaList m_coordinateLsas;
193 NameLsaList m_nameLsas;
194
195 bool m_hasAdjacencyLsas;
196 bool m_hasCoordinateLsas;
197 bool m_hasNameLsas;
198
199 mutable ndn::Block m_wire;
200};
201
202std::ostream&
203operator<<(std::ostream& os, const LsdbStatus& lsdbStatus);
204
205} // namespace tlv
206} // namespace nlsr
207
208#endif // NLSR_TLV_LSDB_STATUS_HPP