NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
data.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_DATA_HPP
23 #define NDN_DATA_HPP
24 
25 #include "meta-info.hpp"
26 #include "name.hpp"
27 #include "packet-base.hpp"
28 #include "signature.hpp"
29 #include "encoding/block.hpp"
30 
31 namespace ndn {
32 
35 class Data : public PacketBase, public enable_shared_from_this<Data>
36 {
37 public:
38  class Error : public tlv::Error
39  {
40  public:
41  explicit
42  Error(const std::string& what)
43  : tlv::Error(what)
44  {
45  }
46  };
47 
52  explicit
53  Data(const Name& name = Name());
54 
59  explicit
60  Data(const Block& wire);
61 
69  template<encoding::Tag TAG>
70  size_t
71  wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const;
72 
89  const Block&
90  wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const;
91 
94  const Block&
95  wireEncode() const;
96 
99  void
100  wireDecode(const Block& wire);
101 
104  bool
105  hasWire() const
106  {
107  return m_wire.hasWire();
108  }
109 
114  const Name&
115  getFullName() const;
116 
117 public: // Data fields
120  const Name&
121  getName() const
122  {
123  return m_name;
124  }
125 
129  Data&
130  setName(const Name& name);
131 
134  const MetaInfo&
135  getMetaInfo() const
136  {
137  return m_metaInfo;
138  }
139 
143  Data&
144  setMetaInfo(const MetaInfo& metaInfo);
145 
151  const Block&
152  getContent() const;
153 
161  Data&
162  setContent(const Block& block);
163 
169  Data&
170  setContent(const uint8_t* value, size_t valueSize);
171 
176  Data&
177  setContent(const ConstBufferPtr& value);
178 
181  const Signature&
182  getSignature() const
183  {
184  return m_signature;
185  }
186 
190  Data&
191  setSignature(const Signature& signature);
192 
196  Data&
197  setSignatureValue(const Block& value);
198 
199 public: // MetaInfo fields
200  uint32_t
202  {
203  return m_metaInfo.getType();
204  }
205 
206  Data&
207  setContentType(uint32_t type);
208 
209  const time::milliseconds&
211  {
212  return m_metaInfo.getFreshnessPeriod();
213  }
214 
215  Data&
216  setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
217 
218  const name::Component&
220  {
221  return m_metaInfo.getFinalBlockId();
222  }
223 
224  Data&
225  setFinalBlockId(const name::Component& finalBlockId);
226 
227 protected:
231  void
232  resetWire();
233 
234 private:
235  Name m_name;
236  MetaInfo m_metaInfo;
237  Block m_content;
238  Signature m_signature;
239 
240  mutable Block m_wire;
241  mutable Name m_fullName;
242 };
243 
244 #ifndef DOXYGEN
245 extern template size_t
246 Data::wireEncode<encoding::EncoderTag>(EncodingBuffer&, bool) const;
247 
248 extern template size_t
249 Data::wireEncode<encoding::EstimatorTag>(EncodingEstimator&, bool) const;
250 #endif
251 
252 std::ostream&
253 operator<<(std::ostream& os, const Data& data);
254 
255 bool
256 operator==(const Data& lhs, const Data& rhs);
257 
258 inline bool
259 operator!=(const Data& lhs, const Data& rhs)
260 {
261  return !(lhs == rhs);
262 }
263 
264 } // namespace ndn
265 
266 #endif // NDN_DATA_HPP
Error(const std::string &what)
Definition: data.hpp:42
Data & setContentType(uint32_t type)
Definition: data.cpp:241
Copyright (c) 2011-2015 Regents of the University of California.
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: data.cpp:122
const time::milliseconds & getFreshnessPeriod() const
Definition: data.hpp:210
Data & setSignature(const Signature &signature)
Set Signature.
Definition: data.cpp:225
uint32_t getContentType() const
Definition: data.hpp:201
Data & setName(const Name &name)
Set name.
Definition: data.cpp:169
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:274
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
Data(const Name &name=Name())
Create a new Data with the given name and empty Content.
Definition: data.cpp:35
Data & setContent(const Block &block)
Set Content from a block.
Definition: data.cpp:194
const Signature & getSignature() const
Get Signature.
Definition: data.hpp:182
void resetWire()
Clear wire encoding and cached FullName.
Definition: data.cpp:162
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
const MetaInfo & getMetaInfo() const
Get MetaInfo.
Definition: data.hpp:135
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:259
Data & setFreshnessPeriod(const time::milliseconds &freshnessPeriod)
Definition: data.cpp:249
Data & setSignatureValue(const Block &value)
Set SignatureValue.
Definition: data.cpp:233
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:58
base class to allow simple management of packet tags
Definition: packet-base.hpp:31
Represents an absolute name.
Definition: name.hpp:42
const Block & wireEncode() const
Encode to a wire format.
Definition: data.cpp:106
const Name & getName() const
Get name.
Definition: data.hpp:121
Component holds a read-only name component value.
const Block & getContent() const
Get Content.
Definition: data.cpp:185
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:265
Data & setMetaInfo(const MetaInfo &metaInfo)
Set MetaInfo.
Definition: data.cpp:177
const Name & getFullName() const
Get full name including implicit digest.
Definition: data.cpp:148
Data & setFinalBlockId(const name::Component &finalBlockId)
Definition: data.cpp:257
Represents a Data packet.
Definition: data.hpp:35
const name::Component & getFinalBlockId() const
Definition: data.hpp:219
bool hasWire() const
Check if already has wire.
Definition: data.hpp:105
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
EncodingImpl< EstimatorTag > EncodingEstimator
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:89