satellite-dama-entry.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
21 #include "satellite-dama-entry.h"
22 
24 #include "satellite-utils.h"
25 
26 #include <ns3/log.h>
27 
28 #include <algorithm>
29 #include <vector>
30 
31 NS_LOG_COMPONENT_DEFINE("SatDamaEntry");
32 
33 namespace ns3
34 {
35 
37  : m_dynamicRatePersistence(0),
38  m_volumeBacklogPersistence(0)
39 {
40  NS_LOG_FUNCTION(this);
41  NS_FATAL_ERROR("The default version of the constructor not supported!!!");
42 }
43 
44 SatDamaEntry::SatDamaEntry(Ptr<SatLowerLayerServiceConf> llsConf)
45  : m_dynamicRatePersistence(0),
46  m_volumeBacklogPersistence(0),
47  m_llsConf(llsConf)
48 {
49  NS_LOG_FUNCTION(this);
50 
51  m_dynamicRateRequestedInKbps = std::vector<uint16_t>(m_llsConf->GetDaServiceCount(), 0.0);
52  m_volumeBacklogRequestedInBytes = std::vector<uint32_t>(m_llsConf->GetDaServiceCount(), 0);
53 }
54 
56 {
57  NS_LOG_FUNCTION(this);
58 }
59 
60 uint8_t
62 {
63  NS_LOG_FUNCTION(this);
64 
65  return m_llsConf->GetDaServiceCount();
66 }
67 
68 uint32_t
69 SatDamaEntry::GetCraBasedBytes(Time duration) const
70 {
71  NS_LOG_FUNCTION(this << duration);
72 
73  uint32_t totalBytes = 0;
74 
75  for (uint8_t i = 0; i < m_llsConf->GetDaServiceCount(); i++)
76  {
77  if (m_llsConf->GetDaConstantAssignmentProvided(i))
78  {
79  totalBytes += (SatConstVariables::BITS_IN_KBIT *
80  m_llsConf->GetDaConstantServiceRateInKbps(i) * duration.GetSeconds()) /
82  }
83  }
84 
85  return totalBytes;
86 }
87 
88 uint32_t
90 {
91  NS_LOG_FUNCTION(this << duration);
92 
93  uint32_t totalBytes = 0;
94 
95  for (uint8_t i = 0; i < m_llsConf->GetDaServiceCount(); i++)
96  {
97  uint16_t minRateInKbps = 0;
98 
99  if (m_llsConf->GetDaConstantAssignmentProvided(i) && m_llsConf->GetDaRbdcAllowed(i))
100  {
101  minRateInKbps = std::max<uint16_t>(m_llsConf->GetDaMinimumServiceRateInKbps(i),
102  m_llsConf->GetDaConstantServiceRateInKbps(i));
103  }
104  else if (m_llsConf->GetDaConstantAssignmentProvided(i))
105  {
106  minRateInKbps = m_llsConf->GetDaConstantServiceRateInKbps(i);
107  }
108  else if (m_llsConf->GetDaRbdcAllowed(i))
109  {
110  minRateInKbps = m_llsConf->GetDaMinimumServiceRateInKbps(i);
111  }
112 
113  totalBytes += (SatConstVariables::BITS_IN_KBIT * minRateInKbps * duration.GetSeconds()) /
115  }
116 
117  return totalBytes;
118 }
119 
120 uint32_t
122 {
123  NS_LOG_FUNCTION(this << duration);
124 
125  uint32_t totalBytes = 0;
126 
127  for (uint8_t i = 0; i < m_dynamicRateRequestedInKbps.size(); i++)
128  {
130  duration.GetSeconds()) /
132  }
133 
134  return totalBytes;
135 }
136 
137 uint32_t
139 {
140  NS_LOG_FUNCTION(this);
141 
142  uint32_t totalBytes = 0;
143 
144  for (uint8_t i = 0; i < m_volumeBacklogRequestedInBytes.size(); i++)
145  {
146  totalBytes += m_volumeBacklogRequestedInBytes[i];
147  }
148 
149  return totalBytes;
150 }
151 
152 uint16_t
153 SatDamaEntry::GetCraInKbps(uint8_t index) const
154 {
155  NS_LOG_FUNCTION(this << (uint32_t)index);
156 
157  if (index >= m_llsConf->GetDaServiceCount())
158  {
159  NS_FATAL_ERROR("RC index requested is out of range!!!");
160  }
161 
162  uint16_t cra(0);
163  if (m_llsConf->GetDaConstantAssignmentProvided(index))
164  {
165  cra = m_llsConf->GetDaConstantServiceRateInKbps(index);
166  }
167 
168  return cra;
169 }
170 
171 uint16_t
172 SatDamaEntry::GetMinRbdcInKbps(uint8_t index) const
173 {
174  NS_LOG_FUNCTION(this << (uint32_t)index);
175 
176  if (index >= m_llsConf->GetDaServiceCount())
177  {
178  NS_FATAL_ERROR("RC index requested is out of range!!!");
179  }
180 
181  uint16_t minRbdc(0);
182 
183  if (m_llsConf->GetDaRbdcAllowed(index) && (m_dynamicRatePersistence > 0))
184  {
185  minRbdc = std::max<uint16_t>(m_llsConf->GetDaMinimumServiceRateInKbps(index),
186  GetCraInKbps(index));
187  }
188 
189  return minRbdc;
190 }
191 
192 uint16_t
193 SatDamaEntry::GetRbdcInKbps(uint8_t index) const
194 {
195  NS_LOG_FUNCTION(this << (uint32_t)index);
196 
197  if (index >= m_dynamicRateRequestedInKbps.size())
198  {
199  NS_FATAL_ERROR("RC index requested is out of range!!!");
200  }
201 
202  return m_dynamicRateRequestedInKbps[index];
203 }
204 
205 void
206 SatDamaEntry::UpdateRbdcInKbps(uint8_t index, uint16_t rateInKbps)
207 {
208  NS_LOG_FUNCTION(this << (uint32_t)index << rateInKbps);
209 
210  if (m_llsConf->GetDaRbdcAllowed(index))
211  {
212  double craRbdcSum = GetCraInKbps(index) + rateInKbps;
213 
214  if (craRbdcSum < GetMinRbdcInKbps(index))
215  {
217  }
218  else if (craRbdcSum > m_llsConf->GetDaMaximumServiceRateInKbps(index))
219  {
221  std::max<double>(0.0,
222  (m_llsConf->GetDaMaximumServiceRateInKbps(index) -
223  m_llsConf->GetDaConstantServiceRateInKbps(index)));
224  }
225  else
226  {
227  m_dynamicRateRequestedInKbps[index] = rateInKbps;
228  }
229  }
230 }
231 
232 uint32_t
233 SatDamaEntry::GetVbdcInBytes(uint8_t index) const
234 {
235  NS_LOG_FUNCTION(this << (uint32_t)index);
236 
237  if (index >= m_volumeBacklogRequestedInBytes.size())
238  {
239  NS_FATAL_ERROR("RC index requested is out of range!!!");
240  }
241 
242  return m_volumeBacklogRequestedInBytes[index];
243 }
244 
245 void
246 SatDamaEntry::UpdateVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
247 {
248  NS_LOG_FUNCTION(this << (uint32_t)index << volumeInBytes);
249 
250  if (m_llsConf->GetDaVolumeAllowed(index))
251  {
252  NS_LOG_INFO("Update VBDC! RC index: " << index << " existing VBDC bytes: "
254  << " updated with " << volumeInBytes << " bytes!");
255 
256  SetVbdcInBytes(index, m_volumeBacklogRequestedInBytes[index] + volumeInBytes);
257  }
258 }
259 
260 void
261 SatDamaEntry::SetVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
262 {
263  NS_LOG_FUNCTION(this << (uint32_t)index << volumeInBytes);
264 
265  if (m_llsConf->GetDaVolumeAllowed(index))
266  {
267  NS_LOG_INFO("Set VBDC bytes to " << volumeInBytes << " for RC index: " << index);
268 
269  m_volumeBacklogRequestedInBytes[index] = volumeInBytes;
270 
272  (SatConstVariables::BYTES_IN_KBYTE * m_llsConf->GetDaMaximumBacklogInKbytes(index)))
273  {
274  uint32_t maxVolumeBacklogInBytes =
275  SatConstVariables::BYTES_IN_KBYTE * m_llsConf->GetDaMaximumBacklogInKbytes(index);
276  NS_LOG_INFO("Max volume backlog reached! Set VBDC bytes to "
277  << maxVolumeBacklogInBytes << " for RC index: " << index);
278  m_volumeBacklogRequestedInBytes[index] = maxVolumeBacklogInBytes;
279  }
280  }
281 }
282 
283 void
285 {
286  NS_LOG_FUNCTION(this);
287 
288  m_dynamicRatePersistence = m_llsConf->GetDynamicRatePersistence();
289 }
290 
291 void
293 {
294  NS_LOG_FUNCTION(this);
295 
296  if (m_dynamicRatePersistence > 0)
297  {
299  }
300 
301  if (m_dynamicRatePersistence == 0)
302  {
303  std::fill(m_dynamicRateRequestedInKbps.begin(), m_dynamicRateRequestedInKbps.end(), 0.0);
304  }
305 }
306 
307 void
309 {
310  NS_LOG_FUNCTION(this);
311 
312  m_volumeBacklogPersistence = m_llsConf->GetVolumeBacklogPersistence();
313 }
314 
315 void
317 {
318  NS_LOG_FUNCTION(this);
319 
321  {
323  }
324 
326  {
327  std::fill(m_volumeBacklogRequestedInBytes.begin(),
329  0);
330  }
331 }
332 
333 } // namespace ns3
uint32_t GetCraBasedBytes(Time duration) const
Get CRA based bytes with given duration.
uint32_t GetVbdcBasedBytes() const
Get VBDC based bytes.
uint8_t m_volumeBacklogPersistence
void DecrementDynamicRatePersistence()
Decrement dynamic rate persistence.
uint16_t GetCraInKbps(uint8_t index) const
Get configured value of the CRA.
~SatDamaEntry()
Destroy a SatDamaEntry.
void UpdateVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
Update VBDC request of the RC.
void UpdateRbdcInKbps(uint8_t index, uint16_t rateInKbps)
Update RBDC request of a RC.
std::vector< uint32_t > m_volumeBacklogRequestedInBytes
void ResetDynamicRatePersistence()
Reset dynamic rate persistence to the value given in lower layer service configuration.
uint32_t GetMinRateBasedBytes(Time duration) const
Get minimum rate based bytes with given duration.
void DecrementVolumeBacklogPersistence()
Decrement volume backlog persistence.
SatDamaEntry()
Default construct a SatDamaEntry.
uint16_t GetRbdcInKbps(uint8_t index) const
Get current value of the RBDC requested.
void ResetVolumeBacklogPersistence()
Reset volume backlog persistence to the value given in lower layer service configuration.
uint32_t GetRbdcBasedBytes(Time duration) const
Get RBDC based bytes with given duration.
std::vector< uint16_t > m_dynamicRateRequestedInKbps
void SetVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
Set VBDC request of the RC.
uint8_t m_dynamicRatePersistence
uint16_t GetMinRbdcInKbps(uint8_t index) const
Get configured value of the minimum RBDC.
uint8_t GetRcCount() const
Get number of RCs in the SatDamaEntry.
Ptr< SatLowerLayerServiceConf > m_llsConf
uint32_t GetVbdcInBytes(uint8_t index) const
Get current value of the VBDC requested.
constexpr uint32_t BITS_IN_KBIT
Number of bits consisting a kilobit.
constexpr uint32_t BITS_PER_BYTE
Number of bits in a byte.
constexpr uint32_t BYTES_IN_KBYTE
Number of bytes consisting a kilobyte.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.