A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bs-scheduler-rtps.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008 INRIA
4  * 2009 TELEMATICS LAB, Politecnico di Bari
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Giuseppe Piro <g.piro@poliba.it>
20  */
21 
22 #include "bs-scheduler-rtps.h"
23 #include "ns3/simulator.h"
24 #include "bs-net-device.h"
25 #include "ns3/packet-burst.h"
26 #include "cid.h"
27 #include "wimax-mac-header.h"
28 #include "ss-record.h"
29 #include "wimax-mac-queue.h"
30 #include "ns3/log.h"
31 #include "burst-profile-manager.h"
32 #include "wimax-connection.h"
33 #include "connection-manager.h"
34 #include "ss-manager.h"
35 #include "service-flow.h"
36 #include "service-flow-record.h"
37 #include "service-flow-manager.h"
38 #include "wimax-mac-queue.h"
39 
40 NS_LOG_COMPONENT_DEFINE ("BSSchedulerRtps");
41 
42 namespace ns3 {
43 
44 NS_OBJECT_ENSURE_REGISTERED (BSSchedulerRtps);
45 
46 TypeId
47 BSSchedulerRtps::GetTypeId (void)
48 {
49  static TypeId tid = TypeId ("ns3::BSSchedulerRtps").SetParent<Object> ().AddConstructor<BSSchedulerRtps> ();
50  return tid;
51 }
52 
53 BSSchedulerRtps::BSSchedulerRtps ()
54  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
55 {
56  SetBs (0);
57 }
58 
59 BSSchedulerRtps::BSSchedulerRtps (Ptr<BaseStationNetDevice> bs)
60  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
61 {
62  // m_downlinkBursts is filled by AddDownlinkBurst and emptied by
63  // wimax-bs-net-device::sendBurst and wimax-ss-net-device::sendBurst
64  SetBs (bs);
65 }
66 
67 BSSchedulerRtps::~BSSchedulerRtps (void)
68 {
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 
79  SetBs (0);
80  delete m_downlinkBursts;
81  m_downlinkBursts = 0;
82 }
83 
84 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
85 BSSchedulerRtps::GetDownlinkBursts (void) const
86 {
87  return m_downlinkBursts;
88 }
89 
90 void
91 BSSchedulerRtps::AddDownlinkBurst (Ptr<const WimaxConnection> connection,
92  uint8_t diuc,
93  WimaxPhy::ModulationType modulationType,
94  Ptr<PacketBurst> burst)
95 {
96  OfdmDlMapIe *dlMapIe = new OfdmDlMapIe ();
97  dlMapIe->SetCid (connection->GetCid ());
98  dlMapIe->SetDiuc (diuc);
99 
100  NS_LOG_INFO ("BS scheduler, burst size: " << burst->GetSize () << " bytes" << ", pkts: " << burst->GetNPackets ()
101  << ", connection: " << connection->GetTypeStr () << ", CID: "
102  << connection->GetCid ());
103  if (connection->GetType () == Cid::TRANSPORT)
104  {
105  NS_LOG_INFO (", SFID: " << connection->GetServiceFlow ()->GetSfid () << ", service: "
106  << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
107  }
108  NS_LOG_INFO (", modulation: " << modulationType << ", DIUC: " << (uint32_t) diuc);
109 
110  m_downlinkBursts->push_back (std::make_pair (dlMapIe, burst));
111 }
112 
127 void
129 {
130 
131  uint32_t availableSymbols = GetBs ()->GetNrDlSymbols ();
132 
133  BSSchedulerBroadcastConnection (availableSymbols);
134 
135  BSSchedulerInitialRangingConnection (availableSymbols);
136 
137  BSSchedulerBasicConnection (availableSymbols);
138 
139  BSSchedulerPrimaryConnection (availableSymbols);
140 
141  BSSchedulerUGSConnection (availableSymbols);
142 
143  BSSchedulerRTPSConnection (availableSymbols);
144 
145  BSSchedulerNRTPSConnection (availableSymbols);
146 
147  BSSchedulerBEConnection (availableSymbols);
148 
149  if (m_downlinkBursts->size ())
150  {
151  NS_LOG_DEBUG ("BS scheduler, number of bursts: " << m_downlinkBursts->size () << ", symbols left: "
152  << availableSymbols << std::endl << "BS scheduler, queues:" << " IR "
153  << GetBs ()->GetInitialRangingConnection ()->GetQueue ()->GetSize ()
154  << " broadcast "
155  << GetBs ()->GetBroadcastConnection ()->GetQueue ()->GetSize ()
156  << " basic "
157  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::BASIC, ServiceFlow::SF_TYPE_NONE)
158  << " primary "
159  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::PRIMARY, ServiceFlow::SF_TYPE_NONE)
160  << " transport "
161  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::TRANSPORT, ServiceFlow::SF_TYPE_ALL));
162  }
163 }
164 
165 
166 Ptr<PacketBurst> BSSchedulerRtps::CreateUgsBurst (ServiceFlow *serviceFlow,
167  WimaxPhy::ModulationType modulationType,
168  uint32_t availableSymbols)
169 {
170  Time timeStamp;
171  GenericMacHeader hdr;
172  Ptr<Packet> packet;
173  Ptr<PacketBurst> burst = Create<PacketBurst> ();
174  uint32_t nrSymbolsRequired = 0;
175 
176  // serviceFlow->CleanUpQueue ();
177  Ptr<WimaxConnection> connection = serviceFlow->GetConnection ();
178  while (serviceFlow->HasPackets ())
179  {
180  uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
181  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
182  if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
183  availableSymbols,
184  modulationType))
185  {
186  uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
187  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
188  availableSymbols = 0;
189  }
190  else
191  {
192  packet = connection->Dequeue ();
193  availableSymbols -= nrSymbolsRequired;
194  }
195  burst->AddPacket (packet);
196  if (availableSymbols <= 0)
197  {
198  break;
199  }
200  }
201  return burst;
202 }
203 
204 
205 bool
206 BSSchedulerRtps::SelectConnection (Ptr<WimaxConnection> &connection)
207 {
208  return false;
209 }
210 
211 void
212 BSSchedulerRtps::BSSchedulerBroadcastConnection (uint32_t &availableSymbols)
213 {
214  Ptr<WimaxConnection> connection;
215  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
216  uint8_t diuc = OfdmDlBurstProfile::DIUC_BURST_PROFILE_1;
217  uint32_t nrSymbolsRequired = 0;
218  GenericMacHeader hdr;
219  Ptr<Packet> packet;
220  Ptr<PacketBurst> burst = Create<PacketBurst> ();
221 
222  while (GetBs ()->GetBroadcastConnection ()->HasPackets () && availableSymbols > 0)
223  {
224  connection = GetBs ()->GetBroadcastConnection ();
225 
226  packet = connection->GetQueue ()->Peek (hdr);
227  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
228 
229  if (availableSymbols < nrSymbolsRequired
230  && !CheckForFragmentation (connection, availableSymbols, modulationType))
231  {
232  break;
233  }
234  else if (availableSymbols < nrSymbolsRequired
235  && CheckForFragmentation (connection, availableSymbols, modulationType))
236  {
237  uint32_t availableByte = GetBs ()->GetPhy ()->
238  GetNrBytes (availableSymbols, modulationType);
239  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC,
240  availableByte);
241  }
242  else
243  {
244  packet = connection->Dequeue ();
245  }
246 
247  NS_ASSERT_MSG (hdr.GetCid ().GetIdentifier () == connection->GetCid (),
248  "Base station: Error while scheduling broadcast connection: header CID != connection CID");
249  burst->AddPacket (packet);
250  availableSymbols -= nrSymbolsRequired;
251  }
252  if (burst->GetNPackets () != 0)
253  {
254  AddDownlinkBurst (connection, diuc, modulationType, burst);
255  }
256 }
257 
258 void
259 BSSchedulerRtps::BSSchedulerInitialRangingConnection (uint32_t &availableSymbols)
260 {
261  Ptr<WimaxConnection> connection;
262  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
263  uint8_t diuc = OfdmDlBurstProfile::DIUC_BURST_PROFILE_1;
264  uint32_t nrSymbolsRequired = 0;
265  GenericMacHeader hdr;
266  Ptr<Packet> packet;
267  Ptr<PacketBurst> burst = Create<PacketBurst> ();
268 
269  while (GetBs ()->GetInitialRangingConnection ()->HasPackets () && availableSymbols > 0)
270  {
271  connection = GetBs ()->GetInitialRangingConnection ();
272 
273  packet = connection->GetQueue ()->Peek (hdr);
274  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
275 
276  // PIRO: check for fragmentation
277  if (availableSymbols < nrSymbolsRequired
278  && !CheckForFragmentation (connection, availableSymbols, modulationType))
279  {
280  break;
281  }
282  else if (availableSymbols < nrSymbolsRequired
283  && CheckForFragmentation (connection, availableSymbols, modulationType))
284  {
285  uint32_t availableByte = GetBs ()->GetPhy ()->
286  GetNrBytes (availableSymbols, modulationType);
287  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC,
288  availableByte);
289  }
290  else
291  {
292  packet = connection->Dequeue ();
293  }
294 
295  NS_ASSERT_MSG (hdr.GetCid () == connection->GetCid (),
296  "Base station: Error while scheduling initial ranging connection: header CID != connection CID");
297  burst->AddPacket (packet);
298  availableSymbols -= nrSymbolsRequired;
299  }
300  if (burst->GetNPackets ())
301  {
302  AddDownlinkBurst (connection, diuc, modulationType, burst);
303  }
304 }
305 
306 void
307 BSSchedulerRtps::BSSchedulerBasicConnection (uint32_t &availableSymbols)
308 {
309  Ptr<WimaxConnection> connection;
310  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
311  uint8_t diuc = OfdmDlBurstProfile::DIUC_BURST_PROFILE_1;
312  uint32_t nrSymbolsRequired = 0;
313  GenericMacHeader hdr;
314  Ptr<Packet> packet;
315  Ptr<PacketBurst> burst = Create<PacketBurst> ();
316 
317  std::vector<Ptr<WimaxConnection> >::const_iterator iter;
318  std::vector<Ptr<WimaxConnection> > connections;
319 
320  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::BASIC);
321  for (iter = connections.begin (); iter != connections.end (); ++iter)
322  {
323  while ((*iter)->HasPackets () && availableSymbols > 0)
324  {
325  connection = *iter;
326 
327  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
328  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
329  WimaxNetDevice::DIRECTION_DOWNLINK);
330 
331  packet = connection->GetQueue ()->Peek (hdr);
332  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
333 
334  // PIRO: check for fragmentation
335  if (availableSymbols < nrSymbolsRequired
336  && !CheckForFragmentation (connection, availableSymbols, modulationType))
337  {
338  break;
339  }
340  else if (availableSymbols < nrSymbolsRequired
341  && CheckForFragmentation (connection, availableSymbols, modulationType))
342  {
343  uint32_t availableByte = GetBs ()->GetPhy ()->
344  GetNrBytes (availableSymbols, modulationType);
345  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
346  }
347  else
348  {
349  packet = connection->Dequeue ();
350  }
351 
352  NS_ASSERT_MSG (hdr.GetCid () == connection->GetCid (),
353  "Base station: Error while scheduling basic connection: header CID != connection CID");
354  burst->AddPacket (packet);
355  availableSymbols -= nrSymbolsRequired;
356  }
357  if (burst->GetNPackets () != 0)
358  {
359  AddDownlinkBurst (connection, diuc, modulationType, burst);
360  burst = Create<PacketBurst> ();
361  }
362  }
363 }
364 
365 void
366 BSSchedulerRtps::BSSchedulerPrimaryConnection (uint32_t &availableSymbols)
367 {
368  Ptr<WimaxConnection> connection;
369  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
370  uint8_t diuc = 0;
371  uint32_t nrSymbolsRequired = 0;
372  GenericMacHeader hdr;
373  Ptr<Packet> packet;
374  Ptr<PacketBurst> burst = Create<PacketBurst> ();
375 
376  std::vector<Ptr<WimaxConnection> >::const_iterator iter;
377  std::vector<Ptr<WimaxConnection> > connections;
378 
379  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::PRIMARY);
380  for (iter = connections.begin (); iter != connections.end (); ++iter)
381  {
382  while ((*iter)->HasPackets () && availableSymbols > 0)
383  {
384  connection = *iter;
385 
386  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
387  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
388  WimaxNetDevice::DIRECTION_DOWNLINK);
389 
390  packet = connection->GetQueue ()->Peek (hdr);
391  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
392 
393  // PIRO: check for fragmentation
394  if (availableSymbols < nrSymbolsRequired
395  && !CheckForFragmentation (connection, availableSymbols, modulationType))
396  {
397  break;
398  }
399  else if (availableSymbols < nrSymbolsRequired
400  && CheckForFragmentation (connection, availableSymbols, modulationType))
401  {
402  uint32_t availableByte = GetBs ()->GetPhy ()->
403  GetNrBytes (availableSymbols, modulationType);
404  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
405  }
406  else
407  {
408  packet = connection->Dequeue ();
409  }
410 
411  NS_ASSERT_MSG (hdr.GetCid () == connection->GetCid (),
412  "Base station: Error while scheduling primary connection: header CID != connection CID");
413  burst->AddPacket (packet);
414  availableSymbols -= nrSymbolsRequired;
415  }
416  if (burst->GetNPackets () != 0)
417  {
418  AddDownlinkBurst (connection, diuc, modulationType, burst);
419  }
420  }
421 }
422 
423 void
424 BSSchedulerRtps::BSSchedulerUGSConnection (uint32_t &availableSymbols)
425 {
426  Ptr<WimaxConnection> connection;
427  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
428  uint8_t diuc;
429  uint32_t nrSymbolsRequired = 0;
430  GenericMacHeader hdr;
431  Ptr<Packet> packet;
432  Ptr<PacketBurst> burst = Create<PacketBurst> ();
433 
434  Time currentTime = Simulator::Now ();
435 
436  std::vector<ServiceFlow*>::iterator iter;
437  ServiceFlowRecord *serviceFlowRecord;
438  std::vector<ServiceFlow*> serviceFlows;
439 
440  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
441  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
442  {
443  serviceFlowRecord = (*iter)->GetRecord ();
444  // if latency would exceed in case grant is allocated in next frame then allocate in current frame
445  if ((*iter)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
446  + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter)->GetMaximumLatency ()))
447  {
448  connection = (*iter)->GetConnection ();
449  if (connection->GetType () == Cid::MULTICAST)
450  {
451  modulationType = connection->GetServiceFlow ()->GetModulation ();
452  }
453  else
454  {
455  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
456  }
457  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
458  WimaxNetDevice::DIRECTION_DOWNLINK);
459 
460  nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
461 
462  // Packet fragmentation for UGS connections has not been implemented yet!
463  if (availableSymbols > nrSymbolsRequired)
464  {
465  availableSymbols -= nrSymbolsRequired;
466  burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
467  if (burst->GetNPackets () != 0)
468  {
469  AddDownlinkBurst (connection, diuc, modulationType, burst);
470  currentTime = Simulator::Now ();
471  serviceFlowRecord->SetDlTimeStamp (currentTime);
472  burst = Create<PacketBurst> ();
473  }
474  }
475  }
476  }
477 
478 }
479 
480 void
481 BSSchedulerRtps::BSSchedulerRTPSConnection (uint32_t &availableSymbols)
482 {
483 
484  Ptr<WimaxConnection> connection;
485  GenericMacHeader hdr;
486  Ptr<Packet> packet;
487  Ptr<PacketBurst> burst = Create<PacketBurst> ();
488 
489  Time currentTime = Simulator::Now ();
490 
491  std::vector<Ptr<WimaxConnection> >::const_iterator iter;
492  std::vector<Ptr<WimaxConnection> > connections;
493  std::vector<ServiceFlow*>::iterator iter2;
494  ServiceFlowRecord *serviceFlowRecord;
495  std::vector<ServiceFlow*> serviceFlows;
496 
497  uint32_t symbolsRequired[100];
498  WimaxPhy::ModulationType modulationType_[100];
499  uint8_t diuc_[100];
500  Ptr<WimaxConnection> rtPSConnection[100];
501  uint32_t dataToSend;
502  uint32_t totSymbolsRequired = 0;
503  int nbConnection = 0;
504 
505  NS_LOG_INFO ("\tDL Scheduler for rtPS flows \n" << "\t\tavailableSymbols = " << availableSymbols);
506 
507  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
508  nbConnection = 0;
509  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
510  {
511  // DL RTPS Scheduler works for all rtPS connection that have packets to transmitt!!!
512  serviceFlowRecord = (*iter2)->GetRecord ();
513 
514  if ((*iter2)->HasPackets ())
515  {
516  currentTime = Simulator::Now ();
517  serviceFlowRecord->SetDlTimeStamp (currentTime);
518  rtPSConnection[nbConnection] = (*iter2)->GetConnection ();
519  if (rtPSConnection[nbConnection]->GetType () == Cid::MULTICAST)
520  {
521  modulationType_[nbConnection] = rtPSConnection[nbConnection]->GetServiceFlow ()->GetModulation ();
522  }
523  else
524  {
525  modulationType_[nbConnection]
526  = GetBs ()->GetSSManager ()->GetSSRecord (rtPSConnection[nbConnection]->GetCid ())->GetModulationType ();
527  }
528  diuc_[nbConnection]
529  = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType_[nbConnection],
530  WimaxNetDevice::DIRECTION_DOWNLINK);
531 
532  dataToSend = rtPSConnection[nbConnection]->GetQueue ()->GetQueueLengthWithMACOverhead ();
533  NS_LOG_INFO ("\t\tRTPS DL Scheduler for CID = " << rtPSConnection[nbConnection]->GetCid ()
534  << "\n\t\t\t dataToSend = " << dataToSend);
535 
536  symbolsRequired[nbConnection] = GetBs ()->GetPhy ()->GetNrSymbols (dataToSend,
537  modulationType_[nbConnection]);
538 
539  totSymbolsRequired += symbolsRequired[nbConnection];
540  nbConnection++;
541  }
542  }
543 
544  NS_LOG_INFO ("\t\ttotSymbolsRequired = " << totSymbolsRequired);
545 
546  // Channel Saturation
547  while (totSymbolsRequired > availableSymbols)
548  {
549  NS_LOG_INFO ("\tDL Channel Saturation: totSymbolsRequired > availableSymbols_rtPS");
550  double delta = double(availableSymbols) / double(totSymbolsRequired);
551  NS_LOG_INFO ("\t\tdelta = " << delta);
552  totSymbolsRequired = 0;
553  for (int i = 0; i < nbConnection; i++)
554  {
555  NS_LOG_INFO ("\t\tprevious symbolsRequired[" << i << "] = " << symbolsRequired[i]);
556  symbolsRequired[i] = (uint32_t) std::floor (symbolsRequired[i] * delta);
557  totSymbolsRequired += symbolsRequired[i];
558  NS_LOG_INFO ("\t\tnew symbolsRequired[" << i << "] = " << symbolsRequired[i]);
559  }
560  NS_LOG_INFO ("\t\ttotSymbolsRequired = " << totSymbolsRequired);
561  }
562 
563  // Downlink Bandwidth Allocation
564  for (int i = 0; i < nbConnection; i++)
565  {
566 
567  packet = rtPSConnection[i]->GetQueue ()->Peek (hdr);
568  uint32_t symbolsForPacketTransmission = 0;
569  burst = Create<PacketBurst> ();
570  NS_LOG_INFO ("\t\tCID = " << rtPSConnection[i]->GetCid () << " assignedSymbols = " << symbolsRequired[i]);
571 
572  while (symbolsRequired[i] > 0)
573  {
574  symbolsForPacketTransmission = GetBs ()->GetPhy ()
575  ->GetNrSymbols (rtPSConnection[i]->GetQueue ()
576  ->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC),
577  modulationType_[i]);
578 
579  // PIRO: check for fragmentation
580  if (symbolsForPacketTransmission > symbolsRequired[i]
581  && !CheckForFragmentation (rtPSConnection[i],
582  symbolsRequired[i],
583  modulationType_[i]))
584  {
585  break;
586  }
587  else if (symbolsForPacketTransmission > symbolsRequired[i]
588  && CheckForFragmentation (rtPSConnection[i],
589  symbolsRequired[i],
590  modulationType_[i]))
591  {
592  uint32_t availableByte = GetBs ()->GetPhy ()->
593  GetNrBytes (symbolsRequired[i], modulationType_[i]);
594  packet = rtPSConnection[i]->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
595  symbolsRequired[i] = 0;
596  }
597  else
598  {
599  packet = rtPSConnection[i]->Dequeue ();
600  symbolsRequired[i] -= symbolsForPacketTransmission;
601  }
602 
603  NS_ASSERT_MSG (hdr.GetCid () == rtPSConnection[i]->GetCid (),
604  "Base station: Error while scheduling RTPs connection: header CID != connection CID");
605  burst->AddPacket (packet);
606  }
607 
608  if (burst->GetNPackets () != 0)
609  {
610  AddDownlinkBurst (rtPSConnection[i], diuc_[i], modulationType_[i], burst);
611  }
612  }
613 
614  availableSymbols -= totSymbolsRequired;
615 }
616 
617 void
618 BSSchedulerRtps::BSSchedulerNRTPSConnection (uint32_t &availableSymbols)
619 {
620  Ptr<WimaxConnection> connection;
621  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
622  uint8_t diuc = 0;
623  uint32_t nrSymbolsRequired = 0;
624  GenericMacHeader hdr;
625  Ptr<Packet> packet;
626  Ptr<PacketBurst> burst = Create<PacketBurst> ();
627 
628  std::vector<ServiceFlow*>::iterator iter;
629  std::vector<ServiceFlow*> serviceFlows;
630 
631  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
632  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
633  {
634  connection = (*iter)->GetConnection ();
635 
636  while ((*iter)->HasPackets () && availableSymbols > 0)
637  {
638  if (connection->GetType () == Cid::MULTICAST)
639  {
640  modulationType = connection->GetServiceFlow ()->GetModulation ();
641  }
642  else
643  {
644  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
645  }
646 
647  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
648  WimaxNetDevice::DIRECTION_DOWNLINK);
649 
650  packet = connection->GetQueue ()->Peek (hdr);
651  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
652 
653  if (availableSymbols < nrSymbolsRequired)
654  {
655  break;
656  }
657 
658  packet = connection->Dequeue ();
659  NS_ASSERT_MSG (hdr.GetCid () == connection->GetCid (),
660  "Base station: Error while scheduling NRTPs connection: header CID != connection CID");
661  burst->AddPacket (packet);
662  availableSymbols -= nrSymbolsRequired;
663  }
664  if (burst->GetNPackets () != 0)
665  {
666  AddDownlinkBurst (connection, diuc, modulationType, burst);
667  burst = Create<PacketBurst> ();
668  }
669  }
670 }
671 
672 void
673 BSSchedulerRtps::BSSchedulerBEConnection (uint32_t &availableSymbols)
674 {
675  Ptr<WimaxConnection> connection;
676  WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
677  uint8_t diuc = 0;
678  uint32_t nrSymbolsRequired = 0;
679  GenericMacHeader hdr;
680  Ptr<Packet> packet;
681  Ptr<PacketBurst> burst = Create<PacketBurst> ();
682 
683  std::vector<ServiceFlow*>::iterator iter;
684  std::vector<ServiceFlow*> serviceFlows;
685 
686  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
687  for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
688  {
689  connection = (*iter)->GetConnection ();
690 
691  while ((*iter)->HasPackets () && availableSymbols > 0)
692  {
693  if (connection->GetType () == Cid::MULTICAST)
694  {
695  modulationType = connection->GetServiceFlow ()->GetModulation ();
696  }
697  else
698  {
699  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
700  }
701  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
702  WimaxNetDevice::DIRECTION_DOWNLINK);
703 
704  packet = connection->GetQueue ()->Peek (hdr);
705  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (packet->GetSize (), modulationType);
706 
707  if (availableSymbols < nrSymbolsRequired)
708  {
709  break;
710  }
711 
712  packet = connection->Dequeue ();
713  NS_ASSERT_MSG (hdr.GetCid () == connection->GetCid (),
714  "Base station: Error while scheduling BE connection: header CID != connection CID");
715  burst->AddPacket (packet);
716  availableSymbols -= nrSymbolsRequired;
717  }
718  if (burst->GetNPackets () != 0)
719  {
720  AddDownlinkBurst (connection, diuc, modulationType, burst);
721  burst = Create<PacketBurst> ();
722  }
723  }
724 }
725 
726 } // namespace ns3
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
this class implements a structure to manage some parameters and statistics related to a service flow ...
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
uint32_t GetSize(void) const
Definition: packet.h:620
#define NS_LOG_INFO(msg)
Definition: log.h:264
this class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
void BSSchedulerRTPSConnection(uint32_t &availableSymbols)
Downlink Scheduler for rtPS connections.
static Time Now(void)
Definition: simulator.cc:179
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void Schedule(void)
Schedule function.
void SetDlTimeStamp(Time dlTimeStamp)
Set the DlTimeStamp.
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Definition: nstime.h:601