A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
backoff.cc
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007, Emmanuelle Laprise
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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
19
*/
20
21
#include "backoff.h"
22
#include "ns3/log.h"
23
24
NS_LOG_COMPONENT_DEFINE
(
"Backoff"
);
25
26
namespace
ns3 {
27
28
Backoff::Backoff ()
29
{
30
m_slotTime
=
MicroSeconds
(1);
31
m_minSlots
= 1;
32
m_maxSlots
= 1000;
33
m_ceiling
= 10;
34
m_maxRetries
= 1000;
35
m_rng = CreateObject<UniformRandomVariable> ();
36
37
ResetBackoffTime
();
38
}
39
40
Backoff::Backoff(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t ceiling, uint32_t maxRetries)
41
{
42
m_slotTime
= slotTime;
43
m_minSlots
= minSlots;
44
m_maxSlots
= maxSlots;
45
m_ceiling
= ceiling;
46
m_maxRetries
= maxRetries;
47
m_rng = CreateObject<UniformRandomVariable> ();
48
}
49
50
Time
51
Backoff::GetBackoffTime
(
void
)
52
{
53
uint32_t ceiling;
54
55
if
((
m_ceiling
> 0) &&(
m_numBackoffRetries
>
m_ceiling
))
56
{
57
ceiling =
m_ceiling
;
58
}
59
else
60
{
61
ceiling =
m_numBackoffRetries
;
62
}
63
64
uint32_t minSlot =
m_minSlots
;
65
uint32_t maxSlot = (uint32_t)pow (2, ceiling) - 1;
66
if
(maxSlot >
m_maxSlots
)
67
{
68
maxSlot =
m_maxSlots
;
69
}
70
71
uint32_t backoffSlots = (uint32_t)m_rng->
GetValue
(minSlot, maxSlot);
72
73
Time
backoff =
Time
(backoffSlots *
m_slotTime
);
74
return
backoff;
75
}
76
77
void
78
Backoff::ResetBackoffTime
(
void
)
79
{
80
m_numBackoffRetries
= 0;
81
}
82
83
bool
84
Backoff::MaxRetriesReached
(
void
)
85
{
86
return
(
m_numBackoffRetries
>=
m_maxRetries
);
87
}
88
89
void
90
Backoff::IncrNumRetries
(
void
)
91
{
92
m_numBackoffRetries
++;
93
}
94
95
int64_t
96
Backoff::AssignStreams
(int64_t stream)
97
{
98
NS_LOG_FUNCTION
(
this
<< stream);
99
m_rng->
SetStream
(stream);
100
return
1;
101
}
102
103
}
// namespace ns3
ns3::Time
keep track of time unit.
Definition:
nstime.h:149
ns3::Backoff::ResetBackoffTime
void ResetBackoffTime(void)
Definition:
backoff.cc:78
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::RandomVariableStream::SetStream
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
Definition:
random-variable-stream.cc:91
ns3::Backoff::m_maxSlots
uint32_t m_maxSlots
Definition:
backoff.h:47
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::Backoff::m_maxRetries
uint32_t m_maxRetries
Definition:
backoff.h:57
ns3::Backoff::MaxRetriesReached
bool MaxRetriesReached(void)
Definition:
backoff.cc:84
ns3::UniformRandomVariable::GetValue
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
Definition:
random-variable-stream.cc:172
ns3::Backoff::AssignStreams
int64_t AssignStreams(int64_t stream)
Definition:
backoff.cc:96
ns3::Backoff::GetBackoffTime
Time GetBackoffTime()
Definition:
backoff.cc:51
ns3::Backoff::m_minSlots
uint32_t m_minSlots
Definition:
backoff.h:42
ns3::Backoff::m_slotTime
Time m_slotTime
Definition:
backoff.h:62
ns3::MicroSeconds
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.
Definition:
nstime.h:615
ns3::Backoff::IncrNumRetries
void IncrNumRetries(void)
Definition:
backoff.cc:90
ns3::Backoff::m_numBackoffRetries
uint32_t m_numBackoffRetries
Definition:
backoff.h:105
ns3::Backoff::m_ceiling
uint32_t m_ceiling
Definition:
backoff.h:52
src
csma
model
backoff.cc
Generated on Sun Mar 16 2014 11:25:03 for ns-3 by
1.8.6