NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
strategy-choice.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
#include "
strategy-choice.hpp
"
23
#include "
encoding/tlv-nfd.hpp
"
24
#include "
encoding/block-helpers.hpp
"
25
#include "
util/concepts.hpp
"
26
27
namespace
ndn
{
28
namespace
nfd
{
29
30
//BOOST_CONCEPT_ASSERT((boost::EqualityComparable<StrategyChoice>));
31
BOOST_CONCEPT_ASSERT((
WireEncodable<StrategyChoice>
));
32
BOOST_CONCEPT_ASSERT((
WireDecodable<StrategyChoice>
));
33
static_assert(std::is_base_of<tlv::Error, StrategyChoice::Error>::value,
34
"StrategyChoice::Error must inherit from tlv::Error"
);
35
36
StrategyChoice::StrategyChoice
()
37
{
38
}
39
40
StrategyChoice::StrategyChoice
(
const
Block
& payload)
41
{
42
this->
wireDecode
(payload);
43
}
44
45
template
<encoding::Tag TAG>
46
size_t
47
StrategyChoice::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
48
{
49
size_t
totalLength = 0;
50
51
totalLength +=
prependNestedBlock
(encoder,
tlv::nfd::Strategy
, m_strategy);
52
totalLength += m_name.
wireEncode
(encoder);
53
54
totalLength += encoder.prependVarNumber(totalLength);
55
totalLength += encoder.prependVarNumber(
tlv::nfd::StrategyChoice
);
56
return
totalLength;
57
}
58
59
template
size_t
60
StrategyChoice::wireEncode<encoding::EncoderTag>(
EncodingImpl<encoding::EncoderTag>
&)
const
;
61
62
template
size_t
63
StrategyChoice::wireEncode<encoding::EstimatorTag>(
EncodingImpl<encoding::EstimatorTag>
&)
const
;
64
65
const
Block
&
66
StrategyChoice::wireEncode
()
const
67
{
68
if
(m_wire.
hasWire
())
69
return
m_wire;
70
71
EncodingEstimator
estimator;
72
size_t
estimatedSize =
wireEncode
(estimator);
73
74
EncodingBuffer
buffer(estimatedSize, 0);
75
wireEncode
(buffer);
76
77
m_wire = buffer.block();
78
return
m_wire;
79
}
80
81
void
82
StrategyChoice::wireDecode
(
const
Block
& block)
83
{
84
if
(block.
type
() !=
tlv::nfd::StrategyChoice
) {
85
BOOST_THROW_EXCEPTION(
Error
(
"expecting StrategyChoice block"
));
86
}
87
m_wire = block;
88
m_wire.
parse
();
89
Block::element_const_iterator
val = m_wire.
elements_begin
();
90
91
if
(val != m_wire.
elements_end
() && val->type() ==
tlv::Name
) {
92
m_name.
wireDecode
(*val);
93
++val;
94
}
95
else
{
96
BOOST_THROW_EXCEPTION(
Error
(
"missing required Name field"
));
97
}
98
99
if
(val != m_wire.
elements_end
() && val->type() ==
tlv::nfd::Strategy
) {
100
val->parse();
101
if
(val->elements().empty()) {
102
BOOST_THROW_EXCEPTION(
Error
(
"expecting Strategy/Name"
));
103
}
104
else
{
105
m_strategy.
wireDecode
(*val->elements_begin());
106
}
107
++val;
108
}
109
else
{
110
BOOST_THROW_EXCEPTION(
Error
(
"missing required Strategy field"
));
111
}
112
}
113
114
StrategyChoice
&
115
StrategyChoice::setName
(
const
Name
&
name
)
116
{
117
m_wire.
reset
();
118
m_name = name;
119
return
*
this
;
120
}
121
122
StrategyChoice
&
123
StrategyChoice::setStrategy
(
const
Name
& strategy)
124
{
125
m_wire.
reset
();
126
m_strategy = strategy;
127
return
*
this
;
128
}
129
130
}
// namespace nfd
131
}
// namespace ndn
ndn::tlv::nfd::StrategyChoice
Definition:
tlv-nfd.hpp:88
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Definition:
block.cpp:589
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:471
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:48
ndn::Block::elements_end
element_const_iterator elements_end() const
Definition:
block.cpp:595
ndn::encoding::prependNestedBlock
size_t prependNestedBlock(EncodingImpl< TAG > &encoder, uint32_t type, const U &value)
Prepend a TLV block of type type with WireEncodable value as a value.
Definition:
block-helpers.hpp:193
ndn::Block::parse
void parse() const
Parse wire buffer into subblocks.
Definition:
block.cpp:322
block-helpers.hpp
ndn::Block
Class representing a wire element of NDN-TLV packet format.
Definition:
block.hpp:43
ndn::tlv::Name
Definition:
tlv.hpp:63
ndn::nfd::StrategyChoice::wireDecode
void wireDecode(const Block &wire)
Definition:
strategy-choice.cpp:82
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:45
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:48
ndn::tlv::nfd::Strategy
Definition:
tlv-nfd.hpp:43
ndn::nfd::StrategyChoice::setStrategy
StrategyChoice & setStrategy(const Name &strategy)
Definition:
strategy-choice.cpp:123
ndn::Block::reset
void reset()
Reset wire buffer of the element.
Definition:
block.cpp:302
ndn::Name
Name abstraction to represent an absolute name.
Definition:
name.hpp:46
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:45
ndn::nfd::StrategyChoice::wireEncode
const Block & wireEncode() const
Definition:
strategy-choice.cpp:66
ndn::nfd::StrategyChoice::StrategyChoice
StrategyChoice()
Definition:
strategy-choice.cpp:36
concepts.hpp
strategy-choice.hpp
tlv-nfd.hpp
ndn::Name::wireEncode
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Definition:
name.cpp:122
ndn::nfd::StrategyChoice
represents NFD StrategyChoice dataset
Definition:
strategy-choice.hpp:36
ndn::Name::wireDecode
void wireDecode(const Block &wire)
Definition:
name.cpp:161
ndn::WireEncodable
a concept check for TLV abstraction with .wireEncode method
Definition:
concepts.hpp:34
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition:
concepts.hpp:70
ndn::nfd::StrategyChoice::setName
StrategyChoice & setName(const Name &name)
Definition:
strategy-choice.cpp:115
ndn::nfd::StrategyChoice::Error
Definition:
strategy-choice.hpp:39
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:324
ndn::name
Definition:
name-component.cpp:36
ndnSIM
ndn-cxx
src
mgmt
nfd
strategy-choice.cpp
Generated on Wed Jan 11 2017 18:17:15 for ndnSIM by
1.8.13