NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
control-response.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2013-2018 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/control-response.hpp
"
23
#include "
ndn-cxx/encoding/block-helpers.hpp
"
24
#include "
ndn-cxx/encoding/tlv-nfd.hpp
"
25
26
namespace
ndn
{
27
namespace
mgmt {
28
29
// BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
30
BOOST_CONCEPT_ASSERT((
WireEncodable<ControlResponse>
));
31
BOOST_CONCEPT_ASSERT((
WireDecodable<ControlResponse>
));
32
static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
33
"ControlResponse::Error must inherit from tlv::Error"
);
34
35
ControlResponse::ControlResponse
()
36
: m_code(200)
37
{
38
}
39
40
ControlResponse::ControlResponse
(uint32_t code,
const
std::string& text)
41
: m_code(code)
42
, m_text(text)
43
{
44
}
45
46
ControlResponse::ControlResponse
(
const
Block
& block)
47
{
48
wireDecode
(block);
49
}
50
51
const
Block
&
52
ControlResponse::wireEncode
()
const
53
{
54
if
(
m_wire
.
hasWire
())
55
return
m_wire
;
56
57
m_wire
=
Block
(
tlv::nfd::ControlResponse
);
58
m_wire
.
push_back
(
makeNonNegativeIntegerBlock
(
tlv::nfd::StatusCode
,
m_code
));
59
m_wire
.
push_back
(
makeStringBlock
(
tlv::nfd::StatusText
,
m_text
));
60
61
if
(
m_body
.
hasWire
()) {
62
m_wire
.
push_back
(
m_body
);
63
}
64
65
m_wire
.
encode
();
66
return
m_wire
;
67
}
68
69
void
70
ControlResponse::wireDecode
(
const
Block
& wire)
71
{
72
m_wire
= wire;
73
m_wire
.
parse
();
74
75
if
(
m_wire
.
type
() !=
tlv::nfd::ControlResponse
)
76
BOOST_THROW_EXCEPTION(
Error
(
"expected ControlResponse, got "
+
to_string
(
m_wire
.
type
()) +
" element"
));
77
78
Block::element_const_iterator
val =
m_wire
.
elements_begin
();
79
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusCode
) {
80
BOOST_THROW_EXCEPTION(
Error
(
"missing StatusCode sub-element"
));
81
}
82
m_code
= readNonNegativeIntegerAs<uint32_t>(*val);
83
++val;
84
85
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusText
) {
86
BOOST_THROW_EXCEPTION(
Error
(
"missing StatusText sub-element"
));
87
}
88
m_text
=
readString
(*val);
89
++val;
90
91
if
(val !=
m_wire
.
elements_end
())
92
m_body
= *val;
93
else
94
m_body
=
Block
();
95
}
96
97
std::ostream&
98
operator<<
(std::ostream& os,
const
ControlResponse
& response)
99
{
100
os << response.
getCode
() <<
" "
<< response.
getText
();
101
return
os;
102
}
103
104
}
// namespace mgmt
105
}
// namespace ndn
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:249
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::tlv::nfd::ControlResponse
Definition:
tlv-nfd.hpp:48
ndn::tlv::nfd::StatusCode
Definition:
tlv-nfd.hpp:49
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:47
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub elements.
Definition:
block.cpp:333
block-helpers.hpp
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::mgmt::ControlResponse::wireEncode
const Block & wireEncode() const
Definition:
control-response.cpp:52
ndn::encoding::readString
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
Definition:
block-helpers.cpp:118
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition:
block.hpp:369
ndn::encoding::makeNonNegativeIntegerBlock
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
Definition:
block-helpers.cpp:48
ndn::mgmt::ControlResponse::Error
Definition:
control-response.hpp:35
ndn::mgmt::ControlResponse::m_text
std::string m_text
Definition:
control-response.hpp:74
control-response.hpp
ndn::mgmt::ControlResponse::m_code
uint32_t m_code
Definition:
control-response.hpp:73
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition:
block.hpp:377
ndn::tlv::nfd::StatusText
Definition:
tlv-nfd.hpp:50
ndn::encoding::makeStringBlock
Block makeStringBlock(uint32_t type, const std::string &value)
Create a TLV block containing a string.
Definition:
block-helpers.cpp:112
ndn::Block::push_back
void push_back(const Block &element)
Append a sub element.
Definition:
block.cpp:465
ndn::mgmt::operator<<
std::ostream & operator<<(std::ostream &os, const ControlResponse &response)
Definition:
control-response.cpp:98
ndn::mgmt::ControlResponse::m_body
Block m_body
Definition:
control-response.hpp:75
ndn::mgmt::ControlResponse::wireDecode
void wireDecode(const Block &block)
Definition:
control-response.cpp:70
ndn::Block::encode
void encode()
Encode sub elements into TLV-VALUE.
Definition:
block.cpp:361
ndn::mgmt::ControlResponse::getCode
uint32_t getCode() const
Definition:
control-response.hpp:81
tlv-nfd.hpp
ndn::mgmt::ControlResponse::m_wire
Block m_wire
Definition:
control-response.hpp:77
ndn::mgmt::ControlResponse::getText
const std::string & getText() const
Definition:
control-response.hpp:95
ndn::to_string
std::string to_string(const V &v)
Definition:
backports.hpp:67
ndn::mgmt::ControlResponse
ControlCommand response.
Definition:
control-response.hpp:32
ndn::WireEncodable
a concept check for TLV abstraction with .wireEncode method
Definition:
concepts.hpp:44
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block
Definition:
concepts.hpp:80
ndn::mgmt::ControlResponse::ControlResponse
ControlResponse()
Definition:
control-response.cpp:35
ndn::Block::type
uint32_t type() const
Get TLV-TYPE.
Definition:
block.hpp:249
ndnSIM
ndn-cxx
ndn-cxx
mgmt
control-response.cpp
Generated on Sun Feb 24 2019 22:16:06 for ndnSIM by
1.8.15