A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ss-link-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008,2009 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
8 * <amine.ismail@UDcast.com>
9 */
10
11#include "ss-link-manager.h"
12
15
16#include "ns3/enum.h"
17#include "ns3/log.h"
18#include "ns3/node.h"
19#include "ns3/packet.h"
20#include "ns3/pointer.h"
21#include "ns3/simulator.h"
22
23#include <stdint.h>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("SSLinkManager");
29
30NS_OBJECT_ENSURE_REGISTERED(SSLinkManager);
31
32TypeId
34{
35 static TypeId tid = TypeId("ns3::SSLinkManager").SetParent<Object>().SetGroupName("Wimax");
36 return tid;
37}
38
40 : m_ss(ss),
41 m_rangingStatus(WimaxNetDevice::RANGING_STATUS_EXPIRED),
42 m_bsEirp(65535),
43 m_eirXPIrMax(65535),
44 m_pTxIrMax(0),
45 m_initRangOppNumber(0),
46 m_contentionRangingRetries(0),
47 m_rngReqFrameNumber(0),
48 m_dlChnlNr(0),
49 m_frequency(0),
50 m_rangingIntervalFound(false),
51 m_nrRngReqsSent(0),
52 m_nrRngRspsRecvd(0),
53 m_nrInvitedPollsRecvd(0),
54 m_rangingCW(0),
55 m_rangingBO(0),
56 m_nrRangingTransOpps(0),
57 m_isBackoffSet(false),
58 m_rangingAnomalies(0)
59{
60}
61
63{
64 m_ss = nullptr;
65}
66
67void
69{
70 m_ss = nullptr;
71}
72
73void
74SSLinkManager::SetBsEirp(uint16_t bs_eirp)
75{
76 m_bsEirp = bs_eirp;
77}
78
79void
80SSLinkManager::SetEirXPIrMax(uint16_t eir_x_p_ir_max)
81{
82 m_eirXPIrMax = eir_x_p_ir_max;
83}
84
85void
87{
88 m_rangingIntervalFound = rangingIntervalFound;
89}
90
91bool
96
97void
98SSLinkManager::SetNrRangingTransOpps(uint8_t nrRangingTransOpps)
99{
100 m_nrRangingTransOpps = nrRangingTransOpps;
101}
102
103void
105{
106 m_rangingCW = rangingCW;
107}
108
109void
114
120
121void
123{
124 // temp parameter "type" just to check on expiry of which event the function was called
125
126 if (deleteParameters)
127 {
129 }
130
131 NS_ASSERT_MSG(!m_ss->IsRegistered(),
132 "Subscriber Station: Error while scanning: Already registered with a BS");
133
135 {
136 m_dlChnlNr++;
137 }
138
139 // using max number of channel according to according to Section 8.5.1 of IEEE 802.16-2004
140 // standard.
141 if (m_dlChnlNr >= 200)
142 {
143 m_dlChnlNr = 0;
144 }
145
146 uint64_t dlChannel = m_ss->GetChannel(m_dlChnlNr);
147
149 m_ss->GetPhy()->StartScanning(dlChannel,
150 m_ss->GetIntervalT20(),
152}
153
154void
155SSLinkManager::EndScanning(bool status, uint64_t frequency)
156{
157 if (status)
158 {
160 m_frequency = frequency;
161 }
162 else
163 {
165 }
166}
167
168void
179
180void
181SSLinkManager::SendRangingRequest(uint8_t uiuc, uint16_t allocationSize)
182{
186 "SS: Error while sending a ranging request: the ss state should be "
187 "SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_WAITING_INV_RANG_INTRVL");
188
189 if (m_nrRngReqsSent == 0) // sending the first time
190 {
192 m_rngreq.SetReqDlBurstProfile(m_ss->GetBurstProfileManager()->GetBurstProfileToRequest());
193 m_rngreq.SetMacAddress(m_ss->GetMacAddress());
194 }
195 else
196 {
197 m_pTxIrMax++;
198 if (m_nrRngRspsRecvd > 0)
199 {
201 }
202 }
203
204 Ptr<Packet> packet = Create<Packet>();
206
207 packet->AddHeader(m_rngreq);
209
210 Ptr<WimaxConnection> connection;
211
213 {
214 connection = m_ss->GetBasicConnection();
215 }
216 else // have been assigned BCID, means currently adjusting parameters
217 {
218 connection = m_ss->GetInitialRangingConnection();
219 }
220
221 m_ss->Enqueue(packet, MacHeaderType(), connection);
222
224 m_ss->SetTimer(
228
229 NS_ASSERT_MSG(allocationSize ==
230 m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize() /
231 m_ss->GetPhy()->GetPsPerSymbol(),
232 "SS: Error while sending a ranging request: the allocation size is not correct");
233
234 // will work even if connection is not passed (i.e. null is passed) as scheduler will
235 // automatically select the same connection
236 m_ss->SendBurst(uiuc, allocationSize, connection);
237}
238
239void
241{
246 "SS: Can not start connection resolution: The SS state should be SS_STATE_WAITING_RNG_RSP "
247 "or SS_STATE_WAITING_REG_RANG_INTRVL or SS_STATE_ADJUSTING_PARAMETERS");
248
250 {
254 }
256 {
258 }
259
260 if (m_contentionRangingRetries == m_ss->GetMaxContentionRangingRetries())
261 {
263 }
264 else
265 {
266 if (!m_isBackoffSet)
267 {
269 }
270 }
271}
272
273void
275{
276 Time deferTime;
277 Time timeToAllocation;
278 uint16_t nrPsPerRangOpp = m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize();
279 uint16_t oppSize = m_ss->GetCurrentUcd().GetChannelEncodings().GetRangReqOppSize() /
280 m_ss->GetPhy()->GetPsPerSymbol();
281
282 for (uint8_t deferTOs = 0; deferTOs < m_nrRangingTransOpps; deferTOs++)
283 {
284 if (m_rangingBO == 0)
285 {
286 deferTime =
287 Seconds(deferTOs * nrPsPerRangOpp * m_ss->GetPhy()->GetPsDuration().GetSeconds());
288 timeToAllocation = m_ss->GetTimeToAllocation(deferTime);
289
290 Simulator::Schedule(timeToAllocation,
292 this,
294 oppSize);
295
296 m_rngReqFrameNumber = m_ss->GetNrFrames();
297 m_initRangOppNumber = deferTOs + 1;
298
299 m_isBackoffSet = false;
300 break;
301 }
302 m_rangingBO--;
303 }
304}
305
306void
308{
310 m_rangingCW != 0 && m_rangingBO == 0,
311 "be sure that CW has been set and BO is not already set"); // ensuring CW has been set and
312 // BO is not already set
313
314 m_rangingBO = (rand() % m_rangingCW);
315 m_isBackoffSet = true;
316}
317
318void
320{
322 std::min(uint8_t((m_rangingCW * 2 + 1) - 1), m_ss->GetCurrentUcd().GetRangingBackoffEnd());
323}
324
325void
327{
329 (uint8_t)std::pow(2.0, (double)m_ss->GetCurrentUcd().GetRangingBackoffStart()) - 1;
330}
331
332void
334{
335 // need to distinguish initial ranging or periodic ranging
336
337 if (cid == m_ss->GetInitialRangingConnection()->GetCid())
338 {
339 if (rngrsp.GetFrameNumber() == m_rngReqFrameNumber &&
341 {
344
345 // RNG-REQ was undecodable
349 return;
350 }
351
352 if (m_ss->GetAddress() != rngrsp.GetMacAddress())
353 {
354 return;
355 }
356
357 m_ss->SetBasicConnection(CreateObject<WimaxConnection>(rngrsp.GetBasicCid(), Cid::BASIC));
358
359 m_ss->SetPrimaryConnection(
361 m_ss->SetAreManagementConnectionsAllocated(true);
362 }
363 else
364 {
365 // either periodic ranging or an additional RNG-RSP during initial ranging
366 }
367
370 {
372 }
373
375
379 "SS: Can not perform ranging: the ranging status should be "
380 "RANGING_STATUS_CONTINUE or RANGING_STATUS_ABORT or RANGING_STATUS_SUCCESS");
381
383 {
384 if (rngrsp.GetDlFreqOverride())
385 {
386 // code to move to new channel/frequency goes here
387 }
388 // deassigning basic and primary CIDs
389 m_ss->SetBasicConnection(nullptr);
390 m_ss->SetPrimaryConnection(nullptr);
391 m_ss->SetAreManagementConnectionsAllocated(false);
392 }
393 else
394 {
396
398 {
400 // initiate service flows
401 if (m_ss->HasServiceFlows() && !m_ss->GetAreServiceFlowsAllocated())
402 {
403 m_ss->GetServiceFlowManager()->InitiateServiceFlows();
404 }
405
407 }
408 else
409 {
411 // wait for invited ranging interval assigned to its Basic CID
412 }
413 }
414}
415
416void
418{
419 m_ss->SetCurrentUcd(Ucd());
420}
421
422bool
424{
425 // don't know how to check if usable, see Figure 58.
426 return true; // temporarily assuming usable
427}
428
429void
431{
432#if 0 /* a template for future implementation following */
433 bool successful = true;
434 uint8_t temp = rngrsp.GetTimingAdjust ();
435 temp = rngrsp.GetPowerLevelAdjust ();
436 temp = rngrsp.GetOffsetFreqAdjust ();
437
438 // code for adjusting parameters goes here
439
440 if (!successful)
441 {
442 // code for setting ranging anomalies goes here
443 }
444#endif
445}
446
447void
449{
450 // code to nagotiate basic capabilities goes here, ignored until very advanced stages
451}
452
453uint16_t
455{
456 // SS obtains RSSI measurement from the OFDM downlink preambles using a complex formula, page
457 // 486
458 uint16_t rss = 1;
459
460 if (m_bsEirp == 65535 || m_eirXPIrMax == 65535)
461 {
463 }
464 else
465 {
466 return m_eirXPIrMax + m_bsEirp - rss;
467 }
468
469 return 0;
470}
471
472uint16_t
474{
475 // code to calculate minimum transmit power level of the SS, see page 189 of amendment
476 return 10; // temp
477}
478
479void
482 bool deleteUlParameters,
483 EventId& eventId)
484{
485 m_ss->SetTimer(Simulator::Schedule(interval,
487 this,
488 eventType,
489 deleteUlParameters),
490 eventId);
491}
492
493} // namespace ns3
Cid class.
Definition cid.h:26
@ PRIMARY
Definition cid.h:34
@ BASIC
Definition cid.h:33
An identifier for simulation events.
Definition event-id.h:45
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
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.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
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 forLocal and metropoli...
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:560
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:274
EventType
EventType enumeration.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
This class implements the UCD message as described by "IEEE Standard forLocal and metropolitan area n...
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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
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:684