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