A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
trickle-timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#ifndef TRICKLE_TIMER_H
21#define TRICKLE_TIMER_H
22
23#include "event-id.h"
24#include "nstime.h"
26
33namespace ns3
34{
35
36class TimerImpl;
37
74{
75 public:
78
92 TrickleTimer(Time minInterval, uint8_t doublings, uint16_t redundancy);
93
96
103 int64_t AssignStreams(int64_t streamNum);
104
118 void SetParameters(Time minInterval, uint8_t doublings, uint16_t redundancy);
119
124 Time GetMinInterval() const;
125
132 Time GetMaxInterval() const;
133
138 uint8_t GetDoublings() const;
139
144 uint16_t GetRedundancy() const;
145
151 Time GetDelayLeft() const;
152
158 Time GetIntervalLeft() const;
159
163 void Enable();
164
168 void ConsistentEvent();
169
173 void InconsistentEvent();
174
178 void Reset();
179
185 void Stop();
186
195 template <typename FN>
196 void SetFunction(FN fn);
197
208 template <typename MEM_PTR, typename OBJ_PTR>
209 void SetFunction(MEM_PTR memPtr, OBJ_PTR objPtr);
210
219 template <typename... Ts>
220 void SetArguments(Ts&&... args);
223 private:
225 void TimerExpire();
227 void IntervalExpire();
228
234
237
240
243 uint16_t m_redundancy;
244
245 uint64_t m_ticks;
247 uint16_t m_counter;
248
250};
251
252} // namespace ns3
253
254/********************************************************************
255 * Implementation of the templates declared above.
256 ********************************************************************/
257
258#include "timer-impl.h"
259
260namespace ns3
261{
262
263template <typename FN>
264void
266{
267 delete m_impl;
268 m_impl = MakeTimerImpl(fn);
269}
270
271template <typename MEM_PTR, typename OBJ_PTR>
272void
273TrickleTimer::SetFunction(MEM_PTR memPtr, OBJ_PTR objPtr)
274{
275 delete m_impl;
276 m_impl = MakeTimerImpl(memPtr, objPtr);
277}
278
279template <typename... Ts>
280void
282{
283 if (m_impl == nullptr)
284 {
286 "You cannot set the arguments of a TrickleTimer before setting its function.");
287 return;
288 }
289 m_impl->SetArgs(std::forward<Ts>(args)...);
290}
291
292} // namespace ns3
293
294#endif /* TRICKLE_TIMER_H */
An identifier for simulation events.
Definition: event-id.h:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
The timer implementation underlying Timer and Watchdog.
Definition: timer-impl.h:43
void SetArgs(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition: timer-impl.h:1085
A Trickle Timer following RFC 6206.
Definition: trickle-timer.h:74
int64_t AssignStreams(int64_t streamNum)
Assigns the stream number for the uniform random number generator to use.
uint8_t GetDoublings() const
Get the doublings of the timer.
Time m_minInterval
Minimum interval.
EventId m_timerExpiration
The future event scheduled to expire the timer.
void Stop()
Stop the timer.
Time m_currentInterval
Current interval.
Time m_maxInterval
Maximum interval.
void SetParameters(Time minInterval, uint8_t doublings, uint16_t redundancy)
Set the timer parameters.
uint64_t m_ticks
Interval span (i.e., exp2(doublings)).
Time GetMinInterval() const
Get the MinInterval of the timer.
void InconsistentEvent()
Records an inconsistent event.
void Reset()
Reset the timer.
void TimerExpire()
Internal callback invoked when the timer expires.
EventId m_intervalExpiration
The future event scheduled to expire the interval.
Time GetDelayLeft() const
uint16_t GetRedundancy() const
Get the Redundancy constant of the timer.
void SetFunction(FN fn)
Set the function to execute when the timer expires.
void Enable()
Enable the timer.
Time GetMaxInterval() const
Get the MaxInterval of the timer.
Ptr< UniformRandomVariable > m_uniRand
Object to generate uniform random numbers.
~TrickleTimer()
Destructor.
void ConsistentEvent()
Records a consistent event.
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Time GetIntervalLeft() const
TrickleTimer()
Constructor.
uint16_t m_counter
Event counter.
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
void IntervalExpire()
Internal callback invoked when the interval expires.
uint16_t m_redundancy
Redundancy constant.
ns3::EventId declarations.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:254
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ns3::RandomVariableStream declaration, and related classes.
ns3::TimerImpl declaration and implementation.