A Discrete-Event Network Simulator
API
ss-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 "ss-link-manager.h"
23 
24 #include "burst-profile-manager.h"
25 #include "service-flow-manager.h"
26 
27 #include "ns3/enum.h"
28 #include "ns3/log.h"
29 #include "ns3/node.h"
30 #include "ns3/packet.h"
31 #include "ns3/pointer.h"
32 #include "ns3/simulator.h"
33 
34 #include <stdint.h>
35 
36 namespace ns3
37 {
38 
39 NS_LOG_COMPONENT_DEFINE("SSLinkManager");
40 
41 NS_OBJECT_ENSURE_REGISTERED(SSLinkManager);
42 
43 TypeId
45 {
46  static TypeId tid = TypeId("ns3::SSLinkManager").SetParent<Object>().SetGroupName("Wimax");
47  return tid;
48 }
49 
51  : m_ss(ss),
52  m_rangingStatus(WimaxNetDevice::RANGING_STATUS_EXPIRED),
53  m_bsEirp(65535),
54  m_eirXPIrMax(65535),
55  m_pTxIrMax(0),
56  m_initRangOppNumber(0),
57  m_contentionRangingRetries(0),
58  m_rngReqFrameNumber(0),
59  m_dlChnlNr(0),
60  m_frequency(0),
61  m_rangingIntervalFound(false),
62  m_nrRngReqsSent(0),
63  m_nrRngRspsRecvd(0),
64  m_nrInvitedPollsRecvd(0),
65  m_rangingCW(0),
66  m_rangingBO(0),
67  m_nrRangingTransOpps(0),
68  m_isBackoffSet(false),
69  m_rangingAnomalies(0)
70 {
71 }
72 
74 {
75  m_ss = nullptr;
76 }
77 
78 void
80 {
81  m_ss = nullptr;
82 }
83 
84 void
85 SSLinkManager::SetBsEirp(uint16_t bs_eirp)
86 {
87  m_bsEirp = bs_eirp;
88 }
89 
90 void
91 SSLinkManager::SetEirXPIrMax(uint16_t eir_x_p_ir_max)
92 {
93  m_eirXPIrMax = eir_x_p_ir_max;
94 }
95 
96 void
97 SSLinkManager::SetRangingIntervalFound(bool rangingIntervalFound)
98 {
99  m_rangingIntervalFound = rangingIntervalFound;
100 }
101 
102 bool
104 {
105  return m_rangingIntervalFound;
106 }
107 
108 void
109 SSLinkManager::SetNrRangingTransOpps(uint8_t nrRangingTransOpps)
110 {
111  m_nrRangingTransOpps = nrRangingTransOpps;
112 }
113 
114 void
115 SSLinkManager::SetRangingCW(uint8_t rangingCW)
116 {
117  m_rangingCW = rangingCW;
118 }
119 
120 void
122 {
124 }
125 
126 EventId
128 {
130 }
131 
132 void
134 {
135  // temp parameter "type" just to check on expiry of which event the function was called
136 
137  if (deleteParameters)
138  {
140  }
141 
142  NS_ASSERT_MSG(!m_ss->IsRegistered(),
143  "Subscriber Station: Error while scanning: Already registered with a BS");
144 
146  {
147  m_dlChnlNr++;
148  }
149 
150  // using max number of channel according to according to Section 8.5.1 of IEEE 802.16-2004
151  // standard.
152  if (m_dlChnlNr >= 200)
153  {
154  m_dlChnlNr = 0;
155  }
156 
157  uint64_t dlChannel = m_ss->GetChannel(m_dlChnlNr);
158 
160  m_ss->GetPhy()->StartScanning(dlChannel,
161  m_ss->GetIntervalT20(),
163 }
164 
165 void
166 SSLinkManager::EndScanning(bool status, uint64_t frequency)
167 {
168  if (status)
169  {
171  m_frequency = frequency;
172  }
173  else
174  {
176  }
177 }
178 
179 void
181 {
183  m_ss->SetTimer(Simulator::Schedule(m_ss->GetIntervalT21(),
185  this,
187  false),
189 }
190 
191 void
192 SSLinkManager::SendRangingRequest(uint8_t uiuc, uint16_t allocationSize)
193 {
197  "SS: Error while sending a ranging request: the ss state should be "
198  "SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_WAITING_INV_RANG_INTRVL");
199 
200  if (m_nrRngReqsSent == 0) // sending the first time
201  {
203  m_rngreq.SetReqDlBurstProfile(m_ss->GetBurstProfileManager()->GetBurstProfileToRequest());
204  m_rngreq.SetMacAddress(m_ss->GetMacAddress());
205  }
206  else
207  {
208  m_pTxIrMax++;
209  if (m_nrRngRspsRecvd > 0)
210  {
212  }
213  }
214 
215  Ptr<Packet> packet = Create<Packet>();
216  Ptr<PacketBurst> burst = Create<PacketBurst>();
217 
218  packet->AddHeader(m_rngreq);
220 
221  Ptr<WimaxConnection> connection;
222 
224  {
225  connection = m_ss->GetBasicConnection();
226  }
227  else // have been assigned BCID, means currently adjusting parameters
228  {
229  connection = m_ss->GetInitialRangingConnection();
230  }
231 
232  m_ss->Enqueue(packet, MacHeaderType(), connection);
233 
235  m_ss->SetTimer(
238  m_nrRngReqsSent++;
239 
240  NS_ASSERT_MSG(allocationSize ==
241  m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize() /
242  m_ss->GetPhy()->GetPsPerSymbol(),
243  "SS: Error while sending a ranging request: the allocation size is not correct");
244 
245  // will work even if connection is not passed (i.e. null is passed) as scheduler will
246  // automatically select the same connection
247  m_ss->SendBurst(uiuc, allocationSize, connection);
248 }
249 
250 void
252 {
257  "SS: Can not start connection resolution: The SS state should be SS_STATE_WAITING_RNG_RSP "
258  "or SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_ADJUSTING_PARAMETERS");
259 
261  {
265  }
267  {
269  }
270 
271  if (m_contentionRangingRetries == m_ss->GetMaxContentionRangingRetries())
272  {
274  }
275  else
276  {
277  if (!m_isBackoffSet)
278  {
280  }
281  }
282 }
283 
284 void
286 {
287  Time deferTime = Seconds(0);
288  Time timeToAllocation = Seconds(0);
289  uint16_t nrPsPerRangOpp = m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize();
290  uint16_t oppSize = m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize() /
291  m_ss->GetPhy()->GetPsPerSymbol();
292 
293  for (uint8_t deferTOs = 0; deferTOs < m_nrRangingTransOpps; deferTOs++)
294  {
295  if (m_rangingBO == 0)
296  {
297  deferTime =
298  Seconds(deferTOs * nrPsPerRangOpp * m_ss->GetPhy()->GetPsDuration().GetSeconds());
299  timeToAllocation = m_ss->GetTimeToAllocation(deferTime);
300 
301  Simulator::Schedule(timeToAllocation,
303  this,
305  oppSize);
306 
307  m_rngReqFrameNumber = m_ss->GetNrFrames();
308  m_initRangOppNumber = deferTOs + 1;
309 
310  m_isBackoffSet = false;
311  break;
312  }
313  m_rangingBO--;
314  }
315 }
316 
317 void
319 {
321  m_rangingCW != 0 && m_rangingBO == 0,
322  "be sure that CW has been set and BO is not already set"); // ensuring CW has been set and
323  // BO is not already set
324 
325  m_rangingBO = (rand() % m_rangingCW);
326  m_isBackoffSet = true;
327 }
328 
329 void
331 {
332  m_rangingCW =
333  std::min(uint8_t((m_rangingCW * 2 + 1) - 1), m_ss->GetCurrentUcd().GetRangingBackoffEnd());
334 }
335 
336 void
338 {
339  m_rangingCW =
340  (uint8_t)std::pow(2.0, (double)m_ss->GetCurrentUcd().GetRangingBackoffStart()) - 1;
341 }
342 
343 void
345 {
346  // need to distinguish initial ranging or periodic ranging
347 
348  if (cid == m_ss->GetInitialRangingConnection()->GetCid())
349  {
350  if (rngrsp.GetFrameNumber() == m_rngReqFrameNumber &&
352  {
355 
356  // RNG-REQ was undecodable
358  AdjustRangingParameters(rngrsp);
360  return;
361  }
362 
363  if (m_ss->GetAddress() != rngrsp.GetMacAddress())
364  {
365  return;
366  }
367 
368  m_ss->SetBasicConnection(CreateObject<WimaxConnection>(rngrsp.GetBasicCid(), Cid::BASIC));
369 
370  m_ss->SetPrimaryConnection(
371  CreateObject<WimaxConnection>(rngrsp.GetPrimaryCid(), Cid::PRIMARY));
372  m_ss->SetAreManagementConnectionsAllocated(true);
373  }
374  else
375  {
376  // either periodic ranging or an additional RNG-RSP during initial ranging
377  }
378 
381  {
383  }
384 
386 
390  "SS: Can not perform ranging: the ranging status should be "
391  "RANGING_STATUS_CONTINUE or RANGING_STATUS_ABORT or RANGING_STATUS_SUCCESS");
392 
394  {
395  if (rngrsp.GetDlFreqOverride())
396  {
397  // code to move to new channel/frequency goes here
398  }
399  // deassigning basic and primary CIDs
400  m_ss->SetBasicConnection(nullptr);
401  m_ss->SetPrimaryConnection(nullptr);
402  m_ss->SetAreManagementConnectionsAllocated(false);
403  }
404  else
405  {
406  AdjustRangingParameters(rngrsp);
407 
409  {
411  // initiate service flows
412  if (m_ss->HasServiceFlows() && !m_ss->GetAreServiceFlowsAllocated())
413  {
414  m_ss->GetServiceFlowManager()->InitiateServiceFlows();
415  }
416 
418  }
419  else
420  {
422  // wait for invited ranging interval assigned to its Basic CID
423  }
424  }
425 }
426 
427 void
429 {
430  m_ss->SetCurrentUcd(Ucd());
431 }
432 
433 bool
435 {
436  // don't know how to check if usable, see Figure 58.
437  return true; // temporarily assuming usable
438 }
439 
440 void
442 {
443 #if 0 /* a template for future implementation following */
444  bool successful = true;
445  uint8_t temp = rngrsp.GetTimingAdjust ();
446  temp = rngrsp.GetPowerLevelAdjust ();
447  temp = rngrsp.GetOffsetFreqAdjust ();
448 
449  // code for adjusting parameters goes here
450 
451  if (!successful)
452  {
453  // code for setting ranging anomalies goes here
454  }
455 #endif
456 }
457 
458 void
460 {
461  // code to nagotiate basic capabilities goes here, ignored until very advanced stages
462 }
463 
464 uint16_t
466 {
467  // SS obtains RSSI measurement from the OFDM downlink preambles using a complex formula, page
468  // 486
469  uint16_t rss = 1;
470 
471  if (m_bsEirp == 65535 || m_eirXPIrMax == 65535)
472  {
473  return GetMinTransmitPowerLevel();
474  }
475  else
476  {
477  return m_eirXPIrMax + m_bsEirp - rss;
478  }
479 
480  return 0;
481 }
482 
483 uint16_t
485 {
486  // code to calculate minimum transmit power level of the SS, see page 189 of amendment
487  return 10; // temp
488 }
489 
490 void
493  bool deleteUlParameters,
494  EventId& eventId)
495 {
496  m_ss->SetTimer(Simulator::Schedule(interval,
498  this,
499  eventType,
500  deleteUlParameters),
501  eventId);
502 }
503 
504 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
Cid class.
Definition: cid.h:37
@ PRIMARY
Definition: cid.h:45
@ BASIC
Definition: cid.h:44
An identifier for simulation events.
Definition: event-id.h:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
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
void SetReqDlBurstProfile(uint8_t reqDlBurstProfile)
Set request DL burst profile field.
void SetRangingAnomalies(uint8_t rangingAnomalies)
Set ranging anomalies field.
void SetMacAddress(Mac48Address macAddress)
Set MAC address field.
This class implements the ranging response message described by "IEEE Standard for Local and metropol...
Definition: mac-messages.h:125
Mac48Address GetMacAddress() const
uint32_t GetTimingAdjust() const
Cid GetPrimaryCid() const
uint8_t GetPowerLevelAdjust() const
uint8_t GetRangStatus() const
uint32_t GetOffsetFreqAdjust() const
uint32_t GetDlFreqOverride() const
Cid GetBasicCid() const
uint32_t GetFrameNumber() const
uint8_t GetInitRangOppNumber() const
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:285
EventType
EventType enumeration.
Definition: ss-net-device.h:70
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
This class implements the UCD message as described by "IEEE Standard for Local and metropolitan area ...
Hold together all WiMAX-related objects in a NetDevice.
RangingStatus
RangingStatus enumeration.
#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_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.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704