NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
channel-status.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2019 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
22
#include "
ndn-cxx/mgmt/nfd/channel-status.hpp
"
23
#include "
ndn-cxx/encoding/block-helpers.hpp
"
24
#include "
ndn-cxx/encoding/tlv-nfd.hpp
"
25
#include "
ndn-cxx/util/concepts.hpp
"
26
27
namespace
ndn
{
28
namespace
nfd
{
29
30
BOOST_CONCEPT_ASSERT((
StatusDatasetItem<ChannelStatus>
));
31
32
ChannelStatus::ChannelStatus
() =
default
;
33
34
ChannelStatus::ChannelStatus
(
const
Block
& payload)
35
{
36
this->
wireDecode
(payload);
37
}
38
39
template
<encoding::Tag TAG>
40
size_t
41
ChannelStatus::wireEncode
(
EncodingImpl<TAG>
& encoder)
const
42
{
43
size_t
totalLength = 0;
44
totalLength +=
prependStringBlock
(encoder,
tlv::nfd::LocalUri
, m_localUri);
45
totalLength += encoder.prependVarNumber(totalLength);
46
totalLength += encoder.prependVarNumber(
tlv::nfd::ChannelStatus
);
47
return
totalLength;
48
}
49
50
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
ChannelStatus
);
51
52
const
Block
&
53
ChannelStatus::wireEncode
()
const
54
{
55
if
(m_wire.
hasWire
())
56
return
m_wire;
57
58
EncodingEstimator
estimator;
59
size_t
estimatedSize =
wireEncode
(estimator);
60
61
EncodingBuffer
buffer(estimatedSize, 0);
62
wireEncode
(buffer);
63
64
m_wire = buffer.block();
65
return
m_wire;
66
}
67
68
void
69
ChannelStatus::wireDecode
(
const
Block
& block)
70
{
71
if
(block.
type
() !=
tlv::nfd::ChannelStatus
) {
72
NDN_THROW
(
Error
(
"ChannelStatus"
, block.
type
()));
73
}
74
75
m_wire = block;
76
m_wire.
parse
();
77
auto
val = m_wire.
elements_begin
();
78
79
if
(val != m_wire.
elements_end
() && val->type() ==
tlv::nfd::LocalUri
) {
80
m_localUri =
readString
(*val);
81
++val;
82
}
83
else
{
84
NDN_THROW
(
Error
(
"Missing required LocalUri field"
));
85
}
86
}
87
88
ChannelStatus
&
89
ChannelStatus::setLocalUri
(
const
std::string localUri)
90
{
91
m_wire.
reset
();
92
m_localUri = localUri;
93
return
*
this
;
94
}
95
96
bool
97
operator==
(
const
ChannelStatus
& a,
const
ChannelStatus
& b)
98
{
99
return
a.
getLocalUri
() == b.
getLocalUri
();
100
}
101
102
std::ostream&
103
operator<<
(std::ostream& os,
const
ChannelStatus
& status)
104
{
105
return
os <<
"Channel(LocalUri: "
<< status.
getLocalUri
() <<
")"
;
106
}
107
108
}
// namespace nfd
109
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::nfd::ChannelStatus::getLocalUri
const std::string & getLocalUri() const
Definition:
channel-status.hpp:61
ndn::nfd::ChannelStatus::Error
Definition:
channel-status.hpp:38
ndn::tlv::nfd::LocalUri
Definition:
tlv-nfd.hpp:64
ndn::nfd::ChannelStatus::wireEncode
const Block & wireEncode() const
Definition:
channel-status.cpp:53
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub-elements.
Definition:
block.cpp:324
block-helpers.hpp
ndn::nfd::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
ndn::Block
Represents a TLV element of the NDN packet format.
Definition:
block.hpp:44
ndn::encoding::prependStringBlock
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
Definition:
block-helpers.cpp:103
ndn::Block::hasWire
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition:
block.hpp:221
ndn::encoding::readString
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
Definition:
block-helpers.cpp:121
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition:
block.hpp:433
ndn::tlv::nfd::ChannelStatus
Definition:
tlv-nfd.hpp:65
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition:
block.hpp:441
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:39
ndn::Block::reset
void reset() noexcept
Reset the Block to a default-constructed state.
Definition:
block.cpp:254
ndn::nfd::operator==
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
Definition:
channel-status.cpp:97
ndn::nfd::operator<<
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
Definition:
nfd-constants.cpp:36
ndn::encoding::EncodingImpl
Definition:
encoding-buffer-fwd.hpp:36
ndn::StatusDatasetItem
concept check for an item in a Status Dataset
Definition:
concepts.hpp:115
ndn::Block::type
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition:
block.hpp:277
concepts.hpp
tlv-nfd.hpp
ndn::nfd::ChannelStatus
represents an item in NFD Channel dataset
Definition:
channel-status.hpp:35
channel-status.hpp
ndn::nfd::ChannelStatus::wireDecode
void wireDecode(const Block &wire)
Definition:
channel-status.cpp:69
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:38
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:39
ndn::nfd::ChannelStatus::setLocalUri
ChannelStatus & setLocalUri(const std::string localUri)
Definition:
channel-status.cpp:89
ndn::nfd::ChannelStatus::ChannelStatus
ChannelStatus()
ndnSIM
ndn-cxx
ndn-cxx
mgmt
nfd
channel-status.cpp
Generated on Fri May 6 2022 12:34:12 for ndnSIM by
1.8.13