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
70
71 if (m_bs->GetUplinkScheduler()->GetIsInvIrIntrvlAllocated())
72 {
73 if (m_bs->GetUplinkScheduler()->GetIsIrIntrvlAllocated())
74 {
76 m_bs->GetUlSubframeStartTime() +
77 Seconds((m_bs->GetUplinkScheduler()->GetNrIrOppsAllocated() + 1) *
78 m_bs->GetRangReqOppSize() * m_bs->GetSymbolDuration().GetSeconds());
79 }
80 else
81 {
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
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 {
104 }
105}
106
107void
109{
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
132 rngrsp.SetRangStatus(WimaxNetDevice::RANGING_STATUS_CONTINUE); // see Figure 64
134 }
135 else
136 {
137 if (cid.IsInitialRanging())
138 {
140 }
141 else
142 {
143 // invited initial ranging or periodic ranging
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 {
166 rngrsp->SetDlFreqOverride(GetNewDlChannel());
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
174 ssRecord->ResetRangingCorrectionRetries();
175 ssRecord->ResetInvitedRangingRetries();
176 }
177 else
178 {
179 m_bs->GetConnectionManager()->AllocateManagementConnections(ssRecord, rngrsp);
180
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 {
206 }
207 else
208 {
210 }
211}
212
213void
215{
216 SSRecord* ssRecord = m_bs->GetSSManager()->GetSSRecord(cid);
218 ssRecord->ResetInvitedRangingRetries();
219
221 {
223 }
224 else
225 {
226 if (ssRecord->GetRangingCorrectionRetries() == m_bs->GetMaxRangingCorrectionRetries())
227 {
229 }
230 else
231 {
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 } // else keep polling
252 }
253 }
254}
255
256void
258{
259 // code to calculate parameter adjustment values goes here
260 rngrsp->SetTimingAdjust(40);
261 rngrsp->SetPowerLevelAdjust(8);
262 rngrsp->SetOffsetFreqAdjust(30);
263}
264
265void
267{
270
271 if (isOldSS)
272 {
274 }
275
276 ssRecord->DisablePollForRanging();
278}
279
280void
282{
285
286 /*Shall not be set until the SS receives the RNG-RSP, as it may be lost etc. may be state field
287 is also added to SSRecord which then set to SS_STATE_REGISTERED once confirmed that SS has
288 received this RNG-RSP, but how to determine that, may be as a data packet is received by the
289 SS*/
291
292 ssRecord->DisablePollForRanging();
293}
294
295void
302
303void
305{
306 if (rngrsp->GetRangStatus() == WimaxNetDevice::RANGING_STATUS_SUCCESS ||
308 {
310 }
311
313 p->AddHeader(*rngrsp);
315
316 m_bs->Enqueue(p, MacHeaderType(), m_bs->GetConnection(cid));
317}
318
319void
321{
322 // if necessary, delete entire connections or simply set CIDs to 0
323}
324
325uint64_t
327{
328 // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
329 // Section 12.3.3.1 from IEEE 802.16-2004 standard
330 // profR10_3 :
331 // channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165,
332 // 167 } temporarily set to 1 for quick scanning. To be standard compliant, use a value in the
333 // list above
334 return m_bs->GetChannel(1);
335}
336
337bool
339{
340 // code to decide if SS shall move to a new channel/frequency goes here
341 return false;
342}
343
346{
347 // code to determine suggested new frequency goes here
348 return 100;
349}
350
351uint8_t
353{
354 // code to measure signal quality goes here
357 return signalQuality;
358}
359
360bool
365
366} // namespace ns3
Cid class.
Definition cid.h:26
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.
Definition ptr.h:66
This class implements the ranging request message described by "IEEE Standard for Local and metropoli...
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
This class is used by the base station to store some information related to subscriber station in the...
Definition ss-record.h:35
void IncrementRangingCorrectionRetries()
Increment ranging correction retries.
Definition ss-record.cc:126
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:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.