A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bandwidth-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDcast
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19 * <amine.ismail@UDcast.com>
20 */
21
22#include "bandwidth-manager.h"
23
24#include "bs-net-device.h"
26#include "connection-manager.h"
28#include "service-flow-record.h"
29#include "service-flow.h"
30#include "ss-manager.h"
31#include "ss-net-device.h"
32#include "ss-record.h"
33
34#include "ns3/node.h"
35#include "ns3/simulator.h"
36
37namespace ns3
38{
39
40NS_LOG_COMPONENT_DEFINE("BandwidthManager");
41
42NS_OBJECT_ENSURE_REGISTERED(BandwidthManager);
43
44TypeId
46{
47 static TypeId tid = TypeId("ns3::BandwidthManager").SetParent<Object>().SetGroupName("Wimax");
48 return tid;
49}
50
52 : m_device(device),
53 m_nrBwReqsSent(0)
54{
55}
56
58{
59}
60
61void
63{
64 m_device = nullptr;
65}
66
69{
70 Time currentTime = Simulator::Now();
72 uint32_t allocationSize = 0;
73
74 // if SS has a UGS flow then it must set poll-me bit in order to be polled for non-UGS flows
75 if (serviceFlow->GetSchedulingType() != ServiceFlow::SF_TYPE_UGS &&
76 ssRecord->GetHasServiceFlowUgs() && !ssRecord->GetPollMeBit())
77 {
78 return 0;
79 }
80
81 switch (serviceFlow->GetSchedulingType())
82 {
84 if ((currentTime - serviceFlow->GetRecord()->GetGrantTimeStamp()).GetMilliSeconds() >=
85 serviceFlow->GetUnsolicitedGrantInterval())
86 {
87 allocationSize = serviceFlow->GetRecord()->GetGrantSize();
88 serviceFlow->GetRecord()->SetGrantTimeStamp(currentTime);
89 }
90 }
91 break;
93 if ((currentTime - serviceFlow->GetRecord()->GetGrantTimeStamp()).GetMilliSeconds() >=
94 serviceFlow->GetUnsolicitedPollingInterval())
95 {
96 allocationSize = bs->GetBwReqOppSize();
97 serviceFlow->GetRecord()->SetGrantTimeStamp(currentTime);
98 }
99 }
100 break;
102 /* nrtPS shall be serviced only if sufficient bandwidth is available after servicing
103 UGS and rtPS scheduling types, hence no specific service interval is used */
104
105 allocationSize = bs->GetBwReqOppSize();
106 }
107 break;
109 /* BE shall be serviced only if sufficient bandwidth is available after servicing
110 the rest of three scheduling types, hence no specific service interval is used */
111
112 allocationSize = bs->GetBwReqOppSize();
113 }
114 break;
115 default:
116 NS_FATAL_ERROR("Invalid scheduling type");
117 }
118
119 return allocationSize;
120}
121
124{
125 Ptr<Packet> packet;
126 ServiceFlow* serviceFlow = nullptr;
127
129 std::vector<ServiceFlow*> serviceFlows =
130 ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
131
132 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin();
133 iter != serviceFlows.end();
134 ++iter)
135 {
136 serviceFlow = *iter;
137 if (serviceFlow->GetSchedulingType() == ServiceFlow::SF_TYPE_RTPS ||
140 {
142 {
143 // bandwidth is requested for all packets
144 bytesToRequest = serviceFlow->GetQueue()->GetQueueLengthWithMACOverhead();
145 break;
146 }
147 }
148 }
149
150 return serviceFlow;
151}
152
153void
154BandwidthManager::SendBandwidthRequest(uint8_t uiuc, uint16_t allocationSize)
155{
157
158 uint32_t bytesToRequest = 0;
159 ServiceFlow* serviceFlow = SelectFlowForRequest(bytesToRequest);
160
161 if (!serviceFlow || !bytesToRequest)
162 {
163 return;
164 }
165 BandwidthRequestHeader bwRequestHdr;
166
167 // bytesToRequest is the queue length of Service Flow and so,
168 // the header type must be HEADER_TYPE_AGGREGATE!
169
171 bwRequestHdr.SetCid(serviceFlow->GetConnection()->GetCid());
172 bwRequestHdr.SetBr(bytesToRequest);
173
174 Ptr<Packet> packet = Create<Packet>();
175 packet->AddHeader(bwRequestHdr);
176 ss->Enqueue(packet,
178 serviceFlow->GetConnection());
181 "Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
182 ss->SendBurst(uiuc,
183 allocationSize,
184 serviceFlow->GetConnection(),
186}
187
188void
190{
192
193 ServiceFlow* serviceFlow =
194 bs->GetConnectionManager()->GetConnection(bwRequestHdr.GetCid())->GetServiceFlow();
195 if (bwRequestHdr.GetType() == (uint8_t)BandwidthRequestHeader::HEADER_TYPE_INCREMENTAL)
196 {
197 serviceFlow->GetRecord()->UpdateRequestedBandwidth(bwRequestHdr.GetBr());
198 }
199 else
200 {
201 serviceFlow->GetRecord()->SetRequestedBandwidth(bwRequestHdr.GetBr());
202 bs->GetUplinkScheduler()->OnSetRequestedBandwidth(serviceFlow->GetRecord());
203 }
204 bs->GetUplinkScheduler()->ProcessBandwidthRequest(bwRequestHdr);
205 // update backlogged
206 serviceFlow->GetRecord()->IncreaseBacklogged(bwRequestHdr.GetBr());
207}
208
209void
211{
212 // sets ratio of the DL and UL subframes
213
215
216 uint32_t symbolsPerFrame = bs->GetPhy()->GetSymbolsPerFrame();
217
218 /* temporarily divided in half (360 symbols each), shall actually be determined based on UL and
219 * DL traffic*/
220 bs->SetNrDlSymbols(symbolsPerFrame / 2);
221 bs->SetNrUlSymbols(symbolsPerFrame / 2);
222}
223
226{
228
229 uint32_t allocationPerFrame = 0;
230
231 std::vector<SSRecord*>* ssRecords = bs->GetSSManager()->GetSSRecords();
232 for (std::vector<SSRecord*>::const_iterator iter1 = ssRecords->begin();
233 iter1 != ssRecords->end();
234 ++iter1)
235 {
236 std::vector<ServiceFlow*> ssServiceFlows =
237 (*iter1)->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
238 for (std::vector<ServiceFlow*>::const_iterator iter2 = ssServiceFlows.begin();
239 iter2 != ssServiceFlows.end();
240 ++iter2)
241 {
242 allocationPerFrame += (*iter2)->GetRecord()->GetGrantSize();
243 }
244 }
245 return allocationPerFrame;
246}
247
248} // namespace ns3
void SetSubframeRatio()
Set subframe ratio.
uint16_t m_nrBwReqsSent
bandwidth requests sent
uint32_t GetSymbolsPerFrameAllocated()
Get symbols per frame allocated.
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.
void DoDispose() override
Destructor implementation.
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()
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.
uint32_t GetBr() const
Get BR field.
void SetType(uint8_t type)
Set type field.
Cid GetCid() const
Get CID field.
void SetCid(Cid cid)
Set CID field.
uint8_t GetType() const
Get type field.
BaseStation NetDevice.
Definition: bs-net-device.h:54
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:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:46
bool GetHasServiceFlowUgs() const
Check if at least one flow has scheduling type SF_TYPE_UGS.
Definition: ss-record.cc:262
bool GetPollMeBit() const
Get poll ME bit.
Definition: ss-record.cc:221
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
ServiceFlow::SchedulingType GetSchedulingType() const
Get scheduling type.
uint16_t GetUnsolicitedPollingInterval() const
Get unsolicited polling interval.
bool HasPackets() const
Check if packets are present.
ServiceFlowRecord * GetRecord() const
Get service flow record.
Ptr< WimaxMacQueue > GetQueue() const
Get pointer to queue.
uint16_t GetUnsolicitedGrantInterval() const
Get unsolicited grant interval.
Ptr< WimaxConnection > GetConnection() const
Can return a null connection is this service flow has not been associated yet to a connection.
uint32_t GetGrantSize() const
void SetGrantTimeStamp(Time grantTimeStamp)
Set the grant time stamp.
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
SubscriberStationNetDevice subclass of WimaxNetDevice.
Definition: ss-net-device.h:50
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.