NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
meta-info.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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_META_INFO_HPP
23 #define NDN_META_INFO_HPP
24 
25 #include "encoding/block.hpp"
27 #include "name-component.hpp"
28 #include "util/time.hpp"
29 
30 #include <list>
31 
32 namespace ndn {
33 
34 const time::milliseconds DEFAULT_FRESHNESS_PERIOD = time::milliseconds::zero();
35 
58 class MetaInfo
59 {
60 public:
61  class Error : public tlv::Error
62  {
63  public:
64  explicit
65  Error(const std::string& what)
66  : tlv::Error(what)
67  {
68  }
69  };
70 
71  MetaInfo();
72 
76  explicit
77  MetaInfo(const Block& block);
78 
79  template<encoding::Tag TAG>
80  size_t
81  wireEncode(EncodingImpl<TAG>& encoder) const;
82 
83  const Block&
84  wireEncode() const;
85 
86  void
87  wireDecode(const Block& wire);
88 
89 public: // getter/setter
94  uint32_t
95  getType() const
96  {
97  return m_type;
98  }
99 
103  MetaInfo&
104  setType(uint32_t type);
105 
110  time::milliseconds
112  {
113  return m_freshnessPeriod;
114  }
115 
119  MetaInfo&
120  setFreshnessPeriod(time::milliseconds freshnessPeriod);
121 
126  {
127  return m_finalBlockId;
128  }
129 
132  MetaInfo&
134 
144  {
145  return getFinalBlock().value_or(name::Component());
146  }
147 
155  MetaInfo&
156  setFinalBlockId(const name::Component& finalBlockId);
157 
158 public: // app-defined MetaInfo items
167  const std::list<Block>&
168  getAppMetaInfo() const;
169 
183  MetaInfo&
184  setAppMetaInfo(const std::list<Block>& info);
185 
197  MetaInfo&
198  addAppMetaInfo(const Block& block);
199 
210  bool
211  removeAppMetaInfo(uint32_t tlvType);
212 
226  const Block*
227  findAppMetaInfo(uint32_t tlvType) const;
228 
229 public: // EqualityComparable concept
230  bool
231  operator==(const MetaInfo& other) const;
232 
233  bool
234  operator!=(const MetaInfo& other) const;
235 
236 private:
237  uint32_t m_type;
238  time::milliseconds m_freshnessPeriod;
239  optional<name::Component> m_finalBlockId;
240  std::list<Block> m_appMetaInfo;
241 
242  mutable Block m_wire;
243 };
244 
246 
247 std::ostream&
248 operator<<(std::ostream& os, const MetaInfo& info);
249 
250 inline bool
251 MetaInfo::operator==(const MetaInfo& other) const
252 {
253  return wireEncode() == other.wireEncode();
254 }
255 
256 inline bool
257 MetaInfo::operator!=(const MetaInfo& other) const
258 {
259  return !(*this == other);
260 }
261 
262 } // namespace ndn
263 
264 #endif // NDN_META_INFO_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const Block * findAppMetaInfo(uint32_t tlvType) const
Find a first app-defined MetaInfo item of type tlvType.
Definition: meta-info.cpp:129
MetaInfo & setFinalBlock(optional< name::Component > finalBlockId)
set FinalBlockId
Definition: meta-info.cpp:66
Error(const std::string &what)
Definition: meta-info.hpp:65
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:337
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
MetaInfo & setFreshnessPeriod(time::milliseconds freshnessPeriod)
set FreshnessPeriod
Definition: meta-info.cpp:55
uint32_t getType() const
return ContentType
Definition: meta-info.hpp:95
NDN_CXX_DEPRECATED MetaInfo & setFinalBlockId(const name::Component &finalBlockId)
set FinalBlockId
Definition: meta-info.cpp:74
const time::milliseconds DEFAULT_FRESHNESS_PERIOD
Definition: meta-info.hpp:34
MetaInfo & setType(uint32_t type)
set ContentType
Definition: meta-info.cpp:47
bool removeAppMetaInfo(uint32_t tlvType)
Remove a first app-defined MetaInfo item with type tlvType.
Definition: meta-info.cpp:115
NDN_CXX_DEPRECATED name::Component getFinalBlockId() const
return FinalBlockId
Definition: meta-info.hpp:143
const Block & wireEncode() const
Definition: meta-info.cpp:180
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:58
time::milliseconds getFreshnessPeriod() const
return FreshnessPeriod
Definition: meta-info.hpp:111
const optional< name::Component > & getFinalBlock() const
return FinalBlockId
Definition: meta-info.hpp:125
const std::list< Block > & getAppMetaInfo() const
Get all app-defined MetaInfo items.
Definition: meta-info.cpp:83
bool operator!=(const MetaInfo &other) const
Definition: meta-info.hpp:257
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Definition: meta-info.cpp:142
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
uint64_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
Definition: packet.cpp:61
Represents a name component.
bool operator==(const MetaInfo &other) const
Definition: meta-info.hpp:251
#define NDN_CXX_DEPRECATED
Mark a type, variable, or function as deprecated.
Definition: backports.hpp:75
MetaInfo & setAppMetaInfo(const std::list< Block > &info)
Set app-defined MetaInfo items.
Definition: meta-info.cpp:89
MetaInfo & addAppMetaInfo(const Block &block)
Add an app-defined MetaInfo item.
Definition: meta-info.cpp:103
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
void wireDecode(const Block &wire)
Definition: meta-info.cpp:196