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
spectrum-decision.cc
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License version 2 as
4
* published by the Free Software Foundation;
5
*
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
*
11
* You should have received a copy of the GNU General Public License
12
* along with this program; if not, write to the Free Software
13
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
*
15
* Author: Abdulla K. Al-Ali <abdulla.alali@qu.edu.qa>
16
*/
17
18
#include "spectrum-decision.h"
19
#include "ns3/random-variable-stream.h"
20
21
namespace
ns3 {
22
23
// Spectrum Decision initializer
24
SpectrumDecision::SpectrumDecision(SpectrumManager *sm) {
25
26
m_decisionPolicy=DECISION_POLICY_ALWAYS_SWITCH;
27
//decision_policy_=DECISION_POLICY_NEVER_SWITCH;
28
29
m_spectrumPolicy=ROUND_ROBIN_SWITCH;
30
31
m_specManager=sm;
32
33
}
34
35
36
37
38
// DecideSwitch: decide wether to stay or leave the current channel, when a PU is detected
39
bool
40
SpectrumDecision::DecideSwitch() {
41
42
double
randomValue;
43
bool
switch_decision;
44
45
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
46
switch
(m_decisionPolicy) {
47
48
// Switch with probability equal to THRESHOLD_SWITCH, stay otherwise
49
case
DECISION_POLICY_PROBABILISTIC_SWITCH:
50
51
randomValue = uv->GetValue();
52
53
if
(randomValue < THRESHOLD_SWITCH)
54
switch_decision=
true
;
55
else
56
switch_decision=
false
;
57
break
;
58
59
// Switch to a new channel in anycase
60
case
DECISION_POLICY_ALWAYS_SWITCH:
61
62
switch_decision=
true
;
63
break
;
64
65
// Never make a switch
66
case
DECISION_POLICY_NEVER_SWITCH:
67
68
switch_decision=
false
;
69
break
;
70
71
default
:
72
73
switch_decision=
true
;
74
break
;
75
}
76
77
return
switch_decision;
78
}
79
80
81
82
83
84
// DecideSpectrum: get the next spectrum to be used, based on the allocation policy
85
int
86
SpectrumDecision::DecideSpectrum(
int
current_channel) {
87
88
int
next_channel;
89
90
Ptr<UniformRandomVariable> uv1 = CreateObject<UniformRandomVariable>();
91
92
switch
(m_spectrumPolicy) {
93
94
// Policy RANDOM_SWITCH: next_channel -> random(1..MAX_CHANNELS)
95
case
RANDOM_SWITCH:
96
uv1->SetAttribute (
"Min"
, DoubleValue (2));
97
uv1->SetAttribute (
"Max"
, DoubleValue (MAX_CHANNELS));
98
next_channel=uv1->GetInteger();
99
100
if
(next_channel >= MAX_CHANNELS)
101
next_channel = MAX_CHANNELS-1;
102
break
;
103
104
// Policy ROUND_ROBIN_SWITCH: next channel -> ( next_channel + 1 ) % MAX_CHANNELS
105
case
ROUND_ROBIN_SWITCH:
106
107
next_channel=(current_channel+1) % MAX_CHANNELS;
108
if
(next_channel==0) next_channel += 2;
109
if
(next_channel ==1)
110
next_channel++;
111
break
;
112
113
}
114
115
return
next_channel;
116
117
}
118
119
}
120
src
cognitive
model
spectrum-decision.cc
Generated on Sun Mar 16 2014 11:25:01 for ns-3 by
1.8.6