A Discrete-Event Network Simulator
API
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 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("ShannonSpectrumErrorModel");
29 
30 NS_OBJECT_ENSURE_REGISTERED (SpectrumErrorModel);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::SpectrumErrorModel")
36  .SetParent<Object> ()
37  .SetGroupName ("Spectrum")
38  // No AddConstructor because this is an abstract class.
39  ;
40  return tid;
41 }
42 
44 {
45 }
46 
47 
49 
50 /* static */
51 TypeId
53 {
54  static TypeId tid = TypeId ("ns3::ShannonSpectrumErrorModel")
56  .SetGroupName ("Spectrum")
57  .AddConstructor<ShannonSpectrumErrorModel> ()
58  ;
59  return tid;
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION (this);
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION (this);
73  m_bytes = p->GetSize ();
74  NS_LOG_LOGIC ("bytes to deliver: " << m_bytes);
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION (this << sinr << duration);
82  SpectrumValue CapacityPerHertz = Log2 (1 + sinr);
83  double capacity = 0;
84 
85  Bands::const_iterator bi = CapacityPerHertz.ConstBandsBegin ();
86  Values::const_iterator vi = CapacityPerHertz.ConstValuesBegin ();
87 
88  while (bi != CapacityPerHertz.ConstBandsEnd ())
89  {
90  NS_ASSERT (vi != CapacityPerHertz.ConstValuesEnd ());
91  capacity += (bi->fh - bi->fl) * (*vi);
92  ++bi;
93  ++vi;
94  }
95  NS_ASSERT (vi == CapacityPerHertz.ConstValuesEnd ());
96  NS_LOG_LOGIC ("ChunkCapacity = " << capacity);
97  m_deliverableBytes += static_cast<uint32_t> (capacity * duration.GetSeconds () / 8);
98  NS_LOG_LOGIC ("DeliverableBytes = " << m_deliverableBytes);
99 }
100 
101 
102 bool
104 {
105  NS_LOG_FUNCTION (this);
106  return (m_deliverableBytes > m_bytes);
107 }
108 
109 
110 } // namespace ns3
void StartRx(Ptr< const Packet > p)
Start a packet reception.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#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:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
void EvaluateChunk(const SpectrumValue &sinr, Time duration)
Evaluates a chunk.
virtual void DoDispose()
Destructor implementation.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
static TypeId GetTypeId()
Register this type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
uint32_t m_deliverableBytes
Bytes that can be received according to the Shnanon&#39;s formula.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
static TypeId GetTypeId(void)
Register this type.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
Values::const_iterator ConstValuesBegin() const
This class implements the error model described in this paper: N.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
uint32_t m_bytes
Length of the packet being received.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Values::const_iterator ConstValuesEnd() const
Introspection did not find any typical Config paths.
bool IsRxCorrect()
Checks if the packet being received is correct.
Bands::const_iterator ConstBandsEnd() const
A base class which provides memory management and object aggregation.
Definition: object.h:87
SpectrumValue Log2(const SpectrumValue &arg)
Set of values corresponding to a given SpectrumModel.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
Bands::const_iterator ConstBandsBegin() const