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
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::RngRsp::SetDlFreqOverride
void SetDlFreqOverride(uint32_t dlFreqOverride)
set the Center frequency, in kHz, of new downlink channel where the SS should redo initial ranging.
Definition: mac-messages.cc:282
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::Cid
Cid class.
Definition: cid.h:38
ns3::RngRsp::SetRangStatus
void SetRangStatus(uint8_t rangStatus)
set the range status.
Definition: mac-messages.cc:276
ns3::RngRsp::SetDlOperBurstProfile
void SetDlOperBurstProfile(uint16_t dlOperBurstProfile)
set the DL oper burst profile
Definition: mac-messages.cc:294
ns3::RngReq::GetMacAddress
Mac48Address GetMacAddress(void) const
Get MAC address field.
Definition: mac-messages.cc:153
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RngRsp::GetRangStatus
uint8_t GetRangStatus(void) const
Definition: mac-messages.cc:360
ns3::OfdmUlBurstProfile::UIUC_INITIAL_RANGING
@ UIUC_INITIAL_RANGING
Definition: ul-mac-messages.h:209
ns3::ManagementMessageType
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43.
Definition: mac-messages.h:44
ns3::RngRsp::SetInitRangOppNumber
void SetInitRangOppNumber(uint8_t initRangOppNumber)
set initial range opp number.
Definition: mac-messages.cc:330
ns3::BaseStationNetDevice::BS_STATE_UL_SUB_FRAME
@ BS_STATE_UL_SUB_FRAME
Definition: bs-net-device.h:59
ns3::MacHeaderType
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
Definition: wimax-mac-header.h:37
ns3::SSRecord::ResetInvitedRangingRetries
void ResetInvitedRangingRetries(void)
Reset invited ranging retries.
Definition: ss-record.cc:146
ns3::RngReq::GetReqDlBurstProfile
uint8_t GetReqDlBurstProfile(void) const
Get request DL burst profile field.
Definition: mac-messages.cc:147
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
ns3::WimaxNetDevice::RANGING_STATUS_SUCCESS
@ RANGING_STATUS_SUCCESS
Definition: wimax-net-device.h:84
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::WimaxPhy::ModulationType
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:52
ns3::SSRecord::GetInvitedRangRetries
uint8_t GetInvitedRangRetries(void) const
Get invited range retries.
Definition: ss-record.cc:140
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::SSRecord
This class is used by the base station to store some information related to subscriber station in the...
Definition: ss-record.h:44
ns3::ManagementMessageType::MESSAGE_TYPE_RNG_RSP
@ MESSAGE_TYPE_RNG_RSP
Definition: mac-messages.h:54
ns3::RngRsp::SetMacAddress
void SetMacAddress(Mac48Address macAddress)
set the MAC address
Definition: mac-messages.cc:300
connection-manager.h
ns3::SSRecord::EnablePollForRanging
void EnablePollForRanging(void)
Enable poll for ranging function.
Definition: ss-record.cc:182
ns3::RngRsp::SetFrameNumber
void SetFrameNumber(uint32_t frameNumber)
set frame number.
Definition: mac-messages.cc:324
ns3::RngRsp::SetOffsetFreqAdjust
void SetOffsetFreqAdjust(uint32_t offsetFreqAdjust)
set the relative change in transmission frequency that the SS should take in order to better match th...
Definition: mac-messages.cc:270
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
ns3::SSRecord::IncrementInvitedRangingRetries
void IncrementInvitedRangingRetries(void)
Increment invited ranging retries.
Definition: ss-record.cc:152
NS_ASSERT_MSG
#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
ns3::Cid::IsInitialRanging
bool IsInitialRanging(void) const
Definition: cid.cc:66
ns3::WimaxNetDevice::RANGING_STATUS_CONTINUE
@ RANGING_STATUS_CONTINUE
Definition: wimax-net-device.h:82
ns3::RngReq::PrintDebug
void PrintDebug(void) const
Print debug function.
Definition: mac-messages.cc:195
ns3::SSRecord::GetRangingCorrectionRetries
uint8_t GetRangingCorrectionRetries(void) const
Get ranging correction retries.
Definition: ss-record.cc:122
uint32_t
ss-record.h
ns3::SSRecord::IncrementRangingCorrectionRetries
void IncrementRangingCorrectionRetries(void)
Increment ranging correction retries.
Definition: ss-record.cc:134
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::RngRsp::SetPowerLevelAdjust
void SetPowerLevelAdjust(uint8_t powerLevelAdjust)
set the relative change in transmission power level that the SS should make in order that transmissio...
Definition: mac-messages.cc:264
ns3::SSRecord::SetModulationType
void SetModulationType(WimaxPhy::ModulationType modulationType)
Set modulation type.
Definition: ss-record.cc:158
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
ns3::SSRecord::ResetRangingCorrectionRetries
void ResetRangingCorrectionRetries(void)
Reset ranging correction retries.
Definition: ss-record.cc:128
ss-manager.h
ns3::WimaxNetDevice::RANGING_STATUS_ABORT
@ RANGING_STATUS_ABORT
Definition: wimax-net-device.h:83
ns3::RngRsp::SetTimingAdjust
void SetTimingAdjust(uint32_t timingAdjust)
set the Tx timing offset adjustment (signed 32-bit).
Definition: mac-messages.cc:258
ns3::SSRecord::GetBasicCid
Cid GetBasicCid(void) const
Get basic CID.
Definition: ss-record.cc:92
ns3::SSRecord::SetRangingStatus
void SetRangingStatus(WimaxNetDevice::RangingStatus rangingStatus)
Set ranging status.
Definition: ss-record.cc:170
ns3::SSRecord::DisablePollForRanging
void DisablePollForRanging(void)
Disable poll for ranging.
Definition: ss-record.cc:188
ns3::RngRsp
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:122
burst-profile-manager.h
ns3::RngReq
This class implements the ranging request message described by "IEEE Standard for Local and metropoli...
Definition: mac-messages.h:643