blob: 217366a449ece818355fb9acc7bbfb096daeda8a [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_LSA_HPP
23#define NLSR_TLV_ADJACENCY_LSA_HPP
24
25#include "lsa-info.hpp"
26#include "adjacency.hpp"
27
28#include <ndn-cxx/util/time.hpp>
29#include <ndn-cxx/encoding/block.hpp>
30#include <ndn-cxx/encoding/encoding-buffer.hpp>
31#include <ndn-cxx/encoding/tlv.hpp>
32#include <ndn-cxx/name.hpp>
33
34#include <list>
35
36namespace nlsr {
Nick G97e34942016-07-11 14:46:27 -050037namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080038
Nick G97e34942016-07-11 14:46:27 -050039/*!
40 \brief Data abstraction for AdjacencyLsa
41
42 AdjacencyLsa := ADJACENCY-LSA-TYPE TLV-LENGTH
43 LsaInfo
44 Adjacency*
45
46 \sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080047 */
48class AdjacencyLsa
49{
50public:
51 class Error : public ndn::tlv::Error
52 {
53 public:
54 explicit
55 Error(const std::string& what)
56 : ndn::tlv::Error(what)
57 {
58 }
59 };
60
61 typedef std::list<Adjacency> AdjacencyList;
62 typedef AdjacencyList::const_iterator iterator;
63
64 AdjacencyLsa();
65
66 explicit
67 AdjacencyLsa(const ndn::Block& block);
68
69 const LsaInfo&
70 getLsaInfo() const
71 {
72 return m_lsaInfo;
73 }
74
75 AdjacencyLsa&
76 setLsaInfo(const LsaInfo& lsaInfo)
77 {
78 m_lsaInfo = lsaInfo;
79 m_wire.reset();
80 return *this;
81 }
82
83 bool
84 hasAdjacencies() const
85 {
86 return m_hasAdjacencies;
87 }
88
89 const std::list<Adjacency>&
90 getAdjacencies() const
91 {
92 return m_adjacencies;
93 }
94
95 AdjacencyLsa&
96 addAdjacency(const Adjacency& adjacency)
97 {
98 m_adjacencies.push_back(adjacency);
99 m_wire.reset();
100 m_hasAdjacencies = true;
101 return *this;
102 }
103
104 AdjacencyLsa&
105 clearAdjacencies()
106 {
107 m_adjacencies.clear();
108 m_hasAdjacencies = false;
109 return *this;
110 }
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
116 const ndn::Block&
117 wireEncode() const;
118
119 void
120 wireDecode(const ndn::Block& wire);
121
122 iterator
123 begin() const;
124
125 iterator
126 end() const;
127
128private:
129 LsaInfo m_lsaInfo;
130 bool m_hasAdjacencies;
131 AdjacencyList m_adjacencies;
132
133 mutable ndn::Block m_wire;
134};
135
136inline AdjacencyLsa::iterator
137AdjacencyLsa::begin() const
138{
139 return m_adjacencies.begin();
140}
141
142inline AdjacencyLsa::iterator
143AdjacencyLsa::end() const
144{
145 return m_adjacencies.end();
146}
147
148std::ostream&
149operator<<(std::ostream& os, const AdjacencyLsa& adjacencyLsa);
150
151} // namespace tlv
152} // namespace nlsr
153
154#endif // NLSR_TLV_ADJACENCY_LSA_HPP