NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
nack-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-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
* @author Eric Newberry <enewberry@email.arizona.edu>
22
*/
23
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
bool
50
isLessSevere
(
lp::NackReason
x,
lp::NackReason
y)
51
{
52
if
(x ==
lp::NackReason::NONE
) {
53
return
false
;
54
}
55
if
(y ==
lp::NackReason::NONE
) {
56
return
true
;
57
}
58
59
return
static_cast<
int
>
(x) < static_cast<int>(y);
60
}
61
62
NackHeader::NackHeader
()
63
: m_reason(
NackReason
::NONE)
64
{
65
}
66
67
NackHeader::NackHeader
(
const
Block
& block)
68
{
69
wireDecode
(block);
70
}
71
72
template
<encoding::Tag TAG>
73
size_t
74
NackHeader::wireEncode
(EncodingImpl<TAG>& encoder)
const
75
{
76
size_t
length = 0;
77
length +=
prependNonNegativeIntegerBlock
(encoder,
tlv::NackReason
, static_cast<uint32_t>(m_reason));
78
length += encoder.prependVarNumber(length);
79
length += encoder.prependVarNumber(
tlv::Nack
);
80
return
length;
81
}
82
83
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
NackHeader
);
84
85
const
Block
&
86
NackHeader::wireEncode
()
const
87
{
88
if
(m_wire.
hasWire
()) {
89
return
m_wire;
90
}
91
92
EncodingEstimator
estimator;
93
size_t
estimatedSize =
wireEncode
(estimator);
94
95
EncodingBuffer
buffer(estimatedSize, 0);
96
wireEncode
(buffer);
97
98
m_wire = buffer.block();
99
100
return
m_wire;
101
}
102
103
void
104
NackHeader::wireDecode
(
const
Block
& wire)
105
{
106
if
(wire.
type
() !=
tlv::Nack
) {
107
BOOST_THROW_EXCEPTION(
ndn::tlv::Error
(
"expecting Nack block"
));
108
}
109
110
m_wire = wire;
111
m_wire.
parse
();
112
m_reason =
NackReason::NONE
;
113
114
if
(m_wire.
elements_size
() > 0) {
115
Block::element_const_iterator
it = m_wire.
elements_begin
();
116
117
if
(it->type() ==
tlv::NackReason
) {
118
m_reason =
static_cast<
NackReason
>
(
readNonNegativeInteger
(*it));
119
}
120
else
{
121
BOOST_THROW_EXCEPTION(
ndn::tlv::Error
(
"expecting NackReason block"
));
122
}
123
}
124
}
125
126
NackReason
127
NackHeader::getReason
()
const
128
{
129
switch
(m_reason) {
130
case
NackReason::CONGESTION
:
131
case
NackReason::DUPLICATE
:
132
case
NackReason::NO_ROUTE
:
133
return
m_reason;
134
default
:
135
return
NackReason::NONE
;
136
}
137
}
138
139
NackHeader
&
140
NackHeader::setReason
(
NackReason
reason)
141
{
142
m_reason = reason;
143
m_wire.
reset
();
144
return
*
this
;
145
}
146
147
}
// namespace lp
148
}
// 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::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Definition:
block-helpers.cpp:31
ndn::lp::NackHeader::setReason
NackHeader & setReason(NackReason reason)
set reason code
Definition:
nack-header.cpp:140
ndn::lp::NackReason::NO_ROUTE
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:47
ndn::lp::NackHeader::wireEncode
const Block & wireEncode() const
Definition:
nack-header.cpp:86
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::lp::NackHeader::wireDecode
void wireDecode(const Block &wire)
Definition:
nack-header.cpp:104
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)
Read a non-negative integer from a TLV element.
Definition:
block-helpers.cpp:60
nack-header.hpp
ndn::Block::elements_size
size_t elements_size() const
Equivalent to elements().size()
Definition:
block.hpp:371
ndn::Block::reset
void reset()
Reset wire buffer of the element.
Definition:
block.cpp:256
ndn::lp::NackHeader::NackHeader
NackHeader()
Definition:
nack-header.cpp:62
ndn::lp::NackReason::NONE
ndn::lp::tlv::NackReason
Definition:
tlv.hpp:40
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub elements.
Definition:
block.cpp:334
ndn::Block::type
uint32_t type() const
Get TLV-TYPE.
Definition:
block.hpp:235
ndn::lp::NackReason::DUPLICATE
ndn::lp::tlv::Nack
Definition:
tlv.hpp:39
ndn::lp::NackHeader::getReason
NackReason getReason() const
Definition:
nack-header.cpp:127
ndn::lp::operator<<
std::ostream & operator<<(std::ostream &os, CachePolicyType policy)
Definition:
cache-policy.cpp:31
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:250
ndn::lp
Definition:
cache-policy.cpp:28
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition:
block.hpp:355
ndn::lp::isLessSevere
bool isLessSevere(lp::NackReason x, lp::NackReason y)
compare NackReason for severity
Definition:
nack-header.cpp:50
ndn::lp::NackReason::CONGESTION
ndn::lp::NackHeader
represents a Network NACK header
Definition:
nack-header.hpp:59
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:38
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition:
tlv.hpp:50
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:39
ndnSIM
ndn-cxx
src
lp
nack-header.cpp
Generated on Thu Nov 2 2017 03:30:28 for ndnSIM by
1.8.11