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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
10
11#include <ns3/log.h>
12#include <ns3/nstime.h>
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("ShannonSpectrumErrorModel");
18
19NS_OBJECT_ENSURE_REGISTERED(SpectrumErrorModel);
20
21TypeId
23{
24 static TypeId tid =
25 TypeId("ns3::SpectrumErrorModel").SetParent<Object>().SetGroupName("Spectrum")
26 // No AddConstructor because this is an abstract class.
27 ;
28 return tid;
29}
30
34
36
37/* static */
40{
41 static TypeId tid = TypeId("ns3::ShannonSpectrumErrorModel")
43 .SetGroupName("Spectrum")
44 .AddConstructor<ShannonSpectrumErrorModel>();
45 return tid;
46}
47
48void
54
55void
57{
58 NS_LOG_FUNCTION(this);
59 m_bytes = p->GetSize();
60 NS_LOG_LOGIC("bytes to deliver: " << m_bytes);
62}
63
64void
66{
67 NS_LOG_FUNCTION(this << sinr << duration);
68 SpectrumValue CapacityPerHertz = Log2(1 + sinr);
69 double capacity = 0;
70
71 auto bi = CapacityPerHertz.ConstBandsBegin();
72 auto vi = CapacityPerHertz.ConstValuesBegin();
73
74 while (bi != CapacityPerHertz.ConstBandsEnd())
75 {
76 NS_ASSERT(vi != CapacityPerHertz.ConstValuesEnd());
77 capacity += (bi->fh - bi->fl) * (*vi);
78 ++bi;
79 ++vi;
80 }
81 NS_ASSERT(vi == CapacityPerHertz.ConstValuesEnd());
82 NS_LOG_LOGIC("ChunkCapacity = " << capacity);
83 m_deliverableBytes += static_cast<uint32_t>(capacity * duration.GetSeconds() / 8);
84 NS_LOG_LOGIC("DeliverableBytes = " << m_deliverableBytes);
85}
86
87bool
93
94} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
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.
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:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SpectrumValue Log2(const SpectrumValue &arg)