A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("BSSchedulerSimple");
39 
40 namespace ns3 {
41 
42 NS_OBJECT_ENSURE_REGISTERED (BSSchedulerSimple)
43  ;
44 
46 {
47  static TypeId tid = TypeId ("ns3::BSSchedulerSimple").SetParent<Object> ().AddConstructor<BSSchedulerSimple> ();
48  return tid;
49 }
50 
52  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
53 {
54  SetBs (0);
55 }
56 
58  : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
59 {
60  // m_downlinkBursts is filled by AddDownlinkBurst and emptied by
61  // wimax-bs-net-device::sendBurst and wimax-ss-net-device::sendBurst
62  SetBs (bs);
63 }
64 
66 {
67  std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > *downlinkBursts = m_downlinkBursts;
68  std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > pair;
69  while (downlinkBursts->size ())
70  {
71  pair = downlinkBursts->front ();
72  pair.second = 0;
73  delete pair.first;
74  }
75  SetBs (0);
76  delete m_downlinkBursts;
77  m_downlinkBursts = 0;
78 }
79 
80 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
82 {
83  return m_downlinkBursts;
84 }
85 
87  uint8_t diuc,
88  WimaxPhy::ModulationType modulationType,
89  Ptr<PacketBurst> burst)
90 {
91  OfdmDlMapIe *dlMapIe = new OfdmDlMapIe ();
92  dlMapIe->SetCid (connection->GetCid ());
93  dlMapIe->SetDiuc (diuc);
94 
95  NS_LOG_INFO ("BS scheduler, burst size: " << burst->GetSize () << " bytes" << ", pkts: " << burst->GetNPackets ()
96  << ", connection: " << connection->GetTypeStr () << ", CID: " << connection->GetCid ());
97  if (connection->GetType () == Cid::TRANSPORT)
98  {
99  NS_LOG_INFO (", SFID: " << connection->GetServiceFlow ()->GetSfid () << ", service: "
100  << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
101  }
102  NS_LOG_INFO (", modulation: " << modulationType << ", DIUC: " << (uint32_t) diuc);
103 
104  m_downlinkBursts->push_back (std::make_pair (dlMapIe, burst));
105 }
106 
108 {
109  Ptr<WimaxConnection> connection;
112  uint32_t nrSymbolsRequired = 0;
113  GenericMacHeader hdr;
114  Ptr<Packet> packet;
115  Ptr<PacketBurst> burst;
117  uint32_t availableSymbols = GetBs ()->GetNrDlSymbols ();
118 
119  while (SelectConnection (connection))
120  {
121  if (connection != GetBs ()->GetInitialRangingConnection () && connection != GetBs ()->GetBroadcastConnection ())
122  {
123  /* determines modulation/DIUC only once per burst as it is always same for a particular CID */
124  if (connection->GetType () == Cid::MULTICAST)
125  {
126  modulationType = connection->GetServiceFlow ()->GetModulation ();
127  }
128  else
129  {
130  modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
131  }
132  diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
134  }
135  else if (connection == GetBs ()->GetInitialRangingConnection () || connection
136  == GetBs ()->GetBroadcastConnection ())
137  {
138 
139  modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
141  }
142 
143  if (connection->GetType () == Cid::TRANSPORT || connection->GetType () == Cid::MULTICAST)
144  {
145  schedulingType = (ServiceFlow::SchedulingType) connection->GetSchedulingType ();
146  }
147 
148  if (schedulingType == ServiceFlow::SF_TYPE_UGS)
149  {
150  nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
151  if (nrSymbolsRequired < availableSymbols)
152  {
153  burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
154  }
155  else
156  {
157  burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, availableSymbols);
158  }
159  if (burst->GetNPackets () != 0)
160  {
161  uint32_t BurstSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (burst->GetSize (), modulationType);
162  AddDownlinkBurst (connection, diuc, modulationType, burst);
163 
164  if (availableSymbols <= BurstSizeSymbols)
165  {
166  availableSymbols -= BurstSizeSymbols;
167  break;
168  }
169  }
170  }
171  else
172  {
173  burst = Create<PacketBurst> ();
174  while (connection->HasPackets () == true)
175  {
176  uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
177  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize, modulationType);
178  if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
179  availableSymbols,
180  modulationType))
181  {
182  uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
183  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
184  availableSymbols = 0;
185  }
186  else if (availableSymbols >= nrSymbolsRequired)
187  {
188  packet = connection->Dequeue ();
189  availableSymbols -= nrSymbolsRequired;
190  }
191  else
192  {
193  break;
194  }
195  burst->AddPacket (packet);
196  }
197  AddDownlinkBurst (connection, diuc, modulationType, burst);
198  }
199  if (availableSymbols == 0)
200  {
201  break;
202  }
203  }
204 
205 
206  if (m_downlinkBursts->size ())
207  {
208  NS_LOG_DEBUG ("BS scheduler, number of bursts: " << m_downlinkBursts->size () << ", symbols left: "
209  << availableSymbols << std::endl << "BS scheduler, queues:" << " IR "
210  << GetBs ()->GetInitialRangingConnection ()->GetQueue ()->GetSize () << " broadcast "
211  << GetBs ()->GetBroadcastConnection ()->GetQueue ()->GetSize () << " basic "
212  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::BASIC, ServiceFlow::SF_TYPE_NONE) << " primary "
213  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::PRIMARY, ServiceFlow::SF_TYPE_NONE) << " transport "
214  << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::TRANSPORT, ServiceFlow::SF_TYPE_ALL));
215  }
216 }
217 
219 {
220  connection = 0;
221  Time currentTime = Simulator::Now ();
222  std::vector<Ptr<WimaxConnection> >::const_iterator iter1;
223  std::vector<ServiceFlow*>::iterator iter2;
224  ServiceFlowRecord *serviceFlowRecord;
225  NS_LOG_INFO ("BS Scheduler: Selecting connection...");
226  if (GetBs ()->GetBroadcastConnection ()->HasPackets ())
227  {
228  NS_LOG_INFO ("Return GetBroadcastConnection");
229  connection = GetBs ()->GetBroadcastConnection ();
230  return true;
231  }
232  else if (GetBs ()->GetInitialRangingConnection ()->HasPackets ())
233  {
234  NS_LOG_INFO ("Return GetInitialRangingConnection");
235  connection = GetBs ()->GetInitialRangingConnection ();
236  return true;
237  }
238  else
239  {
240  std::vector<Ptr<WimaxConnection> > connections;
241  std::vector<ServiceFlow*> serviceFlows;
242 
243  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::BASIC);
244  for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
245  {
246  if ((*iter1)->HasPackets ())
247  {
248  NS_LOG_INFO ("Return Basic");
249  connection = *iter1;
250  return true;
251  }
252  }
253 
254  connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::PRIMARY);
255  for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
256  {
257  if ((*iter1)->HasPackets ())
258  {
259  NS_LOG_INFO ("Return Primary");
260  connection = *iter1;
261  return true;
262  }
263  }
264 
265  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
266  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
267  {
268  serviceFlowRecord = (*iter2)->GetRecord ();
269  NS_LOG_INFO ("processing UGS: HAS PACKET=" << (*iter2)->HasPackets () << "max Latency = "
270  << MilliSeconds ((*iter2)->GetMaximumLatency ()) << "Delay = " << ((currentTime
271  - serviceFlowRecord->GetDlTimeStamp ()) + GetBs ()->GetPhy ()->GetFrameDuration ()));
272  // if latency would exceed in case grant is allocated in next frame then allocate in current frame
273  if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
274  + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
275  {
276  serviceFlowRecord->SetDlTimeStamp (currentTime);
277  connection = (*iter2)->GetConnection ();
278  NS_LOG_INFO ("Return UGS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
279  return true;
280  }
281  }
282 
283  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
284  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
285  {
286  serviceFlowRecord = (*iter2)->GetRecord ();
287  // if latency would exceed in case poll is allocated in next frame then allocate in current frame
288  if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
289  + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
290  {
291  serviceFlowRecord->SetDlTimeStamp (currentTime);
292  connection = (*iter2)->GetConnection ();
293  NS_LOG_INFO ("Return RTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
294  return true;
295  }
296  }
297 
298  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
299  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
300  {
301  //unused: serviceFlowRecord = (*iter2)->GetRecord ();
302  if ((*iter2)->HasPackets ())
303  {
304  NS_LOG_INFO ("Return NRTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
305  connection = (*iter2)->GetConnection ();
306  return true;
307  }
308  }
309 
310  serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
311  for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
312  {
313  //unused: serviceFlowRecord = (*iter2)->GetRecord ();
314  if ((*iter2)->HasPackets ())
315  {
316  NS_LOG_INFO ("Return BE SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
317  connection = (*iter2)->GetConnection ();
318  return true;
319  }
320  }
321  }
322  NS_LOG_INFO ("NO connection is selected!");
323  return false;
324 }
325 
327  WimaxPhy::ModulationType modulationType,
328  uint32_t availableSymbols)
329 {
330  Time timeStamp;
331  GenericMacHeader hdr;
332  Ptr<Packet> packet;
333  Ptr<PacketBurst> burst = Create<PacketBurst> ();
334  uint32_t nrSymbolsRequired = 0;
335 
336  // serviceFlow->CleanUpQueue ();
337  Ptr<WimaxConnection> connection = serviceFlow->GetConnection ();
338  while (serviceFlow->HasPackets ())
339  {
340  uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
341  nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
342  if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
343  availableSymbols,
344  modulationType))
345  {
346  uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
347  packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
348  availableSymbols = 0;
349  }
350  else
351  {
352  packet = connection->Dequeue ();
353  availableSymbols -= nrSymbolsRequired;
354  }
355  burst->AddPacket (packet);
356  if (availableSymbols <= 0)
357  {
358  break;
359  }
360  }
361  return burst;
362 }
363 
364 }
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
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 ...
Ptr< PacketBurst > CreateUgsBurst(ServiceFlow *serviceFlow, WimaxPhy::ModulationType modulationType, uint32_t availableSymbols)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_INFO(msg)
Definition: log.h:298
bool SelectConnection(Ptr< WimaxConnection > &connection)
Ptr< WimaxConnection > GetConnection(void) const
bool CheckForFragmentation(Ptr< WimaxConnection > connection, int availableSymbols, WimaxPhy::ModulationType modulationType)
Definition: bs-scheduler.cc:91
this class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * GetDownlinkBursts(void) const
void SetDiuc(uint8_t diuc)
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
#define list
NS_LOG_COMPONENT_DEFINE("BSSchedulerSimple")
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:39
virtual Ptr< BaseStationNetDevice > GetBs(void)
Definition: bs-scheduler.cc:85
void AddDownlinkBurst(Ptr< const WimaxConnection > connection, uint8_t diuc, WimaxPhy::ModulationType modulationType, Ptr< PacketBurst > burst)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Definition: bs-scheduler.cc:80
void SetDlTimeStamp(Time dlTimeStamp)
Set the DlTimeStamp.
Doxygen introspection did not find any typical Config paths.
Definition: packet-burst.h:32
Time GetDlTimeStamp(void) const
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
void SetCid(Cid cid)
a base class which provides memory management and object aggregation
Definition: object.h:63
static TypeId GetTypeId(void)
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
bool HasPackets(void) const