NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
22
#include "
control-response.hpp
"
23
#include "../encoding/block-helpers.hpp"
24
#include "../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
60
m_wire
.
push_back
(
makeBinaryBlock
(
tlv::nfd::StatusText
,
m_text
.c_str(),
m_text
.size()));
61
62
if
(
m_body
.
hasWire
()) {
63
m_wire
.
push_back
(
m_body
);
64
}
65
66
m_wire
.
encode
();
67
return
m_wire
;
68
}
69
70
void
71
ControlResponse::wireDecode
(
const
Block
& wire)
72
{
73
m_wire
= wire;
74
m_wire
.
parse
();
75
76
if
(
m_wire
.
type
() !=
tlv::nfd::ControlResponse
)
77
throw
Error
(
"Requested decoding of ControlResponse, but Block is of different type"
);
78
79
Block::element_const_iterator
val =
m_wire
.
elements_begin
();
80
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusCode
) {
81
throw
Error
(
"Incorrect ControlResponse format (StatusCode missing or not the first item)"
);
82
}
83
84
m_code
=
readNonNegativeInteger
(*val);
85
++val;
86
87
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusText
) {
88
throw
Error
(
"Incorrect ControlResponse format (StatusText missing or not the second item)"
);
89
}
90
m_text
.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
91
++val;
92
93
if
(val !=
m_wire
.
elements_end
())
94
m_body
= *val;
95
else
96
m_body
=
Block
();
97
}
98
99
std::ostream&
100
operator<<
(std::ostream& os,
const
ControlResponse
& response)
101
{
102
os << response.
getCode
() <<
" "
<< response.
getText
();
103
return
os;
104
}
105
106
}
// namespace mgmt
107
}
// 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::tlv::nfd::ControlResponse
Definition:
tlv-nfd.hpp:47
ndn::tlv::nfd::StatusCode
Definition:
tlv-nfd.hpp:48
ndn::Block::elements_end
element_const_iterator elements_end() const
Definition:
block.cpp:595
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::mgmt::ControlResponse::wireEncode
const Block & wireEncode() const
Definition:
control-response.cpp:52
ndn::encoding::makeNonNegativeIntegerBlock
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block type type containing non-negative integer value.
Definition:
block-helpers.cpp:49
ndn::mgmt::ControlResponse::Error
Definition:
control-response.hpp:35
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::mgmt::ControlResponse::m_text
std::string m_text
Definition:
control-response.hpp:78
control-response.hpp
ndn::mgmt::ControlResponse::m_code
uint32_t m_code
Definition:
control-response.hpp:77
ndn::encoding::makeBinaryBlock
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block type type with value from a buffer value of size length.
Definition:
block-helpers.cpp:143
ndn::tlv::nfd::StatusText
Definition:
tlv-nfd.hpp:49
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:48
ndn::Block::push_back
void push_back(const Block &element)
Definition:
block.cpp:568
ndn::mgmt::operator<<
std::ostream & operator<<(std::ostream &os, const ControlResponse &response)
Definition:
control-response.cpp:100
ndn::mgmt::ControlResponse::m_body
Block m_body
Definition:
control-response.hpp:79
ndn::mgmt::ControlResponse::wireDecode
void wireDecode(const Block &block)
Definition:
control-response.cpp:71
ndn::Block::encode
void encode()
Encode subblocks into wire buffer.
Definition:
block.cpp:355
ndn::mgmt::ControlResponse::getCode
uint32_t getCode() const
Definition:
control-response.hpp:85
ndn::mgmt::ControlResponse::m_wire
Block m_wire
Definition:
control-response.hpp:81
ndn::mgmt::ControlResponse::getText
const std::string & getText() const
Definition:
control-response.hpp:99
ndn::mgmt::ControlResponse
ControlCommand response.
Definition:
control-response.hpp:32
ndn::WireEncodable
a concept check for TLV abstraction with .wireEncode method
Definition:
concepts.hpp:34
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
Definition:
concepts.hpp:70
ndn::mgmt::ControlResponse::ControlResponse
ControlResponse()
Definition:
control-response.cpp:35
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:324
ndnSIM
ndn-cxx
src
mgmt
control-response.cpp
Generated on Wed Jan 11 2017 18:17:13 for ndnSIM by
1.8.13