NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
prefix-announcement.cpp
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
* @author Teng Liang <philoliang@email.arizona.edu>
22
*/
23
24
#include "
prefix-announcement.hpp
"
25
#include "
tlv.hpp
"
26
27
namespace
ndn
{
28
namespace
lp
{
29
30
static
const
name::Component
SELF_LEARNING_PREFIX
(
"self-learning"
);
31
32
PrefixAnnouncement::PrefixAnnouncement
() =
default
;
33
34
PrefixAnnouncement::PrefixAnnouncement
(
const
Block
& block)
35
{
36
wireDecode
(block);
37
}
38
39
PrefixAnnouncement::PrefixAnnouncement
(shared_ptr<const Data> data)
40
{
41
setData
(std::move(data));
42
}
43
44
template
<encoding::Tag TAG>
45
size_t
46
PrefixAnnouncement::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
47
{
48
size_t
length = 0;
49
length += m_data->wireEncode(encoder);
50
length += encoder.prependVarNumber(length);
51
length += encoder.prependVarNumber(
tlv::PrefixAnnouncement
);
52
return
length;
53
}
54
55
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
PrefixAnnouncement
);
56
57
void
58
PrefixAnnouncement::wireDecode
(
const
Block
& wire)
59
{
60
if
(wire.
type
() !=
tlv::PrefixAnnouncement
) {
61
BOOST_THROW_EXCEPTION(
Error
(
"Unexpected TLV-TYPE "
+
to_string
(wire.
type
())));
62
}
63
64
wire.
parse
();
65
setData
(make_shared<Data>(wire.
get
(
ndn::tlv::Data
)));
66
}
67
68
Name
69
PrefixAnnouncement::getAnnouncedName
()
const
70
{
71
if
(m_data ==
nullptr
) {
72
BOOST_THROW_EXCEPTION(
Error
(
"Data is unset in PrefixAnnouncement"
));
73
}
74
75
const
Name
& dataName = m_data->getName();
76
BOOST_ASSERT(dataName.
at
(0) ==
SELF_LEARNING_PREFIX
);
77
BOOST_ASSERT(dataName.
at
(-1).
isVersion
());
78
79
return
dataName.
getSubName
(1, dataName.
size
() - 2);
80
}
81
82
PrefixAnnouncement
&
83
PrefixAnnouncement::setData
(shared_ptr<const Data> data)
84
{
85
if
(data ==
nullptr
) {
86
BOOST_THROW_EXCEPTION(
Error
(
"Unexpected nullptr"
));
87
}
88
89
if
(data->getName().at(0) !=
SELF_LEARNING_PREFIX
) {
90
BOOST_THROW_EXCEPTION(
Error
(
"Unexpected prefix in name "
+ data->getName().toUri()));
91
}
92
93
if
(!data->getName().get(-1).isVersion()) {
94
BOOST_THROW_EXCEPTION(
Error
(
"Last name component of "
+ data->getName().toUri() +
95
" is not a version"
));
96
}
97
98
if
(data->getContent().value_size() != 0 ||
99
data->getMetaInfo().wireEncode().value_size() != 0) {
100
BOOST_THROW_EXCEPTION(
Error
(
"Both Data MetaInfo and Content must be empty"
));
101
}
102
103
m_data = std::move(data);
104
return
*
this
;
105
}
106
107
}
// namespace lp
108
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::lp::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(CachePolicy)
ndn::lp::PrefixAnnouncement::PrefixAnnouncement
PrefixAnnouncement()
ndn::lp::PrefixAnnouncement::Error
Definition:
prefix-announcement.hpp:43
ndn::lp::SELF_LEARNING_PREFIX
static const name::Component SELF_LEARNING_PREFIX("self-learning")
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub elements.
Definition:
block.cpp:335
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::lp::tlv::PrefixAnnouncement
Definition:
tlv.hpp:49
prefix-announcement.hpp
ndn::lp::PrefixAnnouncement::setData
PrefixAnnouncement & setData(shared_ptr< const Data > data)
Definition:
prefix-announcement.cpp:83
ndn::Name::at
const Component & at(ssize_t i) const
Get the component at the given index.
Definition:
name.cpp:185
tlv.hpp
ndn::Block::get
const Block & get(uint32_t type) const
Get the first sub element of specified TLV-TYPE.
Definition:
block.cpp:417
ndn::lp::PrefixAnnouncement::wireDecode
void wireDecode(const Block &wire)
Definition:
prefix-announcement.cpp:58
ndn::tlv::Data
Definition:
tlv.hpp:65
ndn::lp::PrefixAnnouncement::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Definition:
prefix-announcement.cpp:46
ndn::Name
Represents an absolute name.
Definition:
name.hpp:42
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:36
ndn::Name::size
size_t size() const
Get number of components.
Definition:
name.hpp:154
ndn::lp::PrefixAnnouncement
represents a Prefix Announcement
Definition:
prefix-announcement.hpp:40
ndn::name::Component
Component holds a read-only name component value.
Definition:
name-component.hpp:47
ndn::lp::PrefixAnnouncement::getAnnouncedName
Name getAnnouncedName() const
Get announced name.
Definition:
prefix-announcement.cpp:69
ndn::lp
Definition:
cache-policy.cpp:28
ndn::to_string
std::string to_string(const V &v)
Definition:
backports.hpp:84
ndn::name::Component::isVersion
bool isVersion() const
Check if the component is version per NDN naming conventions.
Definition:
name-component.cpp:178
ndn::Name::getSubName
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract some components as a sub-name (PartialName)
Definition:
name.cpp:199
ndn::Block::type
uint32_t type() const
Get TLV-TYPE.
Definition:
block.hpp:235
ndnSIM
ndn-cxx
src
lp
prefix-announcement.cpp
Generated on Sun Feb 25 2018 13:27:04 for ndnSIM by
1.8.14