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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
8 * <amine.ismail@UDcast.com>
9 */
10
11#include "bandwidth-manager.h"
12
13#include "bs-net-device.h"
15#include "connection-manager.h"
17#include "service-flow-record.h"
18#include "service-flow.h"
19#include "ss-manager.h"
20#include "ss-net-device.h"
21#include "ss-record.h"
22
23#include "ns3/node.h"
24#include "ns3/simulator.h"
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("BandwidthManager");
30
31NS_OBJECT_ENSURE_REGISTERED(BandwidthManager);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::BandwidthManager").SetParent<Object>().SetGroupName("Wimax");
37 return tid;
38}
39
41 : m_device(device),
42 m_nrBwReqsSent(0)
43{
44}
45
49
50void
52{
53 m_device = nullptr;
54}
55
58{
59 Time currentTime = Simulator::Now();
61 uint32_t allocationSize = 0;
62
63 // if SS has a UGS flow then it must set poll-me bit in order to be polled for non-UGS flows
64 if (serviceFlow->GetSchedulingType() != ServiceFlow::SF_TYPE_UGS &&
65 ssRecord->GetHasServiceFlowUgs() && !ssRecord->GetPollMeBit())
66 {
67 return 0;
68 }
69
70 switch (serviceFlow->GetSchedulingType())
71 {
73 if ((currentTime - serviceFlow->GetRecord()->GetGrantTimeStamp()).GetMilliSeconds() >=
74 serviceFlow->GetUnsolicitedGrantInterval())
75 {
76 allocationSize = serviceFlow->GetRecord()->GetGrantSize();
77 serviceFlow->GetRecord()->SetGrantTimeStamp(currentTime);
78 }
79 }
80 break;
82 if ((currentTime - serviceFlow->GetRecord()->GetGrantTimeStamp()).GetMilliSeconds() >=
83 serviceFlow->GetUnsolicitedPollingInterval())
84 {
85 allocationSize = bs->GetBwReqOppSize();
86 serviceFlow->GetRecord()->SetGrantTimeStamp(currentTime);
87 }
88 }
89 break;
91 /* nrtPS shall be serviced only if sufficient bandwidth is available after servicing
92 UGS and rtPS scheduling types, hence no specific service interval is used */
94 /* BE shall be serviced only if sufficient bandwidth is available after servicing
95 the rest of three scheduling types, hence no specific service interval is used */
96
97 allocationSize = bs->GetBwReqOppSize();
98 }
99 break;
100 default:
101 NS_FATAL_ERROR("Invalid scheduling type");
102 }
103
104 return allocationSize;
105}
106
109{
110 Ptr<Packet> packet;
111 ServiceFlow* serviceFlow = nullptr;
112
114 std::vector<ServiceFlow*> serviceFlows =
115 ss->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
116
117 for (auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
118 {
119 serviceFlow = *iter;
120 if (serviceFlow->GetSchedulingType() == ServiceFlow::SF_TYPE_RTPS ||
123 {
125 {
126 // bandwidth is requested for all packets
127 bytesToRequest = serviceFlow->GetQueue()->GetQueueLengthWithMACOverhead();
128 break;
129 }
130 }
131 }
132
133 return serviceFlow;
134}
135
136void
137BandwidthManager::SendBandwidthRequest(uint8_t uiuc, uint16_t allocationSize)
138{
140
141 uint32_t bytesToRequest = 0;
142 ServiceFlow* serviceFlow = SelectFlowForRequest(bytesToRequest);
143
144 if (!serviceFlow || !bytesToRequest)
145 {
146 return;
147 }
148 BandwidthRequestHeader bwRequestHdr;
149
150 // bytesToRequest is the queue length of Service Flow and so,
151 // the header type must be HEADER_TYPE_AGGREGATE!
152
154 bwRequestHdr.SetCid(serviceFlow->GetConnection()->GetCid());
155 bwRequestHdr.SetBr(bytesToRequest);
156
157 Ptr<Packet> packet = Create<Packet>();
158 packet->AddHeader(bwRequestHdr);
159 ss->Enqueue(packet,
161 serviceFlow->GetConnection());
164 "Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
165 ss->SendBurst(uiuc,
166 allocationSize,
167 serviceFlow->GetConnection(),
169}
170
171void
173{
175
176 ServiceFlow* serviceFlow =
177 bs->GetConnectionManager()->GetConnection(bwRequestHdr.GetCid())->GetServiceFlow();
178 if (bwRequestHdr.GetType() == (uint8_t)BandwidthRequestHeader::HEADER_TYPE_INCREMENTAL)
179 {
180 serviceFlow->GetRecord()->UpdateRequestedBandwidth(bwRequestHdr.GetBr());
181 }
182 else
183 {
184 serviceFlow->GetRecord()->SetRequestedBandwidth(bwRequestHdr.GetBr());
185 bs->GetUplinkScheduler()->OnSetRequestedBandwidth(serviceFlow->GetRecord());
186 }
187 bs->GetUplinkScheduler()->ProcessBandwidthRequest(bwRequestHdr);
188 // update backlogged
189 serviceFlow->GetRecord()->IncreaseBacklogged(bwRequestHdr.GetBr());
190}
191
192void
194{
195 // sets ratio of the DL and UL subframes
196
198
199 uint32_t symbolsPerFrame = bs->GetPhy()->GetSymbolsPerFrame();
200
201 /* temporarily divided in half (360 symbols each), shall actually be determined based on UL and
202 * DL traffic*/
203 bs->SetNrDlSymbols(symbolsPerFrame / 2);
204 bs->SetNrUlSymbols(symbolsPerFrame / 2);
205}
206
209{
211
212 uint32_t allocationPerFrame = 0;
213
214 std::vector<SSRecord*>* ssRecords = bs->GetSSManager()->GetSSRecords();
215 for (auto iter1 = ssRecords->begin(); iter1 != ssRecords->end(); ++iter1)
216 {
217 std::vector<ServiceFlow*> ssServiceFlows =
218 (*iter1)->GetServiceFlows(ServiceFlow::SF_TYPE_ALL);
219 for (auto iter2 = ssServiceFlows.begin(); iter2 != ssServiceFlows.end(); ++iter2)
220 {
221 allocationPerFrame += (*iter2)->GetRecord()->GetGrantSize();
222 }
223 }
224 return allocationPerFrame;
225}
226
227} // 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.
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:78
Smart pointer class similar to boost::intrusive_ptr.
This class is used by the base station to store some information related to subscriber station in the...
Definition ss-record.h:35
bool GetHasServiceFlowUgs() const
Check if at least one flow has scheduling type SF_TYPE_UGS.
Definition ss-record.cc:249
bool GetPollMeBit() const
Get poll ME bit.
Definition ss-record.cc:210
This class implements service flows as described by the IEEE-802.16 standard.
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.
void SetGrantTimeStamp(Time grantTimeStamp)
Set the grant time stamp.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
SubscriberStationNetDevice subclass of WimaxNetDevice.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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:75
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.