A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bs-link-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 "bs-link-manager.h"
12
13#include "bs-uplink-scheduler.h"
15#include "connection-manager.h"
16#include "ss-manager.h"
17#include "ss-record.h"
18
19#include "ns3/log.h"
20#include "ns3/node.h"
21#include "ns3/packet.h"
22#include "ns3/simulator.h"
23
24#include <stdint.h>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("BSLinkManager");
30
31NS_OBJECT_ENSURE_REGISTERED(BSLinkManager);
32
33TypeId
35{
36 static TypeId tid = TypeId("ns3::BSLinkManager").SetParent<Object>().SetGroupName("Wimax");
37 return tid;
38}
39
41 : m_bs(bs),
42 m_signalQuality(10),
43 m_signalQualityThreshold(10) // arbitrary value
44{
45 tries = 0;
46}
47
49{
50 m_bs = nullptr;
51}
52
53uint8_t
55{
56 // randomly selecting TOs up to 10, shall actually be decided by scheduler
57 return rand() % 8 + 2;
58}
59
60/*
61 * Function mainly to avoid duplicate code in DoReceive ()
62 */
63void
65{
67 "Base station: Error while processing ranging request: !BS_STATE_UL_SUB_FRAME");
68
69 Time irIntervalBoundary;
70
71 if (m_bs->GetUplinkScheduler()->GetIsInvIrIntrvlAllocated())
72 {
73 if (m_bs->GetUplinkScheduler()->GetIsIrIntrvlAllocated())
74 {
75 irIntervalBoundary =
76 m_bs->GetUlSubframeStartTime() +
77 Seconds((m_bs->GetUplinkScheduler()->GetNrIrOppsAllocated() + 1) *
78 m_bs->GetRangReqOppSize() * m_bs->GetSymbolDuration().GetSeconds());
79 }
80 else
81 {
82 irIntervalBoundary =
83 m_bs->GetUlSubframeStartTime() +
84 Seconds(m_bs->GetRangReqOppSize() * m_bs->GetSymbolDuration().GetSeconds());
85 }
86 }
87 else
88 {
90 m_bs->GetUplinkScheduler()->GetIsIrIntrvlAllocated(),
91 "Base station: Error while processing ranging request: IR interval not allocated");
92
93 irIntervalBoundary =
94 m_bs->GetUlSubframeStartTime() +
95 Seconds(m_bs->GetUplinkScheduler()->GetNrIrOppsAllocated() * m_bs->GetRangReqOppSize() *
96 m_bs->GetSymbolDuration().GetSeconds());
97 }
98
99 tries++;
100
101 if (Simulator::Now() >= m_bs->GetUlSubframeStartTime() && Simulator::Now() < irIntervalBoundary)
102 {
103 PerformRanging(cid, rngreq);
104 }
105}
106
107void
109{
110 RngRsp rngrsp;
111 bool decodable = false;
112
113 // assuming low power, packet lost or undecodable first 2 times
114 if (tries < 2)
115 {
116 return;
117 }
118 if (tries >= 3)
119 {
120 decodable = true;
121 }
122
123 NS_LOG_DEBUG("RNG-REQ:");
124 rngreq.PrintDebug();
125
126 if (!decodable)
127 {
128 rngrsp.SetFrameNumber(m_bs->GetNrFrames());
129 rngrsp.SetInitRangOppNumber(m_bs->GetRangingOppNumber());
130
131 SetParametersToAdjust(&rngrsp);
133 ScheduleRngRspMessage(cid, &rngrsp);
134 }
135 else
136 {
137 if (cid.IsInitialRanging())
138 {
139 PerformInitialRanging(cid, &rngreq, &rngrsp);
140 }
141 else
142 {
143 // invited initial ranging or periodic ranging
144 PerformInvitedRanging(cid, &rngrsp);
145 }
146 }
147}
148
149void
151{
152 SSRecord* ssRecord = nullptr;
153 bool isOldSS = m_bs->GetSSManager()->IsInRecord(rngreq->GetMacAddress());
154 if (isOldSS)
155 {
156 ssRecord = m_bs->GetSSManager()->GetSSRecord(rngreq->GetMacAddress());
157 // if this fails it would mean the RNG-RSP with success status was not received by the SS
158 }
159 else
160 {
161 ssRecord = m_bs->GetSSManager()->CreateSSRecord(rngreq->GetMacAddress());
162 }
163
164 if (ChangeDlChannel())
165 {
167 AbortRanging(cid, rngrsp, ssRecord, isOldSS);
168 return;
169 }
170
171 if (isOldSS)
172 {
173 // CIDs already assigned, e.g., RNG-REQ was lost and resent after timeout. reusing old CIDs
175 ssRecord->ResetInvitedRangingRetries();
176 }
177 else
178 {
179 m_bs->GetConnectionManager()->AllocateManagementConnections(ssRecord, rngrsp);
180
181 WimaxPhy::ModulationType modulationType;
182 uint8_t diuc =
183 m_bs->GetBurstProfileManager()->GetBurstProfileForSS(ssRecord, rngreq, modulationType);
184 ssRecord->SetModulationType(modulationType);
185
186 // specify in RNG-RSP only if different than what SS requested
187 if (rngreq->GetReqDlBurstProfile() != diuc)
188 {
189 rngrsp->SetDlOperBurstProfile(diuc);
190 }
191
192 // add SS (Basic CID) to poll list for invited ranging intervals, see Table 115
193 ssRecord->EnablePollForRanging();
194 }
195
196 rngrsp->SetMacAddress(rngreq->GetMacAddress());
197
198 if (isOldSS) // CIDs had already been allocated
199 {
200 cid = ssRecord->GetBasicCid();
201 }
202
204 {
205 AcceptRanging(cid, rngrsp, ssRecord);
206 }
207 else
208 {
209 ContinueRanging(cid, rngrsp, ssRecord);
210 }
211}
212
213void
215{
216 SSRecord* ssRecord = m_bs->GetSSManager()->GetSSRecord(cid);
218 ssRecord->ResetInvitedRangingRetries();
219
221 {
222 AcceptRanging(cid, rngrsp, ssRecord);
223 }
224 else
225 {
226 if (ssRecord->GetRangingCorrectionRetries() == m_bs->GetMaxRangingCorrectionRetries())
227 {
228 AbortRanging(cid, rngrsp, ssRecord, true);
229 }
230 else
231 {
232 ContinueRanging(cid, rngrsp, ssRecord);
233 }
234 }
235}
236
237void
239{
241 {
242 SSRecord* ssRecord = m_bs->GetSSManager()->GetSSRecord(cid);
243 if (ssRecord->GetInvitedRangRetries() > 0)
244 {
246
247 if (ssRecord->GetInvitedRangRetries() == m_bs->GetMaxInvitedRangRetries())
248 {
249 auto rngrsp = new RngRsp();
250 AbortRanging(ssRecord->GetBasicCid(), rngrsp, ssRecord, true);
251 }
252 // else keep polling
253 }
254 }
255}
256
257void
259{
260 // code to calculate parameter adjustment values goes here
261 rngrsp->SetTimingAdjust(40);
262 rngrsp->SetPowerLevelAdjust(8);
263 rngrsp->SetOffsetFreqAdjust(30);
264}
265
266void
267BSLinkManager::AbortRanging(Cid cid, RngRsp* rngrsp, SSRecord* ssRecord, bool isOldSS)
268{
270 ScheduleRngRspMessage(cid, rngrsp);
271
272 if (isOldSS)
273 {
275 }
276
277 ssRecord->DisablePollForRanging();
278 DeallocateCids(cid);
279}
280
281void
283{
285 ScheduleRngRspMessage(cid, rngrsp);
286
287 /*Shall not be set until the SS receives the RNG-RSP, as it may be lost etc. may be state field
288 is also added to SSRecord which then set to SS_STATE_REGISTERED once confirmed that SS has
289 received this RNG-RSP, but how to determine that, may be as a data packet is received by the
290 SS*/
292
293 ssRecord->DisablePollForRanging();
294}
295
296void
303
304void
306{
309 {
310 SetParametersToAdjust(rngrsp);
311 }
312
314 p->AddHeader(*rngrsp);
316
317 m_bs->Enqueue(p, MacHeaderType(), m_bs->GetConnection(cid));
318}
319
320void
322{
323 // if necessary, delete entire connections or simply set CIDs to 0
324}
325
326uint64_t
328{
329 // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
330 // Section 12.3.3.1 from IEEE 802.16-2004 standard
331 // profR10_3 :
332 // channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165,
333 // 167 } temporarily set to 1 for quick scanning. To be standard compliant, use a value in the
334 // list above
335 return m_bs->GetChannel(1);
336}
337
338bool
340{
341 // code to decide if SS shall move to a new channel/frequency goes here
342 return false;
343}
344
347{
348 // code to determine suggested new frequency goes here
349 return 100;
350}
351
352uint8_t
354{
355 // code to measure signal quality goes here
356 uint8_t signalQuality = m_signalQuality;
358 return signalQuality;
359}
360
361bool
366
367} // namespace ns3
Cid class.
Definition cid.h:26
bool IsInitialRanging() const
Definition cid.cc:58
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
This class implements the ranging request message described by "IEEE Standard forLocal and metropolit...
uint8_t GetReqDlBurstProfile() const
Get request DL burst profile field.
void PrintDebug() const
Print debug function.
Mac48Address GetMacAddress() const
Get MAC address field.
This class implements the ranging response message described by "IEEE Standard forLocal and metropoli...
void SetMacAddress(Mac48Address macAddress)
set the MAC address
uint8_t GetRangStatus() const
void SetDlOperBurstProfile(uint16_t dlOperBurstProfile)
set the DL oper burst profile
void SetPowerLevelAdjust(uint8_t powerLevelAdjust)
set the relative change in transmission power level that the SS should make in order that transmissio...
void SetInitRangOppNumber(uint8_t initRangOppNumber)
set initial range opp number.
void SetTimingAdjust(uint32_t timingAdjust)
set the Tx timing offset adjustment (signed 32-bit).
void SetFrameNumber(uint32_t frameNumber)
set frame number.
void SetDlFreqOverride(uint32_t dlFreqOverride)
set the Center frequency, in kHz, of new downlink channel where the SS should redo initial ranging.
void SetOffsetFreqAdjust(uint32_t offsetFreqAdjust)
set the relative change in transmission frequency that the SS should take in order to better match th...
void SetRangStatus(uint8_t rangStatus)
set the range status.
This class is used by the base station to store some information related to subscriber station in the...
Definition ss-record.h:35
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set modulation type.
Definition ss-record.cc:150
Cid GetBasicCid() const
Get basic CID.
Definition ss-record.cc:84
void SetRangingStatus(WimaxNetDevice::RangingStatus rangingStatus)
Set ranging status.
Definition ss-record.cc:162
uint8_t GetInvitedRangRetries() const
Get invited range retries.
Definition ss-record.cc:132
void IncrementRangingCorrectionRetries()
Increment ranging correction retries.
Definition ss-record.cc:126
uint8_t GetRangingCorrectionRetries() const
Get ranging correction retries.
Definition ss-record.cc:114
void EnablePollForRanging()
Enable poll for ranging function.
Definition ss-record.cc:174
void ResetRangingCorrectionRetries()
Reset ranging correction retries.
Definition ss-record.cc:120
void ResetInvitedRangingRetries()
Reset invited ranging retries.
Definition ss-record.cc:138
void DisablePollForRanging()
Disable poll for ranging.
Definition ss-record.cc:180
void IncrementInvitedRangingRetries()
Increment invited ranging retries.
Definition ss-record.cc:144
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
ModulationType
ModulationType enumeration.
Definition wimax-phy.h:43
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Every class exported by the ns3 library is enclosed in the ns3 namespace.