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  ;
39  return tid;
40 }
41 
43 {
44 }
45 
46 void
48 {
49  NS_LOG_FUNCTION (this);
51 }
52 
53 void
55 {
56  NS_LOG_FUNCTION (this);
57  m_bytes = p->GetSize ();
58  NS_LOG_LOGIC ("bytes to deliver: " << m_bytes);
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION (this << sinr << duration);
66  SpectrumValue CapacityPerHertz = Log2 (1 + sinr);
67  double capacity = 0;
68 
69  Bands::const_iterator bi = CapacityPerHertz.ConstBandsBegin ();
70  Values::const_iterator vi = CapacityPerHertz.ConstValuesBegin ();
71 
72  while (bi != CapacityPerHertz.ConstBandsEnd ())
73  {
74  NS_ASSERT (vi != CapacityPerHertz.ConstValuesEnd ());
75  capacity += (bi->fh - bi->fl) * (*vi);
76  ++bi;
77  ++vi;
78  }
79  NS_ASSERT (vi == CapacityPerHertz.ConstValuesEnd ());
80  NS_LOG_LOGIC ("ChunkCapacity = " << capacity);
81  m_deliverableBytes += static_cast<uint32_t> (capacity * duration.GetSeconds () / 8);
82  NS_LOG_LOGIC ("DeliverableBytes = " << m_deliverableBytes);
83 }
84 
85 
86 bool
88 {
89  NS_LOG_FUNCTION (this);
90  return (m_deliverableBytes > m_bytes);
91 }
92 
93 
94 } // namespace ns3
Values::const_iterator ConstValuesEnd() const
void StartRx(Ptr< const Packet > p)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#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:44
void EvaluateChunk(const SpectrumValue &sinr, Time duration)
virtual void DoDispose()
Destructor implementation.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:334
Bands::const_iterator ConstBandsEnd() const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Bands::const_iterator ConstBandsBegin() const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Values::const_iterator ConstValuesBegin() 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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638