NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndnlp-data.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26
#include "
ndnlp-data.hpp
"
27
28
namespace
nfd
{
29
namespace
ndnlp {
30
31
std::tuple<bool, NdnlpData>
32
NdnlpData::fromBlock
(
const
Block
& wire)
33
{
34
if
(wire.
type
() !=
tlv::NdnlpData
) {
35
// top element is not NdnlpData
36
return
std::make_tuple(
false
,
NdnlpData
());
37
}
38
wire.
parse
();
39
const
Block::element_container
& elements = wire.
elements
();
40
if
(elements.size() < 2) {
41
// NdnlpData element has incorrect number of children
42
return
std::make_tuple(
false
,
NdnlpData
());
43
}
44
45
NdnlpData
parsed;
46
47
const
Block
& sequenceElement = elements.front();
48
if
(sequenceElement.
type
() !=
tlv::NdnlpSequence
) {
49
// NdnlpSequence element is missing
50
return
std::make_tuple(
false
,
NdnlpData
());
51
}
52
if
(sequenceElement.
value_size
() !=
sizeof
(uint64_t)) {
53
// NdnlpSequence element has incorrect length
54
return
std::make_tuple(
false
,
NdnlpData
());
55
}
56
parsed.
seq
= be64toh(*reinterpret_cast<const uint64_t*>(&*sequenceElement.
value_begin
()));
57
58
const
Block
& payloadElement = elements.back();
59
if
(payloadElement.
type
() !=
tlv::NdnlpPayload
) {
60
// NdnlpPayload element is missing
61
return
std::make_tuple(
false
,
NdnlpData
());
62
}
63
parsed.
payload
= payloadElement;
64
65
if
(elements.size() == 2) {
// single wire packet
66
parsed.
fragIndex
= 0;
67
parsed.
fragCount
= 1;
68
return
std::make_tuple(
true
, parsed);
69
}
70
if
(elements.size() != 4) {
71
// NdnlpData element has incorrect number of children
72
return
std::make_tuple(
false
,
NdnlpData
());
73
}
74
75
const
Block
& fragIndexElement = elements.at(1);
76
if
(fragIndexElement.
type
() !=
tlv::NdnlpFragIndex
) {
77
// NdnlpFragIndex element is missing
78
return
std::make_tuple(
false
,
NdnlpData
());
79
}
80
uint64_t
fragIndex
=
ndn::readNonNegativeInteger
(fragIndexElement);
81
if
(
fragIndex
> std::numeric_limits<uint16_t>::max()) {
82
// NdnlpFragIndex is too large
83
return
std::make_tuple(
false
,
NdnlpData
());
84
}
85
parsed.
fragIndex
=
static_cast<
uint16_t
>
(
fragIndex
);
86
87
const
Block
& fragCountElement = elements.at(2);
88
if
(fragCountElement.
type
() !=
tlv::NdnlpFragCount
) {
89
// NdnlpFragCount element is missing
90
return
std::make_tuple(
false
,
NdnlpData
());
91
}
92
uint64_t
fragCount
=
ndn::readNonNegativeInteger
(fragCountElement);
93
if
(
fragCount
> std::numeric_limits<uint16_t>::max()) {
94
// NdnlpFragCount is too large
95
return
std::make_tuple(
false
,
NdnlpData
());
96
}
97
parsed.
fragCount
=
static_cast<
uint16_t
>
(
fragCount
);
98
99
if
(parsed.
fragIndex
>= parsed.
fragCount
) {
100
// NdnlpFragIndex must be less than NdnlpFragCount
101
return
std::make_tuple(
false
,
NdnlpData
());
102
}
103
104
return
std::make_tuple(
true
, parsed);
105
}
106
107
}
// namespace ndnlp
108
}
// namespace nfd
ndn::Block::value_size
size_t value_size() const
Definition:
block.cpp:529
nfd::ndnlp::NdnlpData
represents a NdnlpData packet
Definition:
ndnlp-data.hpp:43
nfd::tlv::NdnlpData
Definition:
ndnlp-tlv.hpp:33
ndnlp-data.hpp
nfd::ndnlp::NdnlpData::seq
uint64_t seq
Definition:
ndnlp-data.hpp:53
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
nfd::ndnlp::NdnlpData::fromBlock
static std::tuple< bool, NdnlpData > fromBlock(const Block &wire)
parse a NdnlpData packet
Definition:
ndnlp-data.cpp:32
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
Definition:
block-helpers.cpp:61
nfd::ndnlp::NdnlpData::fragCount
uint16_t fragCount
Definition:
ndnlp-data.hpp:55
ndn::Block::value_begin
Buffer::const_iterator value_begin() const
Definition:
block.hpp:352
nfd::tlv::NdnlpPayload
Definition:
ndnlp-tlv.hpp:37
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
nfd::tlv::NdnlpSequence
Definition:
ndnlp-tlv.hpp:34
nfd::tlv::NdnlpFragIndex
Definition:
ndnlp-tlv.hpp:35
nfd::ndnlp::NdnlpData::fragIndex
uint16_t fragIndex
Definition:
ndnlp-data.hpp:54
ndn::Block::element_container
std::vector< Block > element_container
Definition:
block.hpp:46
nfd::tlv::NdnlpFragCount
Definition:
ndnlp-tlv.hpp:36
ndn::Block::elements
const element_container & elements() const
Get all subelements.
Definition:
block.hpp:364
nfd::ndnlp::NdnlpData::payload
Block payload
Definition:
ndnlp-data.hpp:56
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:346
ndnSIM
NFD
daemon
face
ndnlp-data.cpp
Generated on Fri Feb 23 2018 12:30:55 for ndnSIM by
1.8.14