blob: c911cfdf6e9967ffad042fa1702ba211ac6899b4 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Muktadir R Chowdhury800833b2016-07-29 13:43:59 -05003 * Copyright (c) 2014-2016, 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
48 \sa http://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
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800159 template<ndn::encoding::Tag TAG>
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800160 size_t
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800161 wireEncode(ndn::EncodingImpl<TAG>& block) const;
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800162
163 const ndn::Block&
164 wireEncode() const;
165
166 void
167 wireDecode(const ndn::Block& wire);
168
169private:
170 AdjacencyLsaList m_adjacencyLsas;
171 CoordinateLsaList m_coordinateLsas;
172 NameLsaList m_nameLsas;
173
174 bool m_hasAdjacencyLsas;
175 bool m_hasCoordinateLsas;
176 bool m_hasNameLsas;
177
178 mutable ndn::Block m_wire;
179};
180
181std::ostream&
182operator<<(std::ostream& os, const LsdbStatus& lsdbStatus);
183
184} // namespace tlv
185} // namespace nlsr
186
187#endif // NLSR_TLV_LSDB_STATUS_HPP