NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-block-header.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20
#include "
ndn-block-header.hpp
"
21
22
#include <iosfwd>
23
#include <boost/iostreams/concepts.hpp>
24
#include <boost/iostreams/stream.hpp>
25
26
#include <
ndn-cxx/encoding/tlv.hpp
>
27
#include <
ndn-cxx/interest.hpp
>
28
#include <
ndn-cxx/data.hpp
>
29
#include <
ndn-cxx/lp/packet.hpp
>
30
31
namespace
io = boost::iostreams;
32
namespace
nfdFace
=
nfd::face
;
33
34
namespace
ns3
{
35
namespace
ndn
{
36
37
ns3::TypeId
38
BlockHeader::GetTypeId
()
39
{
40
static
ns3::TypeId tid =
41
ns3::TypeId(
"ns3::ndn::Packet"
)
42
.SetGroupName(
"Ndn"
)
43
.SetParent<Header>()
44
.AddConstructor<BlockHeader>()
45
;
46
return
tid;
47
}
48
49
TypeId
50
BlockHeader::GetInstanceTypeId
(
void
)
const
51
{
52
return
GetTypeId
();
53
}
54
55
BlockHeader::BlockHeader
()
56
{
57
}
58
59
BlockHeader::BlockHeader
(
const
nfdFace::Transport::Packet& packet)
60
: m_block(packet.packet)
61
{
62
}
63
64
uint32_t
65
BlockHeader::GetSerializedSize
(
void
)
const
66
{
67
return
m_block.size();
68
}
69
70
void
71
BlockHeader::Serialize
(ns3::Buffer::Iterator start)
const
72
{
73
start.Write(m_block.wire(), m_block.size());
74
}
75
76
class
Ns3BufferIteratorSource
:
public
io::source {
77
public
:
78
Ns3BufferIteratorSource
(ns3::Buffer::Iterator& is)
79
: m_is(is)
80
{
81
}
82
83
std::streamsize
84
read
(
char
* buf, std::streamsize nMaxRead)
85
{
86
std::streamsize i = 0;
87
for
(; i < nMaxRead && !m_is.IsEnd(); ++i) {
88
buf[i] = m_is.ReadU8();
89
}
90
if
(i == 0) {
91
return
-1;
92
}
93
else
{
94
return
i;
95
}
96
}
97
98
private
:
99
ns3::Buffer::Iterator& m_is;
100
};
101
102
uint32_t
103
BlockHeader::Deserialize
(ns3::Buffer::Iterator start)
104
{
105
io::stream<Ns3BufferIteratorSource> is(start);
106
m_block =
::ndn::Block::fromStream
(is);
107
return
m_block.size();
108
}
109
110
void
111
BlockHeader::Print
(std::ostream& os)
const
112
{
113
namespace
tlv = ::ndn::tlv;
114
namespace
lp
= ::ndn::lp;
115
116
std::function<void(
const
Block& block)> decodeAndPrint = [&os, &decodeAndPrint] (
const
Block& block) {
117
switch
(block.type()) {
118
case
tlv::Interest
: {
119
Interest
i(block);
120
os <<
"Interest: "
<< i;
121
break
;
122
}
123
case
tlv::Data
: {
124
Data
d(block);
125
os <<
"Data: "
<< d.getName();
126
break
;
127
}
128
case
lp::tlv::LpPacket
: {
129
os <<
"NDNLP("
;
130
lp::Packet
p(block);
131
if
(p.
has
<
lp::FragCountField
>() && p.
get
<
lp::FragCountField
>() != 1) {
132
os <<
"fragment "
<< (p.
get
<
lp::FragIndexField
>() + 1) <<
" out of "
<< p.
get
<
lp::FragCountField
>();
133
}
134
else
{
135
if
(p.
has
<
lp::NackField
>()) {
136
lp::NackHeader
nack = p.
get
<
lp::NackField
>();
137
os <<
"NACK("
<< nack.
getReason
() <<
") for "
;
138
}
139
140
::ndn::Buffer::const_iterator first, last;
141
std::tie(first, last) = p.
get
<
lp::FragmentField
>(0);
142
Block fragmentBlock(&*first, std::distance(first, last));
143
decodeAndPrint(fragmentBlock);
144
}
145
os <<
")"
;
146
break
;
147
}
148
default
: {
149
os <<
"Unrecognized"
;
150
break
;
151
}
152
}
153
};
154
155
decodeAndPrint(m_block);
156
}
157
158
Block&
159
BlockHeader::getBlock
()
160
{
161
return
m_block;
162
}
163
164
const
Block&
165
BlockHeader::getBlock
()
const
166
{
167
return
m_block;
168
}
169
170
}
// namespace ndn
171
}
// namespace ns3
tlv.hpp
ns3::ndn::BlockHeader::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ndn-block-header.cpp:65
ndn::Block::fromStream
static Block fromStream(std::istream &is)
Parse Block from an input stream.
Definition:
block.cpp:161
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::lp::tlv::LpPacket
Definition:
tlv.hpp:33
ns3::ndn::BlockHeader::Deserialize
virtual uint32_t Deserialize(ns3::Buffer::Iterator start)
Definition:
ndn-block-header.cpp:103
ns3::ndn::BlockHeader::Serialize
virtual void Serialize(ns3::Buffer::Iterator start) const
Definition:
ndn-block-header.cpp:71
ns3::ndn::BlockHeader::BlockHeader
BlockHeader()
Definition:
ndn-block-header.cpp:55
packet.hpp
ndn::lp::Packet::has
bool has() const
Definition:
packet.hpp:74
ns3::ndn::Ns3BufferIteratorSource::Ns3BufferIteratorSource
Ns3BufferIteratorSource(ns3::Buffer::Iterator &is)
Definition:
ndn-block-header.cpp:78
ndn::lp::NackHeader::getReason
NackReason getReason() const
Definition:
nack-header.cpp:127
ns3::ndn::BlockHeader::Print
virtual void Print(std::ostream &os) const
Definition:
ndn-block-header.cpp:111
ndn::lp::FieldDecl
Declare a field.
Definition:
field-decl.hpp:181
ndn::lp::Packet::get
FIELD::ValueType get(size_t index=0) const
Definition:
packet.hpp:97
nfd::face
Definition:
ndn-common.hpp:86
data.hpp
ns3::ndn::BlockHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition:
ndn-block-header.cpp:50
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
content-store-impl.cpp:38
ns3::ndn::BlockHeader::getBlock
Block & getBlock()
Definition:
ndn-block-header.cpp:159
ndn::tlv::Data
Definition:
tlv.hpp:63
interest.hpp
ndn-block-header.hpp
ndn::tlv::Interest
Definition:
tlv.hpp:62
ns3::ndn::BlockHeader::GetTypeId
static ns3::TypeId GetTypeId()
Definition:
ndn-block-header.cpp:38
ndn::lp
Definition:
cache-policy.cpp:28
ns3::ndn::Ns3BufferIteratorSource::read
std::streamsize read(char *buf, std::streamsize nMaxRead)
Definition:
ndn-block-header.cpp:84
ndn::lp::NackHeader
represents a Network NACK header
Definition:
nack-header.hpp:57
ndn::lp::Packet
Definition:
packet.hpp:30
ns3::ndn::Ns3BufferIteratorSource
Definition:
ndn-block-header.cpp:76
ndnSIM
model
ndn-block-header.cpp
Generated on Sun Feb 24 2019 22:16:05 for ndnSIM by
1.8.15