Loading...
Searching...
No Matches
satellite-scpc-scheduler.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: Bastien Tauran <bastien.tauran@viveris.fr>
19 */
20
22
23#include "ns3/log.h"
24
25#include <utility>
26#include <vector>
27
28NS_LOG_COMPONENT_DEFINE("SatScpcScheduler");
29
30namespace ns3
31{
32
33NS_OBJECT_ENSURE_REGISTERED(SatScpcScheduler);
34
35TypeId
37{
38 static TypeId tid =
39 TypeId("ns3::SatScpcScheduler")
40 .SetParent<SatFwdLinkScheduler>()
41 .AddConstructor<SatScpcScheduler>()
42 .AddAttribute("SchedulingStartThresholdTime",
43 "Threshold time of total transmissions in BB Frame container to trigger "
44 "a scheduling round.",
45 TimeValue(MilliSeconds(5)),
47 MakeTimeChecker())
48 .AddAttribute("SchedulingStopThresholdTime",
49 "Threshold time of total transmissions in BB Frame container to stop a "
50 "scheduling round.",
51 TimeValue(MilliSeconds(15)),
53 MakeTimeChecker())
54 .AddAttribute("BBFrameContainer",
55 "BB frame container of this scheduler.",
56 PointerValue(),
57 MakePointerAccessor(&SatScpcScheduler::m_bbFrameContainer),
58 MakePointerChecker<SatBbFrameContainer>());
59 return tid;
60}
61
64{
65 NS_LOG_FUNCTION(this);
66 NS_FATAL_ERROR("Default constructor for SatScpcScheduler not supported");
67}
68
69SatScpcScheduler::SatScpcScheduler(Ptr<SatBbFrameConf> conf,
70 Mac48Address address,
71 double carrierBandwidthInHz)
72 : SatFwdLinkScheduler(conf, address, carrierBandwidthInHz),
74{
75 NS_LOG_FUNCTION(this << conf << address << carrierBandwidthInHz);
76}
77
78void
80{
81 NS_LOG_FUNCTION(this);
82
84
85 std::vector<SatEnums::SatModcod_t> modCods = m_bbFrameConf->GetModCodsUsed();
86
87 m_bbFrameContainer = CreateObject<SatBbFrameContainer>(modCods, m_bbFrameConf);
88}
89
91{
92 NS_LOG_FUNCTION(this);
93}
94
95void
97{
98 NS_LOG_FUNCTION(this);
100 m_bbFrameContainer = nullptr;
101}
102
103std::pair<Ptr<SatBbFrame>, const Time>
105{
106 NS_LOG_FUNCTION(this);
107
108 if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStartThresholdTime)
109 {
111 }
112
113 Ptr<SatBbFrame> frame = m_bbFrameContainer->GetNextFrame();
114 Time frameDuration;
115
116 if (frame != nullptr)
117 {
118 m_symbolsSent += ceil(frame->GetDuration().GetSeconds() * m_carrierBandwidthInHz);
119 }
120
121 // create dummy frame
122 if (m_dummyFrameSendingEnabled && frame == nullptr)
123 {
124 frame = Create<SatBbFrame>(m_bbFrameConf->GetDefaultModCod(),
127
128 // create dummy packet
129 Ptr<Packet> dummyPacket = Create<Packet>(1);
130
131 // Add MAC tag
132 SatMacTag mTag;
133 mTag.SetDestAddress(Mac48Address::GetBroadcast());
135 dummyPacket->AddPacketTag(mTag);
136
137 // Add E2E address tag
138 SatAddressE2ETag addressE2ETag;
139 addressE2ETag.SetE2EDestAddress(Mac48Address::GetBroadcast());
140 addressE2ETag.SetE2ESourceAddress(m_macAddress);
141 dummyPacket->AddPacketTag(addressE2ETag);
142
143 // Add dummy packet to dummy frame
144 frame->AddPayload(dummyPacket);
145
146 frameDuration = frame->GetDuration();
147 }
148 // If no bb frame available and dummy frames disabled
149 else if (frame == nullptr)
150 {
151 frameDuration = m_bbFrameConf->GetDummyBbFrameDuration();
152 }
153
154 if (frame != nullptr)
155 {
156 frameDuration = frame->GetDuration();
157 frame->SetSliceId(0);
158 }
159
160 return std::make_pair(frame, frameDuration);
161}
162
163void
165{
166 NS_LOG_FUNCTION(this);
167
168 m_schedulingSymbolRateTrace(0, m_symbolsSent / Seconds(1).GetSeconds());
169
170 m_symbolsSent = 0;
171}
172
173void
175{
176 NS_LOG_FUNCTION(this);
177
178 // Get scheduling objects from LLC
179 std::vector<Ptr<SatSchedulingObject>> so;
181
182 for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin();
183 (it != so.end()) &&
185 it++)
186 {
187 uint32_t currentObBytes = (*it)->GetBufferedBytes();
188 uint32_t currentObMinReqBytes = (*it)->GetMinTxOpportunityInBytes();
189 uint8_t flowId = (*it)->GetFlowId();
190 SatEnums::SatModcod_t modcod =
191 m_bbFrameContainer->GetModcod(flowId, GetSchedulingObjectCno(*it));
192
193 uint32_t frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
194
195 while (((m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)) &&
196 (currentObBytes > 0))
197 {
198 if (frameBytes < currentObMinReqBytes)
199 {
200 frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) -
201 m_bbFrameConf->GetBbFrameHeaderSizeInBytes();
202
203 // if frame bytes still too small, we must have too long control message, so let's
204 // crash
205 if (frameBytes < currentObMinReqBytes)
206 {
207 NS_FATAL_ERROR("Control package probably too long!!!");
208 }
209 }
210
211 Ptr<Packet> p = m_txOpportunityCallback(frameBytes,
212 (*it)->GetMacAddress(),
213 flowId,
214 currentObBytes,
215 currentObMinReqBytes);
216
217 if (p)
218 {
219 m_bbFrameContainer->AddData(flowId, modcod, p);
220 frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
221 }
222 else if (m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) !=
223 m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod))
224 {
225 frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod);
226 }
227 else
228 {
229 NS_FATAL_ERROR("Packet does not fit in empty BB Frame. Control package too long or "
230 "fragmentation problem in user package!!!");
231 }
232 }
233
235 }
236}
237
238void
239SatScpcScheduler::GetSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& output)
240{
241 NS_LOG_FUNCTION(this);
242
243 if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)
244 {
245 // Get scheduling objects from LLC
247
248 SortSchedulingObjects(output);
249 }
250}
251
252} // namespace ns3
This class implements a tag that carries the satellite MAC of GW and UT.
void SetE2ESourceAddress(Mac48Address e2eSourceAddress)
Set E2E source MAC address.
void SetE2EDestAddress(Mac48Address e2eDestAddress)
Set E2E destination MAC address.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
SatFwdLinkSchedulerDefault schedules BB frames for forward link.
void SendAndClearSymbolsSentStat()
Send stats and reset all the symbols sent count for each slice to zero.
Ptr< SatBbFrameContainer > m_bbFrameContainer
The container for BB Frames.
~SatScpcScheduler()
Destroy a SatFwdLinkScheduler.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
void DoDispose(void)
Do dispose actions.
void GetSchedulingObjects(std::vector< Ptr< SatSchedulingObject > > &output)
Gets scheduling object in sorted order according to configured sorting criteria.
uint32_t m_symbolsSent
The number of symbols sent for each slice during an allocation cycle.
Time m_schedulingStartThresholdTime
Threshold time of total transmissions in BB Frame container to trigger a scheduling round.
virtual std::pair< Ptr< SatBbFrame >, const Time > GetNextFrame()
Get next frame to be transmitted.
static TypeId GetTypeId(void)
Get the type ID.
SatScpcScheduler()
Construct a SatFwdLinkScheduler.
void ScheduleBbFrames()
Schedule BB Frames.
Time m_schedulingStopThresholdTime
Threshold time of total transmissions in BB Frame container to stop a scheduling round.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.