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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
segment-publisher.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26
#ifndef NFD_CORE_SEGMENT_PUBLISHER_HPP
27
#define NFD_CORE_SEGMENT_PUBLISHER_HPP
28
29
#include "
common.hpp
"
30
31
#include <ndn-cxx/encoding/encoding-buffer.hpp>
32
#include <ndn-cxx/security/key-chain.hpp>
33
34
namespace
nfd {
35
39
template
<
class
FaceBase>
40
class
SegmentPublisher
: noncopyable
41
{
42
public
:
43
SegmentPublisher
(FaceBase& face,
const
Name
& prefix, ndn::KeyChain& keyChain)
44
: m_face(face)
45
, m_prefix(prefix)
46
, m_keyChain(keyChain)
47
{
48
}
49
50
virtual
51
~SegmentPublisher
()
52
{
53
}
54
55
static
size_t
56
getMaxSegmentSize
()
57
{
58
static
const
size_t
MAX_SEGMENT_SIZE = ndn::MAX_NDN_PACKET_SIZE >> 1;
59
return
MAX_SEGMENT_SIZE;
60
}
61
62
void
63
publish
()
64
{
65
ndn::EncodingBuffer buffer;
66
generate
(buffer);
67
68
const
uint8_t* rawBuffer = buffer.buf();
69
const
uint8_t* segmentBegin = rawBuffer;
70
const
uint8_t* end = rawBuffer + buffer.size();
71
72
Name
segmentPrefix(m_prefix);
73
segmentPrefix.appendVersion();
74
75
uint64_t segmentNo = 0;
76
do
{
77
const
uint8_t* segmentEnd = segmentBegin +
getMaxSegmentSize
();
78
if
(segmentEnd > end) {
79
segmentEnd = end;
80
}
81
82
Name
segmentName(segmentPrefix);
83
segmentName.appendSegment(segmentNo);
84
85
shared_ptr<Data> data = make_shared<Data>(segmentName);
86
data->setContent(segmentBegin, segmentEnd - segmentBegin);
87
88
segmentBegin = segmentEnd;
89
if
(segmentBegin >= end) {
90
data->setFinalBlockId(segmentName[-1]);
91
}
92
93
publishSegment(data);
94
++segmentNo;
95
}
while
(segmentBegin < end);
96
}
97
98
protected
:
101
virtual
size_t
102
generate
(ndn::EncodingBuffer& outBuffer) = 0;
103
104
private
:
105
void
106
publishSegment(shared_ptr<Data>& data)
107
{
108
m_keyChain.sign(*data);
109
m_face.put(*data);
110
}
111
112
private
:
113
FaceBase& m_face;
114
const
Name
m_prefix;
115
ndn::KeyChain& m_keyChain;
116
};
117
118
}
// namespace nfd
119
120
#endif // NFD_CORE_SEGMENT_PUBLISHER_HPP
nfd::SegmentPublisher::generate
virtual size_t generate(ndn::EncodingBuffer &outBuffer)=0
In a derived class, write the octets into outBuffer.
nfd::SegmentPublisher
provides a publisher of Status Dataset or other segmented octet stream
Definition:
segment-publisher.hpp:40
nfd::SegmentPublisher::~SegmentPublisher
virtual ~SegmentPublisher()
Definition:
segment-publisher.hpp:51
common.hpp
ns3::ndn::Name
Name
Definition:
ndn-common.cpp:25
nfd::SegmentPublisher::publish
void publish()
Definition:
segment-publisher.hpp:63
nfd::SegmentPublisher::SegmentPublisher
SegmentPublisher(FaceBase &face, const Name &prefix, ndn::KeyChain &keyChain)
Definition:
segment-publisher.hpp:43
nfd::SegmentPublisher::getMaxSegmentSize
static size_t getMaxSegmentSize()
Definition:
segment-publisher.hpp:56
ndnSIM
NFD
core
segment-publisher.hpp
Generated on Wed Feb 18 2015 16:31:16 for ndnSIM by
1.8.7