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 (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
133 {
134 serviceFlow = *iter;
135 if (serviceFlow->GetSchedulingType() == ServiceFlow::SF_TYPE_RTPS ||
138 {
140 {
141 // bandwidth is requested for all packets
142 bytesToRequest = serviceFlow->GetQueue()->GetQueueLengthWithMACOverhead();
143 break;
144 }
145 }
146 }
147
148 return serviceFlow;
149}
150
151void
152BandwidthManager::SendBandwidthRequest(uint8_t uiuc, uint16_t allocationSize)
153{
155
156 uint32_t bytesToRequest = 0;
157 ServiceFlow* serviceFlow = SelectFlowForRequest(bytesToRequest);
158
159 if (!serviceFlow || !bytesToRequest)
160 {
161 return;
162 }
163 BandwidthRequestHeader bwRequestHdr;
164
165 // bytesToRequest is the queue length of Service Flow and so,
166 // the header type must be HEADER_TYPE_AGGREGATE!
167
169 bwRequestHdr.SetCid(serviceFlow->GetConnection()->GetCid());
170 bwRequestHdr.SetBr(bytesToRequest);
171
172 Ptr<Packet> packet = Create<Packet>();
173 packet->AddHeader(bwRequestHdr);
174 ss->Enqueue(packet,
176 serviceFlow->GetConnection());
179 "Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
180 ss->SendBurst(uiuc,
181 allocationSize,
182 serviceFlow->GetConnection(),
184}
185
186void
188{
190
191 ServiceFlow* serviceFlow =
192 bs->GetConnectionManager()->GetConnection(bwRequestHdr.GetCid())->GetServiceFlow();
193 if (bwRequestHdr.GetType() == (uint8_t)BandwidthRequestHeader::HEADER_TYPE_INCREMENTAL)
194 {
195 serviceFlow->GetRecord()->UpdateRequestedBandwidth(bwRequestHdr.GetBr());
196 }
197 else
198 {
199 serviceFlow->GetRecord()->SetRequestedBandwidth(bwRequestHdr.GetBr());
200 bs->GetUplinkScheduler()->OnSetRequestedBandwidth(serviceFlow->GetRecord());
201 }
202 bs->GetUplinkScheduler()->ProcessBandwidthRequest(bwRequestHdr);
203 // update backlogged
204 serviceFlow->GetRecord()->IncreaseBacklogged(bwRequestHdr.GetBr());
205}
206
207void
209{
210 // sets ratio of the DL and UL subframes
211
213
214 uint32_t symbolsPerFrame = bs->GetPhy()->GetSymbolsPerFrame();
215
216 /* temporarily divided in half (360 symbols each), shall actually be determined based on UL and
217 * DL traffic*/
218 bs->SetNrDlSymbols(symbolsPerFrame / 2);
219 bs->SetNrUlSymbols(symbolsPerFrame / 2);
220}
221
224{
226
227 uint32_t allocationPerFrame = 0;
228
229 std::vector<SSRecord*>* ssRecords = bs->GetSSManager()->GetSSRecords();
230 for (auto iter1 = ssRecords->begin(); iter1 != ssRecords->end(); ++iter1)
231 {
232 std::vector<ServiceFlow*> ssServiceFlows =
233 (*iter1)->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
234 for (auto iter2 = ssServiceFlows.begin(); iter2 != ssServiceFlows.end(); ++iter2)
235 {
236 allocationPerFrame += (*iter2)->GetRecord()->GetGrantSize();
237 }
238 }
239 return allocationPerFrame;
240}
241
242} // 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:77
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:260
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:208
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:932
#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.