lsa-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, 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 "lsa.hpp"
26 
27 #include <ndn-cxx/util/time.hpp>
28 #include <ndn-cxx/encoding/block.hpp>
29 #include <ndn-cxx/encoding/encoding-buffer.hpp>
30 #include <ndn-cxx/encoding/tlv.hpp>
31 #include <ndn-cxx/name.hpp>
32 #include <boost/throw_exception.hpp>
33 
34 namespace nlsr {
35 namespace tlv {
36 
47 class LsaInfo
48 {
49 public:
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&
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
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&
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
114  {
115  return m_hasInfiniteExpirationPeriod;
116  }
117 
127  template<ndn::encoding::Tag TAG>
128  size_t
129  wireEncode(ndn::EncodingImpl<TAG>& block) const;
130 
139  const ndn::Block&
140  wireEncode() const;
141 
145  void
146  wireDecode(const ndn::Block& wire);
147 
148 private:
149  ndn::Name m_originRouter;
150  uint64_t m_sequenceNumber;
151  ndn::time::milliseconds m_expirationPeriod;
152  bool m_hasInfiniteExpirationPeriod;
153 
154  mutable ndn::Block m_wire;
155 };
156 
158 
159 std::ostream&
160 operator<<(std::ostream& os, const LsaInfo& lsaInfo);
161 
162 std::shared_ptr<LsaInfo>
163 makeLsaInfo(const Lsa& lsa);
164 
165 } // namespace tlv
166 } // namespace nlsr
167 
168 #endif // NLSR_TLV_LSA_INFO_HPP
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:28
LsaInfo & setSequenceNumber(uint64_t sequenceNumber)
Definition: lsa-info.hpp:86
LsaInfo & setExpirationPeriod(const ndn::time::milliseconds &expirationPeriod)
Definition: lsa-info.hpp:102
const ndn::time::milliseconds & getExpirationPeriod() const
Definition: lsa-info.hpp:96
std::shared_ptr< LsaInfo > makeLsaInfo(const Lsa &lsa)
Definition: lsa-info.cpp:170
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
Definition: lsa-info.cpp:78
const ndn::Name & getOriginRouter() const
Definition: lsa-info.hpp:66
Data abstraction for LsaInfo.
Definition: lsa-info.hpp:47
uint64_t getSequenceNumber() const
Definition: lsa-info.hpp:80
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
LsaInfo & setOriginRouter(const ndn::Name &name)
Definition: lsa-info.hpp:72
bool hasInfiniteExpirationPeriod() const
Definition: lsa-info.hpp:113
std::ostream & operator<<(std::ostream &os, const AdjacencyLsa &adjacencyLsa)
static const ndn::time::milliseconds INFINITE_EXPIRATION_PERIOD
Definition: lsa-info.hpp:93
Error(const std::string &what)
Definition: lsa-info.hpp:54
void wireDecode(const ndn::Block &wire)
Populate this object by decoding the one contained in the given block.
Definition: lsa-info.cpp:96
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(AdjacencyLsa)