A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
backoff.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007, Emmanuelle Laprise
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
7
*/
8
9
#include "
backoff.h
"
10
11
#include "ns3/log.h"
12
13
namespace
ns3
14
{
15
16
NS_LOG_COMPONENT_DEFINE
(
"Backoff"
);
17
18
Backoff::Backoff
()
19
{
20
m_slotTime
=
MicroSeconds
(1);
21
m_minSlots
= 1;
22
m_maxSlots
= 1000;
23
m_ceiling
= 10;
24
m_maxRetries
= 1000;
25
m_numBackoffRetries
= 0;
26
m_rng
=
CreateObject<UniformRandomVariable>
();
27
28
ResetBackoffTime
();
29
}
30
31
Backoff::Backoff
(
Time
slotTime,
32
uint32_t
minSlots,
33
uint32_t
maxSlots,
34
uint32_t
ceiling,
35
uint32_t
maxRetries)
36
{
37
m_slotTime
= slotTime;
38
m_minSlots
= minSlots;
39
m_maxSlots
= maxSlots;
40
m_ceiling
= ceiling;
41
m_maxRetries
= maxRetries;
42
m_numBackoffRetries
= 0;
43
m_rng
=
CreateObject<UniformRandomVariable>
();
44
}
45
46
Time
47
Backoff::GetBackoffTime
()
48
{
49
uint32_t
ceiling;
50
51
if
((
m_ceiling
> 0) && (
m_numBackoffRetries
>
m_ceiling
))
52
{
53
ceiling =
m_ceiling
;
54
}
55
else
56
{
57
ceiling =
m_numBackoffRetries
;
58
}
59
60
uint32_t
minSlot =
m_minSlots
;
61
uint32_t
maxSlot = (
uint32_t
)pow(2, ceiling) - 1;
62
if
(maxSlot >
m_maxSlots
)
63
{
64
maxSlot =
m_maxSlots
;
65
}
66
67
auto
backoffSlots = (
uint32_t
)
m_rng
->GetValue(minSlot, maxSlot);
68
69
Time
backoff =
Time
(backoffSlots *
m_slotTime
);
70
return
backoff;
71
}
72
73
void
74
Backoff::ResetBackoffTime
()
75
{
76
m_numBackoffRetries
= 0;
77
}
78
79
bool
80
Backoff::MaxRetriesReached
()
const
81
{
82
return
(
m_numBackoffRetries
>=
m_maxRetries
);
83
}
84
85
void
86
Backoff::IncrNumRetries
()
87
{
88
m_numBackoffRetries
++;
89
}
90
91
int64_t
92
Backoff::AssignStreams
(int64_t stream)
93
{
94
NS_LOG_FUNCTION
(
this
<< stream);
95
m_rng
->SetStream(stream);
96
return
1;
97
}
98
99
}
// 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:74
ns3::Backoff::m_maxRetries
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
Definition
backoff.h:50
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:92
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:40
ns3::Backoff::m_numBackoffRetries
uint32_t m_numBackoffRetries
Number of times that the transmitter has tried to unsuccessfuly transmit the current packet.
Definition
backoff.h:110
ns3::Backoff::MaxRetriesReached
bool MaxRetriesReached() const
Definition
backoff.cc:80
ns3::Backoff::IncrNumRetries
void IncrNumRetries()
Increments the number of retries by 1.
Definition
backoff.cc:86
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:34
ns3::Backoff::Backoff
Backoff()
Definition
backoff.cc:18
ns3::Backoff::GetBackoffTime
Time GetBackoffTime()
Definition
backoff.cc:47
ns3::Backoff::m_rng
Ptr< UniformRandomVariable > m_rng
Random number generator.
Definition
backoff.h:115
ns3::Backoff::m_ceiling
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
Definition
backoff.h:45
ns3::Backoff::m_slotTime
Time m_slotTime
Length of one slot.
Definition
backoff.h:56
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
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:229
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1332
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
csma
model
backoff.cc
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0