NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
control-response.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26
#include "
control-response.hpp
"
27
#include "../encoding/block-helpers.hpp"
28
#include "../encoding/tlv-nfd.hpp"
29
30
namespace
ndn
{
31
namespace
mgmt {
32
33
// BOOST_CONCEPT_ASSERT((boost::EqualityComparable<ControlResponse>));
34
BOOST_CONCEPT_ASSERT((
WireEncodable<ControlResponse>
));
35
BOOST_CONCEPT_ASSERT((
WireDecodable<ControlResponse>
));
36
static_assert(std::is_base_of<tlv::Error, ControlResponse::Error>::value,
37
"ControlResponse::Error must inherit from tlv::Error"
);
38
39
ControlResponse::ControlResponse
()
40
: m_code(200)
41
{
42
}
43
44
ControlResponse::ControlResponse
(uint32_t code,
const
std::string& text)
45
:
m_code
(code)
46
,
m_text
(text)
47
{
48
}
49
50
ControlResponse::ControlResponse
(
const
Block
& block)
51
{
52
wireDecode
(block);
53
}
54
55
const
Block
&
56
ControlResponse::wireEncode
()
const
57
{
58
if
(
m_wire
.
hasWire
())
59
return
m_wire
;
60
61
m_wire
=
Block
(
tlv::nfd::ControlResponse
);
62
m_wire
.
push_back
(
nonNegativeIntegerBlock
(
tlv::nfd::StatusCode
,
m_code
));
63
64
m_wire
.
push_back
(
dataBlock
(
tlv::nfd::StatusText
,
m_text
.c_str(),
m_text
.size()));
65
66
if
(
m_body
.
hasWire
()) {
67
m_wire
.
push_back
(
m_body
);
68
}
69
70
m_wire
.
encode
();
71
return
m_wire
;
72
}
73
74
void
75
ControlResponse::wireDecode
(
const
Block
& wire)
76
{
77
m_wire
= wire;
78
m_wire
.
parse
();
79
80
if
(
m_wire
.
type
() !=
tlv::nfd::ControlResponse
)
81
throw
Error
(
"Requested decoding of ControlResponse, but Block is of different type"
);
82
83
Block::element_const_iterator
val =
m_wire
.
elements_begin
();
84
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusCode
) {
85
throw
Error
(
"Incorrect ControlResponse format (StatusCode missing or not the first item)"
);
86
}
87
88
m_code
=
readNonNegativeInteger
(*val);
89
++val;
90
91
if
(val ==
m_wire
.
elements_end
() || val->type() !=
tlv::nfd::StatusText
) {
92
throw
Error
(
"Incorrect ControlResponse format (StatusText missing or not the second item)"
);
93
}
94
m_text
.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
95
++val;
96
97
if
(val !=
m_wire
.
elements_end
())
98
m_body
= *val;
99
else
100
m_body
=
Block
();
101
}
102
103
std::ostream&
104
operator<<
(std::ostream& os,
const
ControlResponse
& response)
105
{
106
os << response.
getCode
() <<
" "
<< response.
getText
();
107
return
os;
108
}
109
110
}
// namespace mgmt
111
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::tlv::nfd::StatusCode
Definition:
tlv-nfd.hpp:47
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:56
ndn::tlv::nfd::ControlResponse
Definition:
tlv-nfd.hpp:46
ndn::mgmt::ControlResponse::getText
const std::string & getText() const
Definition:
control-response.hpp:103
ndn::mgmt::ControlResponse::Error
Definition:
control-response.hpp:39
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:82
ndn::Block::elements_end
element_const_iterator elements_end() const
Definition:
block.cpp:595
ndn::encoding::nonNegativeIntegerBlock
Block nonNegativeIntegerBlock(uint32_t type, uint64_t value)
Definition:
block-helpers.hpp:251
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Definition:
block.cpp:589
ndn::mgmt::ControlResponse::getCode
uint32_t getCode() const
Definition:
control-response.hpp:89
control-response.hpp
ndn::mgmt::ControlResponse::m_code
uint32_t m_code
Definition:
control-response.hpp:81
ndn::tlv::nfd::StatusText
Definition:
tlv-nfd.hpp:48
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:104
ndn::Block::parse
void parse() const
Parse wire buffer into subblocks.
Definition:
block.cpp:322
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:346
ndn::mgmt::ControlResponse::m_body
Block m_body
Definition:
control-response.hpp:83
ndn::encoding::dataBlock
Block dataBlock(uint32_t type, const uint8_t *data, size_t dataSize)
Definition:
block-helpers.hpp:279
ndn::mgmt::ControlResponse::wireDecode
void wireDecode(const Block &block)
Definition:
control-response.cpp:75
ndn::Block::encode
void encode()
Encode subblocks into wire buffer.
Definition:
block.cpp:355
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:471
ndn::mgmt::ControlResponse::m_wire
Block m_wire
Definition:
control-response.hpp:85
ndn::mgmt::ControlResponse
ControlCommand response.
Definition:
control-response.hpp:36
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:39
ndnSIM
ndn-cxx
src
mgmt
control-response.cpp
Generated on Tue Feb 23 2016 22:18:43 for ndnSIM by
1.8.11