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 */
105 /* BE shall be serviced only if sufficient bandwidth is available after servicing
106 the rest of three scheduling types, hence no specific service interval is used */
107
108 allocationSize = bs->GetBwReqOppSize();
109 }
110 break;
111 default:
112 NS_FATAL_ERROR("Invalid scheduling type");
113 }
114
115 return allocationSize;
116}
117
120{
121 Ptr<Packet> packet;
122 ServiceFlow* serviceFlow = nullptr;
123
125 std::vector<ServiceFlow*> serviceFlows =
126 ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
127
128 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
129 {
130 serviceFlow = *iter;
131 if (serviceFlow->GetSchedulingType() == ServiceFlow::SF_TYPE_RTPS ||
134 {
136 {
137 // bandwidth is requested for all packets
138 bytesToRequest = serviceFlow->GetQueue()->GetQueueLengthWithMACOverhead();
139 break;
140 }
141 }
142 }
143
144 return serviceFlow;
145}
146
147void
148BandwidthManager::SendBandwidthRequest(uint8_t uiuc, uint16_t allocationSize)
149{
151
152 uint32_t bytesToRequest = 0;
153 ServiceFlow* serviceFlow = SelectFlowForRequest(bytesToRequest);
154
155 if (!serviceFlow || !bytesToRequest)
156 {
157 return;
158 }
159 BandwidthRequestHeader bwRequestHdr;
160
161 // bytesToRequest is the queue length of Service Flow and so,
162 // the header type must be HEADER_TYPE_AGGREGATE!
163
165 bwRequestHdr.SetCid(serviceFlow->GetConnection()->GetCid());
166 bwRequestHdr.SetBr(bytesToRequest);
167
168 Ptr<Packet> packet = Create<Packet>();
169 packet->AddHeader(bwRequestHdr);
170 ss->Enqueue(packet,
172 serviceFlow->GetConnection());
175 "Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
176 ss->SendBurst(uiuc,
177 allocationSize,
178 serviceFlow->GetConnection(),
180}
181
182void
184{
186
187 ServiceFlow* serviceFlow =
188 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
203void
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
213 * DL traffic*/
214 bs->SetNrDlSymbols(symbolsPerFrame / 2);
215 bs->SetNrUlSymbols(symbolsPerFrame / 2);
216}
217
220{
222
223 uint32_t allocationPerFrame = 0;
224
225 std::vector<SSRecord*>* ssRecords = bs->GetSSManager()->GetSSRecords();
226 for (auto iter1 = ssRecords->begin(); iter1 != ssRecords->end(); ++iter1)
227 {
228 std::vector<ServiceFlow*> ssServiceFlows =
229 (*iter1)->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
230 for (auto iter2 = ssServiceFlows.begin(); iter2 != ssServiceFlows.end(); ++iter2)
231 {
232 allocationPerFrame += (*iter2)->GetRecord()->GetGrantSize();
233 }
234 }
235 return allocationPerFrame;
236}
237
238} // 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.