lsa-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
157 std::ostream&
158 operator<<(std::ostream& os, const LsaInfo& lsaInfo);
159 
160 std::shared_ptr<LsaInfo>
161 makeLsaInfo(const Lsa& lsa);
162 
163 } // namespace tlv
164 } // namespace nlsr
165 
166 #endif // NLSR_TLV_LSA_INFO_HPP
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:27
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:174
const ndn::Block & wireEncode() const
Create a TLV encoding of this object.
Definition: lsa-info.cpp:82
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-2017, 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:100