A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("ShannonSpectrumErrorModel");
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (SpectrumErrorModel);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::SpectrumErrorModel")
36  .SetParent<Object> ()
37  ;
38  return tid;
39 }
40 
42 {
43 }
44 
45 void
47 {
48  NS_LOG_FUNCTION (this);
50 }
51 
52 void
54 {
55  NS_LOG_FUNCTION (this);
56  m_bytes = p->GetSize ();
57  NS_LOG_LOGIC ("bytes to deliver: " << m_bytes);
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION (this << sinr << duration);
65  SpectrumValue CapacityPerHertz = Log2 (1 + sinr);
66  double capacity = 0;
67 
68  Bands::const_iterator bi = CapacityPerHertz.ConstBandsBegin ();
69  Values::const_iterator vi = CapacityPerHertz.ConstValuesBegin ();
70 
71  while (bi != CapacityPerHertz.ConstBandsEnd ())
72  {
73  NS_ASSERT (vi != CapacityPerHertz.ConstValuesEnd ());
74  capacity += (bi->fh - bi->fl) * (*vi);
75  ++bi;
76  ++vi;
77  }
78  NS_ASSERT (vi == CapacityPerHertz.ConstValuesEnd ());
79  NS_LOG_LOGIC ("ChunkCapacity = " << capacity);
80  m_deliverableBytes += static_cast<uint32_t> (capacity * duration.GetSeconds () / 8);
81  NS_LOG_LOGIC ("DeliverableBytes = " << m_deliverableBytes);
82 }
83 
84 
85 bool
87 {
88  NS_LOG_FUNCTION (this);
89  return (m_deliverableBytes > m_bytes);
90 }
91 
92 
93 } // namespace ns3
Values::const_iterator ConstValuesEnd() const
void StartRx(Ptr< const Packet > p)
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
void EvaluateChunk(const SpectrumValue &sinr, Time duration)
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
Definition: packet.h:650
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
NS_LOG_COMPONENT_DEFINE("ShannonSpectrumErrorModel")
double GetSeconds(void) const
Definition: nstime.h:274
Bands::const_iterator ConstBandsEnd() const
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
Bands::const_iterator ConstBandsBegin() const
Values::const_iterator ConstValuesBegin() const
a base class which provides memory management and object aggregation
Definition: object.h:63
SpectrumValue Log2(const SpectrumValue &arg)
Set of values corresponding to a given SpectrumModel.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611