A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
24
namespace
ns3
25
{
26
27
NS_LOG_COMPONENT_DEFINE
(
"Backoff"
);
28
29
Backoff::Backoff
()
30
{
31
m_slotTime
=
MicroSeconds
(1);
32
m_minSlots
= 1;
33
m_maxSlots
= 1000;
34
m_ceiling
= 10;
35
m_maxRetries
= 1000;
36
m_numBackoffRetries
= 0;
37
m_rng
= CreateObject<UniformRandomVariable>();
38
39
ResetBackoffTime
();
40
}
41
42
Backoff::Backoff
(
Time
slotTime,
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;
53
m_numBackoffRetries
= 0;
54
m_rng
= CreateObject<UniformRandomVariable>();
55
}
56
57
Time
58
Backoff::GetBackoffTime
()
59
{
60
uint32_t
ceiling;
61
62
if
((
m_ceiling
> 0) && (
m_numBackoffRetries
>
m_ceiling
))
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
uint32_t
backoffSlots = (
uint32_t
)
m_rng
->
GetValue
(minSlot, maxSlot);
79
80
Time
backoff =
Time
(backoffSlots *
m_slotTime
);
81
return
backoff;
82
}
83
84
void
85
Backoff::ResetBackoffTime
()
86
{
87
m_numBackoffRetries
= 0;
88
}
89
90
bool
91
Backoff::MaxRetriesReached
()
92
{
93
return
(
m_numBackoffRetries
>=
m_maxRetries
);
94
}
95
96
void
97
Backoff::IncrNumRetries
()
98
{
99
m_numBackoffRetries
++;
100
}
101
102
int64_t
103
Backoff::AssignStreams
(int64_t stream)
104
{
105
NS_LOG_FUNCTION
(
this
<< stream);
106
m_rng
->
SetStream
(stream);
107
return
1;
108
}
109
110
}
// namespace ns3
backoff.h
ns3::Backoff::ResetBackoffTime
void ResetBackoffTime()
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
Definition:
backoff.cc:85
ns3::Backoff::m_maxRetries
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition:
backoff.h:61
ns3::Backoff::AssignStreams
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
ns3::Backoff::m_maxSlots
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time)
Definition:
backoff.h:51
ns3::Backoff::MaxRetriesReached
bool MaxRetriesReached()
Definition:
backoff.cc:91
ns3::Backoff::m_numBackoffRetries
uint32_t m_numBackoffRetries
Number of times that the transmitter has tried to unsuccessfully transmit the current packet.
Definition:
backoff.h:121
ns3::Backoff::IncrNumRetries
void IncrNumRetries()
Increments the number of retries by 1.
Definition:
backoff.cc:97
ns3::Backoff::m_minSlots
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time)
Definition:
backoff.h:45
ns3::Backoff::Backoff
Backoff()
Definition:
backoff.cc:29
ns3::Backoff::GetBackoffTime
Time GetBackoffTime()
Definition:
backoff.cc:58
ns3::Backoff::m_rng
Ptr< UniformRandomVariable > m_rng
Random number generator.
Definition:
backoff.h:126
ns3::Backoff::m_ceiling
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition:
backoff.h:56
ns3::Backoff::m_slotTime
Time m_slotTime
Length of one slot.
Definition:
backoff.h:67
ns3::RandomVariableStream::SetStream
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Definition:
random-variable-stream.cc:106
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
ns3::UniformRandomVariable::GetValue
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
Definition:
random-variable-stream.cc:189
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:238
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1362
ns3::TracedValueCallback::Time
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition:
nstime.h:850
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
csma
model
backoff.cc
Generated on Tue Nov 1 2022 22:59:49 for ns-3 by
1.9.3