A Discrete-Event Network Simulator
API
 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 
42 {
43  static TypeId tid = TypeId ("ns3::BSLinkManager")
44  .SetParent<Object> ();
45  return tid;
46 }
47 
49  : m_bs (bs),
50  m_signalQuality (10),
51  m_signalQualityThreshold (10) // arbitrary value
52 {
53  tries = 0;
54 }
55 
57 {
58  m_bs = 0;
59 }
60 
61 uint8_t
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
73 {
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
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
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
219 {
220  SSRecord *ssRecord = m_bs->GetSSManager ()->GetSSRecord (cid);
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
243 {
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
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 {
273  ScheduleRngRspMessage (cid, rngrsp);
274 
275  if (isOldSS)
276  {
278  }
279 
280  ssRecord->DisablePollForRanging ();
281  DeallocateCids (cid);
282 }
283 
284 void
286 {
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*/
294 
295  ssRecord->DisablePollForRanging ();
296 }
297 
298 void
300 {
302  ScheduleRngRspMessage (cid, rngrsp);
304 }
305 
306 void
308 {
311  {
312  SetParametersToAdjust (rngrsp);
313  }
314 
315  Ptr<Packet> p = Create<Packet> ();
316  p->AddHeader (*rngrsp);
318 
319  m_bs->Enqueue (p, MacHeaderType (), m_bs->GetConnection (cid));
320 }
321 
322 void
324 {
325  // if necessary, delete entire connections or simply set CIDs to 0
326 }
327 
328 uint64_t
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
341 {
342  // code to decide if SS shall move to a new channel/frequency goes here
343  return false;
344 }
345 
346 uint32_t
348 {
349  // code to determine suggested new frequency goes here
350  return 100;
351 }
352 
353 uint8_t
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
364 {
366 }
367 
368 } // namespace ns3
void IncrementRangingCorrectionRetries(void)
Definition: ss-record.cc:134
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
void SetPowerLevelAdjust(uint8_t powerLevelAdjust)
set the relative change in transmission power level that the SS should make in order that transmissio...
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:97
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
Cid GetBasicCid(void) const
Definition: ss-record.cc:92
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:41
uint8_t GetReqDlBurstProfile(void) const
void SetMacAddress(Mac48Address macAddress)
Doxygen introspection did not find any typical Config paths.
Definition: mac-messages.h:476
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Mac48Address GetMacAddress(void) const
void DisablePollForRanging(void)
Definition: ss-record.cc:188
void SetDlOperBurstProfile(uint16_t dlOperBurstProfile)
void SetModulationType(WimaxPhy::ModulationType modulationType)
Definition: ss-record.cc:158
void SetRangingStatus(WimaxNetDevice::RangingStatus rangingStatus)
Definition: ss-record.cc:170
void ResetInvitedRangingRetries(void)
Definition: ss-record.cc:146
void SetRangStatus(uint8_t rangStatus)
void ResetRangingCorrectionRetries(void)
Definition: ss-record.cc:128
bool IsInitialRanging(void) const
Definition: cid.cc:66
void EnablePollForRanging(void)
Definition: ss-record.cc:182
void SetTimingAdjust(uint32_t timingAdjust)
set the Tx timing offset adjustment (signed 32-bit).
void PrintDebug(void) const
Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
uint8_t GetRangingCorrectionRetries(void) const
Definition: ss-record.cc:122
uint8_t GetRangStatus(void) const
void IncrementInvitedRangingRetries(void)
Definition: ss-record.cc:152
Definition: cid.h:35
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)
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
void SetOffsetFreqAdjust(uint32_t offsetFreqAdjust)
set the relative change in transmission frequency that the SS should take in order to better match th...
#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:84
uint8_t GetInvitedRangRetries(void) const
Definition: ss-record.cc:140
void SetFrameNumber(uint32_t frameNumber)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:43
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253