A Discrete-Event Network Simulator
API
bs-scheduler-simple.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008 INRIA
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: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  */
20 
21 #include "bs-scheduler-simple.h"
22 #include "ns3/simulator.h"
23 #include "bs-net-device.h"
24 #include "ns3/packet-burst.h"
25 #include "cid.h"
26 #include "wimax-mac-header.h"
27 #include "ss-record.h"
28 #include "wimax-mac-queue.h"
29 #include "ns3/log.h"
30 #include "burst-profile-manager.h"
31 #include "wimax-connection.h"
32 #include "connection-manager.h"
33 #include "ss-manager.h"
34 #include "service-flow.h"
35 #include "service-flow-record.h"
36 #include "service-flow-manager.h"
37 
38 namespace ns3 {
39 
40 NS_LOG_COMPONENT_DEFINE ("BSSchedulerSimple");
41 
42 NS_OBJECT_ENSURE_REGISTERED (BSSchedulerSimple);
43 
45 {
46  static TypeId tid = TypeId ("ns3::BSSchedulerSimple")
48  .SetGroupName("Wimax")
49  .AddConstructor<BSSchedulerSimple> ()
50  ;
51  return tid;
52 }
53 
55  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
56 {
57  SetBs (0);
58 }
59 
61  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
62 {
63  // m_downlinkBursts is filled by AddDownlinkBurst and emptied by
64  // wimax-bs-net-device::sendBurst and wimax-ss-net-device::sendBurst
65  SetBs (bs);
66 }
67 
69 {
70  std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > *downlinkBursts = m_downlinkBursts;
71  std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > pair;
72  while (downlinkBursts->size ())
73  {
74  pair = downlinkBursts->front ();
75  pair.second = 0;
76  delete pair.first;
77  }
78  SetBs (0);
79  delete m_downlinkBursts;
80  m_downlinkBursts = 0;
81 }
82 
83 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
85 {
86  return m_downlinkBursts;
87 }
88 
90  uint8_t diuc,
91  WimaxPhy::ModulationType modulationType,
92  Ptr<PacketBurst> burst)
93 {
94  OfdmDlMapIe *dlMapIe = new OfdmDlMapIe ();
95  dlMapIe->SetCid (connection->GetCid ());
96  dlMapIe->SetDiuc (diuc);
97 
98  NS_LOG_INFO ("BS scheduler, burst size: " << burst->GetSize () << " bytes" << ", pkts: " << burst->GetNPackets ()
99  << ", connection: " << connection->GetTypeStr () << ", CID: " << connection->GetCid ());
100  if (connection->GetType () == Cid::TRANSPORT)
101  {
102  NS_LOG_INFO (", SFID: " << connection->GetServiceFlow ()->GetSfid () << ", service: "
103  << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
104  }
105  NS_LOG_INFO (", modulation: " << modulationType << ", DIUC: " << (uint32_t) diuc);
106 
107  m_downlinkBursts->push_back (std::make_pair (dlMapIe, burst));
108 }
109 
111 {
112  Ptr<WimaxConnection> connection;
115  uint32_t nrSymbolsRequired = 0;
116  GenericMacHeader hdr;
117  Ptr<Packet> packet;
118  Ptr<PacketBurst> burst;
120  uint32_t availableSymbols = GetBs ()->GetNrDlSymbols ();
121 
122  while (SelectConnection (connection))
123  {
124  if (connection != GetBs ()->GetInitialRangingConnection () && connection != GetBs ()->GetBroadcastConnection ())
125  {
126  /* determines modulation/DIUC only once per burst as it is always same for a particular CID */
127  if (connection->GetType () == Cid::MULTICAST)
128  {
129  modulationType = connection->GetServiceFlow ()->GetModulation ();
130  }
131  else
132  {
133  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
134  }
135  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
137  }
138  else if (connection == GetBs ()->GetInitialRangingConnection () || connection
139  == GetBs ()->GetBroadcastConnection ())
140  {
141 
142  modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
144  }
145 
146  if (connection->GetType () == Cid::TRANSPORT || connection->GetType () == Cid::MULTICAST)
147  {
148  schedulingType = (ServiceFlow::SchedulingType) connection->GetSchedulingType ();
149  }
150 
151  if (schedulingType == ServiceFlow::SF_TYPE_UGS)
152  {
153  nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
154  if (nrSymbolsRequired < availableSymbols)
155  {
156  burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
157  }
158  else
159  {
160  burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, availableSymbols);
161  }
162  if (burst->GetNPackets () != 0)
163  {
164  uint32_t BurstSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (burst->GetSize (), modulationType);
165  AddDownlinkBurst (connection, diuc, modulationType, burst);
166 
167  if (availableSymbols <= BurstSizeSymbols)
168  {
169  availableSymbols -= BurstSizeSymbols;
170  break;
171  }
172  }
173  }
174  else
175  {
176  burst = Create<PacketBurst> ();
177  while (connection->HasPackets () == true)
178  {
179  uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
180  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize, modulationType);
181  if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
182  availableSymbols,
183  modulationType))
184  {
185  uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
186  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
187  availableSymbols = 0;
188  }
189  else if (availableSymbols >= nrSymbolsRequired)
190  {
191  packet = connection->Dequeue ();
192  availableSymbols -= nrSymbolsRequired;
193  }
194  else
195  {
196  break;
197  }
198  burst->AddPacket (packet);
199  }
200  AddDownlinkBurst (connection, diuc, modulationType, burst);
201  }
202  if (availableSymbols == 0)
203  {
204  break;
205  }
206  }
207 
208 
209  if (m_downlinkBursts->size ())
210  {
211  NS_LOG_DEBUG ("BS scheduler, number of bursts: " << m_downlinkBursts->size () << ", symbols left: "
212  << availableSymbols << std::endl << "BS scheduler, queues:" << " IR "
213  << GetBs ()->GetInitialRangingConnection ()->GetQueue ()->GetSize () << " broadcast "
214  << GetBs ()->GetBroadcastConnection ()->GetQueue ()->GetSize () << " basic "
215  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::BASIC, ServiceFlow::SF_TYPE_NONE) << " primary "
216  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::PRIMARY, ServiceFlow::SF_TYPE_NONE) << " transport "
217  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::TRANSPORT, ServiceFlow::SF_TYPE_ALL));
218  }
219 }
220 
222 {
223  connection = 0;
224  Time currentTime = Simulator::Now ();
225  std::vector<Ptr<WimaxConnection> >::const_iterator iter1;
226  std::vector<ServiceFlow*>::iterator iter2;
227  ServiceFlowRecord *serviceFlowRecord;
228  NS_LOG_INFO ("BS Scheduler: Selecting connection...");
229  if (GetBs ()->GetBroadcastConnection ()->HasPackets ())
230  {
231  NS_LOG_INFO ("Return GetBroadcastConnection");
232  connection = GetBs ()->GetBroadcastConnection ();
233  return true;
234  }
235  else if (GetBs ()->GetInitialRangingConnection ()->HasPackets ())
236  {
237  NS_LOG_INFO ("Return GetInitialRangingConnection");
238  connection = GetBs ()->GetInitialRangingConnection ();
239  return true;
240  }
241  else
242  {
243  std::vector<Ptr<WimaxConnection> > connections;
244  std::vector<ServiceFlow*> serviceFlows;
245 
246  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::BASIC);
247  for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
248  {
249  if ((*iter1)->HasPackets ())
250  {
251  NS_LOG_INFO ("Return Basic");
252  connection = *iter1;
253  return true;
254  }
255  }
256 
257  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::PRIMARY);
258  for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
259  {
260  if ((*iter1)->HasPackets ())
261  {
262  NS_LOG_INFO ("Return Primary");
263  connection = *iter1;
264  return true;
265  }
266  }
267 
268  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
269  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
270  {
271  serviceFlowRecord = (*iter2)->GetRecord ();
272  NS_LOG_INFO ("processing UGS: HAS PACKET=" << (*iter2)->HasPackets () << "max Latency = "
273  << MilliSeconds ((*iter2)->GetMaximumLatency ()) << "Delay = " << ((currentTime
274  - serviceFlowRecord->GetDlTimeStamp ()) + GetBs ()->GetPhy ()->GetFrameDuration ()));
275  // if latency would exceed in case grant is allocated in next frame then allocate in current frame
276  if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
277  + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
278  {
279  serviceFlowRecord->SetDlTimeStamp (currentTime);
280  connection = (*iter2)->GetConnection ();
281  NS_LOG_INFO ("Return UGS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
282  return true;
283  }
284  }
285 
286  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
287  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
288  {
289  serviceFlowRecord = (*iter2)->GetRecord ();
290  // if latency would exceed in case poll is allocated in next frame then allocate in current frame
291  if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
292  + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
293  {
294  serviceFlowRecord->SetDlTimeStamp (currentTime);
295  connection = (*iter2)->GetConnection ();
296  NS_LOG_INFO ("Return RTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
297  return true;
298  }
299  }
300 
301  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
302  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
303  {
304  //unused: serviceFlowRecord = (*iter2)->GetRecord ();
305  if ((*iter2)->HasPackets ())
306  {
307  NS_LOG_INFO ("Return NRTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
308  connection = (*iter2)->GetConnection ();
309  return true;
310  }
311  }
312 
313  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
314  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
315  {
316  //unused: serviceFlowRecord = (*iter2)->GetRecord ();
317  if ((*iter2)->HasPackets ())
318  {
319  NS_LOG_INFO ("Return BE SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
320  connection = (*iter2)->GetConnection ();
321  return true;
322  }
323  }
324  }
325  NS_LOG_INFO ("NO connection is selected!");
326  return false;
327 }
328 
330  WimaxPhy::ModulationType modulationType,
331  uint32_t availableSymbols)
332 {
333  Time timeStamp;
334  GenericMacHeader hdr;
335  Ptr<Packet> packet;
336  Ptr<PacketBurst> burst = Create<PacketBurst> ();
337  uint32_t nrSymbolsRequired = 0;
338 
339  // serviceFlow->CleanUpQueue ();
340  Ptr<WimaxConnection> connection = serviceFlow->GetConnection ();
341  while (serviceFlow->HasPackets ())
342  {
343  uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
344  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
345  if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
346  availableSymbols,
347  modulationType))
348  {
349  uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
350  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
351  availableSymbols = 0;
352  }
353  else
354  {
355  packet = connection->Dequeue ();
356  availableSymbols -= nrSymbolsRequired;
357  }
358  burst->AddPacket (packet);
359  if (availableSymbols <= 0)
360  {
361  break;
362  }
363  }
364  return burst;
365 }
366 
367 }
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * GetDownlinkBursts(void) const
This function returns all the downlink bursts scheduled for the next downlink sub-frame.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
this class implements a structure to manage some parameters and statistics related to a service flow ...
Ptr< PacketBurst > CreateUgsBurst(ServiceFlow *serviceFlow, WimaxPhy::ModulationType modulationType, uint32_t availableSymbols)
Creates a downlink UGS burst.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
bool SelectConnection(Ptr< WimaxConnection > &connection)
Selects a connection from the list of connections having packets to be sent .
STL namespace.
bool CheckForFragmentation(Ptr< WimaxConnection > connection, int availableSymbols, WimaxPhy::ModulationType modulationType)
Check if the packet fragmentation is possible for transport connection.
Definition: bs-scheduler.cc:95
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:58
Ptr< WimaxConnection > GetConnection(void) const
Can return a null connection is this service flow has not been associated yet to a connection...
void SetDiuc(uint8_t diuc)
Set DIUC field.
void Schedule(void)
the scheduling function for the downlink subframe.
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
down link bursts
#define list
Every class exported by the ns3 library is enclosed in the ns3 namespace.
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
virtual Ptr< BaseStationNetDevice > GetBs(void)
Get the base station.
Definition: bs-scheduler.cc:89
void AddDownlinkBurst(Ptr< const WimaxConnection > connection, uint8_t diuc, WimaxPhy::ModulationType modulationType, Ptr< PacketBurst > burst)
This function adds a downlink burst to the list of downlink bursts scheduled for the next downlink su...
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Set the base station.
Definition: bs-scheduler.cc:84
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:49
void SetDlTimeStamp(Time dlTimeStamp)
Set the DlTimeStamp.
this class implement a burst as a list of packets
Definition: packet-burst.h:35
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Time GetDlTimeStamp(void) const
bool HasPackets(void) const
Check if packets are present.
void SetCid(Cid cid)
Set CID function.
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
This class implements the OFDM DL-MAP information element as described by "IEEE Standard for Local an...