NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
nack-header.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24
#include "
nack-header.hpp
"
25
26
namespace
ndn
{
27
namespace
lp
{
28
29
std::ostream&
30
operator<<
(std::ostream& os,
NackReason
reason)
31
{
32
switch
(reason) {
33
case
NackReason::CONGESTION
:
34
os <<
"Congestion"
;
35
break
;
36
case
NackReason::DUPLICATE
:
37
os <<
"Duplicate"
;
38
break
;
39
case
NackReason::NO_ROUTE
:
40
os <<
"NoRoute"
;
41
break
;
42
default
:
43
os <<
"None"
;
44
break
;
45
}
46
return
os;
47
}
48
49
NackHeader::NackHeader
()
50
: m_reason(
NackReason
::NONE)
51
{
52
}
53
54
NackHeader::NackHeader
(
const
Block
& block)
55
{
56
wireDecode
(block);
57
}
58
59
template
<encoding::Tag TAG>
60
size_t
61
NackHeader::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
62
{
63
size_t
length = 0;
64
length +=
prependNonNegativeIntegerBlock
(encoder,
tlv::NackReason
,
65
static_cast<uint32_t>(m_reason));
66
length += encoder.prependVarNumber(length);
67
length += encoder.prependVarNumber(
tlv::Nack
);
68
return
length;
69
}
70
71
template
size_t
72
NackHeader::wireEncode<encoding::EncoderTag>(
EncodingImpl<encoding::EncoderTag>
& encoder)
const
;
73
74
template
size_t
75
NackHeader::wireEncode<encoding::EstimatorTag>(
EncodingImpl<encoding::EstimatorTag>
& encoder)
const
;
76
77
const
Block
&
78
NackHeader::wireEncode
()
const
79
{
80
if
(m_wire.
hasWire
()) {
81
return
m_wire;
82
}
83
84
EncodingEstimator
estimator;
85
size_t
estimatedSize =
wireEncode
(estimator);
86
87
EncodingBuffer
buffer(estimatedSize, 0);
88
wireEncode
(buffer);
89
90
m_wire = buffer.block();
91
92
return
m_wire;
93
}
94
95
void
96
NackHeader::wireDecode
(
const
Block
& wire)
97
{
98
if
(wire.
type
() !=
tlv::Nack
) {
99
BOOST_THROW_EXCEPTION(
ndn::tlv::Error
(
"expecting Nack block"
));
100
}
101
102
m_wire = wire;
103
m_wire.
parse
();
104
m_reason =
NackReason::NONE
;
105
106
if
(m_wire.
elements_size
() > 0) {
107
Block::element_const_iterator
it = m_wire.
elements_begin
();
108
109
if
(it->type() ==
tlv::NackReason
) {
110
m_reason =
static_cast<
NackReason
>
(
readNonNegativeInteger
(*it));
111
}
112
else
{
113
BOOST_THROW_EXCEPTION(
ndn::tlv::Error
(
"expecting NackReason block"
));
114
}
115
}
116
}
117
118
NackReason
119
NackHeader::getReason
()
const
120
{
121
switch
(m_reason) {
122
case
NackReason::CONGESTION
:
123
case
NackReason::DUPLICATE
:
124
case
NackReason::NO_ROUTE
:
125
return
m_reason;
126
default
:
127
return
NackReason::NONE
;
128
}
129
}
130
131
NackHeader
&
132
NackHeader::setReason
(
NackReason
reason)
133
{
134
m_reason = reason;
135
m_wire.
reset
();
136
return
*
this
;
137
}
138
139
}
// namespace lp
140
}
// namespace ndn
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::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
Definition:
block-helpers.cpp:29
ndn::lp::NackHeader::setReason
NackHeader & setReason(NackReason reason)
set reason code
Definition:
nack-header.cpp:132
ndn::lp::NackHeader::wireEncode
const Block & wireEncode() const
Definition:
nack-header.cpp:78
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:48
ndn::lp::tlv::NackReason
Definition:
tlv.hpp:40
ndn::lp::NackReason::NO_ROUTE
ndn::lp::tlv::Nack
Definition:
tlv.hpp:39
ndn::Block::parse
void parse() const
Parse wire buffer into subblocks.
Definition:
block.cpp:322
ndn::Block
Class representing a wire element of NDN-TLV packet format.
Definition:
block.hpp:43
ndn::lp::NackHeader::wireDecode
void wireDecode(const Block &wire)
Definition:
nack-header.cpp:96
ndn::lp::NackReason
NackReason
indicates the reason type of a network NACK
Definition:
nack-header.hpp:39
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
Definition:
block-helpers.cpp:61
ndn::lp::NackHeader::getReason
NackReason getReason() const
Definition:
nack-header.cpp:119
nack-header.hpp
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:45
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:48
ndn::Block::reset
void reset()
Reset wire buffer of the element.
Definition:
block.cpp:302
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:45
ndn::Block::elements_size
size_t elements_size() const
Definition:
block.cpp:601
ndn::lp::NackHeader::NackHeader
NackHeader()
Definition:
nack-header.cpp:49
ndn::lp::NackReason::NONE
ndn::lp::NackReason::DUPLICATE
ndn::lp::operator<<
std::ostream & operator<<(std::ostream &os, CachePolicyType policy)
Definition:
cache-policy.cpp:30
ndn::lp
Definition:
cache-policy.cpp:27
ndn::lp::NackReason::CONGESTION
ndn::lp::NackHeader
represents a Network NACK header
Definition:
nack-header.hpp:52
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:324
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition:
tlv.hpp:50
ndnSIM
ndn-cxx
src
lp
nack-header.cpp
Generated on Wed Jan 11 2017 18:17:13 for ndnSIM by
1.8.13