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