Loading...
Searching...
No Matches
satellite-bbframe.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-bbframe.h"
22
24#include "satellite-utils.h"
25
26#include "ns3/log.h"
27
28NS_LOG_COMPONENT_DEFINE("SatBbFrame");
29
30namespace ns3
31{
32
34 : m_modCod(SatEnums::SAT_MODCOD_QPSK_1_TO_2),
38 m_frameType(SatEnums::NORMAL_FRAME)
39{
40 NS_LOG_FUNCTION(this);
41 NS_FATAL_ERROR("Default constructor of SatBbFrame not supported.");
42}
43
46 Ptr<SatBbFrameConf> conf)
47 : m_modCod(modCod),
48 m_frameType(type)
49{
50 NS_LOG_FUNCTION(this << modCod << type);
51
52 switch (type)
53 {
57 (conf->GetBbFramePayloadBits(modCod, type) / SatConstVariables::BITS_PER_BYTE);
58 m_headerSizeInBytes = conf->GetBbFrameHeaderSizeInBytes();
60 m_duration = conf->GetBbFrameDuration(modCod, type);
61 break;
62
67 switch (conf->GetDvbVersion())
68 {
70 m_maxSpaceInBytes = conf->GetBbFramePayloadBits(modCod, SatEnums::SHORT_FRAME) /
72 break;
74 m_maxSpaceInBytes = conf->GetBbFramePayloadBits(conf->GetDefaultModCodDummyFramesS2X(),
77 break;
78 default:
79 NS_FATAL_ERROR("Unknown DVB version");
80 }
81
82 m_headerSizeInBytes = conf->GetBbFrameHeaderSizeInBytes();
84 m_duration = conf->GetDummyBbFrameDuration();
85 break;
86
87 default:
88 NS_FATAL_ERROR("Invalid BBFrame type!!!");
89 break;
90 }
91}
92
94{
95 NS_LOG_FUNCTION(this);
96}
97
100{
101 NS_LOG_FUNCTION(this);
102 return m_framePayload;
103}
104
105uint32_t
106SatBbFrame::AddPayload(Ptr<Packet> data)
107{
108 NS_LOG_FUNCTION(this);
109
110 uint32_t dataLengthInBytes = data->GetSize();
111
112 if (dataLengthInBytes <= m_freeSpaceInBytes)
113 {
114 m_framePayload.push_back(data);
115 m_freeSpaceInBytes -= dataLengthInBytes;
116 }
117 else
118 {
119 NS_FATAL_ERROR("Data cannot be added to BB frame (length, free space): "
120 << dataLengthInBytes << ", " << m_freeSpaceInBytes);
121 }
122
123 return GetSpaceLeftInBytes();
124}
125
126uint32_t
128{
129 NS_LOG_FUNCTION(this);
130 return m_freeSpaceInBytes;
131}
132
133uint32_t
135{
136 NS_LOG_FUNCTION(this);
138}
139
140uint32_t
142{
143 NS_LOG_FUNCTION(this);
144 return m_maxSpaceInBytes;
145}
146
147double
149{
150 NS_LOG_FUNCTION(this);
151 return ((double)GetSpaceUsedInBytes() / (double)m_maxSpaceInBytes);
152}
153
154double
155SatBbFrame::GetOccupancyIfMerged(Ptr<SatBbFrame> mergedFrame) const
156{
157 NS_LOG_FUNCTION(this);
158
159 double ifMergedOccupancy = 0.0;
160
161 uint32_t mergedFrameDataBytes =
162 mergedFrame->GetSpaceUsedInBytes() - mergedFrame->GetFrameHeaderSize();
163
164 if (mergedFrameDataBytes <= m_freeSpaceInBytes)
165 {
166 ifMergedOccupancy = ((double)GetSpaceUsedInBytes() + (double)mergedFrameDataBytes) /
167 (double)m_maxSpaceInBytes;
168 }
169
170 return ifMergedOccupancy;
171}
172
173double
174SatBbFrame::GetSpectralEfficiency(double carrierBandwidthInHz) const
175{
176 NS_LOG_FUNCTION(this << carrierBandwidthInHz);
177
179 m_duration.GetSeconds() / carrierBandwidthInHz);
180}
181
182bool
183SatBbFrame::MergeWithFrame(Ptr<SatBbFrame> mergedFrame,
184 TracedCallback<Ptr<SatBbFrame>, Ptr<SatBbFrame>> mergeTraceCb)
185{
186 NS_LOG_FUNCTION(this);
187
188 bool merged = false;
189
190 uint32_t dataBytes = mergedFrame->GetSpaceUsedInBytes() - mergedFrame->GetFrameHeaderSize();
191
192 if (dataBytes <= m_freeSpaceInBytes)
193 {
194 mergeTraceCb(this, mergedFrame);
195 m_framePayload.insert(m_framePayload.end(),
196 mergedFrame->GetPayload().begin(),
197 mergedFrame->GetPayload().end());
198 m_freeSpaceInBytes -= dataBytes;
199 merged = true;
200 }
201
202 return merged;
203}
204
205Time
206SatBbFrame::Shrink(Ptr<SatBbFrameConf> conf)
207{
208 NS_LOG_FUNCTION(this);
209
210 Time durationDecrease(0);
211
213 {
214 uint32_t maxShortFrameSpaceInBytes =
215 (conf->GetBbFramePayloadBits(m_modCod, SatEnums::SHORT_FRAME) /
217 uint32_t spaceUsedInbytes = GetSpaceUsedInBytes();
218
219 // shrink only if data used in normal frame can fit in short frame
220 if (spaceUsedInbytes < maxShortFrameSpaceInBytes)
221 {
223 m_maxSpaceInBytes = maxShortFrameSpaceInBytes - m_headerSizeInBytes;
224 m_freeSpaceInBytes = m_maxSpaceInBytes - spaceUsedInbytes;
225
226 Time oldDuration = m_duration;
227 m_duration = conf->GetBbFrameDuration(m_modCod, SatEnums::SHORT_FRAME);
228 durationDecrease = oldDuration - m_duration;
229 }
230 }
231
232 return durationDecrease;
233}
234
235Time
236SatBbFrame::Extend(Ptr<SatBbFrameConf> conf)
237{
238 NS_LOG_FUNCTION(this);
239
240 Time durationIncrease(0);
241
243 {
244 uint32_t spaceUsedInbytes = GetSpaceUsedInBytes();
245
247 m_maxSpaceInBytes = (conf->GetBbFramePayloadBits(m_modCod, SatEnums::NORMAL_FRAME) /
249 m_freeSpaceInBytes = m_maxSpaceInBytes - spaceUsedInbytes;
250
251 Time oldDuration = m_duration;
252 m_duration = conf->GetBbFrameDuration(m_modCod, SatEnums::NORMAL_FRAME);
253 durationIncrease = m_duration - oldDuration;
254 }
255
256 return durationIncrease;
257}
258
259} // namespace ns3
double GetOccupancy() const
Get the occupancy of the of the BB Frame.
SatEnums::SatModcod_t m_modCod
uint32_t AddPayload(Ptr< Packet > packet)
Add payload (packet) to transmit buffer of this BB Frame info.
double GetOccupancyIfMerged(Ptr< SatBbFrame > mergedFrame) const
Checks occupancy of the frame if given frame would been merged with this frame.
double GetSpectralEfficiency(double carrierBandwidthInHz) const
Get spectra efficiency of the frame.
Time Extend(Ptr< SatBbFrameConf > conf)
Extent BB frame to the longest type.
const SatBbFramePayload_t & GetPayload()
Get the data in the BB Frame info as container of the packet pointers.
SatBbFramePayload_t m_framePayload
bool MergeWithFrame(Ptr< SatBbFrame > mergedFrame, TracedCallback< Ptr< SatBbFrame >, Ptr< SatBbFrame > > mergeTraceCb)
Merge given frame with this frame.
SatBbFrame()
Default constructor.
uint32_t GetSpaceLeftInBytes() const
Get space left in BB frame transmit buffer in bytes.
Time Shrink(Ptr< SatBbFrameConf > conf)
Shrink BB frame to the shortest type possible according to current load in the frame.
uint32_t GetSpaceUsedInBytes() const
Get space used in BB frame transmit buffer in bytes.
uint32_t GetMaxSpaceInBytes() const
Get the maximum size of the BB Frame transmit buffer in bytes.
SatEnums::SatBbFrameType_t m_frameType
std::vector< Ptr< Packet > > SatBbFramePayload_t
Define type SatBbFramePayload_t.
virtual ~SatBbFrame()
Destructor fro BB frame.
SatEnums class is for simplifying the use of enumerators in the satellite module.
SatBbFrameType_t
BB frame type used in DVB-S2 FWD link.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
constexpr uint32_t BITS_PER_BYTE
Number of bits in a byte.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.