NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2
/*
3
* Copyright (c) 2013-2022 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 "
ndn-cxx/lp/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
return
os <<
"Congestion"
;
35
case
NackReason::DUPLICATE
:
36
return
os <<
"Duplicate"
;
37
case
NackReason::NO_ROUTE
:
38
return
os <<
"NoRoute"
;
39
default
:
40
return
os <<
"None"
;
41
}
42
}
43
44
bool
45
isLessSevere
(
lp::NackReason
x,
lp::NackReason
y)
46
{
47
if
(x ==
lp::NackReason::NONE
) {
48
return
false
;
49
}
50
if
(y ==
lp::NackReason::NONE
) {
51
return
true
;
52
}
53
54
return
to_underlying
(x) <
to_underlying
(y);
55
}
56
57
NackHeader::NackHeader
()
58
: m_reason(
NackReason
::NONE)
59
{
60
}
61
62
NackHeader::NackHeader
(
const
Block
& block)
63
{
64
wireDecode
(block);
65
}
66
67
template
<encoding::Tag TAG>
68
size_t
69
NackHeader::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
70
{
71
size_t
length = 0;
72
length +=
prependNonNegativeIntegerBlock
(encoder,
tlv::NackReason
, static_cast<uint64_t>(m_reason));
73
length += encoder.prependVarNumber(length);
74
length += encoder.prependVarNumber(
tlv::Nack
);
75
return
length;
76
}
77
78
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
NackHeader
);
79
80
const
Block
&
81
NackHeader::wireEncode
()
const
82
{
83
if
(m_wire.
hasWire
()) {
84
return
m_wire;
85
}
86
87
EncodingEstimator
estimator;
88
size_t
estimatedSize =
wireEncode
(estimator);
89
90
EncodingBuffer
buffer(estimatedSize, 0);
91
wireEncode
(buffer);
92
93
m_wire = buffer.block();
94
95
return
m_wire;
96
}
97
98
void
99
NackHeader::wireDecode
(
const
Block
& wire)
100
{
101
if
(wire.
type
() !=
tlv::Nack
) {
102
NDN_THROW
(
ndn::tlv::Error
(
"Nack"
, wire.
type
()));
103
}
104
105
m_wire = wire;
106
m_wire.
parse
();
107
m_reason =
NackReason::NONE
;
108
109
if
(m_wire.
elements_size
() > 0) {
110
auto
it = m_wire.
elements_begin
();
111
if
(it->type() ==
tlv::NackReason
) {
112
m_reason = readNonNegativeIntegerAs<NackReason>(*it);
113
}
114
else
{
115
NDN_THROW
(
ndn::tlv::Error
(
"NackReason"
, it->type()));
116
}
117
}
118
}
119
120
NackReason
121
NackHeader::getReason
()
const
122
{
123
switch
(m_reason) {
124
case
NackReason::CONGESTION
:
125
case
NackReason::DUPLICATE
:
126
case
NackReason::NO_ROUTE
:
127
return
m_reason;
128
default
:
129
return
NackReason::NONE
;
130
}
131
}
132
133
NackHeader
&
134
NackHeader::setReason
(
NackReason
reason)
135
{
136
m_reason = reason;
137
m_wire.
reset
();
138
return
*
this
;
139
}
140
141
}
// namespace lp
142
}
// 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:35
ndn::lp::NackHeader::setReason
NackHeader & setReason(NackReason reason)
set reason code
Definition:
nack-header.cpp:134
ndn::lp::NackHeader::wireEncode
const Block & wireEncode() const
Definition:
nack-header.cpp:81
ndn::lp::NackReason::NO_ROUTE
ndn::lp::tlv::NackReason
Definition:
tlv.hpp:43
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition:
block.cpp:324
ndn::Block
Represents a TLV element of the NDN packet format.
Definition:
block.hpp:44
ndn::lp::NackHeader::wireDecode
void wireDecode(const Block &wire)
Definition:
nack-header.cpp:99
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition:
block.hpp:221
ndn::lp::NackReason
NackReason
indicates the reason type of a network NACK
Definition:
nack-header.hpp:37
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition:
block.hpp:433
ndn::lp::NackHeader::getReason
NackReason getReason() const
Definition:
nack-header.cpp:121
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
nack-header.hpp
ndn::to_underlying
NDN_CXX_NODISCARD constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
Definition:
backports.hpp:125
ndn::Block::reset
void reset() noexcept
Reset the Block to a default-constructed state.
Definition:
block.cpp:254
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:36
ndn::Block::elements_size
size_t elements_size() const
Equivalent to elements().size()
Definition:
block.hpp:449
ndn::lp::tlv::Nack
Definition:
tlv.hpp:42
ndn::lp::NackHeader::NackHeader
NackHeader()
Definition:
nack-header.cpp:57
ndn::lp::NackReason::NONE
ndn::lp::NackReason::DUPLICATE
ndn::Block::type
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition:
block.hpp:277
ndn::lp::operator<<
std::ostream & operator<<(std::ostream &os, CachePolicyType policy)
Definition:
cache-policy.cpp:31
ndn::lp
Definition:
cache-policy.cpp:28
ndn::lp::isLessSevere
bool isLessSevere(lp::NackReason x, lp::NackReason y)
compare NackReason for severity
Definition:
nack-header.cpp:45
ndn::lp::NackReason::CONGESTION
ndn::lp::NackHeader
represents a Network NACK header
Definition:
nack-header.hpp:57
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:52
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:39
ndnSIM
ndn-cxx
ndn-cxx
lp
nack-header.cpp
Generated on Fri May 6 2022 12:34:12 for ndnSIM by
1.8.13