A Discrete-Event Network Simulator
API
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"
30#include "ss-record.h"
31#include "ss-manager.h"
32#include "bs-uplink-scheduler.h"
33#include "connection-manager.h"
34
35namespace ns3 {
36
37NS_LOG_COMPONENT_DEFINE ("BSLinkManager");
38
39NS_OBJECT_ENSURE_REGISTERED (BSLinkManager);
40
42{
43 static TypeId tid = TypeId ("ns3::BSLinkManager")
44 .SetParent<Object> ()
45 .SetGroupName("Wimax");
46 return tid;
47}
48
50 : m_bs (bs),
51 m_signalQuality (10),
52 m_signalQualityThreshold (10) // arbitrary value
53{
54 tries = 0;
55}
56
58{
59 m_bs = 0;
60}
61
62uint8_t
64{
65 // randomly selecting TOs up to 10, shall actually be decided by scheduler
66 return rand () % 8 + 2;
67}
68
69/*
70 * Function mainly to avoid duplicate code in DoReceive ()
71 */
72void
74{
76 "Base station: Error while processing ranging request: !BS_STATE_UL_SUB_FRAME");
77
78 Time irIntervalBoundary = Seconds (0);
79
80 if (m_bs->GetUplinkScheduler ()->GetIsInvIrIntrvlAllocated ())
81 {
82 if (m_bs->GetUplinkScheduler ()->GetIsIrIntrvlAllocated ())
83 {
84 irIntervalBoundary = m_bs->GetUlSubframeStartTime ()
85 + Seconds ((m_bs->GetUplinkScheduler ()->GetNrIrOppsAllocated () + 1) * m_bs->GetRangReqOppSize ()
86 * m_bs->GetSymbolDuration ().GetSeconds ());
87 }
88 else
89 {
90 irIntervalBoundary = m_bs->GetUlSubframeStartTime () + Seconds (m_bs->GetRangReqOppSize ()
91 * m_bs->GetSymbolDuration ().GetSeconds ());
92 }
93 }
94 else
95 {
96 NS_ASSERT_MSG (m_bs->GetUplinkScheduler ()->GetIsIrIntrvlAllocated (),
97 "Base station: Error while processing ranging request: IR interval not allocated");
98
99 irIntervalBoundary = m_bs->GetUlSubframeStartTime ()
100 + Seconds (m_bs->GetUplinkScheduler ()->GetNrIrOppsAllocated () * m_bs->GetRangReqOppSize ()
101 * m_bs->GetSymbolDuration ().GetSeconds ());
102 }
103
104 tries++;
105
106 if (Simulator::Now () >= m_bs->GetUlSubframeStartTime () && Simulator::Now () < irIntervalBoundary)
107 {
108 PerformRanging (cid, rngreq);
109 }
110}
111
112void
114{
115 RngRsp rngrsp;
116 bool decodable = false;
117
118 // assuming low power, packet lost or undecodable first 2 times
119 if (tries < 2)
120 {
121 return;
122 }
123 if (tries >= 3)
124 {
125 decodable = true;
126 }
127
128 NS_LOG_DEBUG ("RNG-REQ:");
129 rngreq.PrintDebug ();
130
131 if (!decodable)
132 {
133 rngrsp.SetFrameNumber (m_bs->GetNrFrames ());
134 rngrsp.SetInitRangOppNumber (m_bs->GetRangingOppNumber ());
135
136 SetParametersToAdjust (&rngrsp);
138 ScheduleRngRspMessage (cid, &rngrsp);
139 }
140 else
141 {
142 if (cid.IsInitialRanging ())
143 {
144 PerformInitialRanging (cid, &rngreq, &rngrsp);
145 }
146 else
147 {
148 // invited initial ranging or periodic ranging
149 PerformInvitedRanging (cid, &rngrsp);
150 }
151 }
152}
153
154void
156{
157
158 SSRecord *ssRecord = 0;
159 bool isOldSS = m_bs->GetSSManager ()->IsInRecord (rngreq->GetMacAddress ());
160 if (isOldSS)
161 {
162 ssRecord = m_bs->GetSSManager ()->GetSSRecord (rngreq->GetMacAddress ());
163 // if this fails it would mean the RNG-RSP with success status was not received by the SS
164 }
165 else
166 {
167 ssRecord = m_bs->GetSSManager ()->CreateSSRecord (rngreq->GetMacAddress ());
168 }
169
170 if (ChangeDlChannel ())
171 {
173 AbortRanging (cid, rngrsp, ssRecord, isOldSS);
174 return;
175 }
176
177 if (isOldSS)
178 {
179 // CIDs already assigned, e.g., RNG-REQ was lost and resent after timeout. reusing old CIDs
181 ssRecord->ResetInvitedRangingRetries ();
182 }
183 else
184 {
185 m_bs->GetConnectionManager ()->AllocateManagementConnections (ssRecord, rngrsp);
186
187 WimaxPhy::ModulationType modulationType;
188 uint8_t diuc = m_bs->GetBurstProfileManager ()->GetBurstProfileForSS (ssRecord, rngreq, modulationType);
189 ssRecord->SetModulationType (modulationType);
190
191 // specify in RNG-RSP only if different than what SS requested
192 if (rngreq->GetReqDlBurstProfile () != diuc)
193 {
194 rngrsp->SetDlOperBurstProfile (diuc);
195 }
196
197 // add SS (Basic CID) to poll list for invited ranging intervals, see Table 115
198 ssRecord->EnablePollForRanging ();
199 }
200
201 rngrsp->SetMacAddress (rngreq->GetMacAddress ());
202
203 if (isOldSS) // CIDs had already been allocated
204 {
205 cid = ssRecord->GetBasicCid ();
206 }
207
208 if (IsRangingAcceptable ())
209 {
210 AcceptRanging (cid, rngrsp, ssRecord);
211 }
212 else
213 {
214 ContinueRanging (cid, rngrsp, ssRecord);
215 }
216}
217
218void
220{
221 SSRecord *ssRecord = m_bs->GetSSManager ()->GetSSRecord (cid);
223 ssRecord->ResetInvitedRangingRetries ();
224
225 if (IsRangingAcceptable ())
226 {
227 AcceptRanging (cid, rngrsp, ssRecord);
228 }
229 else
230 {
231 if (ssRecord->GetRangingCorrectionRetries () == m_bs->GetMaxRangingCorrectionRetries ())
232 {
233 AbortRanging (cid, rngrsp, ssRecord, true);
234 }
235 else
236 {
237 ContinueRanging (cid, rngrsp, ssRecord);
238 }
239 }
240}
241
242void
244{
246 {
247 SSRecord *ssRecord = m_bs->GetSSManager ()->GetSSRecord (cid);
248 if (ssRecord->GetInvitedRangRetries () > 0)
249 {
251
252 if (ssRecord->GetInvitedRangRetries () == m_bs->GetMaxInvitedRangRetries ())
253 {
254 RngRsp *rngrsp = new RngRsp ();
255 AbortRanging (ssRecord->GetBasicCid (), rngrsp, ssRecord, true);
256 } // else keep polling
257 }
258 }
259}
260
261void
263{
264 // code to calculate parameter adjustment values goes here
265 rngrsp->SetTimingAdjust (40);
266 rngrsp->SetPowerLevelAdjust (8);
267 rngrsp->SetOffsetFreqAdjust (30);
268}
269
270void
271BSLinkManager::AbortRanging (Cid cid, RngRsp *rngrsp, SSRecord *ssRecord, bool isOldSS)
272{
274 ScheduleRngRspMessage (cid, rngrsp);
275
276 if (isOldSS)
277 {
279 }
280
281 ssRecord->DisablePollForRanging ();
282 DeallocateCids (cid);
283}
284
285void
287{
289 ScheduleRngRspMessage (cid, rngrsp);
290
291 /*Shall not be set until the SS receives the RNG-RSP, as it may be lost etc. may be state field
292 is also added to SSRecord which then set to SS_STATE_REGISTERED once confirmed that SS has received
293 this RNG-RSP, but how to determine that, may be as a data packet is received by the SS*/
295
296 ssRecord->DisablePollForRanging ();
297}
298
299void
301{
303 ScheduleRngRspMessage (cid, rngrsp);
305}
306
307void
309{
312 {
313 SetParametersToAdjust (rngrsp);
314 }
315
316 Ptr<Packet> p = Create<Packet> ();
317 p->AddHeader (*rngrsp);
319
320 m_bs->Enqueue (p, MacHeaderType (), m_bs->GetConnection (cid));
321}
322
323void
325{
326 // if necessary, delete entire connections or simply set CIDs to 0
327}
328
329uint64_t
331{
332 // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
333 // Section 12.3.3.1 from IEEE 802.16-2004 standard
334 // profR10_3 :
335 // channels: 5000 + n ⋅ 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167 }
336 // temporarily set to 1 for quick scanning. To be standard compliant, use a value in the list above
337 return m_bs->GetChannel (1);
338}
339
340bool
342{
343 // code to decide if SS shall move to a new channel/frequency goes here
344 return false;
345}
346
349{
350 // code to determine suggested new frequency goes here
351 return 100;
352}
353
354uint8_t
356{
357 // code to measure signal quality goes here
358 uint8_t signalQuality = m_signalQuality;
360 return signalQuality;
361}
362
363bool
365{
367}
368
369} // namespace ns3
Cid class.
Definition: cid.h:38
bool IsInitialRanging(void) const
Definition: cid.cc:66
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.
Definition: mac-messages.h:44
A base class which provides memory management and object aggregation.
Definition: object.h:88
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
This class implements the ranging request message described by "IEEE Standard for Local and metropoli...
Definition: mac-messages.h:643
Mac48Address GetMacAddress(void) const
Get MAC address field.
uint8_t GetReqDlBurstProfile(void) const
Get request DL burst profile field.
void PrintDebug(void) const
Print debug function.
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:122
void SetMacAddress(Mac48Address macAddress)
set the MAC address
uint8_t GetRangStatus(void) 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:44
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set modulation type.
Definition: ss-record.cc:158
void SetRangingStatus(WimaxNetDevice::RangingStatus rangingStatus)
Set ranging status.
Definition: ss-record.cc:170
void EnablePollForRanging(void)
Enable poll for ranging function.
Definition: ss-record.cc:182
void DisablePollForRanging(void)
Disable poll for ranging.
Definition: ss-record.cc:188
uint8_t GetRangingCorrectionRetries(void) const
Get ranging correction retries.
Definition: ss-record.cc:122
void IncrementInvitedRangingRetries(void)
Increment invited ranging retries.
Definition: ss-record.cc:152
Cid GetBasicCid(void) const
Get basic CID.
Definition: ss-record.cc:92
void IncrementRangingCorrectionRetries(void)
Increment ranging correction retries.
Definition: ss-record.cc:134
void ResetRangingCorrectionRetries(void)
Reset ranging correction retries.
Definition: ss-record.cc:128
uint8_t GetInvitedRangRetries(void) const
Get invited range retries.
Definition: ss-record.cc:140
void ResetInvitedRangingRetries(void)
Reset invited ranging retries.
Definition: ss-record.cc:146
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:52
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.