A Discrete-Event Network Simulator
API
trickle-timer.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2020 Universita' di Firenze, Italy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19 */
20
21#ifndef TRICKLE_TIMER_H
22#define TRICKLE_TIMER_H
23
24#include "nstime.h"
25#include "event-id.h"
27
34namespace ns3 {
35
36class TimerImpl;
37
74{
75public:
77 TrickleTimer ();
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 (void) const;
125
132 Time GetMaxInterval (void) const;
133
138 uint8_t GetDoublings (void) const;
139
144 uint16_t GetRedundancy (void) const;
145
151 Time GetDelayLeft (void) const;
152
158 Time GetIntervalLeft (void) 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
211
220 template <typename... Ts>
221 void SetArguments (Ts&&... args);
224private:
226 void TimerExpire (void);
228 void IntervalExpire (void);
229
235
238
241
242
245 uint16_t m_redundancy;
246
247 uint64_t m_ticks;
249 uint16_t m_counter;
250
252};
253
254} // namespace ns3
255
256
257/********************************************************************
258 * Implementation of the templates declared above.
259 ********************************************************************/
260
261#include "timer-impl.h"
262
263namespace ns3 {
264
265
266template <typename FN>
267void
269{
270 delete m_impl;
271 m_impl = MakeTimerImpl (fn);
272}
273template <typename MEM_PTR, typename OBJ_PTR>
274void
275TrickleTimer::SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
276{
277 delete m_impl;
278 m_impl = MakeTimerImpl (memPtr, objPtr);
279}
280
281template <typename... Ts>
282void
284{
285 if (m_impl == 0)
286 {
287 NS_FATAL_ERROR ("You cannot set the arguments of a TrickleTimer before setting its function.");
288 return;
289 }
290 m_impl->SetArgs (std::forward<Ts>(args)...);
291}
292
293} // namespace ns3
294
295
296#endif /* TRICKLE_TIMER_H */
An identifier for simulation events.
Definition: event-id.h:54
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
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:959
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.
uint16_t GetRedundancy(void) const
Get the Redundancy constant of the timer.
void IntervalExpire(void)
Internal callback invoked when the interval expires.
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.
Time GetMinInterval(void) const
Get the MinInterval of the timer.
uint64_t m_ticks
Interval span (i.e., exp2(doublings)).
void TimerExpire(void)
Internal callback invoked when the timer expires.
void InconsistentEvent()
Records an inconsistent event.
Time GetIntervalLeft(void) const
void Reset()
Reset the timer.
Time GetDelayLeft(void) const
EventId m_intervalExpiration
The future event scheduled to expire the interval.
void SetFunction(FN fn)
Set the function to execute when the timer expires.
void Enable()
Enable the timer.
Time GetMaxInterval(void) const
Get the MaxInterval of the timer.
uint8_t GetDoublings(void) const
Get the doublings 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.
TrickleTimer()
Constructor.
uint16_t m_counter
Event counter.
TimerImpl * m_impl
The timer implementation, which contains the bound callback function and arguments.
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:165
TimerImpl * MakeTimerImpl(FN fn)
Make a TimerImpl from a function pointer taking varying numbers of arguments.
Definition: timer-impl.h:252
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.