A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
backoff.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, Emmanuelle Laprise
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
18 */
19
20#include "backoff.h"
21
22#include "ns3/log.h"
23
24namespace ns3
25{
26
28
30{
32 m_minSlots = 1;
33 m_maxSlots = 1000;
34 m_ceiling = 10;
35 m_maxRetries = 1000;
37 m_rng = CreateObject<UniformRandomVariable>();
38
40}
41
43 uint32_t minSlots,
44 uint32_t maxSlots,
45 uint32_t ceiling,
46 uint32_t maxRetries)
47{
48 m_slotTime = slotTime;
49 m_minSlots = minSlots;
50 m_maxSlots = maxSlots;
51 m_ceiling = ceiling;
52 m_maxRetries = maxRetries;
54 m_rng = CreateObject<UniformRandomVariable>();
55}
56
57Time
59{
60 uint32_t ceiling;
61
63 {
64 ceiling = m_ceiling;
65 }
66 else
67 {
68 ceiling = m_numBackoffRetries;
69 }
70
71 uint32_t minSlot = m_minSlots;
72 uint32_t maxSlot = (uint32_t)pow(2, ceiling) - 1;
73 if (maxSlot > m_maxSlots)
74 {
75 maxSlot = m_maxSlots;
76 }
77
78 auto backoffSlots = (uint32_t)m_rng->GetValue(minSlot, maxSlot);
79
80 Time backoff = Time(backoffSlots * m_slotTime);
81 return backoff;
82}
83
84void
86{
88}
89
90bool
92{
94}
95
96void
98{
100}
101
102int64_t
104{
105 NS_LOG_FUNCTION(this << stream);
106 m_rng->SetStream(stream);
107 return 1;
108}
109
110} // namespace ns3
void ResetBackoffTime()
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
Definition: backoff.cc:85
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition: backoff.h:61
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: backoff.cc:103
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time)
Definition: backoff.h:51
uint32_t m_numBackoffRetries
Number of times that the transmitter has tried to unsuccessfuly transmit the current packet.
Definition: backoff.h:121
bool MaxRetriesReached() const
Definition: backoff.cc:91
void IncrNumRetries()
Increments the number of retries by 1.
Definition: backoff.cc:97
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time)
Definition: backoff.h:45
Time GetBackoffTime()
Definition: backoff.cc:58
Ptr< UniformRandomVariable > m_rng
Random number generator.
Definition: backoff.h:126
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition: backoff.h:56
Time m_slotTime
Length of one slot.
Definition: backoff.h:67
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetValue(double min, double max)
Get the next random value drawn from the distribution.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.