Loading...
Searching...
No Matches
satellite-ut-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: Jani Puttonen <jani.puttonen@magister.fi>
19 */
20
22
24#include "satellite-node-info.h"
26
27#include "ns3/boolean.h"
28#include "ns3/log.h"
29#include "ns3/packet.h"
30#include "ns3/uinteger.h"
31
32#include <algorithm>
33#include <vector>
34
35NS_LOG_COMPONENT_DEFINE("SatUtScheduler");
36
37namespace ns3
38{
39
40NS_OBJECT_ENSURE_REGISTERED(SatUtScheduler);
41
42TypeId
44{
45 static TypeId tid =
46 TypeId("ns3::SatUtScheduler")
47 .SetParent<Object>()
48 .AddConstructor<SatUtScheduler>()
49 .AddAttribute("StrictPriorityForControl",
50 "Utilize strict priority for control packets",
51 BooleanValue(true),
52 MakeBooleanAccessor(&SatUtScheduler::m_prioritizeControl),
53 MakeBooleanChecker())
54 .AddAttribute("FramePduHeaderSize",
55 "Frame PDU header size in bytes",
56 UintegerValue(1),
58 MakeUintegerChecker<uint32_t>());
59 return tid;
60}
61
71
72SatUtScheduler::SatUtScheduler(Ptr<SatLowerLayerServiceConf> lls)
75 m_llsConf(lls),
79{
80 NS_LOG_FUNCTION(this);
81}
82
83void
85{
86 NS_LOG_FUNCTION(this);
87
88 Object::NotifyConstructionCompleted();
89
90 m_utScheduledByteCounters = std::vector<uint32_t>(m_llsConf->GetDaServiceCount(), 0);
91
92 for (uint32_t i = 0; i < SatEnums::NUM_FIDS; ++i)
93 {
94 m_rcIndices.push_back(i);
95 }
96}
97
99{
100 NS_LOG_FUNCTION(this);
101}
102
103void
105{
106 NS_LOG_FUNCTION(this);
107
108 m_schedContextCallback.Nullify();
109 m_txOpportunityCallback.Nullify();
110 m_llsConf = nullptr;
111 m_nodeInfo = nullptr;
112
113 Object::DoDispose();
114}
115
116void
122
123void
130
131void
132SatUtScheduler::DoScheduling(std::vector<Ptr<Packet>>& packets,
133 uint32_t payloadBytes,
135 uint8_t rcIndex,
137{
138 NS_LOG_FUNCTION(this << payloadBytes << (uint32_t)rcIndex << policy);
139
140 NS_LOG_INFO("UT scheduling RC: " << (uint32_t)(rcIndex) << " with " << payloadBytes
141 << " bytes");
142
143 if (type == SatTimeSlotConf::SLOT_TYPE_C && rcIndex != SatEnums::CONTROL_FID)
144 {
145 NS_FATAL_ERROR("Conflict in time slot data between RC index and slot type!");
146 }
147
148 // Schedule
149 // - 1. control
150 // - 2. rc index
152 {
153 DoSchedulingForRcIndex(packets, payloadBytes, SatEnums::CONTROL_FID);
154
155 if (payloadBytes > 0)
156 {
157 DoSchedulingForRcIndex(packets, payloadBytes, rcIndex);
158 }
159 }
160 // Schedule only the requested RC index
161 else
162 {
163 DoSchedulingForRcIndex(packets, payloadBytes, rcIndex);
164 }
165
166 // If we still have bytes left and the
167 // scheduling policy is loose
168 if (payloadBytes > 0 && policy == LOOSE && type == SatTimeSlotConf::SLOT_TYPE_TRC)
169 {
170 std::vector<uint8_t> rcIndices = GetPrioritizedRcIndexOrder();
171
172 for (std::vector<uint8_t>::const_iterator it = rcIndices.begin(); it != rcIndices.end();
173 ++it)
174 {
175 // No use asking the given RC index again
176 if (*it != rcIndex)
177 {
178 NS_LOG_INFO("UT scheduling RC: " << (uint32_t)(rcIndex) << " with " << payloadBytes
179 << " bytes");
180
181 // Schedule the requested RC index
182 uint32_t bytes = DoSchedulingForRcIndex(packets, payloadBytes, *it);
183
184 // If the UT was scheduled update the payload counters
185 if (bytes > 0)
186 {
188 }
189 }
190
191 if (payloadBytes == 0)
192 {
193 break;
194 }
195 }
196 }
197}
198
199uint32_t
200SatUtScheduler::DoSchedulingForRcIndex(std::vector<Ptr<Packet>>& packets,
201 uint32_t& payloadBytes,
202 uint8_t rcIndex)
203{
204 NS_LOG_FUNCTION(this << payloadBytes << (uint32_t)rcIndex);
205
206 uint32_t schedBytes(0);
207 uint32_t bytesLeft(0);
208 uint32_t nextMinTxO(0);
209
210 // User data packets are encapsulated within Frame PDU
211 if (rcIndex != SatEnums::CONTROL_FID)
212 {
213 payloadBytes -= m_framePduHeaderSizeInBytes;
214 }
215
216 while (payloadBytes > 0)
217 {
218 Ptr<Packet> p = m_txOpportunityCallback(payloadBytes,
219 m_nodeInfo->GetMacAddress(),
220 rcIndex,
221 bytesLeft,
222 nextMinTxO);
223 if (p)
224 {
225 NS_LOG_INFO("Created a packet from RC: " << (uint32_t)(rcIndex)
226 << " size: " << p->GetSize());
227
228 packets.push_back(p);
229
230 NS_ASSERT(payloadBytes >= p->GetSize());
231
232 schedBytes += p->GetSize();
233 payloadBytes -= p->GetSize();
234 }
235 // LLC returned NULL packet
236 else
237 {
238 break;
239 }
240 }
241
242 // If no packets were scheduled, return the frame PDU
243 // header size
244 if (schedBytes == 0 && rcIndex != SatEnums::CONTROL_FID)
245 {
246 payloadBytes += m_framePduHeaderSizeInBytes;
247 }
248
249 return schedBytes;
250}
251
252void
253SatUtScheduler::SetNodeInfo(Ptr<SatNodeInfo> nodeInfo)
254{
255 NS_LOG_FUNCTION(this);
256
257 m_nodeInfo = nodeInfo;
258}
259
260std::vector<uint8_t>
262{
263 NS_LOG_FUNCTION(this);
264
266
267 return m_rcIndices;
268}
269
270} // namespace ns3
SatTimeSlotType_t
Types for time slot.
@ SLOT_TYPE_TRC
Control or traffic slot.
The SatUtScheduler is responsible of getting a packet of proper size from higher protocol layer.
SatUtScheduler()
Default constructor.
static TypeId GetTypeId(void)
Derived from Object.
virtual void DoDispose(void)
Dispose of SatUtScheduler.
void SetSchedContextCallback(SatUtScheduler::SchedContextCallback cb)
Method to set Tx opportunity callback.
bool m_prioritizeControl
Strictly prioritize the control message scheduling regardless of the time slot information given from...
SatCompliancePolicy_t
Enum describing the wanted scheduler policy.
uint32_t DoSchedulingForRcIndex(std::vector< Ptr< Packet > > &packets, uint32_t &payloadBytes, uint8_t rcIndex)
Do scheduling for a given RC index.
std::vector< uint8_t > m_rcIndices
Available RC indices for scheduling.
SatUtScheduler::TxOpportunityCallback m_txOpportunityCallback
Callback to notify the txOpportunity to upper layer Returns a packet Attributes: payload in bytes.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
Ptr< SatLowerLayerServiceConf > m_llsConf
The configured lower layer service configuration for this UT MAC.
virtual ~SatUtScheduler()
Destructor.
Callback< void, std::vector< Ptr< SatSchedulingObject > > & > SchedContextCallback
Callback to get scheduling contexts from upper layer.
SatUtScheduler::SchedContextCallback m_schedContextCallback
The scheduling context getter callback.
std::vector< uint8_t > GetPrioritizedRcIndexOrder()
Get a prioritized order of the available RC indices for LOOSE policy UT scheduling.
void DoScheduling(std::vector< Ptr< Packet > > &packets, uint32_t payloadBytes, SatTimeSlotConf::SatTimeSlotType_t type, uint8_t rcIndex, SatCompliancePolicy_t policy)
UT scheduling is responsible of selecting with which RC index to use when requesting packets from hig...
void SetTxOpportunityCallback(SatUtScheduler::TxOpportunityCallback cb)
Method to set Tx opportunity callback.
ByteCounterContainer_t m_utScheduledByteCounters
Byte counters for RC indices.
virtual void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info.
Callback< Ptr< Packet >, uint32_t, Mac48Address, uint8_t, uint32_t &, uint32_t & > TxOpportunityCallback
Callback to notify upper layer about Tx opportunity.
Ptr< SatNodeInfo > m_nodeInfo
Node information.
uint32_t m_framePduHeaderSizeInBytes
Frame PDU header size.
Sort metric which sorts a vector available RC indices based on "unallocated load".
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.