NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
prefix-announcement-header.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2019 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
#include "
ndn-cxx/lp/prefix-announcement-header.hpp
"
23
#include "
ndn-cxx/lp/tlv.hpp
"
24
25
namespace
ndn
{
26
namespace
lp
{
27
28
PrefixAnnouncementHeader::PrefixAnnouncementHeader
() =
default
;
29
30
PrefixAnnouncementHeader::PrefixAnnouncementHeader
(
const
Block
& block)
31
{
32
wireDecode
(block);
33
}
34
35
PrefixAnnouncementHeader::PrefixAnnouncementHeader
(
PrefixAnnouncement
prefixAnn)
36
: m_prefixAnn(std::
move
(prefixAnn))
37
{
38
if
(m_prefixAnn->getData() ==
nullopt
) {
39
NDN_THROW
(
Error
(
"PrefixAnnouncement does not contain Data"
));
40
}
41
}
42
43
template
<encoding::Tag TAG>
44
size_t
45
PrefixAnnouncementHeader::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
46
{
47
if
(m_prefixAnn ==
nullopt
) {
48
NDN_THROW
(
Error
(
"PrefixAnnouncementHeader does not contain a PrefixAnnouncement"
));
49
}
50
51
size_t
length = 0;
52
length += m_prefixAnn->getData()->wireEncode(encoder);
53
length += encoder.prependVarNumber(length);
54
length += encoder.prependVarNumber(
tlv::PrefixAnnouncement
);
55
return
length;
56
}
57
58
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
PrefixAnnouncementHeader
);
59
60
void
61
PrefixAnnouncementHeader::wireDecode
(
const
Block
& wire)
62
{
63
if
(wire.
type
() !=
tlv::PrefixAnnouncement
) {
64
NDN_THROW
(
Error
(
"PrefixAnnouncement"
, wire.
type
()));
65
}
66
67
wire.
parse
();
68
m_prefixAnn.emplace(
Data
(wire.
get
(
ndn::tlv::Data
)));
69
}
70
}
// namespace lp
71
}
// namespace ndn
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
ndn::lp::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(CachePolicy)
ndn::lp::PrefixAnnouncementHeader::PrefixAnnouncementHeader
PrefixAnnouncementHeader()
ndn::PrefixAnnouncement
A prefix announcement object that represents an application's intent of registering a prefix toward i...
Definition:
prefix-announcement.hpp:34
ndn::Block::get
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
Definition:
block.cpp:414
ndn::Block::type
uint32_t type() const
Return the TLV-TYPE of the Block.
Definition:
block.hpp:274
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
tlv.hpp
ndn::lp::PrefixAnnouncementHeader::Error
Definition:
prefix-announcement-header.hpp:36
nonstd::optional_lite::nullopt
const nullopt_t nullopt((nullopt_t::init()))
ndn::lp::PrefixAnnouncementHeader::wireDecode
void wireDecode(const Block &wire)
Definition:
prefix-announcement-header.cpp:61
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition:
block.cpp:325
ndn::tlv::Data
@ Data
Definition:
tlv.hpp:66
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:36
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:43
prefix-announcement-header.hpp
ndn::lp
Definition:
cache-policy.cpp:28
ndn::lp::PrefixAnnouncementHeader
represents a PrefixAnnouncement header field in NDNLP
Definition:
prefix-announcement-header.hpp:33
ndn::lp::PrefixAnnouncementHeader::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
encodes the prefix announcement header to the wire format
Definition:
prefix-announcement-header.cpp:45
ndn::lp::tlv::PrefixAnnouncement
@ PrefixAnnouncement
Definition:
tlv.hpp:52
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndnSIM
ndn-cxx
ndn-cxx
lp
prefix-announcement-header.cpp
Generated on Mon Jun 1 2020 22:32:14 for ndnSIM by
1.8.18