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 NS_LOG_COMPONENT_DEFINE("SatDamaEntry");
29 
30 namespace ns3
31 {
32 
34  : m_dynamicRatePersistence(0),
35  m_volumeBacklogPersistence(0)
36 {
37  NS_LOG_FUNCTION(this);
38  NS_FATAL_ERROR("The default version of the constructor not supported!!!");
39 }
40 
41 SatDamaEntry::SatDamaEntry(Ptr<SatLowerLayerServiceConf> llsConf)
42  : m_dynamicRatePersistence(0),
43  m_volumeBacklogPersistence(0),
44  m_llsConf(llsConf)
45 {
46  NS_LOG_FUNCTION(this);
47 
48  m_dynamicRateRequestedInKbps = std::vector<uint16_t>(m_llsConf->GetDaServiceCount(), 0.0);
49  m_volumeBacklogRequestedInBytes = std::vector<uint32_t>(m_llsConf->GetDaServiceCount(), 0);
50 }
51 
53 {
54  NS_LOG_FUNCTION(this);
55 }
56 
57 uint8_t
59 {
60  NS_LOG_FUNCTION(this);
61 
62  return m_llsConf->GetDaServiceCount();
63 }
64 
65 uint32_t
66 SatDamaEntry::GetCraBasedBytes(Time duration) const
67 {
68  NS_LOG_FUNCTION(this << duration);
69 
70  uint32_t totalBytes = 0;
71 
72  for (uint8_t i = 0; i < m_llsConf->GetDaServiceCount(); i++)
73  {
74  if (m_llsConf->GetDaConstantAssignmentProvided(i))
75  {
76  totalBytes += (SatConstVariables::BITS_IN_KBIT *
77  m_llsConf->GetDaConstantServiceRateInKbps(i) * duration.GetSeconds()) /
79  }
80  }
81 
82  return totalBytes;
83 }
84 
85 uint32_t
87 {
88  NS_LOG_FUNCTION(this << duration);
89 
90  uint32_t totalBytes = 0;
91 
92  for (uint8_t i = 0; i < m_llsConf->GetDaServiceCount(); i++)
93  {
94  uint16_t minRateInKbps = 0;
95 
96  if (m_llsConf->GetDaConstantAssignmentProvided(i) && m_llsConf->GetDaRbdcAllowed(i))
97  {
98  minRateInKbps = std::max<uint16_t>(m_llsConf->GetDaMinimumServiceRateInKbps(i),
99  m_llsConf->GetDaConstantServiceRateInKbps(i));
100  }
101  else if (m_llsConf->GetDaConstantAssignmentProvided(i))
102  {
103  minRateInKbps = m_llsConf->GetDaConstantServiceRateInKbps(i);
104  }
105  else if (m_llsConf->GetDaRbdcAllowed(i))
106  {
107  minRateInKbps = m_llsConf->GetDaMinimumServiceRateInKbps(i);
108  }
109 
110  totalBytes += (SatConstVariables::BITS_IN_KBIT * minRateInKbps * duration.GetSeconds()) /
112  }
113 
114  return totalBytes;
115 }
116 
117 uint32_t
119 {
120  NS_LOG_FUNCTION(this << duration);
121 
122  uint32_t totalBytes = 0;
123 
124  for (uint8_t i = 0; i < m_dynamicRateRequestedInKbps.size(); i++)
125  {
127  duration.GetSeconds()) /
129  }
130 
131  return totalBytes;
132 }
133 
134 uint32_t
136 {
137  NS_LOG_FUNCTION(this);
138 
139  uint32_t totalBytes = 0;
140 
141  for (uint8_t i = 0; i < m_volumeBacklogRequestedInBytes.size(); i++)
142  {
143  totalBytes += m_volumeBacklogRequestedInBytes[i];
144  }
145 
146  return totalBytes;
147 }
148 
149 uint16_t
150 SatDamaEntry::GetCraInKbps(uint8_t index) const
151 {
152  NS_LOG_FUNCTION(this << (uint32_t)index);
153 
154  if (index >= m_llsConf->GetDaServiceCount())
155  {
156  NS_FATAL_ERROR("RC index requested is out of range!!!");
157  }
158 
159  uint16_t cra(0);
160  if (m_llsConf->GetDaConstantAssignmentProvided(index))
161  {
162  cra = m_llsConf->GetDaConstantServiceRateInKbps(index);
163  }
164 
165  return cra;
166 }
167 
168 uint16_t
169 SatDamaEntry::GetMinRbdcInKbps(uint8_t index) const
170 {
171  NS_LOG_FUNCTION(this << (uint32_t)index);
172 
173  if (index >= m_llsConf->GetDaServiceCount())
174  {
175  NS_FATAL_ERROR("RC index requested is out of range!!!");
176  }
177 
178  uint16_t minRbdc(0);
179 
180  if (m_llsConf->GetDaRbdcAllowed(index) && (m_dynamicRatePersistence > 0))
181  {
182  minRbdc = std::max<uint16_t>(m_llsConf->GetDaMinimumServiceRateInKbps(index),
183  GetCraInKbps(index));
184  }
185 
186  return minRbdc;
187 }
188 
189 uint16_t
190 SatDamaEntry::GetRbdcInKbps(uint8_t index) const
191 {
192  NS_LOG_FUNCTION(this << (uint32_t)index);
193 
194  if (index >= m_dynamicRateRequestedInKbps.size())
195  {
196  NS_FATAL_ERROR("RC index requested is out of range!!!");
197  }
198 
199  return m_dynamicRateRequestedInKbps[index];
200 }
201 
202 void
203 SatDamaEntry::UpdateRbdcInKbps(uint8_t index, uint16_t rateInKbps)
204 {
205  NS_LOG_FUNCTION(this << (uint32_t)index << rateInKbps);
206 
207  if (m_llsConf->GetDaRbdcAllowed(index))
208  {
209  double craRbdcSum = GetCraInKbps(index) + rateInKbps;
210 
211  if (craRbdcSum < GetMinRbdcInKbps(index))
212  {
214  }
215  else if (craRbdcSum > m_llsConf->GetDaMaximumServiceRateInKbps(index))
216  {
218  std::max<double>(0.0,
219  (m_llsConf->GetDaMaximumServiceRateInKbps(index) -
220  m_llsConf->GetDaConstantServiceRateInKbps(index)));
221  }
222  else
223  {
224  m_dynamicRateRequestedInKbps[index] = rateInKbps;
225  }
226  }
227 }
228 
229 uint32_t
230 SatDamaEntry::GetVbdcInBytes(uint8_t index) const
231 {
232  NS_LOG_FUNCTION(this << (uint32_t)index);
233 
234  if (index >= m_volumeBacklogRequestedInBytes.size())
235  {
236  NS_FATAL_ERROR("RC index requested is out of range!!!");
237  }
238 
239  return m_volumeBacklogRequestedInBytes[index];
240 }
241 
242 void
243 SatDamaEntry::UpdateVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
244 {
245  NS_LOG_FUNCTION(this << (uint32_t)index << volumeInBytes);
246 
247  if (m_llsConf->GetDaVolumeAllowed(index))
248  {
249  NS_LOG_INFO("Update VBDC! RC index: " << index << " existing VBDC bytes: "
251  << " updated with " << volumeInBytes << " bytes!");
252 
253  SetVbdcInBytes(index, m_volumeBacklogRequestedInBytes[index] + volumeInBytes);
254  }
255 }
256 
257 void
258 SatDamaEntry::SetVbdcInBytes(uint8_t index, uint32_t volumeInBytes)
259 {
260  NS_LOG_FUNCTION(this << (uint32_t)index << volumeInBytes);
261 
262  if (m_llsConf->GetDaVolumeAllowed(index))
263  {
264  NS_LOG_INFO("Set VBDC bytes to " << volumeInBytes << " for RC index: " << index);
265 
266  m_volumeBacklogRequestedInBytes[index] = volumeInBytes;
267 
269  (SatConstVariables::BYTES_IN_KBYTE * m_llsConf->GetDaMaximumBacklogInKbytes(index)))
270  {
271  uint32_t maxVolumeBacklogInBytes =
272  SatConstVariables::BYTES_IN_KBYTE * m_llsConf->GetDaMaximumBacklogInKbytes(index);
273  NS_LOG_INFO("Max volume backlog reached! Set VBDC bytes to "
274  << maxVolumeBacklogInBytes << " for RC index: " << index);
275  m_volumeBacklogRequestedInBytes[index] = maxVolumeBacklogInBytes;
276  }
277  }
278 }
279 
280 void
282 {
283  NS_LOG_FUNCTION(this);
284 
285  m_dynamicRatePersistence = m_llsConf->GetDynamicRatePersistence();
286 }
287 
288 void
290 {
291  NS_LOG_FUNCTION(this);
292 
293  if (m_dynamicRatePersistence > 0)
294  {
296  }
297 
298  if (m_dynamicRatePersistence == 0)
299  {
300  std::fill(m_dynamicRateRequestedInKbps.begin(), m_dynamicRateRequestedInKbps.end(), 0.0);
301  }
302 }
303 
304 void
306 {
307  NS_LOG_FUNCTION(this);
308 
309  m_volumeBacklogPersistence = m_llsConf->GetVolumeBacklogPersistence();
310 }
311 
312 void
314 {
315  NS_LOG_FUNCTION(this);
316 
318  {
320  }
321 
323  {
324  std::fill(m_volumeBacklogRequestedInBytes.begin(),
326  0);
327  }
328 }
329 
330 } // 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.