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-sensing.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-sensing.h"
19
#include "ns3/mobility-model.h"
20
21
NS_LOG_COMPONENT_DEFINE
(
"CogSpectrumSensing"
);
22
23
namespace
ns3 {
24
// SpectrumSensing initialization: PU model off
25
SpectrumSensing::SpectrumSensing(SpectrumManager *sm) {
26
27
m_specManager=sm;
28
}
29
30
31
32
33
// SpectrumSensing initialization: PU model on
34
SpectrumSensing::SpectrumSensing(SpectrumManager *sm,
double
prob_misdetect, Ptr<PUModel> p) {
35
36
m_puModel=p;
37
38
m_probMisdetect=prob_misdetect;
39
40
}
41
42
43
44
45
// sense: return true if PU activity is detected in the time interval [current_time:current_time + sense_time]
46
bool
47
SpectrumSensing::GetSenseResultsFuture(
int
id
, Time sense_time, Time transmit_time,
int
channel) {
48
49
NodeContainer
const
& n =
NodeContainer::GetGlobal
();
50
Ptr<Node> node = n.Get(
id
);
51
Ptr<MobilityModel> mm = node->GetObject<MobilityModel>();
52
double
x = mm->GetPosition().x;
53
double
y = mm->GetPosition().y;
54
bool
cr_on=
false
;
55
NS_LOG_DEBUG
(
"POSITIONS: x:"
<< x <<
" and y:"
<< y);
56
57
if
(m_puModel) {
58
59
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
60
double
randomValue = uv->GetValue();
//by default, min 0 and max 1
61
// Ask the PUmodel if a PU is active in the time interval [current_time:current_time + sense_time]
62
cr_on=m_puModel->IsPuActive(
Simulator::Now
(),sense_time,x,y, channel);
63
// Apply the probability of false negative detection
64
if
((randomValue < m_probMisdetect) and cr_on)
65
cr_on=
false
;
66
67
}
68
//#ifdef SENSING_VERBOSE_MODE
69
// printf("[SENSING-DBG] Node %d sensed pu activity on channel %d at time %f\n", id, channel, Scheduler::instance().clock());
70
//#endif
71
return
cr_on;
72
73
}
74
75
}
76
77
78
79
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::Simulator::Now
static Time Now(void)
Definition:
simulator.cc:179
ns3::NodeContainer::GetGlobal
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Definition:
node-container.cc:129
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Definition:
log.h:255
src
cognitive
model
spectrum-sensing.cc
Generated on Sun Mar 16 2014 11:25:01 for ns-3 by
1.8.6