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"
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 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("BSLinkManager");
38 
39 NS_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 
62 uint8_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  */
72 void
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 
112 void
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);
137  rngrsp.SetRangStatus (WimaxNetDevice::RANGING_STATUS_CONTINUE); // see Figure 64
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 
154 void
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  {
172  rngrsp->SetDlFreqOverride (GetNewDlChannel ());
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
180  ssRecord->ResetRangingCorrectionRetries ();
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 
218 void
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 
242 void
244 {
246  {
247  SSRecord *ssRecord = m_bs->GetSSManager ()->GetSSRecord (cid);
248  if (ssRecord->GetInvitedRangRetries () > 0)
249  {
250  ssRecord->IncrementInvitedRangingRetries ();
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 
261 void
263 {
264  // code to calculate parameter adjustment values goes here
265  rngrsp->SetTimingAdjust (40);
266  rngrsp->SetPowerLevelAdjust (8);
267  rngrsp->SetOffsetFreqAdjust (30);
268 }
269 
270 void
271 BSLinkManager::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 
285 void
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 
299 void
301 {
303  ScheduleRngRspMessage (cid, rngrsp);
305 }
306 
307 void
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 
323 void
325 {
326  // if necessary, delete entire connections or simply set CIDs to 0
327 }
328 
329 uint64_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 
340 bool
342 {
343  // code to decide if SS shall move to a new channel/frequency goes here
344  return false;
345 }
346 
347 uint32_t
349 {
350  // code to determine suggested new frequency goes here
351  return 100;
352 }
353 
354 uint8_t
356 {
357  // code to measure signal quality goes here
358  uint8_t signalQuality = m_signalQuality;
359  m_signalQuality++;
360  return signalQuality;
361 }
362 
363 bool
365 {
367 }
368 
369 } // namespace ns3
uint8_t GetReqDlBurstProfile(void) const
Get request DL burst profile field.
void IncrementRangingCorrectionRetries(void)
Increment ranging correction retries.
Definition: ss-record.cc:134
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetPowerLevelAdjust(uint8_t powerLevelAdjust)
set the relative change in transmission power level that the SS should make in order that transmissio...
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:121
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool IsInitialRanging(void) const
Definition: cid.cc:66
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43...
Definition: mac-messages.h:43
void SetMacAddress(Mac48Address macAddress)
set the MAC address
uint8_t GetRangingCorrectionRetries(void) const
Get ranging correction retries.
Definition: ss-record.cc:122
This class implements the ranging request message described by "IEEE Standard for Local and metropoli...
Definition: mac-messages.h:642
Mac48Address GetMacAddress(void) const
Get MAC address field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void DisablePollForRanging(void)
Disable poll for ranging.
Definition: ss-record.cc:188
void SetDlOperBurstProfile(uint16_t dlOperBurstProfile)
set the DL oper burst profile
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 ResetInvitedRangingRetries(void)
Reset invited ranging retries.
Definition: ss-record.cc:146
void SetRangStatus(uint8_t rangStatus)
set the range status.
void ResetRangingCorrectionRetries(void)
Reset ranging correction retries.
Definition: ss-record.cc:128
void PrintDebug(void) const
Print debug function.
void EnablePollForRanging(void)
Enable poll for ranging function.
Definition: ss-record.cc:182
void SetTimingAdjust(uint32_t timingAdjust)
set the Tx timing offset adjustment (signed 32-bit).
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers...
uint8_t GetInvitedRangRetries(void) const
Get invited range retries.
Definition: ss-record.cc:140
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void IncrementInvitedRangingRetries(void)
Increment invited ranging retries.
Definition: ss-record.cc:152
Cid class.
Definition: cid.h:37
void SetDlFreqOverride(uint32_t dlFreqOverride)
set the Center frequency, in kHz, of new downlink channel where the SS should redo initial ranging...
void SetInitRangOppNumber(uint8_t initRangOppNumber)
set initial range opp number.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
void SetOffsetFreqAdjust(uint32_t offsetFreqAdjust)
set the relative change in transmission frequency that the SS should take in order to better match th...
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:49
void SetFrameNumber(uint32_t frameNumber)
set frame number.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:43
Cid GetBasicCid(void) const
Get basic CID.
Definition: ss-record.cc:92
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint8_t GetRangStatus(void) const