blob: b144ae291f95767c4e76574e7540c8f9adcaa319 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
laqinfan35731852017-08-08 06:17:39 -05003 * 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/>.
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
laqinfan35731852017-08-08 06:17:39 -050040/*! \brief Data abstraction for LsdbStatus
41 *
42 * LsdbStatus := LSDB-STATUS-TYPE TLV-LENGTH
43 * AdjacencyLsa*
44 * CoordinateLsa*
45 * NameLsa*
46 *
47 * \sa https://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080048 */
49class LsdbStatus
50{
51public:
52 class Error : public ndn::tlv::Error
53 {
54 public:
55 explicit
56 Error(const std::string& what)
57 : ndn::tlv::Error(what)
58 {
59 }
60 };
61
62 typedef std::list<AdjacencyLsa> AdjacencyLsaList;
63 typedef std::list<CoordinateLsa> CoordinateLsaList;
64 typedef std::list<NameLsa> NameLsaList;
65
66 LsdbStatus();
67
68 explicit
69 LsdbStatus(const ndn::Block& block);
70
71 const std::list<AdjacencyLsa>&
72 getAdjacencyLsas() const
73 {
74 return m_adjacencyLsas;
75 }
76
77 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -050078 addAdjacencyLsa(const AdjacencyLsa& adjacencyLsa);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080079
80 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -050081 clearAdjacencyLsas();
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080082
83 bool
84 hasAdjacencyLsas()
85 {
86 return m_hasAdjacencyLsas;
87 }
88
89 const std::list<CoordinateLsa>&
90 getCoordinateLsas() const
91 {
92 return m_coordinateLsas;
93 }
94
95 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -050096 addCoordinateLsa(const CoordinateLsa& coordinateLsa);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080097
98 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -050099 clearCoordinateLsas();
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800100
101 bool
102 hasCoordinateLsas()
103 {
104 return m_hasCoordinateLsas;
105 }
106
107 const std::list<NameLsa>&
108 getNameLsas() const
109 {
110 return m_nameLsas;
111 }
112
113 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -0500114 addNameLsa(const NameLsa& nameLsa);
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800115
116 LsdbStatus&
laqinfan35731852017-08-08 06:17:39 -0500117 clearNameLsas();
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800118
119 bool
120 hasNameLsas()
121 {
122 return m_hasNameLsas;
123 }
124
Nick Gordond0a7df32017-05-30 16:44:34 -0500125 /*! \brief Encodes the LSA objects and some info for each LSA using
126 * the method in TAG.
127 *
128 * This function will TLV-format the LSA objects and some LSA
129 * info using the implementation specified by TAG. Usually this is
130 * called with an estimator first to guess how long the buffer needs
131 * to be, then with an encoder to do the real work. This process is
132 * automated by the other wireEncode.
133 * \sa LsdbStatus::wireEncode()
134 */
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800135 template<ndn::encoding::Tag TAG>
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800136 size_t
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800137 wireEncode(ndn::EncodingImpl<TAG>& block) const;
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800138
Nick Gordond0a7df32017-05-30 16:44:34 -0500139 /*! \brief Create a TLV encoding of this object.
140 *
141 * Create a block containing the TLV encoding of this object. That
142 * involves two steps: estimating the size that the information will
143 * take up, and then creating a buffer of that size and encoding the
144 * information into it. Both steps are accomplished by
145 * LsdbStatus::wireEncode(ndn::EncodingImpl<TAG>&)
146 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800147 const ndn::Block&
148 wireEncode() const;
149
Nick Gordond0a7df32017-05-30 16:44:34 -0500150 /*! \brief Populate this object by decoding the one contained in the
151 * given block.
152 */
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800153 void
154 wireDecode(const ndn::Block& wire);
155
156private:
157 AdjacencyLsaList m_adjacencyLsas;
158 CoordinateLsaList m_coordinateLsas;
159 NameLsaList m_nameLsas;
160
161 bool m_hasAdjacencyLsas;
162 bool m_hasCoordinateLsas;
163 bool m_hasNameLsas;
164
165 mutable ndn::Block m_wire;
166};
167
168std::ostream&
169operator<<(std::ostream& os, const LsdbStatus& lsdbStatus);
170
171} // namespace tlv
172} // namespace nlsr
173
174#endif // NLSR_TLV_LSDB_STATUS_HPP