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-error-model.cc
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
SpectrumErrorModel::~SpectrumErrorModel ()
31
{
32
}
33
34
void
35
ShannonSpectrumErrorModel::DoDispose
()
36
{
37
NS_LOG_FUNCTION
(
this
);
38
SpectrumErrorModel::DoDispose
();
39
}
40
41
void
42
ShannonSpectrumErrorModel::StartRx (
Ptr<const Packet>
p)
43
{
44
NS_LOG_FUNCTION
(
this
);
45
m_bytes = p->
GetSize
();
46
NS_LOG_LOGIC
(
"bytes to deliver: "
<< m_bytes);
47
m_deliverableBytes = 0;
48
}
49
50
void
51
ShannonSpectrumErrorModel::EvaluateChunk (
const
SpectrumValue& sinr, Time duration)
52
{
53
NS_LOG_FUNCTION
(
this
<< sinr << duration);
54
SpectrumValue CapacityPerHertz =
Log2
(1 + sinr);
55
double
capacity = 0;
56
57
Bands::const_iterator bi = CapacityPerHertz.ConstBandsBegin ();
58
Values::const_iterator vi = CapacityPerHertz.ConstValuesBegin ();
59
60
while
(bi != CapacityPerHertz.ConstBandsEnd ())
61
{
62
NS_ASSERT
(vi != CapacityPerHertz.ConstValuesEnd ());
63
capacity += (bi->fh - bi->fl) * (*vi);
64
++bi;
65
++vi;
66
}
67
NS_ASSERT
(vi == CapacityPerHertz.ConstValuesEnd ());
68
NS_LOG_LOGIC
(
"ChunkCapacity = "
<< capacity);
69
m_deliverableBytes +=
static_cast<
uint32_t
>
(capacity * duration.GetSeconds () / 8);
70
NS_LOG_LOGIC
(
"DeliverableBytes = "
<< m_deliverableBytes);
71
}
72
73
74
bool
75
ShannonSpectrumErrorModel::IsRxCorrect ()
76
{
77
NS_LOG_FUNCTION
(
this
);
78
return
(m_deliverableBytes > m_bytes);
79
}
80
81
82
}
// namespace ns3
ns3::Ptr< const Packet >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::ShannonSpectrumErrorModel::DoDispose
virtual void DoDispose()
Definition:
spectrum-error-model.cc:35
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::Packet::GetSize
uint32_t GetSize(void) const
Definition:
packet.h:620
ns3::Object::DoDispose
virtual void DoDispose(void)
Definition:
object.cc:335
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:334
ns3::Log2
SpectrumValue Log2(const SpectrumValue &arg)
Definition:
spectrum-value.cc:581
src
spectrum
model
spectrum-error-model.cc
Generated on Sun Mar 16 2014 11:25:10 for ns-3 by
1.8.6