Loading...
Searching...
No Matches
satellite-markov-container.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Magister Solutions Ltd.
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: Frans Laakso <frans.laakso@magister.fi>
19 */
20
22
23#include "satellite-utils.h"
24
25#include "ns3/log.h"
26
27#include <vector>
28
29namespace ns3
30{
31
32NS_OBJECT_ENSURE_REGISTERED(SatMarkovContainer);
33NS_LOG_COMPONENT_DEFINE("SatMarkovContainer");
34
35TypeId
37{
38 static TypeId tid =
39 TypeId("ns3::SatMarkovContainer")
40 .SetParent<SatBaseFading>()
41 .AddConstructor<SatMarkovContainer>()
42 .AddTraceSource("FadingTrace",
43 "The trace for fading values",
44 MakeTraceSourceAccessor(&SatMarkovContainer::m_fadingTrace),
45 "ns3::SatMarkovContainer::FadingTraceCallback");
46 return tid;
47}
48
50 : m_markovModel(nullptr),
51 m_markovConf(nullptr),
52 m_fader_up(nullptr),
53 m_fader_down(nullptr),
64 m_enableSetLock(false),
65 m_enableStateLock(false),
66 m_velocity(),
68 m_useDecibels(false)
69{
70 NS_LOG_FUNCTION(this);
71 NS_FATAL_ERROR("SatMarkovContainer::SatMarkovContainer - Constructor not in use");
72}
73
74SatMarkovContainer::SatMarkovContainer(Ptr<SatMarkovConf> markovConf,
77 : m_markovModel(nullptr),
78 m_markovConf(markovConf),
79 m_fader_up(nullptr),
80 m_fader_down(nullptr),
81 m_numOfStates(markovConf->GetStateCount()),
82 m_numOfSets(markovConf->GetNumOfSets()),
83 m_currentState(markovConf->GetInitialState()),
84 m_cooldownPeriodLength(markovConf->GetCooldownPeriod()),
85 m_minimumPositionChangeInMeters(markovConf->GetMinimumPositionChange()),
90 m_enableSetLock(false),
91 m_enableStateLock(false),
92 m_velocity(velocity),
94 m_currentElevation(elevation),
95 m_useDecibels(markovConf->AreDecibelsUsed())
96{
97 NS_LOG_FUNCTION(this);
98
100 m_markovModel = CreateObject<SatMarkovModel>(m_numOfStates, m_currentState);
101
103 m_currentSet = m_markovConf->GetProbabilitySetID(m_currentElevation());
105 m_markovModel->DoTransition();
106
108 CreateFaders(m_markovConf->GetFaderType());
109
113
114 NS_LOG_INFO("Creating SatMarkovContainer, States: "
115 << m_numOfStates << " Elevation: " << m_currentElevation()
116 << " Current Set ID: " << m_currentSet
117 << " Cool down Period Length In Seconds: " << m_cooldownPeriodLength.GetSeconds()
118 << " Minimum Position Change In Meters: " << m_minimumPositionChangeInMeters);
119}
120
122{
123 NS_LOG_FUNCTION(this);
124
125 Reset();
126}
127
128void
130{
131 NS_LOG_FUNCTION(this);
132
133 Reset();
134 SatBaseFading::DoDispose();
135}
136
137void
139{
140 NS_LOG_FUNCTION(this);
141
142 m_markovConf = nullptr;
143 m_fader_up = nullptr;
144 m_fader_down = nullptr;
145 m_markovModel = nullptr;
146
147 m_currentElevation.Nullify();
148 m_velocity.Nullify();
149}
150
151void
153{
154 NS_LOG_FUNCTION(this << faderType);
155
156 switch (faderType)
157 {
159 m_fader_up = CreateObject<SatLooModel>(m_markovConf->GetLooConf(),
163 m_fader_down = CreateObject<SatLooModel>(m_markovConf->GetLooConf(),
167 break;
168 }
170 m_fader_up = CreateObject<SatRayleighModel>(m_markovConf->GetRayleighConf(),
173 m_fader_down = CreateObject<SatRayleighModel>(m_markovConf->GetRayleighConf(),
176 break;
177 }
178 default: {
179 NS_FATAL_ERROR("SatMarkovContainer::CreateFaders - Invalid fader type");
180 }
181 }
182}
183
184double
186{
187 NS_LOG_FUNCTION(this << channelType);
188
189 double fadingValue;
190
191 NS_LOG_INFO("Getting fading");
192
193 if (HasCooldownPeriodPassed(channelType))
194 {
195 NS_LOG_INFO("Cool down period has passed, calculating new fading value");
196
197 if (m_velocity() > 0)
198 {
199 EvaluateStateChange(channelType);
200 }
201 fadingValue = CalculateFading(channelType);
202 }
203 else
204 {
205 NS_LOG_INFO("Cool down period in effect, using old fading value");
206 fadingValue = GetCachedFadingValue(channelType);
207 }
208
209 m_fadingTrace(Now().GetSeconds(), channelType, fadingValue);
210
211 return fadingValue;
212}
213
214double
216{
217 NS_LOG_FUNCTION(this << channelType);
218
219 switch (channelType)
220 {
224 }
228 }
229 default: {
230 NS_FATAL_ERROR("SatMarkovContainer::GetCachedFadingValue - Invalid channel type");
231 }
232 }
233 return 0;
234}
235
236void
238{
239 NS_LOG_FUNCTION(this);
240
242 {
243 uint32_t newSetId;
244
245 if (!m_enableSetLock)
246 {
247 newSetId = m_markovConf->GetProbabilitySetID(m_currentElevation());
248
249 if (m_currentSet != newSetId)
250 {
251 NS_LOG_INFO("Elevation: " << m_currentElevation() << ", set ID [old, new]: ["
252 << m_currentSet << "," << newSetId << "]");
253
254 m_currentSet = newSetId;
256 }
257 }
258
260 {
262 m_markovModel->DoTransition();
263 }
264 }
265}
266
267bool
269{
270 NS_LOG_FUNCTION(this << channelType);
271
272 switch (channelType)
273 {
276 if ((Now().GetSeconds() - m_latestCalculationTime_up.GetSeconds()) >
277 m_cooldownPeriodLength.GetSeconds())
278 {
279 return true;
280 }
281 break;
282 }
285 if ((Now().GetSeconds() - m_latestCalculationTime_down.GetSeconds()) >
286 m_cooldownPeriodLength.GetSeconds())
287 {
288 return true;
289 }
290 break;
291 }
292 default: {
293 NS_FATAL_ERROR("SatMarkovContainer::HasCooldownPeriodPassed - Invalid channel type");
294 }
295 }
296 return false;
297}
298
299void
301{
302 NS_LOG_FUNCTION(this << set);
303
304 std::vector<std::vector<double>> probabilities = m_markovConf->GetElevationProbabilities(set);
305
306 NS_LOG_INFO("Updating probabilities...");
307
308 for (uint32_t i = 0; i < m_numOfStates; ++i)
309 {
310 for (uint32_t j = 0; j < m_numOfStates; ++j)
311 {
312 m_markovModel->SetProbability(i, j, probabilities[i][j]);
313 }
314 NS_LOG_INFO("------");
315 }
316}
317
318double
320{
321 NS_LOG_FUNCTION(this << channelType);
322
323 double fadingValue;
324
326 {
327 m_currentState = m_markovModel->GetState();
328 }
329
330 NS_ASSERT((m_currentState >= 0) && (m_currentState < m_numOfStates));
331
332 switch (channelType)
333 {
336 m_fader_up->UpdateParameters(m_currentSet, m_currentState);
337
338 if (m_useDecibels)
339 {
341 }
342 else
343 {
345 }
346
347 NS_LOG_INFO("Calculated feeder fading value " << m_latestCalculatedFadingValue_up);
348
350
352 break;
353 }
356 m_fader_down->UpdateParameters(m_currentSet, m_currentState);
357
358 if (m_useDecibels)
359 {
361 }
362 else
363 {
365 }
366
367 NS_LOG_INFO("Calculated return fading value " << m_latestCalculatedFadingValue_down);
368
370
372 break;
373 }
374 default: {
375 NS_FATAL_ERROR("SatMarkovContainer::CalculateFading - Invalid channel type");
376 }
377 }
378 return fadingValue;
379}
380
381void
382SatMarkovContainer::LockToSetAndState(uint32_t newSet, uint32_t newState)
383{
384 NS_LOG_FUNCTION(this << newSet << " " << newState);
385
386 if (newState >= m_numOfStates)
387 {
388 NS_FATAL_ERROR("SatMarkovContainer::LockToSetAndState - Invalid state");
389 }
390 if (newSet >= m_numOfSets)
391 {
392 NS_FATAL_ERROR("SatMarkovContainer::LockToSetAndState - Invalid set");
393 }
394
395 m_currentSet = newSet;
396 m_currentState = newState;
397
399
400 m_enableSetLock = true;
401 m_enableStateLock = true;
402}
403
404void
406{
407 NS_LOG_FUNCTION(this << newSet);
408
409 if (newSet >= m_numOfSets)
410 {
411 NS_FATAL_ERROR("SatMarkovContainer::LockToSet - Invalid set");
412 }
413
414 m_currentSet = newSet;
415
417
418 m_enableSetLock = true;
419 m_enableStateLock = false;
420}
421
422void
424{
425 NS_LOG_FUNCTION(this);
426
427 uint32_t newSet = 0;
428 uint32_t newState = 0;
429
430 if (m_numOfSets > 1)
431 {
432 newSet = (rand() % (m_numOfSets - 1));
433 }
434
435 if (m_numOfStates > 1)
436 {
437 newState = (rand() % (m_numOfStates - 1));
438 }
439
440 LockToSetAndState(newSet, newState);
441}
442
443void
445{
446 NS_LOG_FUNCTION(this);
447
448 LockToSet(set);
449
450 uint32_t newState = 0;
451
452 if (m_numOfStates > 1)
453 {
454 newState = (rand() % (m_numOfStates - 1));
455 }
456
457 m_currentState = newState;
458
459 m_enableStateLock = true;
460}
461
462void
464{
465 NS_LOG_FUNCTION(this);
466
467 m_enableSetLock = false;
468 m_enableStateLock = false;
469}
470
471double
473{
474 NS_LOG_FUNCTION(this);
475
476 return (Now().GetSeconds() - m_latestStateChangeTime.GetSeconds()) * m_velocity();
477}
478
479} // namespace ns3
Callback< double > VelocityCallback
Gets velocity in m/s.
Callback< double > ElevationCallback
Gets elevation angle in degrees.
ChannelType_t
Types of channel.
MarkovFaderType_t
Possible types of Markov state faders.
Container for Markov-model.
double DoGetFading(Address macAddress, SatEnums::ChannelType_t channeltype)
Function for getting the fading.
void UpdateProbabilities(uint32_t set)
Function for updating the state change probabilities.
Time m_latestCalculationTime_up
Latest calculation time for uplink fading value.
bool m_useDecibels
Defines whether the calculations should return the fading value in decibels or not.
double m_minimumPositionChangeInMeters
Minimum state change distance in meters.
void UnlockSetAndState()
Function for unlocking the parameter set and state.
void EvaluateStateChange(SatEnums::ChannelType_t channelType)
Function for evaluating state change.
void DoDispose()
Do needed dispose actions.
uint32_t m_currentState
Current state.
double m_latestCalculatedFadingValue_down
Latest calculated downlink fading value.
Time m_latestCalculationTime_down
Latest calculation time for downlink fading value.
uint32_t m_numOfSets
Number of parameter sets available.
double GetCachedFadingValue(SatEnums::ChannelType_t channelType)
Function for getting the cached fading values.
double m_latestCalculatedFadingValue_up
Latest calculated uplink fading value.
void LockToSet(uint32_t newSet)
Function for locking the parameter set.
void RandomizeLockedSetAndState()
Function for locking the parameter set and state to random values.
Ptr< SatMarkovConf > m_markovConf
Markoc model configuration.
TracedCallback< double, SatEnums::ChannelType_t, double > m_fadingTrace
Fading trace function.
bool m_enableSetLock
Variable for disabling the parameter set change.
uint32_t m_numOfStates
Number of states available.
double CalculateFading(SatEnums::ChannelType_t channelType)
Function for calculating the fading value.
VelocityCallback m_velocity
Node movement velocity.
void Reset()
Clear used variables.
double CalculateDistanceSinceLastStateChange()
Function for calculating the distance since latest state change position.
static TypeId GetTypeId(void)
NS-3 function for type id.
bool HasCooldownPeriodPassed(SatEnums::ChannelType_t channelType)
Function for checking whether the cooldown period has passed.
uint32_t m_currentSet
Current parameter set.
ElevationCallback m_currentElevation
Current elevation value.
bool m_enableStateLock
Variable for disabling state changes.
void RandomizeLockedState(uint32_t set)
Function for locking the state to random value.
Ptr< SatBaseFader > m_fader_up
Uplink fader.
Time m_cooldownPeriodLength
Cooldown period length in time.
Time m_latestStateChangeTime
Latest calculation time for state change.
Ptr< SatBaseFader > m_fader_down
Downlink fader.
void LockToSetAndState(uint32_t newSet, uint32_t newState)
Function for locking the parameter set and state.
void CreateFaders(SatMarkovConf::MarkovFaderType_t faderType)
Function for creating the Markov state faders.
Ptr< SatMarkovModel > m_markovModel
Markov model object.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.