A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-error-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
21
22#include <ns3/log.h>
23#include <ns3/nstime.h>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("ShannonSpectrumErrorModel");
29
30NS_OBJECT_ENSURE_REGISTERED(SpectrumErrorModel);
31
32TypeId
34{
35 static TypeId tid =
36 TypeId("ns3::SpectrumErrorModel").SetParent<Object>().SetGroupName("Spectrum")
37 // No AddConstructor because this is an abstract class.
38 ;
39 return tid;
40}
41
43{
44}
45
47
48/* static */
51{
52 static TypeId tid = TypeId("ns3::ShannonSpectrumErrorModel")
54 .SetGroupName("Spectrum")
55 .AddConstructor<ShannonSpectrumErrorModel>();
56 return tid;
57}
58
59void
61{
62 NS_LOG_FUNCTION(this);
64}
65
66void
68{
69 NS_LOG_FUNCTION(this);
70 m_bytes = p->GetSize();
71 NS_LOG_LOGIC("bytes to deliver: " << m_bytes);
73}
74
75void
77{
78 NS_LOG_FUNCTION(this << sinr << duration);
79 SpectrumValue CapacityPerHertz = Log2(1 + sinr);
80 double capacity = 0;
81
82 Bands::const_iterator bi = CapacityPerHertz.ConstBandsBegin();
83 Values::const_iterator vi = CapacityPerHertz.ConstValuesBegin();
84
85 while (bi != CapacityPerHertz.ConstBandsEnd())
86 {
87 NS_ASSERT(vi != CapacityPerHertz.ConstValuesEnd());
88 capacity += (bi->fh - bi->fl) * (*vi);
89 ++bi;
90 ++vi;
91 }
92 NS_ASSERT(vi == CapacityPerHertz.ConstValuesEnd());
93 NS_LOG_LOGIC("ChunkCapacity = " << capacity);
94 m_deliverableBytes += static_cast<uint32_t>(capacity * duration.GetSeconds() / 8);
95 NS_LOG_LOGIC("DeliverableBytes = " << m_deliverableBytes);
96}
97
98bool
100{
101 NS_LOG_FUNCTION(this);
102 return (m_deliverableBytes > m_bytes);
103}
104
105} // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This class implements the error model described in this paper: N.
void StartRx(Ptr< const Packet > p) override
Start a packet reception.
uint32_t m_bytes
Length of the packet being received.
void EvaluateChunk(const SpectrumValue &sinr, Time duration) override
Evaluates a chunk.
bool IsRxCorrect() override
Checks if the packet being received is correct.
uint32_t m_deliverableBytes
Bytes that can be received according to the Shnanon's formula.
static TypeId GetTypeId()
Register this type.
void DoDispose() override
Destructor implementation.
Introspection did not find any typical Config paths.
static TypeId GetTypeId()
Register this type.
Set of values corresponding to a given SpectrumModel.
Values::const_iterator ConstValuesBegin() const
Bands::const_iterator ConstBandsEnd() const
Bands::const_iterator ConstBandsBegin() const
Values::const_iterator ConstValuesEnd() const
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SpectrumValue Log2(const SpectrumValue &arg)