A Discrete-Event Network Simulator
API
ss-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 "ss-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 "ns3/pointer.h"
30 #include "ns3/enum.h"
31 #include "burst-profile-manager.h"
32 #include "service-flow-manager.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("SSLinkManager");
37 
38 NS_OBJECT_ENSURE_REGISTERED (SSLinkManager);
39 
41 {
42  static TypeId tid = TypeId ("ns3::SSLinkManager")
43  .SetParent<Object> ()
44  .SetGroupName("Wimax");
45  return tid;
46 }
47 
49  : m_ss (ss),
50  m_rangingStatus (WimaxNetDevice::RANGING_STATUS_EXPIRED),
51  m_bsEirp (65535),
52  m_eirXPIrMax (65535),
53  m_pTxIrMax (0),
54  m_initRangOppNumber (0),
55  m_contentionRangingRetries (0),
56  m_rngReqFrameNumber (0),
57  m_dlChnlNr (0),
58  m_frequency (0),
59  m_rangingIntervalFound (false),
60  m_nrRngReqsSent (0),
61  m_nrRngRspsRecvd (0),
62  m_nrInvitedPollsRecvd (0),
63  m_rangingCW (0),
64  m_rangingBO (0),
65  m_nrRangingTransOpps (0),
66  m_isBackoffSet (false),
67  m_rangingAnomalies (0)
68 {
69 
70 }
71 
73 {
74  m_ss = 0;
75 }
76 
77 
78 void
80 {
81  m_ss = 0;
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  SubscriberStationNetDevice::EventType type, bool deleteParameters)
135 {
136  // temp parameter "type" just to check on expiry of which event the function was called
137 
138  if (deleteParameters)
139  {
141  }
142 
143  NS_ASSERT_MSG (!m_ss->IsRegistered (),
144  "Subscriber Station: Error while scanning: Already registered with a BS");
145 
147  {
148  m_dlChnlNr++;
149  }
150 
151  // using max number of channel according to according to Section 8.5.1 of IEEE 802.16-2004 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, m_ss->GetIntervalT20 (),
162 }
163 
164 void
165 SSLinkManager::EndScanning (bool status, uint64_t frequency)
166 {
167  if (status)
168  {
170  m_frequency = frequency;
171  }
172  else
173  {
175  }
176 }
177 
178 void
180 {
182  m_ss->SetTimer (Simulator::Schedule (m_ss->GetIntervalT21 (),
186 }
187 
188 void
189 SSLinkManager::SendRangingRequest (uint8_t uiuc, uint16_t allocationSize)
190 {
191  NS_ASSERT_MSG (
192  m_ss->GetState ()
194  || m_ss->GetState ()
196  "SS: Error while sending a ranging request: the ss state should be SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_WAITING_INV_RANG_INTRVL");
197 
198  if (m_nrRngReqsSent == 0) // sending the first time
199  {
202  m_ss->GetBurstProfileManager ()->GetBurstProfileToRequest ());
203  m_rngreq.SetMacAddress (m_ss->GetMacAddress ());
204  }
205  else
206  {
207  m_pTxIrMax++;
208  if (m_nrRngRspsRecvd > 0)
209  {
211  }
212  }
213 
214  Ptr<Packet> packet = Create<Packet> ();
215  Ptr<PacketBurst> burst = Create<PacketBurst> ();
216 
217  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 (Simulator::Schedule (m_ss->GetIntervalT3 (),
237  m_nrRngReqsSent++;
238 
239  NS_ASSERT_MSG (allocationSize
240  == m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ()
241  / m_ss->GetPhy ()->GetPsPerSymbol (),
242  "SS: Error while sending a ranging request: the allocation size is not correct");
243 
244  // will work even if connection is not passed (i.e. null is passed) as scheduler will automatically select the same connection
245  m_ss->SendBurst (uiuc, allocationSize, connection);
246 }
247 
248 void
250 {
251  NS_ASSERT_MSG (
252  m_ss->GetState ()
254  || m_ss->GetState ()
256  || m_ss->GetState ()
258  "SS: Can not start connection resolution: The SS state should be SS_STATE_WAITING_RNG_RSP or SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_ADJUSTING_PARAMETERS");
259 
260  if (m_ss->GetState ()
262  {
263  m_ss->SetState (
267  }
268  else if (m_ss->GetState ()
270  {
271  m_ss->SetState (
273  }
274 
275  if (m_contentionRangingRetries == m_ss->GetMaxContentionRangingRetries ())
276  {
278  }
279  else
280  {
281  if (!m_isBackoffSet)
282  {
284  }
285  }
286 }
287 
288 void
290 {
291  Time defferTime = Seconds (0);
292  Time timeToAllocation = Seconds (0);
293  uint16_t nrPsPerRangOpp =
294  m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ();
295  uint16_t oppSize =
296  m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ()
297  / m_ss->GetPhy ()->GetPsPerSymbol ();
298 
299  for (uint8_t deferTOs = 0; deferTOs < m_nrRangingTransOpps; deferTOs++)
300  {
301  if (m_rangingBO == 0)
302  {
303  defferTime = Seconds (deferTOs * nrPsPerRangOpp
304  * m_ss->GetPhy ()->GetPsDuration ().GetSeconds ());
305  timeToAllocation = m_ss->GetTimeToAllocation (defferTime);
306 
307  Simulator::Schedule (timeToAllocation,
310 
311  m_rngReqFrameNumber = m_ss->GetNrFrames ();
312  m_initRangOppNumber = deferTOs + 1;
313 
314  m_isBackoffSet = false;
315  break;
316  }
317  m_rangingBO--;
318  }
319 }
320 
321 void
323 {
324  NS_ASSERT_MSG (m_rangingCW != 0 && m_rangingBO == 0,
325  "be sure that CW has been set and BO is not already set"); // ensuring CW has been set and BO is not already set
326 
327  m_rangingBO = (rand () % m_rangingCW);
328  m_isBackoffSet = true;
329 }
330 
331 void
333 {
334  m_rangingCW = std::min (uint8_t ((m_rangingCW * 2 + 1) - 1),
335  m_ss->GetCurrentUcd ().GetRangingBackoffEnd ());
336 }
337 
338 void
340 {
341  m_rangingCW = (uint8_t) std::pow ((double) 2,
342  (double) m_ss->GetCurrentUcd ().GetRangingBackoffStart ()) - 1;
343 }
344 
345 void
347  RngRsp rngrsp)
348 {
349  // need to distinguish initial ranging or periodic ranging
350 
351  if (cid == m_ss->GetInitialRangingConnection ()->GetCid ())
352  {
353  if (rngrsp.GetFrameNumber () == m_rngReqFrameNumber
355  {
358 
359  // RNG-REQ was undecodable
361  AdjustRangingParameters (rngrsp);
362  m_ss->SetState (
364  return;
365  }
366 
367  if (m_ss->GetAddress () != rngrsp.GetMacAddress ())
368  {
369  return;
370  }
371 
372  m_ss->SetBasicConnection (CreateObject<WimaxConnection> (rngrsp.GetBasicCid (),
373  Cid::BASIC));
374 
375  m_ss->SetPrimaryConnection (CreateObject<WimaxConnection> (rngrsp.GetPrimaryCid (),
376  Cid::PRIMARY));
377  m_ss->SetAreManagementConnectionsAllocated (true);
378  }
379  else
380  {
381  // either periodic ranging or an additional RNG-RSP during initial ranging
382  }
383 
386  {
388  }
389 
391 
392  NS_ASSERT_MSG (
396  "SS: Can not perform ranging: the ranging status should be RANGING_STATUS_CONTINUE or RANGING_STATUS_ABORT or RANGING_STATUS_SUCCESS");
397 
399  {
400  if (rngrsp.GetDlFreqOverride ())
401  {
402  // code to move to new channel/frequency goes here
403  }
404  // deassigning basic and primary CIDs
405  m_ss->SetBasicConnection (0);
406  m_ss->SetPrimaryConnection (0);
407  m_ss->SetAreManagementConnectionsAllocated (false);
408  }
409  else
410  {
411  AdjustRangingParameters (rngrsp);
412 
414  {
415 
417  // initiate service flows
418  if (m_ss->HasServiceFlows () && !m_ss->GetAreServiceFlowsAllocated ())
419  {
420  m_ss->GetServiceFlowManager ()->InitiateServiceFlows ();
421  }
422 
424  }
425  else
426  {
427 
428  m_ss->SetState (
430  // wait for invited ranging interval assigned to its Basic CID
431  }
432  }
433 }
434 
435 void
437 {
438  m_ss->SetCurrentUcd (Ucd ());
439 }
440 
441 bool
443 {
444  // don't know how to check if usable, see Figure 58.
445  return true; // temporarily assuming usable
446 }
447 
448 void
450 {
451 #if 0 /* a template for future implementation following */
452  bool successful = true;
453  uint8_t temp = rngrsp.GetTimingAdjust ();
454  temp = rngrsp.GetPowerLevelAdjust ();
455  temp = rngrsp.GetOffsetFreqAdjust ();
456 
457  // code for adjusting parameters goes here
458 
459  if (!successful)
460  {
461  // code for setting ranging anomalies goes here
462  }
463 #endif
464 }
465 
466 void
468 {
469  // code to nagotiate basic capabilities goes here, ignored until very advanced stages
470 }
471 
472 uint16_t
474 {
475  // SS obtains RSSI measurement from the OFDM downlink preambles using a complex formula, page 486
476  uint16_t rss = 1;
477 
478  if (m_bsEirp == 65535 || m_eirXPIrMax == 65535)
479  {
480  return GetMinTransmitPowerLevel ();
481  }
482  else
483  {
484  return m_eirXPIrMax + m_bsEirp - rss;
485  }
486 
487  return 0;
488 }
489 
490 uint16_t
492 {
493  // code to calculate minimum transmit power level of the SS, see page 189 of amendment
494  return 10; // temp
495 }
496 
497 void
500  bool deleteUlParameters, EventId &eventId)
501 {
503  this, eventType, deleteUlParameters), eventId);
504 }
505 
506 } // namespace ns3
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
void SetMacAddress(Mac48Address macAddress)
Set MAC address field.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetReqDlBurstProfile(uint8_t reqDlBurstProfile)
Set request DL burst profile field.
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
#define min(a, b)
Definition: 80211b.c:42
Mac Management messages Section 6.3.2.3 MAC Management messages page 42, Table 14 page 43...
Definition: mac-messages.h:43
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint32_t GetTimingAdjust(void) const
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
Definition: simulator.cc:268
Cid GetPrimaryCid(void) const
Cid GetBasicCid(void) const
EventType
EventType enumeration.
Definition: ss-net-device.h:68
uint32_t GetDlFreqOverride(void) const
This class implements the UCD message as described by "IEEE Standard for Local and metropolitan area ...
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers...
Hold together all WiMAX-related objects in a NetDevice.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Cid class.
Definition: cid.h:37
uint32_t GetOffsetFreqAdjust(void) const
uint32_t GetFrameNumber(void) const
uint8_t GetInitRangOppNumber(void) const
#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
Mac48Address GetMacAddress(void) const
An identifier for simulation events.
Definition: event-id.h:53
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1278
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
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
RangingStatus
RangingStatus enumeration.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint8_t GetRangStatus(void) const
void SetRangingAnomalies(uint8_t rangingAnomalies)
Set ranging anomalies field.
uint8_t GetPowerLevelAdjust(void) const