23 #include "bandwidth-manager.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"
40 NS_OBJECT_ENSURE_REGISTERED (BandwidthManager);
42 TypeId BandwidthManager::GetTypeId (
void)
44 static TypeId tid = TypeId (
"ns3::BandwidthManager")
45 .SetParent<Object> ();
49 BandwidthManager::BandwidthManager (Ptr<WimaxNetDevice> device)
55 BandwidthManager::~BandwidthManager (
void)
66 BandwidthManager::CalculateAllocationSize (
const SSRecord *ssRecord,
const ServiceFlow *serviceFlow)
70 uint32_t allocationSize = 0;
73 if (serviceFlow->GetSchedulingType () != ServiceFlow::SF_TYPE_UGS
74 && ssRecord->GetHasServiceFlowUgs ()
75 && !ssRecord->GetPollMeBit ())
80 switch (serviceFlow->GetSchedulingType ())
82 case ServiceFlow::SF_TYPE_UGS:
84 if ((currentTime - serviceFlow->GetRecord ()->
GetGrantTimeStamp ()).GetMilliSeconds ()
85 >= serviceFlow->GetUnsolicitedGrantInterval ())
87 allocationSize = serviceFlow->GetRecord ()->
GetGrantSize ();
92 case ServiceFlow::SF_TYPE_RTPS:
94 if ((currentTime - serviceFlow->GetRecord ()->
GetGrantTimeStamp ()).GetMilliSeconds ()
95 >= serviceFlow->GetUnsolicitedPollingInterval ())
97 allocationSize = bs->GetBwReqOppSize ();
102 case ServiceFlow::SF_TYPE_NRTPS:
107 allocationSize = bs->GetBwReqOppSize ();
110 case ServiceFlow::SF_TYPE_BE:
115 allocationSize = bs->GetBwReqOppSize ();
122 return allocationSize;
126 BandwidthManager::SelectFlowForRequest (uint32_t &bytesToRequest)
129 ServiceFlow *serviceFlow = 0;
131 Ptr<SubscriberStationNetDevice> ss = m_device->GetObject<SubscriberStationNetDevice> ();
132 std::vector<ServiceFlow*> serviceFlows = ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_ALL);
134 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
137 if (serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_RTPS
138 || serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_NRTPS
139 || serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_BE)
141 if (serviceFlow->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC))
144 bytesToRequest = serviceFlow->GetQueue ()->GetQueueLengthWithMACOverhead ();
154 BandwidthManager::SendBandwidthRequest (uint8_t uiuc, uint16_t allocationSize)
156 Ptr<SubscriberStationNetDevice> ss = m_device->GetObject<SubscriberStationNetDevice> ();
158 uint32_t bytesToRequest = 0;
159 ServiceFlow *serviceFlow = SelectFlowForRequest (bytesToRequest);
161 if (!serviceFlow || !bytesToRequest)
165 BandwidthRequestHeader bwRequestHdr;
170 bwRequestHdr.SetType ((uint8_t) BandwidthRequestHeader::HEADER_TYPE_AGGREGATE);
171 bwRequestHdr.SetCid (serviceFlow->GetConnection ()->GetCid ());
172 bwRequestHdr.SetBr (bytesToRequest);
174 Ptr<Packet> packet = Create<Packet> ();
175 packet->AddHeader (bwRequestHdr);
176 ss->Enqueue (packet, MacHeaderType (MacHeaderType::HEADER_TYPE_BANDWIDTH), serviceFlow->GetConnection ());
178 NS_ASSERT_MSG (uiuc == OfdmUlBurstProfile::UIUC_REQ_REGION_FULL,
"Send Bandwidth Request: !UIUC_REQ_REGION_FULL");
179 ss->SendBurst (uiuc, allocationSize, serviceFlow->GetConnection (), MacHeaderType::HEADER_TYPE_BANDWIDTH);
183 BandwidthManager::ProcessBandwidthRequest (
const BandwidthRequestHeader &bwRequestHdr)
185 Ptr<BaseStationNetDevice> bs = m_device->GetObject<BaseStationNetDevice> ();
187 ServiceFlow *serviceFlow = bs->GetConnectionManager ()->GetConnection (bwRequestHdr.GetCid ())->GetServiceFlow ();
188 if (bwRequestHdr.GetType () == (uint8_t) BandwidthRequestHeader::HEADER_TYPE_INCREMENTAL)
190 serviceFlow->GetRecord ()->UpdateRequestedBandwidth (bwRequestHdr.GetBr ());
194 serviceFlow->GetRecord ()->SetRequestedBandwidth (bwRequestHdr.GetBr ());
195 bs->GetUplinkScheduler ()->OnSetRequestedBandwidth (serviceFlow->GetRecord ());
197 bs->GetUplinkScheduler ()->ProcessBandwidthRequest (bwRequestHdr);
199 serviceFlow->GetRecord ()->IncreaseBacklogged (bwRequestHdr.GetBr ());
203 BandwidthManager::SetSubframeRatio (
void)
207 Ptr<BaseStationNetDevice> bs = m_device->GetObject<BaseStationNetDevice> ();
209 uint32_t symbolsPerFrame = bs->GetPhy ()->GetSymbolsPerFrame ();
212 bs->SetNrDlSymbols (symbolsPerFrame / 2);
213 bs->SetNrUlSymbols (symbolsPerFrame / 2);
217 BandwidthManager::GetSymbolsPerFrameAllocated (
void)
219 Ptr<BaseStationNetDevice> bs = m_device->GetObject<BaseStationNetDevice> ();
221 uint32_t allocationPerFrame = 0;
223 std::vector<SSRecord*> *ssRecords = bs->GetSSManager ()->GetSSRecords ();
224 for (std::vector<SSRecord*>::iterator iter1 = ssRecords->begin (); iter1 != ssRecords->end (); ++iter1)
226 for (std::vector<ServiceFlow*>::iterator iter2 = (*iter1)->GetServiceFlows (ServiceFlow::SF_TYPE_ALL).begin ();
227 iter2 != (*iter1)->GetServiceFlows (ServiceFlow::SF_TYPE_ALL).end (); ++iter2)
229 allocationPerFrame += (*iter2)->GetRecord ()->GetGrantSize ();
232 return allocationPerFrame;
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_FATAL_ERROR(msg)
fatal error handling
Time GetGrantTimeStamp(void) const
void SetGrantTimeStamp(Time grantTimeStamp)
Set the grant time stamp. Used for data alocation for ugs flows, and unicast poll (bw request) for no...
#define NS_ASSERT_MSG(condition, message)
uint32_t GetGrantSize(void) const
This class is used by the base station to store some information related to subscriber station in the...