blob: c39694b09e20c26d4d8256a36cb11739e5d44da3 [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_LSA_INFO_HPP
23#define NLSR_TLV_LSA_INFO_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
Jiewen Tana0497d82015-02-02 21:59:18 -080031#include "lsa.hpp"
32
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080033namespace nlsr {
Nick G97e34942016-07-11 14:46:27 -050034namespace tlv {
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080035
Nick G97e34942016-07-11 14:46:27 -050036/*!
37 \brief Data abstraction for LsaInfo
38
39 LsaInfo := LSA-TYPE TLV-LENGTH
40 OriginRouter
41 SequenceNumber
42 ExpirationPeriod?
43
44 \sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
Jiewen Tan7a56d1c2015-01-26 23:26:51 -080045 */
46class LsaInfo
47{
48public:
49 class Error : public ndn::tlv::Error
50 {
51 public:
52 explicit
53 Error(const std::string& what)
54 : ndn::tlv::Error(what)
55 {
56 }
57 };
58
59 LsaInfo();
60
61 explicit
62 LsaInfo(const ndn::Block& block);
63
64 const ndn::Name&
65 getOriginRouter() const
66 {
67 return m_originRouter;
68 }
69
70 LsaInfo&
71 setOriginRouter(const ndn::Name& name)
72 {
73 m_originRouter = name;
74 m_wire.reset();
75 return *this;
76 }
77
78 uint64_t
79 getSequenceNumber() const
80 {
81 return m_sequenceNumber;
82 }
83
84 LsaInfo&
85 setSequenceNumber(uint64_t sequenceNumber)
86 {
87 m_sequenceNumber = sequenceNumber;
88 m_wire.reset();
89 return *this;
90 }
91
92 static const ndn::time::milliseconds INFINITE_EXPIRATION_PERIOD;
93
94 const ndn::time::milliseconds&
95 getExpirationPeriod() const
96 {
97 return m_expirationPeriod;
98 }
99
100 LsaInfo&
101 setExpirationPeriod(const ndn::time::milliseconds& expirationPeriod)
102 {
103 m_expirationPeriod = expirationPeriod;
104
105 m_hasInfiniteExpirationPeriod = (m_expirationPeriod == INFINITE_EXPIRATION_PERIOD);
106
107 m_wire.reset();
108 return *this;
109 }
110
111 bool
112 hasInfiniteExpirationPeriod() const
113 {
114 return m_hasInfiniteExpirationPeriod;
115 }
116
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800117 template<ndn::encoding::Tag TAG>
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800118 size_t
Alexander Afanasyevf9f39102015-12-01 17:43:40 -0800119 wireEncode(ndn::EncodingImpl<TAG>& block) const;
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800120
121 const ndn::Block&
122 wireEncode() const;
123
124 void
125 wireDecode(const ndn::Block& wire);
126
127private:
128 ndn::Name m_originRouter;
129 uint64_t m_sequenceNumber;
130 ndn::time::milliseconds m_expirationPeriod;
131 bool m_hasInfiniteExpirationPeriod;
132
133 mutable ndn::Block m_wire;
134};
135
136std::ostream&
137operator<<(std::ostream& os, const LsaInfo& lsaInfo);
138
Jiewen Tana0497d82015-02-02 21:59:18 -0800139std::shared_ptr<LsaInfo>
140makeLsaInfo(const Lsa& lsa);
141
Jiewen Tan7a56d1c2015-01-26 23:26:51 -0800142} // namespace tlv
143} // namespace nlsr
144
145#endif // NLSR_TLV_LSA_INFO_HPP