blob: a5cf7bf23049362183ab3dd6f5d7f4ca36ec5de4 [file] [log] [blame]
Jiewen Tan7a56d1c2015-01-26 23:26:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, The University of Memphis,
4 * 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
31namespace nlsr {
32namespace tlv {
33
34/**
35 * @brief Data abstraction for LsaInfo
36 *
37 * LsaInfo := LSA-TYPE TLV-LENGTH
38 * OriginRouter
39 * SequenceNumber
40 * ExpirationPeriod?
41 *
42 * @sa http://redmine.named-data.net/projects/nlsr/wiki/LSDB_DataSet
43 */
44class LsaInfo
45{
46public:
47 class Error : public ndn::tlv::Error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : ndn::tlv::Error(what)
53 {
54 }
55 };
56
57 LsaInfo();
58
59 explicit
60 LsaInfo(const ndn::Block& block);
61
62 const ndn::Name&
63 getOriginRouter() const
64 {
65 return m_originRouter;
66 }
67
68 LsaInfo&
69 setOriginRouter(const ndn::Name& name)
70 {
71 m_originRouter = name;
72 m_wire.reset();
73 return *this;
74 }
75
76 uint64_t
77 getSequenceNumber() const
78 {
79 return m_sequenceNumber;
80 }
81
82 LsaInfo&
83 setSequenceNumber(uint64_t sequenceNumber)
84 {
85 m_sequenceNumber = sequenceNumber;
86 m_wire.reset();
87 return *this;
88 }
89
90 static const ndn::time::milliseconds INFINITE_EXPIRATION_PERIOD;
91
92 const ndn::time::milliseconds&
93 getExpirationPeriod() const
94 {
95 return m_expirationPeriod;
96 }
97
98 LsaInfo&
99 setExpirationPeriod(const ndn::time::milliseconds& expirationPeriod)
100 {
101 m_expirationPeriod = expirationPeriod;
102
103 m_hasInfiniteExpirationPeriod = (m_expirationPeriod == INFINITE_EXPIRATION_PERIOD);
104
105 m_wire.reset();
106 return *this;
107 }
108
109 bool
110 hasInfiniteExpirationPeriod() const
111 {
112 return m_hasInfiniteExpirationPeriod;
113 }
114
115 template<bool T>
116 size_t
117 wireEncode(ndn::EncodingImpl<T>& block) const;
118
119 const ndn::Block&
120 wireEncode() const;
121
122 void
123 wireDecode(const ndn::Block& wire);
124
125private:
126 ndn::Name m_originRouter;
127 uint64_t m_sequenceNumber;
128 ndn::time::milliseconds m_expirationPeriod;
129 bool m_hasInfiniteExpirationPeriod;
130
131 mutable ndn::Block m_wire;
132};
133
134std::ostream&
135operator<<(std::ostream& os, const LsaInfo& lsaInfo);
136
137} // namespace tlv
138} // namespace nlsr
139
140#endif // NLSR_TLV_LSA_INFO_HPP