A Discrete-Event Network Simulator
API
bs-link-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007,2008,2009 INRIA, UDcast
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@UDcast.com>
20  */
21 
22 #include "bs-link-manager.h"
23 
24 #include "bs-uplink-scheduler.h"
25 #include "burst-profile-manager.h"
26 #include "connection-manager.h"
27 #include "ss-manager.h"
28 #include "ss-record.h"
29 
30 #include "ns3/log.h"
31 #include "ns3/node.h"
32 #include "ns3/packet.h"
33 #include "ns3/simulator.h"
34 
35 #include <stdint.h>
36 
37 namespace ns3
38 {
39 
40 NS_LOG_COMPONENT_DEFINE("BSLinkManager");
41 
42 NS_OBJECT_ENSURE_REGISTERED(BSLinkManager);
43 
44 TypeId
46 {
47  static TypeId tid = TypeId("ns3::BSLinkManager").SetParent<Object>().SetGroupName("Wimax");
48  return tid;
49 }
50 
52  : m_bs(bs),
53  m_signalQuality(10),
54  m_signalQualityThreshold(10) // arbitrary value
55 {
56  tries = 0;
57 }
58 
60 {
61  m_bs = nullptr;
62 }
63 
64 uint8_t
66 {
67  // randomly selecting TOs up to 10, shall actually be decided by scheduler
68  return rand() % 8 + 2;
69 }
70 
71 /*
72  * Function mainly to avoid duplicate code in DoReceive ()
73  */
74 void
76 {
78  "Base station: Error while processing ranging request: !BS_STATE_UL_SUB_FRAME");
79 
80  Time irIntervalBoundary = Seconds(0);
81 
82  if (m_bs->GetUplinkScheduler()->GetIsInvIrIntrvlAllocated())
83  {
84  if (m_bs->GetUplinkScheduler()->GetIsIrIntrvlAllocated())
85  {
86  irIntervalBoundary =
87  m_bs->GetUlSubframeStartTime() +
88  Seconds((m_bs->GetUplinkScheduler()->GetNrIrOppsAllocated() + 1) *
89  m_bs->GetRangReqOppSize() * m_bs->GetSymbolDuration().GetSeconds());
90  }
91  else
92  {
93  irIntervalBoundary =
94  m_bs->GetUlSubframeStartTime() +
95  Seconds(m_bs->GetRangReqOppSize() * m_bs->GetSymbolDuration().GetSeconds());
96  }
97  }
98  else
99  {
101  m_bs->GetUplinkScheduler()->GetIsIrIntrvlAllocated(),
102  "Base station: Error while processing ranging request: IR interval not allocated");
103 
104  irIntervalBoundary =
105  m_bs->GetUlSubframeStartTime() +
106  Seconds(m_bs->GetUplinkScheduler()->GetNrIrOppsAllocated() * m_bs->GetRangReqOppSize() *
107  m_bs->GetSymbolDuration().GetSeconds());
108  }
109 
110  tries++;
111 
112  if (Simulator::Now() >= m_bs->GetUlSubframeStartTime() && Simulator::Now() < irIntervalBoundary)
113  {
114  PerformRanging(cid, rngreq);
115  }
116 }
117 
118 void
120 {
121  RngRsp rngrsp;
122  bool decodable = false;
123 
124  // assuming low power, packet lost or undecodable first 2 times
125  if (tries < 2)
126  {
127  return;
128  }
129  if (tries >= 3)
130  {
131  decodable = true;
132  }
133 
134  NS_LOG_DEBUG("RNG-REQ:");
135  rngreq.PrintDebug();
136 
137  if (!decodable)
138  {
139  rngrsp.SetFrameNumber(m_bs->GetNrFrames());
140  rngrsp.SetInitRangOppNumber(m_bs->GetRangingOppNumber());
141 
142  SetParametersToAdjust(&rngrsp);
144  ScheduleRngRspMessage(cid, &rngrsp);
145  }
146  else
147  {
148  if (cid.IsInitialRanging())
149  {
150  PerformInitialRanging(cid, &rngreq, &rngrsp);
151  }
152  else
153  {
154  // invited initial ranging or periodic ranging
155  PerformInvitedRanging(cid, &rngrsp);
156  }
157  }
158 }
159 
160 void
162 {
163  SSRecord* ssRecord = nullptr;
164  bool isOldSS = m_bs->GetSSManager()->IsInRecord(rngreq->GetMacAddress());
165  if (isOldSS)
166  {
167  ssRecord = m_bs->GetSSManager()->GetSSRecord(rngreq->GetMacAddress());
168  // if this fails it would mean the RNG-RSP with success status was not received by the SS
169  }
170  else
171  {
172  ssRecord = m_bs->GetSSManager()->CreateSSRecord(rngreq->GetMacAddress());
173  }
174 
175  if (ChangeDlChannel())
176  {
178  AbortRanging(cid, rngrsp, ssRecord, isOldSS);
179  return;
180  }
181 
182  if (isOldSS)
183  {
184  // CIDs already assigned, e.g., RNG-REQ was lost and resent after timeout. reusing old CIDs
185  ssRecord->ResetRangingCorrectionRetries();
186  ssRecord->ResetInvitedRangingRetries();
187  }
188  else
189  {
190  m_bs->GetConnectionManager()->AllocateManagementConnections(ssRecord, rngrsp);
191 
192  WimaxPhy::ModulationType modulationType;
193  uint8_t diuc =
194  m_bs->GetBurstProfileManager()->GetBurstProfileForSS(ssRecord, rngreq, modulationType);
195  ssRecord->SetModulationType(modulationType);
196 
197  // specify in RNG-RSP only if different than what SS requested
198  if (rngreq->GetReqDlBurstProfile() != diuc)
199  {
200  rngrsp->SetDlOperBurstProfile(diuc);
201  }
202 
203  // add SS (Basic CID) to poll list for invited ranging intervals, see Table 115
204  ssRecord->EnablePollForRanging();
205  }
206 
207  rngrsp->SetMacAddress(rngreq->GetMacAddress());
208 
209  if (isOldSS) // CIDs had already been allocated
210  {
211  cid = ssRecord->GetBasicCid();
212  }
213 
214  if (IsRangingAcceptable())
215  {
216  AcceptRanging(cid, rngrsp, ssRecord);
217  }
218  else
219  {
220  ContinueRanging(cid, rngrsp, ssRecord);
221  }
222 }
223 
224 void
226 {
227  SSRecord* ssRecord = m_bs->GetSSManager()->GetSSRecord(cid);
229  ssRecord->ResetInvitedRangingRetries();
230 
231  if (IsRangingAcceptable())
232  {
233  AcceptRanging(cid, rngrsp, ssRecord);
234  }
235  else
236  {
237  if (ssRecord->GetRangingCorrectionRetries() == m_bs->GetMaxRangingCorrectionRetries())
238  {
239  AbortRanging(cid, rngrsp, ssRecord, true);
240  }
241  else
242  {
243  ContinueRanging(cid, rngrsp, ssRecord);
244  }
245  }
246 }
247 
248 void
250 {
252  {
253  SSRecord* ssRecord = m_bs->GetSSManager()->GetSSRecord(cid);
254  if (ssRecord->GetInvitedRangRetries() > 0)
255  {
256  ssRecord->IncrementInvitedRangingRetries();
257 
258  if (ssRecord->GetInvitedRangRetries() == m_bs->GetMaxInvitedRangRetries())
259  {
260  auto rngrsp = new RngRsp();
261  AbortRanging(ssRecord->GetBasicCid(), rngrsp, ssRecord, true);
262  } // else keep polling
263  }
264  }
265 }
266 
267 void
269 {
270  // code to calculate parameter adjustment values goes here
271  rngrsp->SetTimingAdjust(40);
272  rngrsp->SetPowerLevelAdjust(8);
273  rngrsp->SetOffsetFreqAdjust(30);
274 }
275 
276 void
277 BSLinkManager::AbortRanging(Cid cid, RngRsp* rngrsp, SSRecord* ssRecord, bool isOldSS)
278 {
280  ScheduleRngRspMessage(cid, rngrsp);
281 
282  if (isOldSS)
283  {
285  }
286 
287  ssRecord->DisablePollForRanging();
288  DeallocateCids(cid);
289 }
290 
291 void
293 {
295  ScheduleRngRspMessage(cid, rngrsp);
296 
297  /*Shall not be set until the SS receives the RNG-RSP, as it may be lost etc. may be state field
298  is also added to SSRecord which then set to SS_STATE_REGISTERED once confirmed that SS has
299  received this RNG-RSP, but how to determine that, may be as a data packet is received by the
300  SS*/
302 
303  ssRecord->DisablePollForRanging();
304 }
305 
306 void
308 {
310  ScheduleRngRspMessage(cid, rngrsp);
312 }
313 
314 void
316 {
319  {
320  SetParametersToAdjust(rngrsp);
321  }
322 
323  Ptr<Packet> p = Create<Packet>();
324  p->AddHeader(*rngrsp);
326 
327  m_bs->Enqueue(p, MacHeaderType(), m_bs->GetConnection(cid));
328 }
329 
330 void
332 {
333  // if necessary, delete entire connections or simply set CIDs to 0
334 }
335 
336 uint64_t
338 {
339  // Values according to WirelessMAN-OFDM RF profile for 10 MHz channelization
340  // Section 12.3.3.1 from IEEE 802.16-2004 standard
341  // profR10_3 :
342  // channels: 5000 + n â‹… 5 MHz, ∀n ∈ { 147, 149, 151, 153, 155, 157, 159, 161, 163, 165,
343  // 167 } temporarily set to 1 for quick scanning. To be standard compliant, use a value in the
344  // list above
345  return m_bs->GetChannel(1);
346 }
347 
348 bool
350 {
351  // code to decide if SS shall move to a new channel/frequency goes here
352  return false;
353 }
354 
355 uint32_t
357 {
358  // code to determine suggested new frequency goes here
359  return 100;
360 }
361 
362 uint8_t
364 {
365  // code to measure signal quality goes here
366  uint8_t signalQuality = m_signalQuality;
367  m_signalQuality++;
368  return signalQuality;
369 }
370 
371 bool
373 {
375 }
376 
377 } // namespace ns3
Cid class.
Definition: cid.h:37
bool IsInitialRanging() const
Definition: cid.cc:69
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:89
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:268
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
This class implements the ranging request message described by "IEEE Standard for Local and metropoli...
Definition: mac-messages.h:664
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 for Local and metropol...
Definition: mac-messages.h:125
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:46
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set modulation type.
Definition: ss-record.cc:161
Cid GetBasicCid() const
Get basic CID.
Definition: ss-record.cc:95
void SetRangingStatus(WimaxNetDevice::RangingStatus rangingStatus)
Set ranging status.
Definition: ss-record.cc:173
uint8_t GetInvitedRangRetries() const
Get invited range retries.
Definition: ss-record.cc:143
void IncrementRangingCorrectionRetries()
Increment ranging correction retries.
Definition: ss-record.cc:137
uint8_t GetRangingCorrectionRetries() const
Get ranging correction retries.
Definition: ss-record.cc:125
void EnablePollForRanging()
Enable poll for ranging function.
Definition: ss-record.cc:185
void ResetRangingCorrectionRetries()
Reset ranging correction retries.
Definition: ss-record.cc:131
void ResetInvitedRangingRetries()
Reset invited ranging retries.
Definition: ss-record.cc:149
void DisablePollForRanging()
Disable poll for ranging.
Definition: ss-record.cc:191
void IncrementInvitedRangingRetries()
Increment invited ranging retries.
Definition: ss-record.cc:155
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.