satellite-fwd-link-scheduler-default.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 NS_LOG_COMPONENT_DEFINE("SatFwdLinkSchedulerDefault");
26 
27 namespace ns3
28 {
29 
30 NS_OBJECT_ENSURE_REGISTERED(SatFwdLinkSchedulerDefault);
31 
32 TypeId
34 {
35  static TypeId tid =
36  TypeId("ns3::SatFwdLinkSchedulerDefault")
37  .SetParent<SatFwdLinkScheduler>()
38  .AddConstructor<SatFwdLinkSchedulerDefault>()
39  .AddAttribute(
40  "SchedulingStartThresholdTime",
41  "Threshold time of total transmissions in BB Frame container to trigger a "
42  "scheduling round.",
43  TimeValue(MilliSeconds(5)),
45  MakeTimeChecker())
46  .AddAttribute(
47  "SchedulingStopThresholdTime",
48  "Threshold time of total transmissions in BB Frame container to stop a scheduling "
49  "round.",
50  TimeValue(MilliSeconds(15)),
52  MakeTimeChecker())
53  .AddAttribute("BBFrameContainer",
54  "BB frame container of this scheduler.",
55  PointerValue(),
57  MakePointerChecker<SatBbFrameContainer>());
58  return tid;
59 }
60 
61 TypeId
63 {
64  NS_LOG_FUNCTION(this);
65 
66  return GetTypeId();
67 }
68 
71 {
72  NS_LOG_FUNCTION(this);
73  NS_FATAL_ERROR("Default constructor for SatFwdLinkSchedulerDefault not supported");
74 }
75 
77  Mac48Address address,
78  double carrierBandwidthInHz)
79  : SatFwdLinkScheduler(conf, address, carrierBandwidthInHz),
80  m_symbolsSent(0)
81 {
82  NS_LOG_FUNCTION(this);
83 
84  ObjectBase::ConstructSelf(AttributeConstructionList());
85 
86  std::vector<SatEnums::SatModcod_t> modCods = conf->GetModCodsUsed();
87 
88  m_bbFrameContainer = CreateObject<SatBbFrameContainer>(modCods, m_bbFrameConf);
89 
90  Simulator::Schedule(m_periodicInterval,
92  this);
93 }
94 
96 {
97  NS_LOG_FUNCTION(this);
98 }
99 
100 void
102 {
103  NS_LOG_FUNCTION(this);
105  m_bbFrameContainer = NULL;
106 }
107 
108 std::pair<Ptr<SatBbFrame>, const Time>
110 {
111  NS_LOG_FUNCTION(this);
112 
113  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStartThresholdTime)
114  {
116  }
117 
118  Ptr<SatBbFrame> frame = m_bbFrameContainer->GetNextFrame();
119  Time frameDuration;
120 
121  if (frame != NULL)
122  {
123  m_symbolsSent += ceil(frame->GetDuration().GetSeconds() * m_carrierBandwidthInHz);
124  }
125 
126  // create dummy frame
127  if (m_dummyFrameSendingEnabled && frame == NULL)
128  {
129  frame = Create<SatBbFrame>(m_bbFrameConf->GetDefaultModCod(),
131  m_bbFrameConf);
132 
133  // create dummy packet
134  Ptr<Packet> dummyPacket = Create<Packet>(1);
135 
136  // Add MAC tag
137  SatMacTag mTag;
138  mTag.SetDestAddress(Mac48Address::GetBroadcast());
140  dummyPacket->AddPacketTag(mTag);
141 
142  // Add E2E address tag
143  SatAddressE2ETag addressE2ETag;
144  addressE2ETag.SetE2EDestAddress(Mac48Address::GetBroadcast());
145  addressE2ETag.SetE2ESourceAddress(m_macAddress);
146  dummyPacket->AddPacketTag(addressE2ETag);
147 
148  // Add dummy packet to dummy frame
149  frame->AddPayload(dummyPacket);
150 
151  frameDuration = frame->GetDuration();
152  }
153  // If no bb frame available and dummy frames disabled
154  else if (frame == NULL)
155  {
156  frameDuration = m_bbFrameConf->GetDummyBbFrameDuration();
157  }
158 
159  if (frame != NULL)
160  {
161  frameDuration = frame->GetDuration();
162  frame->SetSliceId(0);
163  }
164 
165  return std::make_pair(frame, frameDuration);
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION(this);
172 
175 
176  Simulator::Schedule(m_periodicInterval,
178  this);
179 }
180 
181 void
183 {
184  NS_LOG_FUNCTION(this);
185 
186  m_schedulingSymbolRateTrace(0, m_symbolsSent / Seconds(1).GetSeconds());
187 
188  m_symbolsSent = 0;
189 }
190 
191 void
193 {
194  NS_LOG_FUNCTION(this);
195 
196  // Get scheduling objects from LLC
197  std::vector<Ptr<SatSchedulingObject>> so;
199 
200  for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin();
201  (it != so.end()) &&
202  (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime);
203  it++)
204  {
205  uint32_t currentObBytes = (*it)->GetBufferedBytes();
206  uint32_t currentObMinReqBytes = (*it)->GetMinTxOpportunityInBytes();
207  uint8_t flowId = (*it)->GetFlowId();
208  SatEnums::SatModcod_t modcod =
209  m_bbFrameContainer->GetModcod(flowId, GetSchedulingObjectCno(*it));
210 
211  uint32_t frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
212 
213  while (((m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)) &&
214  (currentObBytes > 0))
215  {
216  if (frameBytes < currentObMinReqBytes)
217  {
218  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) -
219  m_bbFrameConf->GetBbFrameHeaderSizeInBytes();
220 
221  // if frame bytes still too small, we must have too long control message, so let's
222  // crash
223  if (frameBytes < currentObMinReqBytes)
224  {
225  NS_FATAL_ERROR("Control package too probably too long!!!");
226  }
227  }
228 
229  Ptr<Packet> p = m_txOpportunityCallback(frameBytes,
230  (*it)->GetMacAddress(),
231  flowId,
232  currentObBytes,
233  currentObMinReqBytes);
234 
235  if (p)
236  {
237  m_bbFrameContainer->AddData(flowId, modcod, p);
238  frameBytes = m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod);
239  }
240  else if (m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod) !=
241  m_bbFrameContainer->GetBytesLeftInTailFrame(flowId, modcod))
242  {
243  frameBytes = m_bbFrameContainer->GetMaxFramePayloadInBytes(flowId, modcod);
244  }
245  else
246  {
247  NS_FATAL_ERROR("Packet does not fit in empty BB Frame. Control package too long or "
248  "fragmentation problem in user package!!!");
249  }
250  }
251 
253  }
254 }
255 
256 void
257 SatFwdLinkSchedulerDefault::GetSchedulingObjects(std::vector<Ptr<SatSchedulingObject>>& output)
258 {
259  NS_LOG_FUNCTION(this);
260 
261  if (m_bbFrameContainer->GetTotalDuration() < m_schedulingStopThresholdTime)
262  {
263  // Get scheduling objects from LLC
264  m_schedContextCallback(output);
265 
266  SortSchedulingObjects(output);
267  }
268 }
269 
270 } // 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.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.