A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
bs-link-manager.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007,2008,2009 INRIA, UDcast
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19
* Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20
* <amine.ismail@UDcast.com>
21
*/
22
23
#include "
bs-link-manager.h
"
24
#include <stdint.h>
25
#include "ns3/node.h"
26
#include "ns3/packet.h"
27
#include "ns3/simulator.h"
28
#include "ns3/log.h"
29
#include "
burst-profile-manager.h
"
30
#include "
ss-record.h
"
31
#include "
ss-manager.h
"
32
#include "
bs-uplink-scheduler.h
"
33
#include "
connection-manager.h
"
34
35
NS_LOG_COMPONENT_DEFINE
(
"BSLinkManager"
);
36
37
namespace
ns3 {
38
39
NS_OBJECT_ENSURE_REGISTERED
(BSLinkManager);
40
41
TypeId
BSLinkManager::GetTypeId
(
void
)
42
{
43
static
TypeId
tid =
TypeId
(
"ns3::BSLinkManager"
)
44
.
SetParent
<
Object
> ();
45
return
tid;
46
}
47
48
BSLinkManager::BSLinkManager
(
Ptr<BaseStationNetDevice>
bs)
49
: m_bs (bs),
50
m_signalQuality (10),
51
m_signalQualityThreshold (10)
// arbitrary value
52
{
53
tries
= 0;
54
}
55
56
BSLinkManager::~BSLinkManager
(
void
)
57
{
58
m_bs
= 0;
59
}
60
61
uint8_t
62
BSLinkManager::CalculateRangingOppsToAllocate
(
void
)
63
{
64
// randomly selecting TOs up to 10, shall actually be decided by scheduler
65
return
rand () % 8 + 2;
66
}
67
68
/*
69
* Function mainly to avoid duplicate code in DoReceive ()
70
*/
71
void
72
BSLinkManager::ProcessRangingRequest
(
Cid
cid,
RngReq
rngreq)
73
{
74
NS_ASSERT_MSG
(
m_bs
->
GetState
() ==
BaseStationNetDevice::BS_STATE_UL_SUB_FRAME
,
75
"Base station: Error while processing ranging request: !BS_STATE_UL_SUB_FRAME"
);
76
77
Time
irIntervalBoundary =
Seconds
(0);
78
79
if
(
m_bs
->
GetUplinkScheduler
()->
GetIsInvIrIntrvlAllocated
())
80
{
81
if
(
m_bs
->
GetUplinkScheduler
()->
GetIsIrIntrvlAllocated
())
82
{
83
irIntervalBoundary =
m_bs
->
GetUlSubframeStartTime
()
84
+
Seconds
((
m_bs
->
GetUplinkScheduler
()->
GetNrIrOppsAllocated
() + 1) *
m_bs
->
GetRangReqOppSize
()
85
*
m_bs
->
GetSymbolDuration
().
GetSeconds
());
86
}
87
else
88
{
89
irIntervalBoundary =
m_bs
->
GetUlSubframeStartTime
() +
Seconds
(
m_bs
->
GetRangReqOppSize
()
90
*
m_bs
->
GetSymbolDuration
().
GetSeconds
());
91
}
92
}
93
else
94
{
95
NS_ASSERT_MSG
(
m_bs
->
GetUplinkScheduler
()->
GetIsIrIntrvlAllocated
(),
96
"Base station: Error while processing ranging request: IR interval not allocated"
);
97
98
irIntervalBoundary =
m_bs
->
GetUlSubframeStartTime
()
99
+
Seconds
(
m_bs
->
GetUplinkScheduler
()->
GetNrIrOppsAllocated
() *
m_bs
->
GetRangReqOppSize
()
100
*
m_bs
->
GetSymbolDuration
().
GetSeconds
());
101
}
102
103
tries
++;
104
105
if
(
Simulator::Now
() >=
m_bs
->
GetUlSubframeStartTime
() &&
Simulator::Now
() < irIntervalBoundary)
106
{
107
PerformRanging
(cid, rngreq);
108
}
109
}
110
111
void
112
BSLinkManager::PerformRanging
(
Cid
cid,
RngReq
rngreq)
113
{
114
RngRsp
rngrsp;
115
bool
decodable =
false
;
116
117
// assuming low power, packet lost or undecodable first 2 times
118
if
(
tries
< 2)
119
{
120
return
;
121
}
122
if
(
tries
>= 3)
123
{
124
decodable =
true
;
125
}
126
127
NS_LOG_DEBUG
(
"RNG-REQ:"
);
128
rngreq.
PrintDebug
();
129
130
if
(!decodable)
131
{
132
rngrsp.
SetFrameNumber
(
m_bs
->
GetNrFrames
());
133
rngrsp.
SetInitRangOppNumber
(
m_bs
->
GetRangingOppNumber
());
134
135
SetParametersToAdjust
(&rngrsp);
136
rngrsp.
SetRangStatus
(
WimaxNetDevice::RANGING_STATUS_CONTINUE
);
// see Figure 64
137
ScheduleRngRspMessage
(cid, &rngrsp);
138
}
139
else
140
{
141
if
(cid.
IsInitialRanging
())
142
{
143
PerformInitialRanging
(cid, &rngreq, &rngrsp);
144
}
145
else
146
{
147
// invited initial ranging or periodic ranging
148
PerformInvitedRanging
(cid, &rngrsp);
149
}
150
}
151
}
152
153
void
154
BSLinkManager::PerformInitialRanging
(
Cid
cid,
RngReq
*rngreq,
RngRsp
*rngrsp)
155
{
156
157
SSRecord
*ssRecord = 0;
158
bool
isOldSS =
m_bs
->
GetSSManager
()->
IsInRecord
(rngreq->
GetMacAddress
());
159
if
(isOldSS)
160
{
161
ssRecord =
m_bs
->
GetSSManager
()->
GetSSRecord
(rngreq->
GetMacAddress
());
162
// if this fails it would mean the RNG-RSP with success status was not received by the SS
163
}
164
else
165
{
166
ssRecord =
m_bs
->
GetSSManager
()->
CreateSSRecord
(rngreq->
GetMacAddress
());
167
}
168
169
if
(
ChangeDlChannel
())
170
{
171
rngrsp->
SetDlFreqOverride
(
GetNewDlChannel
());
172
AbortRanging
(cid, rngrsp, ssRecord, isOldSS);
173
return
;
174
}
175
176
if
(isOldSS)
177
{
178
// CIDs already assigned, e.g., RNG-REQ was lost and resent after timeout. reusing old CIDs
179
ssRecord->
ResetRangingCorrectionRetries
();
180
ssRecord->
ResetInvitedRangingRetries
();
181
}
182
else
183
{
184
m_bs
->
GetConnectionManager
()->
AllocateManagementConnections
(ssRecord, rngrsp);
185
186
WimaxPhy::ModulationType
modulationType;
187
uint8_t diuc =
m_bs
->
GetBurstProfileManager
()->
GetBurstProfileForSS
(ssRecord, rngreq, modulationType);
188
ssRecord->
SetModulationType
(modulationType);
189
190
// specify in RNG-RSP only if different than what SS requested
191
if
(rngreq->
GetReqDlBurstProfile
() != diuc)
192
{
193
rngrsp->
SetDlOperBurstProfile
(diuc);
194
}
195
196
// add SS (Basic CID) to poll list for invited ranging intervals, see Table 115
197
ssRecord->
EnablePollForRanging
();
198
}
199
200
rngrsp->
SetMacAddress
(rngreq->
GetMacAddress
());
201
202
if
(isOldSS)
// CIDs had already been allocated
203
{
204
cid = ssRecord->
GetBasicCid
();
205
}
206
207
if
(
IsRangingAcceptable
())
208
{
209
AcceptRanging
(cid, rngrsp, ssRecord);
210
}
211
else
212
{
213
ContinueRanging
(cid, rngrsp, ssRecord);
214
}
215
}
216
217
void
218
BSLinkManager::PerformInvitedRanging
(
Cid
cid,
RngRsp
*rngrsp)
219
{
220
SSRecord
*ssRecord =
m_bs
->
GetSSManager
()->
GetSSRecord
(cid);
221
ssRecord->
IncrementRangingCorrectionRetries
();
222
ssRecord->
ResetInvitedRangingRetries
();
223
224
if
(
IsRangingAcceptable
())
225
{
226
AcceptRanging
(cid, rngrsp, ssRecord);
227
}
228
else
229
{
230
if
(ssRecord->
GetRangingCorrectionRetries
() ==
m_bs
->
GetMaxRangingCorrectionRetries
())
231
{
232
AbortRanging
(cid, rngrsp, ssRecord,
true
);
233
}
234
else
235
{
236
ContinueRanging
(cid, rngrsp, ssRecord);
237
}
238
}
239
}
240
241
void
242
BSLinkManager::VerifyInvitedRanging
(
Cid
cid, uint8_t uiuc)
243
{
244
if
(uiuc ==
OfdmUlBurstProfile::UIUC_INITIAL_RANGING
)
245
{
246
SSRecord
*ssRecord =
m_bs
->
GetSSManager
()->
GetSSRecord
(cid);
247
if
(ssRecord->
GetInvitedRangRetries
() > 0)
248
{
249
ssRecord->
IncrementInvitedRangingRetries
();
250
251
if
(ssRecord->
GetInvitedRangRetries
() ==
m_bs
->
GetMaxInvitedRangRetries
())
252
{
253
RngRsp
*rngrsp =
new
RngRsp
();
254
AbortRanging
(ssRecord->
GetBasicCid
(), rngrsp, ssRecord,
true
);
255
}
// else keep polling
256
}
257
}
258
}
259
260
void
261
BSLinkManager::SetParametersToAdjust
(
RngRsp
*rngrsp)
262
{
263
// code to calculate parameter adjustment values goes here
264
rngrsp->
SetTimingAdjust
(40);
265
rngrsp->
SetPowerLevelAdjust
(8);
266
rngrsp->
SetOffsetFreqAdjust
(30);
267
}
268
269
void
270
BSLinkManager::AbortRanging
(
Cid
cid,
RngRsp
*rngrsp,
SSRecord
*ssRecord,
bool
isOldSS)
271
{
272
rngrsp->
SetRangStatus
(
WimaxNetDevice::RANGING_STATUS_ABORT
);
273
ScheduleRngRspMessage
(cid, rngrsp);
274
275
if
(isOldSS)
276
{
277
ssRecord->
SetRangingStatus
(
WimaxNetDevice::RANGING_STATUS_ABORT
);
278
}
279
280
ssRecord->
DisablePollForRanging
();
281
DeallocateCids
(cid);
282
}
283
284
void
285
BSLinkManager::AcceptRanging
(
Cid
cid,
RngRsp
*rngrsp,
SSRecord
*ssRecord)
286
{
287
rngrsp->
SetRangStatus
(
WimaxNetDevice::RANGING_STATUS_SUCCESS
);
288
ScheduleRngRspMessage
(cid, rngrsp);
289
290
/*Shall not be set until the SS receives the RNG-RSP, as it may be lost etc. may be state field
291
is also added to SSRecord which then set to SS_STATE_REGISTERED once confirmed that SS has received
292
this RNG-RSP, but how to determine that, may be as a data packet is received by the SS*/
293
ssRecord->
SetRangingStatus
(
WimaxNetDevice::RANGING_STATUS_SUCCESS
);
294
295
ssRecord->
DisablePollForRanging
();
296
}
297
298
void
299
BSLinkManager::ContinueRanging
(
Cid
cid,
RngRsp
*rngrsp,
SSRecord
*ssRecord)
300
{
301
rngrsp->
SetRangStatus
(
WimaxNetDevice::RANGING_STATUS_CONTINUE
);
302
ScheduleRngRspMessage
(cid, rngrsp);
303
ssRecord->
SetRangingStatus
(
WimaxNetDevice::RANGING_STATUS_CONTINUE
);
304
}
305
306
void
307
BSLinkManager::ScheduleRngRspMessage
(
Cid
cid,
RngRsp
*rngrsp)
308
{
309
if
(rngrsp->
GetRangStatus
() ==
WimaxNetDevice::RANGING_STATUS_SUCCESS
|| rngrsp->
GetRangStatus
()
310
==
WimaxNetDevice::RANGING_STATUS_CONTINUE
)
311
{
312
SetParametersToAdjust
(rngrsp);
313
}
314
315
Ptr<Packet>
p = Create<Packet> ();
316
p->
AddHeader
(*rngrsp);
317
p->
AddHeader
(
ManagementMessageType
(
ManagementMessageType::MESSAGE_TYPE_RNG_RSP
));
318
319
m_bs
->
Enqueue
(p,
MacHeaderType
(),
m_bs
->
GetConnection
(cid));
320
}
321
322
void
323
BSLinkManager::DeallocateCids
(
Cid
cid)
324
{
325
// if necessary, delete entire connections or simply set CIDs to 0
326
}
327
328
uint64_t
329
BSLinkManager::SelectDlChannel
(
void
)
330
{
331
// Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
332
// Section 12.3.3.1 from IEEE 802.16-2004 standard
333
// profR10_3 :
334
// channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
335
// temporarily set to 1 for quick scanning. To be standard compliant, use a value in the list above
336
return
m_bs
->
GetChannel
(1);
337
}
338
339
bool
340
BSLinkManager::ChangeDlChannel
(
void
)
341
{
342
// code to decide if SS shall move to a new channel/frequency goes here
343
return
false
;
344
}
345
346
uint32_t
347
BSLinkManager::GetNewDlChannel
(
void
)
348
{
349
// code to determine suggested new frequency goes here
350
return
100;
351
}
352
353
uint8_t
354
BSLinkManager::GetSignalQuality
(
void
)
355
{
356
// code to measure signal quality goes here
357
uint8_t signalQuality =
m_signalQuality
;
358
m_signalQuality
++;
359
return
signalQuality;
360
}
361
362
bool
363
BSLinkManager::IsRangingAcceptable
(
void
)
364
{
365
return
GetSignalQuality
() >
m_signalQualityThreshold
;
366
}
367
368
}
// namespace ns3
src
wimax
model
bs-link-manager.cc
Generated on Tue Oct 9 2012 16:45:49 for ns-3 by
1.8.1.2