NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
22 #ifndef NDN_DATA_HPP
23 #define NDN_DATA_HPP
24 
25 #include "common.hpp"
26 #include "name.hpp"
27 #include "encoding/block.hpp"
28 
29 #include "signature.hpp"
30 #include "meta-info.hpp"
31 #include "key-locator.hpp"
32 #include "lp/tags.hpp"
33 #include "tag-host.hpp"
34 
35 namespace ndn {
36 
39 class Data : public TagHost, public enable_shared_from_this<Data>
40 {
41 public:
42  class Error : public tlv::Error
43  {
44  public:
45  explicit
46  Error(const std::string& what)
47  : tlv::Error(what)
48  {
49  }
50  };
51 
62  Data();
63 
76  Data(const Name& name);
77 
88  explicit
89  Data(const Block& wire);
90 
100  template<encoding::Tag TAG>
101  size_t
102  wireEncode(EncodingImpl<TAG>& encoder, bool wantUnsignedPortionOnly = false) const;
103 
107  const Block&
108  wireEncode() const;
109 
129  const Block&
130  wireEncode(EncodingBuffer& encoder, const Block& signatureValue) const;
131 
135  void
136  wireDecode(const Block& wire);
137 
141  bool
142  hasWire() const;
143 
145 
149  const Name&
150  getName() const;
151 
157  Data&
158  setName(const Name& name);
159 
160  //
161 
168  const Name&
169  getFullName() const;
170 
174  const MetaInfo&
175  getMetaInfo() const;
176 
182  Data&
183  setMetaInfo(const MetaInfo& metaInfo);
184 
185  //
186 
190  // MetaInfo proxy methods
191 
192  uint32_t
193  getContentType() const;
194 
195  Data&
196  setContentType(uint32_t type);
197 
198  //
199 
200  const time::milliseconds&
201  getFreshnessPeriod() const;
202 
203  Data&
204  setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
205 
206  //
207 
208  const name::Component&
209  getFinalBlockId() const;
210 
211  Data&
212  setFinalBlockId(const name::Component& finalBlockId);
213 
214  //
218 
225  const Block&
226  getContent() const;
227 
236  Data&
237  setContent(const uint8_t* buffer, size_t bufferSize);
238 
254  Data&
255  setContent(const Block& block);
256 
268  Data&
269  setContent(const ConstBufferPtr& contentValue);
270 
271  //
272 
273  const Signature&
274  getSignature() const;
275 
280  Data&
281  setSignature(const Signature& signature);
282 
283  Data&
284  setSignatureValue(const Block& value);
285 
287 
288 #ifdef NDN_LP_KEEP_LOCAL_CONTROL_HEADER
289 
291  DEPRECATED(
293  getLocalControlHeader());
294 
297  DEPRECATED(
299  getLocalControlHeader() const);
300 
303  DEPRECATED(
304  uint64_t
305  getIncomingFaceId() const);
306 
309  DEPRECATED(
310  Data&
311  setIncomingFaceId(uint64_t incomingFaceId));
312 
315  DEPRECATED(
317  getCachingPolicy() const);
318 
321  DEPRECATED(
322  Data&
323  setCachingPolicy(lp::LocalControlHeaderFacade::CachingPolicy cachingPolicy));
324 #endif // NDN_LP_KEEP_LOCAL_CONTROL_HEADER
325 
326 public: // EqualityComparable concept
327  bool
328  operator==(const Data& other) const;
329 
330  bool
331  operator!=(const Data& other) const;
332 
333 protected:
337  void
338  onChanged();
339 
340 private:
341  Name m_name;
342  MetaInfo m_metaInfo;
343  mutable Block m_content;
344  Signature m_signature;
345 
346  mutable Block m_wire;
347  mutable Name m_fullName;
348 };
349 
350 std::ostream&
351 operator<<(std::ostream& os, const Data& data);
352 
353 inline bool
355 {
356  return m_wire.hasWire();
357 }
358 
359 inline const Name&
361 {
362  return m_name;
363 }
364 
365 inline const MetaInfo&
367 {
368  return m_metaInfo;
369 }
370 
371 inline uint32_t
373 {
374  return m_metaInfo.getType();
375 }
376 
377 inline const time::milliseconds&
379 {
380  return m_metaInfo.getFreshnessPeriod();
381 }
382 
383 inline const name::Component&
385 {
386  return m_metaInfo.getFinalBlockId();
387 }
388 
389 inline const Signature&
391 {
392  return m_signature;
393 }
394 
395 } // namespace ndn
396 
397 #endif
Error(const std::string &what)
Definition: data.hpp:46
const Block & wireEncode() const
Encode to a wire format.
Definition: data.cpp:119
Data & setContentType(uint32_t type)
Definition: data.cpp:203
Copyright (c) 2011-2015 Regents of the University of California.
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: data.cpp:135
const Block & getContent() const
Get content Block.
Definition: data.cpp:230
Data()
Create an empty Data object.
Definition: data.cpp:35
Data & setSignature(const Signature &signature)
Set the signature to a copy of the given signature.
Definition: data.cpp:275
Base class to store tag information (e.g., inside Interest and Data packets)
Definition: tag-host.hpp:34
Data & setName(const Name &name)
Set name to a copy of the given Name.
Definition: data.cpp:170
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:360
const name::Component & getFinalBlockId() const
Definition: data.hpp:384
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:320
Data & setContent(const uint8_t *buffer, size_t bufferSize)
Set the content from the buffer (buffer will be copied)
Definition: data.cpp:241
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
bool operator!=(const Data &other) const
Definition: data.cpp:314
bool operator==(const Data &other) const
Definition: data.cpp:305
Copyright (c) 2013-2015 Regents of the University of California.
Data & setFreshnessPeriod(const time::milliseconds &freshnessPeriod)
Definition: data.cpp:212
void onChanged()
Clear the wire encoding.
Definition: data.cpp:293
Data & setSignatureValue(const Block &value)
Definition: data.cpp:284
EncodingImpl< EncoderTag > EncodingBuffer
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:56
bool hasWire() const
Check if Data is already has wire encoding.
Definition: data.hpp:354
const MetaInfo & getMetaInfo() const
Get MetaInfo block from Data packet.
Definition: data.hpp:366
Name abstraction to represent an absolute name.
Definition: name.hpp:46
expose NDNLPv2 tags as LocalControlHeader API
Definition: tags.hpp:64
const Name & getFullName() const
Get full name of Data packet, including the implicit digest.
Definition: data.cpp:179
const time::milliseconds & getFreshnessPeriod() const
Definition: data.hpp:378
DEPRECATED(lp::LocalControlHeaderFacade getLocalControlHeader())
Component holds a read-only name component value.
Data & setMetaInfo(const MetaInfo &metaInfo)
Set metaInfo to a copy of the given MetaInfo.
Definition: data.cpp:194
const Signature & getSignature() const
Definition: data.hpp:390
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
Data & setFinalBlockId(const name::Component &finalBlockId)
Definition: data.cpp:221
represents a Data packet
Definition: data.hpp:39
uint32_t getContentType() const
Definition: data.hpp:372
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:33