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 
21 #include "satellite-ut-scheduler.h"
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 
34 NS_LOG_COMPONENT_DEFINE("SatUtScheduler");
35 
36 namespace ns3
37 {
38 
39 NS_OBJECT_ENSURE_REGISTERED(SatUtScheduler);
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::SatUtScheduler")
46  .SetParent<Object>()
47  .AddConstructor<SatUtScheduler>()
48  .AddAttribute("StrictPriorityForControl",
49  "Utilize strict priority for control packets",
50  BooleanValue(true),
51  MakeBooleanAccessor(&SatUtScheduler::m_prioritizeControl),
52  MakeBooleanChecker())
53  .AddAttribute("FramePduHeaderSize",
54  "Frame PDU header size in bytes",
55  UintegerValue(1),
56  MakeUintegerAccessor(&SatUtScheduler::m_framePduHeaderSizeInBytes),
57  MakeUintegerChecker<uint32_t>());
58  return tid;
59 }
60 
61 TypeId
63 {
64  NS_LOG_FUNCTION(this);
65 
66  return GetTypeId();
67 }
68 
70  : m_schedContextCallback(),
71  m_txOpportunityCallback(),
72  m_llsConf(),
73  m_prioritizeControl(true),
74  m_framePduHeaderSizeInBytes(1),
75  m_nodeInfo()
76 {
77 }
78 
79 SatUtScheduler::SatUtScheduler(Ptr<SatLowerLayerServiceConf> lls)
80  : m_schedContextCallback(),
81  m_txOpportunityCallback(),
82  m_llsConf(lls),
83  m_prioritizeControl(true),
84  m_framePduHeaderSizeInBytes(1),
85  m_nodeInfo()
86 {
87  NS_LOG_FUNCTION(this);
88 
89  ObjectBase::ConstructSelf(AttributeConstructionList());
90 
91  m_utScheduledByteCounters = std::vector<uint32_t>(m_llsConf->GetDaServiceCount(), 0);
92 
93  for (uint32_t i = 0; i < SatEnums::NUM_FIDS; ++i)
94  {
95  m_rcIndices.push_back(i);
96  }
97 }
98 
100 {
101  NS_LOG_FUNCTION(this);
102 }
103 
104 void
106 {
107  NS_LOG_FUNCTION(this);
108 
109  m_schedContextCallback.Nullify();
110  m_txOpportunityCallback.Nullify();
111  m_llsConf = NULL;
112  m_nodeInfo = NULL;
113 
114  Object::DoDispose();
115 }
116 
117 void
119 {
120  NS_LOG_FUNCTION(this << &cb);
122 }
123 
124 void
126 {
127  NS_LOG_FUNCTION(this << &cb);
128 
130 }
131 
132 void
133 SatUtScheduler::DoScheduling(std::vector<Ptr<Packet>>& packets,
134  uint32_t payloadBytes,
136  uint8_t rcIndex,
137  SatCompliancePolicy_t policy)
138 {
139  NS_LOG_FUNCTION(this << payloadBytes << (uint32_t)rcIndex << policy);
140 
141  NS_LOG_INFO("UT scheduling RC: " << (uint32_t)(rcIndex) << " with " << payloadBytes
142  << " bytes");
143 
144  if (type == SatTimeSlotConf::SLOT_TYPE_C && rcIndex != SatEnums::CONTROL_FID)
145  {
146  NS_FATAL_ERROR("Conflict in time slot data between RC index and slot type!");
147  }
148 
149  // Schedule
150  // - 1. control
151  // - 2. rc index
153  {
154  DoSchedulingForRcIndex(packets, payloadBytes, SatEnums::CONTROL_FID);
155 
156  if (payloadBytes > 0)
157  {
158  DoSchedulingForRcIndex(packets, payloadBytes, rcIndex);
159  }
160  }
161  // Schedule only the requested RC index
162  else
163  {
164  DoSchedulingForRcIndex(packets, payloadBytes, rcIndex);
165  }
166 
167  // If we still have bytes left and the
168  // scheduling policy is loose
169  if (payloadBytes > 0 && policy == LOOSE && type == SatTimeSlotConf::SLOT_TYPE_TRC)
170  {
171  std::vector<uint8_t> rcIndices = GetPrioritizedRcIndexOrder();
172 
173  for (std::vector<uint8_t>::const_iterator it = rcIndices.begin(); it != rcIndices.end();
174  ++it)
175  {
176  // No use asking the given RC index again
177  if (*it != rcIndex)
178  {
179  NS_LOG_INFO("UT scheduling RC: " << (uint32_t)(rcIndex) << " with " << payloadBytes
180  << " bytes");
181 
182  // Schedule the requested RC index
183  uint32_t bytes = DoSchedulingForRcIndex(packets, payloadBytes, *it);
184 
185  // If the UT was scheduled update the payload counters
186  if (bytes > 0)
187  {
188  m_utScheduledByteCounters.at(*it) = m_utScheduledByteCounters.at(*it) + bytes;
189  }
190  }
191 
192  if (payloadBytes == 0)
193  {
194  break;
195  }
196  }
197  }
198 }
199 
200 uint32_t
201 SatUtScheduler::DoSchedulingForRcIndex(std::vector<Ptr<Packet>>& packets,
202  uint32_t& payloadBytes,
203  uint8_t rcIndex)
204 {
205  NS_LOG_FUNCTION(this << payloadBytes << (uint32_t)rcIndex);
206 
207  uint32_t schedBytes(0);
208  uint32_t bytesLeft(0);
209  uint32_t nextMinTxO(0);
210 
211  // User data packets are encapsulated within Frame PDU
212  if (rcIndex != SatEnums::CONTROL_FID)
213  {
214  payloadBytes -= m_framePduHeaderSizeInBytes;
215  }
216 
217  while (payloadBytes > 0)
218  {
219  Ptr<Packet> p = m_txOpportunityCallback(payloadBytes,
220  m_nodeInfo->GetMacAddress(),
221  rcIndex,
222  bytesLeft,
223  nextMinTxO);
224  if (p)
225  {
226  NS_LOG_INFO("Created a packet from RC: " << (uint32_t)(rcIndex)
227  << " size: " << p->GetSize());
228 
229  packets.push_back(p);
230 
231  NS_ASSERT(payloadBytes >= p->GetSize());
232 
233  schedBytes += p->GetSize();
234  payloadBytes -= p->GetSize();
235  }
236  // LLC returned NULL packet
237  else
238  {
239  break;
240  }
241  }
242 
243  // If no packets were scheduled, return the frame PDU
244  // header size
245  if (schedBytes == 0 && rcIndex != SatEnums::CONTROL_FID)
246  {
247  payloadBytes += m_framePduHeaderSizeInBytes;
248  }
249 
250  return schedBytes;
251 }
252 
253 void
254 SatUtScheduler::SetNodeInfo(Ptr<SatNodeInfo> nodeInfo)
255 {
256  NS_LOG_FUNCTION(this);
257 
258  m_nodeInfo = nodeInfo;
259 }
260 
261 std::vector<uint8_t>
263 {
264  NS_LOG_FUNCTION(this);
265 
267 
268  return m_rcIndices;
269 }
270 
271 } // namespace ns3
SatTimeSlotType_t
Types for time slot.
@ SLOT_TYPE_TRC
Control or traffic slot.
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.
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.
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.
virtual TypeId GetInstanceTypeId(void) const
Derived from Object.
std::vector< uint8_t > GetPrioritizedRcIndexOrder()
Get a prioritized order of the available RC indices for LOOSE policy UT scheduling.
void SetTxOpportunityCallback(SatUtScheduler::TxOpportunityCallback cb)
Method to set Tx opportunity callback.
uint32_t DoSchedulingForRcIndex(std::vector< Ptr< Packet >> &packets, uint32_t &payloadBytes, uint8_t rcIndex)
Do scheduling for a given RC index.
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.
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...
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.