23 #include "ss-link-manager.h"
26 #include "ns3/packet.h"
27 #include "ns3/simulator.h"
29 #include "ns3/pointer.h"
31 #include "burst-profile-manager.h"
32 #include "service-flow-manager.h"
38 NS_OBJECT_ENSURE_REGISTERED (SSLinkManager);
40 TypeId SSLinkManager::GetTypeId (
void)
42 static TypeId tid = TypeId (
"ns3::SSLinkManager")
43 .SetParent<Object> ();
47 SSLinkManager::SSLinkManager (Ptr<SubscriberStationNetDevice> ss)
49 m_rangingStatus (WimaxNetDevice::RANGING_STATUS_EXPIRED),
53 m_initRangOppNumber (0),
54 m_contentionRangingRetries (0),
55 m_rngReqFrameNumber (0),
58 m_rangingIntervalFound (false),
61 m_nrInvitedPollsRecvd (0),
64 m_nrRangingTransOpps (0),
65 m_isBackoffSet (false),
66 m_rangingAnomalies (0)
71 SSLinkManager::~SSLinkManager (
void)
84 SSLinkManager::SetBsEirp (uint16_t bs_eirp)
90 SSLinkManager::SetEirXPIrMax (uint16_t eir_x_p_ir_max)
92 m_eirXPIrMax = eir_x_p_ir_max;
96 SSLinkManager::SetRangingIntervalFound (
bool rangingIntervalFound)
98 m_rangingIntervalFound = rangingIntervalFound;
102 SSLinkManager::GetRangingIntervalFound (
void)
const
104 return m_rangingIntervalFound;
108 SSLinkManager::SetNrRangingTransOpps (uint8_t nrRangingTransOpps)
110 m_nrRangingTransOpps = nrRangingTransOpps;
114 SSLinkManager::SetRangingCW (uint8_t rangingCW)
116 m_rangingCW = rangingCW;
120 SSLinkManager::IncrementNrInvitedPollsRecvd (
void)
122 m_nrInvitedPollsRecvd++;
126 SSLinkManager::GetDlMapSyncTimeoutEvent (
void)
128 return m_dlMapSyncTimeoutEvent;
132 SSLinkManager::StartScanning (
133 SubscriberStationNetDevice::EventType type,
bool deleteParameters)
137 if (deleteParameters)
139 DeleteUplinkParameters ();
143 "Subscriber Station: Error while scanning: Already registered with a BS");
145 if (m_ss->GetState () != SubscriberStationNetDevice::SS_STATE_IDLE)
151 if (m_dlChnlNr >= 200)
156 uint64_t dlChannel = m_ss->GetChannel (m_dlChnlNr);
158 m_ss->SetState (SubscriberStationNetDevice::SS_STATE_SCANNING);
159 m_ss->GetPhy ()->StartScanning (dlChannel, m_ss->GetIntervalT20 (),
164 SSLinkManager::EndScanning (
bool status, uint64_t frequency)
168 StartSynchronizing ();
169 m_frequency = frequency;
173 StartScanning (SubscriberStationNetDevice::EVENT_NONE,
false);
178 SSLinkManager::StartSynchronizing (
void)
180 m_ss->SetState (SubscriberStationNetDevice::SS_STATE_SYNCHRONIZING);
182 &SSLinkManager::StartScanning,
this,
183 SubscriberStationNetDevice::EVENT_DL_MAP_SYNC_TIMEOUT,
false),
184 m_dlMapSyncTimeoutEvent);
188 SSLinkManager::SendRangingRequest (uint8_t uiuc, uint16_t allocationSize)
192 == SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL
194 == SubscriberStationNetDevice::SS_STATE_WAITING_INV_RANG_INTRVL,
195 "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 if (m_nrRngReqsSent == 0)
199 m_pTxIrMax = CalculateMaxIRSignalStrength ();
200 m_rngreq.SetReqDlBurstProfile (
201 m_ss->GetBurstProfileManager ()->GetBurstProfileToRequest ());
202 m_rngreq.SetMacAddress (m_ss->GetMacAddress ());
207 if (m_nrRngRspsRecvd > 0)
209 m_rngreq.SetRangingAnomalies (m_rangingAnomalies);
213 Ptr<Packet> packet = Create<Packet> ();
214 Ptr<PacketBurst> burst = Create<PacketBurst> ();
216 packet->AddHeader (m_rngreq);
217 packet->AddHeader (ManagementMessageType (
218 ManagementMessageType::MESSAGE_TYPE_RNG_REQ));
220 Ptr<WimaxConnection> connection;
222 if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_CONTINUE)
224 connection = m_ss->GetBasicConnection ();
228 connection = m_ss->GetInitialRangingConnection ();
231 m_ss->Enqueue (packet, MacHeaderType (), connection);
233 m_ss->SetState (SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP);
235 &SSLinkManager::StartContentionResolution,
this), m_waitForRngRspEvent);
239 == m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ()
240 / m_ss->GetPhy ()->GetPsPerSymbol (),
241 "SS: Error while sending a ranging request: the allocation size is not correct");
244 m_ss->SendBurst (uiuc, allocationSize, connection);
248 SSLinkManager::StartContentionResolution (
void)
252 == SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP
254 == SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL
256 == SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS,
257 "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 if (m_ss->GetState ()
260 == SubscriberStationNetDevice::SS_STATE_WAITING_RNG_RSP)
263 SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL);
264 IncreaseRangingRequestCW ();
265 m_contentionRangingRetries++;
267 else if (m_ss->GetState ()
268 == SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS)
271 SubscriberStationNetDevice::SS_STATE_WAITING_REG_RANG_INTRVL);
274 if (m_contentionRangingRetries == m_ss->GetMaxContentionRangingRetries ())
276 StartScanning (SubscriberStationNetDevice::EVENT_NONE,
false);
282 SelectRandomBackoff ();
288 SSLinkManager::PerformBackoff (
void)
291 Time timeToAllocation =
Seconds (0);
292 uint16_t nrPsPerRangOpp =
293 m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ();
295 m_ss->GetCurrentUcd ().GetChannelEncodings ().GetRangReqOppSize ()
296 / m_ss->GetPhy ()->GetPsPerSymbol ();
298 for (uint8_t deferTOs = 0; deferTOs < m_nrRangingTransOpps; deferTOs++)
300 if (m_rangingBO == 0)
302 defferTime =
Seconds (deferTOs * nrPsPerRangOpp
303 * m_ss->GetPhy ()->GetPsDuration ().GetSeconds ());
304 timeToAllocation = m_ss->GetTimeToAllocation (defferTime);
307 &SSLinkManager::SendRangingRequest,
this,
308 OfdmUlBurstProfile::UIUC_INITIAL_RANGING, oppSize);
310 m_rngReqFrameNumber = m_ss->GetNrFrames ();
311 m_initRangOppNumber = deferTOs + 1;
313 m_isBackoffSet =
false;
321 SSLinkManager::SelectRandomBackoff (
void)
324 "be sure that CW has been set and BO is not already set");
326 m_rangingBO = (rand () % m_rangingCW);
327 m_isBackoffSet =
true;
331 SSLinkManager::IncreaseRangingRequestCW (
void)
333 m_rangingCW = std::min (uint8_t ((m_rangingCW * 2 + 1) - 1),
334 m_ss->GetCurrentUcd ().GetRangingBackoffEnd ());
338 SSLinkManager::ResetRangingRequestCW (
void)
340 m_rangingCW = (uint8_t) std::pow ((
double) 2,
341 (double) m_ss->GetCurrentUcd ().GetRangingBackoffStart ()) - 1;
345 SSLinkManager::PerformRanging (Cid cid,
350 if (cid == m_ss->GetInitialRangingConnection ()->GetCid ())
352 if (rngrsp.GetFrameNumber () == m_rngReqFrameNumber
353 && rngrsp.GetInitRangOppNumber () == m_initRangOppNumber)
359 ResetRangingRequestCW ();
360 AdjustRangingParameters (rngrsp);
362 SubscriberStationNetDevice::SS_STATE_ADJUSTING_PARAMETERS);
366 if (m_ss->GetAddress () != rngrsp.GetMacAddress ())
371 m_ss->SetBasicConnection (CreateObject<WimaxConnection> (rngrsp.GetBasicCid (),
374 m_ss->SetPrimaryConnection (CreateObject<WimaxConnection> (rngrsp.GetPrimaryCid (),
376 m_ss->SetAreManagementConnectionsAllocated (
true);
389 m_rangingStatus = (WimaxNetDevice::RangingStatus) rngrsp.GetRangStatus ();
392 m_rangingStatus == WimaxNetDevice::RANGING_STATUS_CONTINUE
393 || m_rangingStatus == WimaxNetDevice::RANGING_STATUS_ABORT
394 || m_rangingStatus == WimaxNetDevice::RANGING_STATUS_SUCCESS,
395 "SS: Can not perform ranging: the ranging status should be RANGING_STATUS_CONTINUE or RANGING_STATUS_ABORT or RANGING_STATUS_SUCCESS");
397 if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_ABORT)
399 if (rngrsp.GetDlFreqOverride ())
404 m_ss->SetBasicConnection (0);
405 m_ss->SetPrimaryConnection (0);
406 m_ss->SetAreManagementConnectionsAllocated (
false);
410 AdjustRangingParameters (rngrsp);
412 if (m_rangingStatus == WimaxNetDevice::RANGING_STATUS_SUCCESS)
415 m_ss->SetState (SubscriberStationNetDevice::SS_STATE_REGISTERED);
417 if (m_ss->HasServiceFlows () && !m_ss->GetAreServiceFlowsAllocated ())
419 m_ss->GetServiceFlowManager ()->InitiateServiceFlows ();
422 NegotiateBasicCapabilities ();
428 SubscriberStationNetDevice::SS_STATE_WAITING_INV_RANG_INTRVL);
435 SSLinkManager::DeleteUplinkParameters (
void)
437 m_ss->SetCurrentUcd (Ucd ());
441 SSLinkManager::IsUlChannelUsable (
void)
448 SSLinkManager::AdjustRangingParameters (
const RngRsp &rngrsp)
451 bool successful =
true;
452 uint8_t temp = rngrsp.GetTimingAdjust ();
453 temp = rngrsp.GetPowerLevelAdjust ();
454 temp = rngrsp.GetOffsetFreqAdjust ();
466 SSLinkManager::NegotiateBasicCapabilities (
void)
472 SSLinkManager::CalculateMaxIRSignalStrength (
void)
477 if (m_bsEirp == 65535 || m_eirXPIrMax == 65535)
479 return GetMinTransmitPowerLevel ();
483 return m_eirXPIrMax + m_bsEirp - rss;
490 SSLinkManager::GetMinTransmitPowerLevel (
void)
497 SSLinkManager::ScheduleScanningRestart (Time interval,
498 SubscriberStationNetDevice::EventType eventType,
499 bool deleteUlParameters, EventId &eventId)
502 this, eventType, deleteUlParameters), eventId);
#define NS_LOG_COMPONENT_DEFINE(name)
static void Cancel(const EventId &id)
bool IsRunning(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
#define NS_ASSERT_MSG(condition, message)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.