A Discrete-Event Network Simulator
API
bandwidth-manager.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,2009 INRIA, UDcast
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  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  * <amine.ismail@UDcast.com>
21  */
22 
23 #include "bandwidth-manager.h"
24 #include "ns3/node.h"
25 #include "bs-net-device.h"
26 #include "ss-net-device.h"
27 #include "ns3/simulator.h"
28 #include "burst-profile-manager.h"
29 #include "ss-manager.h"
30 #include "ss-record.h"
31 #include "service-flow.h"
32 #include "service-flow-record.h"
33 #include "service-flow-manager.h"
34 #include "connection-manager.h"
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("BandwidthManager");
39 
40 NS_OBJECT_ENSURE_REGISTERED (BandwidthManager);
41 
43 {
44  static TypeId tid = TypeId ("ns3::BandwidthManager")
45  .SetParent<Object> ()
46  .SetGroupName("Wimax");
47  return tid;
48 }
49 
51  : m_device (device),
52  m_nrBwReqsSent (0)
53 {
54 }
55 
57 {
58 }
59 
60 void
62 {
63  m_device = 0;
64 }
65 
66 uint32_t
67 BandwidthManager::CalculateAllocationSize (const SSRecord *ssRecord, const ServiceFlow *serviceFlow)
68 {
69  Time currentTime = Simulator::Now ();
71  uint32_t allocationSize = 0;
72 
73  // if SS has a UGS flow then it must set poll-me bit in order to be polled for non-UGS flows
74  if (serviceFlow->GetSchedulingType () != ServiceFlow::SF_TYPE_UGS
75  && ssRecord->GetHasServiceFlowUgs ()
76  && !ssRecord->GetPollMeBit ())
77  {
78  return 0;
79  }
80 
81  switch (serviceFlow->GetSchedulingType ())
82  {
84  {
85  if ((currentTime - serviceFlow->GetRecord ()->GetGrantTimeStamp ()).GetMilliSeconds ()
86  >= serviceFlow->GetUnsolicitedGrantInterval ())
87  {
88  allocationSize = serviceFlow->GetRecord ()->GetGrantSize ();
89  serviceFlow->GetRecord ()->SetGrantTimeStamp (currentTime);
90  }
91  }
92  break;
94  {
95  if ((currentTime - serviceFlow->GetRecord ()->GetGrantTimeStamp ()).GetMilliSeconds ()
96  >= serviceFlow->GetUnsolicitedPollingInterval ())
97  {
98  allocationSize = bs->GetBwReqOppSize ();
99  serviceFlow->GetRecord ()->SetGrantTimeStamp (currentTime);
100  }
101  }
102  break;
104  {
105  /* nrtPS shall be serviced only if sufficient bandwidth is available after servicing
106  UGS and rtPS scheduling types, hence no specific service interval is used */
107 
108  allocationSize = bs->GetBwReqOppSize ();
109  }
110  break;
112  {
113  /* BE shall be serviced only if sufficient bandwidth is available after servicing
114  the rest of three scheduling types, hence no specific service interval is used */
115 
116  allocationSize = bs->GetBwReqOppSize ();
117  }
118  break;
119  default:
120  NS_FATAL_ERROR ("Invalid scheduling type");
121  }
122 
123  return allocationSize;
124 }
125 
127 BandwidthManager::SelectFlowForRequest (uint32_t &bytesToRequest)
128 {
129  Ptr<Packet> packet;
130  ServiceFlow *serviceFlow = 0;
131 
133  std::vector<ServiceFlow*> serviceFlows = ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_ALL);
134 
135  for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
136  {
137  serviceFlow = *iter;
138  if (serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_RTPS
139  || serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_NRTPS
140  || serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_BE)
141  {
143  {
144  // bandwidth is requested for all packets
145  bytesToRequest = serviceFlow->GetQueue ()->GetQueueLengthWithMACOverhead ();
146  break;
147  }
148  }
149  }
150 
151  return serviceFlow;
152 }
153 
154 void
155 BandwidthManager::SendBandwidthRequest (uint8_t uiuc, uint16_t allocationSize)
156 {
158 
159  uint32_t bytesToRequest = 0;
160  ServiceFlow *serviceFlow = SelectFlowForRequest (bytesToRequest);
161 
162  if (!serviceFlow || !bytesToRequest)
163  {
164  return;
165  }
166  BandwidthRequestHeader bwRequestHdr;
167 
168  // bytesToRequest is the queue length of Service Flow and so,
169  // the header type must be HEADER_TYPE_AGGREGATE!
170 
172  bwRequestHdr.SetCid (serviceFlow->GetConnection ()->GetCid ());
173  bwRequestHdr.SetBr (bytesToRequest);
174 
175  Ptr<Packet> packet = Create<Packet> ();
176  packet->AddHeader (bwRequestHdr);
177  ss->Enqueue (packet, MacHeaderType (MacHeaderType::HEADER_TYPE_BANDWIDTH), serviceFlow->GetConnection ());
178  m_nrBwReqsSent++;
179  NS_ASSERT_MSG (uiuc == OfdmUlBurstProfile::UIUC_REQ_REGION_FULL, "Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
180  ss->SendBurst (uiuc, allocationSize, serviceFlow->GetConnection (), MacHeaderType::HEADER_TYPE_BANDWIDTH);
181 }
182 
183 void
185 {
187 
188  ServiceFlow *serviceFlow = bs->GetConnectionManager ()->GetConnection (bwRequestHdr.GetCid ())->GetServiceFlow ();
189  if (bwRequestHdr.GetType () == (uint8_t) BandwidthRequestHeader::HEADER_TYPE_INCREMENTAL)
190  {
191  serviceFlow->GetRecord ()->UpdateRequestedBandwidth (bwRequestHdr.GetBr ());
192  }
193  else
194  {
195  serviceFlow->GetRecord ()->SetRequestedBandwidth (bwRequestHdr.GetBr ());
196  bs->GetUplinkScheduler ()->OnSetRequestedBandwidth (serviceFlow->GetRecord ());
197  }
198  bs->GetUplinkScheduler ()->ProcessBandwidthRequest (bwRequestHdr);
199  // update backlogged
200  serviceFlow->GetRecord ()->IncreaseBacklogged (bwRequestHdr.GetBr ());
201 }
202 
203 void
205 {
206  // sets ratio of the DL and UL subframes
207 
209 
210  uint32_t symbolsPerFrame = bs->GetPhy ()->GetSymbolsPerFrame ();
211 
212  /* temporarily divided in half (360 symbols each), shall actually be determined based on UL and DL traffic*/
213  bs->SetNrDlSymbols (symbolsPerFrame / 2);
214  bs->SetNrUlSymbols (symbolsPerFrame / 2);
215 }
216 
217 uint32_t
219 {
221 
222  uint32_t allocationPerFrame = 0;
223 
224  std::vector<SSRecord*> *ssRecords = bs->GetSSManager ()->GetSSRecords ();
225  for (std::vector<SSRecord*>::const_iterator iter1 = ssRecords->begin (); iter1 != ssRecords->end (); ++iter1)
226  {
227  std::vector<ServiceFlow*> ssServiceFlows = (*iter1)->GetServiceFlows (ServiceFlow::SF_TYPE_ALL);
228  for (std::vector<ServiceFlow*>::const_iterator iter2 = ssServiceFlows.begin (); iter2 != ssServiceFlows.end (); ++iter2)
229  {
230  allocationPerFrame += (*iter2)->GetRecord ()->GetGrantSize ();
231  }
232  }
233  return allocationPerFrame;
234 }
235 
236 } // namespace ns3
void DoDispose(void)
Destructor implementation.
uint16_t m_nrBwReqsSent
bandwidth requests sent
void SetSubframeRatio(void)
Set subframe ratio.
Ptr< WimaxNetDevice > m_device
the device
uint32_t CalculateAllocationSize(const SSRecord *ssRecord, const ServiceFlow *serviceFlow)
Calculate allocation size function.
ServiceFlow * SelectFlowForRequest(uint32_t &bytesToRequest)
Select flow for request function.
uint32_t GetSymbolsPerFrameAllocated(void)
Get symbols per frame allocated.
BandwidthManager(Ptr< WimaxNetDevice > device)
Constructor.
void ProcessBandwidthRequest(const BandwidthRequestHeader &bwRequestHdr)
Process bandwidth request.
void SendBandwidthRequest(uint8_t uiuc, uint16_t allocationSize)
Send bandwidth request.
static TypeId GetTypeId(void)
Get the type ID.
This class implements the bandwidth-request mac Header as described by IEEE Standard for Local and me...
void SetBr(uint32_t br)
Set BR field.
Cid GetCid(void) const
Get CID field.
void SetType(uint8_t type)
Set type field.
uint32_t GetBr(void) const
Get BR field.
void SetCid(Cid cid)
Set CID field.
uint8_t GetType(void) const
Get type field.
BaseStation NetDevice.
Definition: bs-net-device.h:53
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
A base class which provides memory management and object aggregation.
Definition: object.h:88
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:44
bool GetPollMeBit(void) const
Get poll ME bit.
Definition: ss-record.cc:218
bool GetHasServiceFlowUgs(void) const
Check if at least one flow has scheduling type SF_TYPE_UGS.
Definition: ss-record.cc:255
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:40
uint16_t GetUnsolicitedPollingInterval(void) const
Get unsolicited polling interval.
uint16_t GetUnsolicitedGrantInterval(void) const
Get unsolicited grant interval.
Ptr< WimaxMacQueue > GetQueue(void) const
Get pointer to queue.
bool HasPackets(void) const
Check if packets are present.
enum ServiceFlow::SchedulingType GetSchedulingType(void) const
Get scheduling type.
ServiceFlowRecord * GetRecord(void) const
Get service flow record.
Ptr< WimaxConnection > GetConnection(void) const
Can return a null connection is this service flow has not been associated yet to a connection.
Time GetGrantTimeStamp(void) const
uint32_t GetGrantSize(void) const
void SetGrantTimeStamp(Time grantTimeStamp)
Set the grant time stamp.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:49
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.