NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
notification-subscriber.hpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2014-2019 Regents of the University of California,
4
* Arizona Board of Regents,
5
* Colorado State University,
6
* University Pierre & Marie Curie, Sorbonne University,
7
* Washington University in St. Louis,
8
* Beijing Institute of Technology,
9
* The University of Memphis.
10
*
11
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
12
*
13
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
14
* terms of the GNU Lesser General Public License as published by the Free Software
15
* Foundation, either version 3 of the License, or (at your option) any later version.
16
*
17
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
18
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20
*
21
* You should have received copies of the GNU General Public License and GNU Lesser
22
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
23
* <http://www.gnu.org/licenses/>.
24
*
25
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
26
*/
27
28
#ifndef NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
29
#define NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
30
31
#include "
ndn-cxx/face.hpp
"
32
#include "
ndn-cxx/util/concepts.hpp
"
33
#include "
ndn-cxx/util/scheduler.hpp
"
34
#include "
ndn-cxx/util/signal.hpp
"
35
#include "
ndn-cxx/util/time.hpp
"
36
37
namespace
ndn
{
38
namespace
util {
39
40
class
NotificationSubscriberBase
: noncopyable
41
{
42
public
:
43
virtual
44
~NotificationSubscriberBase
();
45
51
time::milliseconds
52
getInterestLifetime
()
const
53
{
54
return
m_interestLifetime;
55
}
56
57
bool
58
isRunning
()
const
59
{
60
return
m_isRunning;
61
}
62
67
void
68
start
();
69
72
void
73
stop
();
74
75
protected
:
80
NotificationSubscriberBase
(
Face
& face,
const
Name
& prefix,
81
time::milliseconds interestLifetime);
82
83
private
:
84
void
85
sendInitialInterest();
86
87
void
88
sendNextInterest();
89
90
void
91
sendInterest(
const
Interest
& interest);
92
93
virtual
bool
94
hasSubscriber()
const
= 0;
95
99
bool
100
shouldStop();
101
102
void
103
afterReceiveData(
const
Data
& data);
104
108
virtual
bool
109
decodeAndDeliver(
const
Data
& data) = 0;
110
111
void
112
afterReceiveNack(
const
lp::Nack
& nack);
113
114
void
115
afterTimeout();
116
117
time::milliseconds
118
exponentialBackoff(
lp::Nack
nack);
119
120
public
:
123
signal::Signal<NotificationSubscriberBase, lp::Nack>
onNack
;
124
127
signal::Signal<NotificationSubscriberBase>
onTimeout
;
128
131
signal::Signal<NotificationSubscriberBase, Data>
onDecodeError
;
132
133
private
:
134
Face
& m_face;
135
Name
m_prefix;
136
bool
m_isRunning;
137
uint64_t m_lastSequenceNum;
138
uint64_t m_lastNackSequenceNum;
139
uint64_t m_attempts;
140
Scheduler
m_scheduler;
141
scheduler::ScopedEventId
m_nackEvent;
142
ScopedPendingInterestHandle
m_lastInterest;
143
time::milliseconds m_interestLifetime;
144
};
145
150
template
<
typename
Notification>
151
class
NotificationSubscriber
:
public
NotificationSubscriberBase
152
{
153
public
:
154
BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<Notification>));
155
BOOST_CONCEPT_ASSERT((
WireDecodable<Notification>
));
156
161
NotificationSubscriber
(
Face
& face,
const
Name
& prefix,
162
time::milliseconds interestLifetime = 1_min)
163
:
NotificationSubscriberBase
(face, prefix, interestLifetime)
164
{
165
}
166
167
public
:
171
signal::Signal<NotificationSubscriber, Notification>
onNotification
;
172
173
private
:
174
bool
175
hasSubscriber()
const override
176
{
177
return
!
onNotification
.isEmpty();
178
}
179
180
bool
181
decodeAndDeliver(
const
Data
& data)
override
182
{
183
Notification notification;
184
try
{
185
notification.wireDecode(data.
getContent
().
blockFromValue
());
186
}
187
catch
(
const
tlv::Error
&) {
188
return
false
;
189
}
190
191
onNotification
(notification);
192
return
true
;
193
}
194
};
195
196
}
// namespace util
197
}
// namespace ndn
198
199
#endif // NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
ndn::Block::blockFromValue
Block blockFromValue() const
Definition:
block.cpp:314
signal.hpp
ndn::util::NotificationSubscriberBase::start
void start()
start or resume receiving notifications
Definition:
notification-subscriber.cpp:52
ndn::Data::getContent
const Block & getContent() const
Get Content.
Definition:
data.cpp:232
concepts.hpp
ndn::Face
Provide a communication channel with local or remote NDN forwarder.
Definition:
face.hpp:90
scheduler.hpp
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition:
signal.hpp:52
ndn::WireDecodable
a concept check for TLV abstraction with .wireDecode method and constructible from Block
Definition:
concepts.hpp:81
ndn::util::NotificationSubscriberBase
Definition:
notification-subscriber.hpp:41
ndn::util::NotificationSubscriberBase::isRunning
bool isRunning() const
Definition:
notification-subscriber.hpp:58
ndn::Name
Represents an absolute name.
Definition:
name.hpp:44
ndn::util::NotificationSubscriberBase::getInterestLifetime
time::milliseconds getInterestLifetime() const
Definition:
notification-subscriber.hpp:52
ndn::util::NotificationSubscriberBase::stop
void stop()
stop receiving notifications
Definition:
notification-subscriber.cpp:62
ndn::Interest
Represents an Interest packet.
Definition:
interest.hpp:44
ndn::util::NotificationSubscriber::onNotification
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
Definition:
notification-subscriber.hpp:171
ndn::util::NotificationSubscriberBase::onTimeout
signal::Signal< NotificationSubscriberBase > onTimeout
fires when no Notification is received within .getInterestLifetime period
Definition:
notification-subscriber.hpp:127
ndn::Data
Represents a Data packet.
Definition:
data.hpp:36
ndn::util::NotificationSubscriberBase::NotificationSubscriberBase
NotificationSubscriberBase(Face &face, const Name &prefix, time::milliseconds interestLifetime)
construct a NotificationSubscriber
Definition:
notification-subscriber.cpp:36
face.hpp
ndn::lp::Nack
represents a Network Nack
Definition:
nack.hpp:39
ndn::scheduler::Scheduler
Generic time-based scheduler.
Definition:
scheduler.hpp:133
ndn::util::NotificationSubscriber
provides a subscriber of Notification Stream
Definition:
notification-subscriber.hpp:152
time.hpp
ndn::util::NotificationSubscriber::NotificationSubscriber
NotificationSubscriber(Face &face, const Name &prefix, time::milliseconds interestLifetime=1_min)
construct a NotificationSubscriber
Definition:
notification-subscriber.hpp:161
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition:
tlv.hpp:53
ndn::util::NotificationSubscriberBase::~NotificationSubscriberBase
virtual ~NotificationSubscriberBase()
ndn::util::NotificationSubscriberBase::onNack
signal::Signal< NotificationSubscriberBase, lp::Nack > onNack
fires when a NACK is received
Definition:
notification-subscriber.hpp:123
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::detail::ScopedCancelHandle< EventId >
ndn::util::NotificationSubscriberBase::onDecodeError
signal::Signal< NotificationSubscriberBase, Data > onDecodeError
fires when a Data packet in the Notification Stream cannot be decoded as Notification
Definition:
notification-subscriber.hpp:131
ndnSIM
ndn-cxx
ndn-cxx
util
notification-subscriber.hpp
Generated on Mon Jun 1 2020 22:32:15 for ndnSIM by
1.8.18