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
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
spectrum-error-model.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
#include "
spectrum-error-model.h
"
22
23
#include <ns3/nstime.h>
24
#include <ns3/log.h>
25
26
NS_LOG_COMPONENT_DEFINE
(
"ShannonSpectrumErrorModel"
);
27
28
namespace
ns3 {
29
30
NS_OBJECT_ENSURE_REGISTERED
(SpectrumErrorModel);
31
32
TypeId
33
SpectrumErrorModel::GetTypeId
()
34
{
35
static
TypeId
tid =
TypeId
(
"ns3::SpectrumErrorModel"
)
36
.
SetParent
<
Object
> ()
37
;
38
return
tid;
39
}
40
41
SpectrumErrorModel::~SpectrumErrorModel
()
42
{
43
}
44
45
void
46
ShannonSpectrumErrorModel::DoDispose
()
47
{
48
NS_LOG_FUNCTION
(
this
);
49
SpectrumErrorModel::DoDispose
();
50
}
51
52
void
53
ShannonSpectrumErrorModel::StartRx
(
Ptr<const Packet>
p)
54
{
55
NS_LOG_FUNCTION
(
this
);
56
m_bytes
= p->
GetSize
();
57
NS_LOG_LOGIC
(
"bytes to deliver: "
<<
m_bytes
);
58
m_deliverableBytes
= 0;
59
}
60
61
void
62
ShannonSpectrumErrorModel::EvaluateChunk
(
const
SpectrumValue
& sinr,
Time
duration)
63
{
64
NS_LOG_FUNCTION
(
this
<< sinr << duration);
65
SpectrumValue
CapacityPerHertz =
Log2
(1 + sinr);
66
double
capacity = 0;
67
68
Bands::const_iterator bi = CapacityPerHertz.
ConstBandsBegin
();
69
Values::const_iterator vi = CapacityPerHertz.
ConstValuesBegin
();
70
71
while
(bi != CapacityPerHertz.
ConstBandsEnd
())
72
{
73
NS_ASSERT
(vi != CapacityPerHertz.
ConstValuesEnd
());
74
capacity += (bi->fh - bi->fl) * (*vi);
75
++bi;
76
++vi;
77
}
78
NS_ASSERT
(vi == CapacityPerHertz.
ConstValuesEnd
());
79
NS_LOG_LOGIC
(
"ChunkCapacity = "
<< capacity);
80
m_deliverableBytes
+=
static_cast<
uint32_t
>
(capacity * duration.
GetSeconds
() / 8);
81
NS_LOG_LOGIC
(
"DeliverableBytes = "
<<
m_deliverableBytes
);
82
}
83
84
85
bool
86
ShannonSpectrumErrorModel::IsRxCorrect
()
87
{
88
NS_LOG_FUNCTION
(
this
);
89
return
(
m_deliverableBytes
>
m_bytes
);
90
}
91
92
93
}
// namespace ns3
ns3::SpectrumValue::ConstValuesEnd
Values::const_iterator ConstValuesEnd() const
Definition:
spectrum-value.cc:71
ns3::ShannonSpectrumErrorModel::StartRx
void StartRx(Ptr< const Packet > p)
Definition:
spectrum-error-model.cc:53
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
ns3::Ptr< const Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::ShannonSpectrumErrorModel::EvaluateChunk
void EvaluateChunk(const SpectrumValue &sinr, Time duration)
Definition:
spectrum-error-model.cc:62
ns3::ShannonSpectrumErrorModel::DoDispose
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition:
spectrum-error-model.cc:46
ns3::SpectrumErrorModel::GetTypeId
static TypeId GetTypeId()
Definition:
spectrum-error-model.cc:33
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::ShannonSpectrumErrorModel::m_deliverableBytes
uint32_t m_deliverableBytes
Definition:
spectrum-error-model.h:72
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::Packet::GetSize
uint32_t GetSize(void) const
Definition:
packet.h:650
ns3::Object::DoDispose
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition:
object.cc:336
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("ShannonSpectrumErrorModel")
ns3::Time::GetSeconds
double GetSeconds(void) const
Definition:
nstime.h:274
ns3::SpectrumValue::ConstBandsEnd
Bands::const_iterator ConstBandsEnd() const
Definition:
spectrum-value.cc:96
spectrum-error-model.h
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:368
ns3::SpectrumValue::ConstBandsBegin
Bands::const_iterator ConstBandsBegin() const
Definition:
spectrum-value.cc:90
ns3::ShannonSpectrumErrorModel::m_bytes
uint32_t m_bytes
Definition:
spectrum-error-model.h:71
ns3::SpectrumErrorModel::~SpectrumErrorModel
virtual ~SpectrumErrorModel()
Definition:
spectrum-error-model.cc:41
ns3::ShannonSpectrumErrorModel::IsRxCorrect
bool IsRxCorrect()
Definition:
spectrum-error-model.cc:86
ns3::SpectrumValue::ConstValuesBegin
Values::const_iterator ConstValuesBegin() const
Definition:
spectrum-value.cc:65
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::Log2
SpectrumValue Log2(const SpectrumValue &arg)
Definition:
spectrum-value.cc:581
ns3::SpectrumValue
Set of values corresponding to a given SpectrumModel.
Definition:
spectrum-value.h:57
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
src
spectrum
model
spectrum-error-model.cc
Generated on Sat Apr 19 2014 14:07:08 for ns-3 by
1.8.6