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"
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 
290 
292  getLocalControlHeader() const;
293 
294  uint64_t
295  getIncomingFaceId() const;
296 
297  Data&
298  setIncomingFaceId(uint64_t incomingFaceId);
299 
301  getCachingPolicy() const;
302 
303  Data&
305 
306 public: // EqualityComparable concept
307  bool
308  operator==(const Data& other) const;
309 
310  bool
311  operator!=(const Data& other) const;
312 
313 protected:
317  void
318  onChanged();
319 
320 private:
321  Name m_name;
322  MetaInfo m_metaInfo;
323  mutable Block m_content;
324  Signature m_signature;
325 
326  mutable Block m_wire;
327  mutable Name m_fullName;
328 
329  nfd::LocalControlHeader m_localControlHeader;
331 };
332 
333 std::ostream&
334 operator<<(std::ostream& os, const Data& data);
335 
336 inline bool
338 {
339  return m_wire.hasWire();
340 }
341 
342 inline const Name&
344 {
345  return m_name;
346 }
347 
348 inline const MetaInfo&
350 {
351  return m_metaInfo;
352 }
353 
354 inline uint32_t
356 {
357  return m_metaInfo.getType();
358 }
359 
360 inline const time::milliseconds&
362 {
363  return m_metaInfo.getFreshnessPeriod();
364 }
365 
366 inline const name::Component&
368 {
369  return m_metaInfo.getFinalBlockId();
370 }
371 
372 inline const Signature&
374 {
375  return m_signature;
376 }
377 
380 {
381  return m_localControlHeader;
382 }
383 
384 inline const nfd::LocalControlHeader&
386 {
387  return m_localControlHeader;
388 }
389 
390 inline uint64_t
392 {
394 }
395 
398 {
400 }
401 
402 } // namespace ndn
403 
404 #endif
Error(const std::string &what)
Definition: data.hpp:46
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
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
uint32_t getContentType() const
Definition: data.hpp:355
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
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:340
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
Copyright (c) 2013-2014 Regents of the University of California.
const MetaInfo & getMetaInfo() const
Get MetaInfo block from Data packet.
Definition: data.hpp:349
bool operator!=(const Data &other) const
Definition: data.cpp:334
Data & setFreshnessPeriod(const time::milliseconds &freshnessPeriod)
Definition: data.cpp:212
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:343
void onChanged()
Clear the wire encoding.
Definition: data.cpp:313
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
Class to handle work with LocalControlHeader.
const name::Component & getFinalBlockId() const
Definition: data.hpp:367
Name abstraction to represent an absolute name.
Definition: name.hpp:46
const Block & wireEncode() const
Encode to a wire format.
Definition: data.cpp:119
nfd::LocalControlHeader::CachingPolicy getCachingPolicy() const
Definition: data.hpp:397
const Signature & getSignature() const
Definition: data.hpp:373
Component holds a read-only name component value.
uint64_t getIncomingFaceId() const
Definition: data.hpp:391
const Block & getContent() const
Get content Block.
Definition: data.cpp:230
bool operator==(const Data &other) const
Definition: data.cpp:325
Data & setMetaInfo(const MetaInfo &metaInfo)
Set metaInfo to a copy of the given MetaInfo.
Definition: data.cpp:194
Data & setIncomingFaceId(uint64_t incomingFaceId)
Definition: data.cpp:295
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
const Name & getFullName() const
Get full name of Data packet, including the implicit digest.
Definition: data.cpp:179
Data & setFinalBlockId(const name::Component &finalBlockId)
Definition: data.cpp:221
represents a Data packet
Definition: data.hpp:39
bool hasWire() const
Check if Data is already has wire encoding.
Definition: data.hpp:337
nfd::LocalControlHeader & getLocalControlHeader()
Definition: data.hpp:379
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
const time::milliseconds & getFreshnessPeriod() const
Definition: data.hpp:361
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:33
Data & setCachingPolicy(nfd::LocalControlHeader::CachingPolicy cachingPolicy)
Definition: data.cpp:304