A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-sinr-chunk-processor.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Centre Tecnologic de Telecomunicacions de Catalunya (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  * Modified by : Marco Miozzo <mmiozzo@cttc.es>
20  * (move from CQI to Ctrl and Data SINR Chunk processors
21  */
22 
23 
24 #include <ns3/log.h>
25 
26 #include "lte-sinr-chunk-processor.h"
27 
28 NS_LOG_COMPONENT_DEFINE ("LteSinrChunkProcessor");
29 
30 namespace ns3 {
31 
32 LteSinrChunkProcessor::~LteSinrChunkProcessor ()
33 {
34  NS_LOG_FUNCTION (this);
35 }
36 
37 
38 // ------------- LteCtrlSinrChunkProcessor ------------------------------
39 
40 LteCtrlSinrChunkProcessor::LteCtrlSinrChunkProcessor (Ptr<LtePhy> p)
41  : m_phy (p),
42  m_spectrumPhy (0)
43 {
44  NS_LOG_FUNCTION (this << p);
45  NS_ASSERT (m_phy);
46 }
47 
48 LteCtrlSinrChunkProcessor::LteCtrlSinrChunkProcessor (Ptr<LtePhy> p, Ptr<LteSpectrumPhy> s)
49 : m_phy (p),
50  m_spectrumPhy (s)
51 {
52  NS_LOG_FUNCTION (this << p);
53  NS_ASSERT (m_phy);
54  NS_ASSERT (m_spectrumPhy);
55 }
56 
57 
58 LteCtrlSinrChunkProcessor::~LteCtrlSinrChunkProcessor ()
59 {
60  NS_LOG_FUNCTION (this);
61 }
62 
63 
64 void
65 LteCtrlSinrChunkProcessor::Start ()
66 {
67  NS_LOG_FUNCTION (this);
68  m_sumSinr = 0;
69  m_totDuration = MicroSeconds (0);
70 }
71 
72 
73 void
74 LteCtrlSinrChunkProcessor::EvaluateSinrChunk (const SpectrumValue& sinr, Time duration)
75 {
76  NS_LOG_FUNCTION (this << sinr << duration);
77  if (m_sumSinr == 0)
78  {
79  m_sumSinr = Create<SpectrumValue> (sinr.GetSpectrumModel ());
80  }
81  (*m_sumSinr) += sinr * duration.GetSeconds ();
82  m_totDuration += duration;
83 }
84 
85 void
86 LteCtrlSinrChunkProcessor::End ()
87 {
88  NS_LOG_FUNCTION (this);
89  if (m_totDuration.GetSeconds () > 0)
90  {
91  m_phy->GenerateCtrlCqiReport ((*m_sumSinr) / m_totDuration.GetSeconds ());
92  if (m_spectrumPhy)
93  {
94  m_spectrumPhy->UpdateSinrPerceived ((*m_sumSinr) / m_totDuration.GetSeconds ());
95  }
96  }
97  else
98  {
99  NS_LOG_WARN ("m_numSinr == 0");
100  }
101 }
102 
103 
104 // ------------- LteDataSinrChunkProcessor ------------------------------
105 
106 LteDataSinrChunkProcessor::LteDataSinrChunkProcessor (Ptr<LteSpectrumPhy> s, Ptr<LtePhy> p)
107 : m_spectrumPhy (s),
108  m_phy (p)
109 {
110  NS_LOG_FUNCTION (this << p);
111  NS_ASSERT (m_spectrumPhy);
112  NS_ASSERT (m_phy);
113 }
114 
115 LteDataSinrChunkProcessor::LteDataSinrChunkProcessor (Ptr<LteSpectrumPhy> p)
116 : m_spectrumPhy (p),
117  m_phy (0)
118 {
119  NS_LOG_FUNCTION (this << p);
120  NS_ASSERT (m_spectrumPhy);
121 
122 }
123 
124 
125 
126 LteDataSinrChunkProcessor::~LteDataSinrChunkProcessor ()
127 {
128  NS_LOG_FUNCTION (this);
129 }
130 
131 
132 void
133 LteDataSinrChunkProcessor::Start ()
134 {
135  NS_LOG_FUNCTION (this);
136  m_sumSinr = 0;
137  m_totDuration = MicroSeconds (0);
138 }
139 
140 
141 void
142 LteDataSinrChunkProcessor::EvaluateSinrChunk (const SpectrumValue& sinr, Time duration)
143 {
144  NS_LOG_FUNCTION (this << sinr << duration);
145  if (m_sumSinr == 0)
146  {
147  m_sumSinr = Create<SpectrumValue> (sinr.GetSpectrumModel ());
148  }
149  (*m_sumSinr) += sinr * duration.GetSeconds ();
150  m_totDuration += duration;
151 }
152 
153 void
154 LteDataSinrChunkProcessor::End ()
155 {
156  NS_LOG_FUNCTION (this);
157  if (m_totDuration.GetSeconds () > 0)
158  {
159  m_spectrumPhy->UpdateSinrPerceived ((*m_sumSinr) / m_totDuration.GetSeconds ());
160  if (m_phy)
161  {
162  m_phy->GenerateDataCqiReport ((*m_sumSinr) / m_totDuration.GetSeconds ());
163  }
164  }
165  else
166  {
167  NS_LOG_WARN ("m_numSinr == 0");
168  }
169 }
170 
171 
172 
173 
174 // ------------- LteRsReceivedPowerChunkProcessor ------------------------------
175 
176 LteRsReceivedPowerChunkProcessor::LteRsReceivedPowerChunkProcessor (Ptr<LtePhy> p)
177 : m_phy (p)
178 {
179  NS_LOG_FUNCTION (this << p);
180  NS_ASSERT (m_phy);
181 }
182 
183 LteRsReceivedPowerChunkProcessor::~LteRsReceivedPowerChunkProcessor ()
184 {
185  NS_LOG_FUNCTION (this);
186 }
187 
188 
189 void
190 LteRsReceivedPowerChunkProcessor::Start ()
191 {
192  NS_LOG_FUNCTION (this);
193  m_sumSinr = 0;
194  m_totDuration = MicroSeconds (0);
195 }
196 
197 
198 void
199 LteRsReceivedPowerChunkProcessor::EvaluateSinrChunk (const SpectrumValue& sinr, Time duration)
200 {
201  NS_LOG_FUNCTION (this << sinr << duration);
202  if (m_sumSinr == 0)
203  {
204  m_sumSinr = Create<SpectrumValue> (sinr.GetSpectrumModel ());
205  }
206  (*m_sumSinr) += sinr * duration.GetSeconds ();
207  m_totDuration += duration;
208 }
209 
210 void
211 LteRsReceivedPowerChunkProcessor::End ()
212 {
213  NS_LOG_FUNCTION (this);
214  if (m_totDuration.GetSeconds () > 0)
215  {
216  m_phy->ReportRsReceivedPower ((*m_sumSinr) / m_totDuration.GetSeconds ());
217  }
218  else
219  {
220  NS_LOG_WARN ("m_numSinr == 0");
221  }
222 }
223 
224 
225 
226 
227 
228 // ------------- LteInterferencePowerChunkProcessor ------------------------------
229 
230 LteInterferencePowerChunkProcessor::LteInterferencePowerChunkProcessor (Ptr<LtePhy> p)
231 : m_phy (p)
232 {
233  NS_LOG_FUNCTION (this << p);
234  NS_ASSERT (m_phy);
235 }
236 
237 LteInterferencePowerChunkProcessor::~LteInterferencePowerChunkProcessor ()
238 {
239  NS_LOG_FUNCTION (this);
240 }
241 
242 
243 void
244 LteInterferencePowerChunkProcessor::Start ()
245 {
246  NS_LOG_FUNCTION (this);
247  m_sumSinr = 0;
248  m_totDuration = MicroSeconds (0);
249 }
250 
251 
252 void
253 LteInterferencePowerChunkProcessor::EvaluateSinrChunk (const SpectrumValue& sinr, Time duration)
254 {
255  NS_LOG_FUNCTION (this << sinr << duration);
256  if (m_sumSinr == 0)
257  {
258  m_sumSinr = Create<SpectrumValue> (sinr.GetSpectrumModel ());
259  }
260  (*m_sumSinr) += sinr * duration.GetSeconds ();
261  m_totDuration += duration;
262 }
263 
264 void
265 LteInterferencePowerChunkProcessor::End ()
266 {
267  NS_LOG_FUNCTION (this);
268  if (m_totDuration.GetSeconds () > 0)
269  {
270  m_phy->ReportInterference ((*m_sumSinr) / m_totDuration.GetSeconds ());
271  }
272  else
273  {
274  NS_LOG_WARN ("m_numSinr == 0");
275  }
276 }
277 
278 
279 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
double GetSeconds(void) const
Definition: nstime.h:262
#define NS_LOG_WARN(msg)
Definition: log.h:246
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.
Definition: nstime.h:615