NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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-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_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
90  uint32_t
91  getType() const;
92 
96  MetaInfo&
97  setType(uint32_t type);
98 
99  const time::milliseconds&
100  getFreshnessPeriod() const;
101 
105  MetaInfo&
106  setFreshnessPeriod(time::milliseconds freshnessPeriod);
107 
108  const name::Component&
109  getFinalBlockId() const;
110 
111  MetaInfo&
112  setFinalBlockId(const name::Component& finalBlockId);
113 
114 public: // app-defined MetaInfo items
123  const std::list<Block>&
124  getAppMetaInfo() const;
125 
139  MetaInfo&
140  setAppMetaInfo(const std::list<Block>& info);
141 
153  MetaInfo&
154  addAppMetaInfo(const Block& block);
155 
166  bool
167  removeAppMetaInfo(uint32_t tlvType);
168 
182  const Block*
183  findAppMetaInfo(uint32_t tlvType) const;
184 
185 public: // EqualityComparable concept
186  bool
187  operator==(const MetaInfo& other) const;
188 
189  bool
190  operator!=(const MetaInfo& other) const;
191 
192 private:
193  uint32_t m_type;
194  time::milliseconds m_freshnessPeriod;
195  name::Component m_finalBlockId;
196  std::list<Block> m_appMetaInfo;
197 
198  mutable Block m_wire;
199 };
200 
202 
203 std::ostream&
204 operator<<(std::ostream& os, const MetaInfo& info);
205 
206 inline uint32_t
208 {
209  return m_type;
210 }
211 
212 inline const time::milliseconds&
214 {
215  return m_freshnessPeriod;
216 }
217 
218 inline const name::Component&
220 {
221  return m_finalBlockId;
222 }
223 
224 inline bool
225 MetaInfo::operator==(const MetaInfo& other) const
226 {
227  return wireEncode() == other.wireEncode();
228 }
229 
230 inline bool
231 MetaInfo::operator!=(const MetaInfo& other) const
232 {
233  return !(*this == other);
234 }
235 
236 } // namespace ndn
237 
238 #endif // NDN_META_INFO_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const time::milliseconds & getFreshnessPeriod() const
Definition: meta-info.hpp:213
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Definition: meta-info.cpp:133
Error(const std::string &what)
Definition: meta-info.hpp:65
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
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
MetaInfo & setFreshnessPeriod(time::milliseconds freshnessPeriod)
set FreshnessPeriod
Definition: meta-info.cpp:55
const Block & wireEncode() const
Definition: meta-info.cpp:171
MetaInfo & setFinalBlockId(const name::Component &finalBlockId)
Definition: meta-info.cpp:66
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:106
const std::list< Block > & getAppMetaInfo() const
Get all app-defined MetaInfo items.
Definition: meta-info.cpp:74
An MetaInfo holds the meta info which is signed inside the data packet.
Definition: meta-info.hpp:58
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
bool operator!=(const MetaInfo &other) const
Definition: meta-info.hpp:231
uint64_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
Definition: packet.cpp:61
Component holds a read-only name component value.
const Block * findAppMetaInfo(uint32_t tlvType) const
Find a first app-defined MetaInfo item of type tlvType.
Definition: meta-info.cpp:120
bool operator==(const MetaInfo &other) const
Definition: meta-info.hpp:225
MetaInfo & setAppMetaInfo(const std::list< Block > &info)
Set app-defined MetaInfo items.
Definition: meta-info.cpp:80
uint32_t getType() const
Definition: meta-info.hpp:207
MetaInfo & addAppMetaInfo(const Block &block)
Add an app-defined MetaInfo item.
Definition: meta-info.cpp:94
const name::Component & getFinalBlockId() const
Definition: meta-info.hpp:219
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
void wireDecode(const Block &wire)
Definition: meta-info.cpp:187