void DcfManagerTest::AddRxStartEvt (uint64_t at, uint64_t duration) { Simulator::Schedule (MicroSeconds (at) - Now (), &DcfManager::NotifyRxStartNow, m_dcfManager, MicroSeconds (duration)); }
void DcfManagerTest::StartTest (uint64_t slotTime, uint64_t sifs, uint64_t eifsNoDifsNoSifs, uint32_t ackTimeoutValue) { m_dcfManager = new DcfManager (); m_dcfManager->SetSlot (MicroSeconds (slotTime)); m_dcfManager->SetSifs (MicroSeconds (sifs)); m_dcfManager->SetEifsNoDifs (MicroSeconds (eifsNoDifsNoSifs + sifs)); m_ackTimeoutValue = ackTimeoutValue; }
void DcfManagerTest::NotifyAccessGranted (uint32_t i) { DcfStateTest *state = m_dcfStates[i]; NS_TEST_EXPECT_MSG_EQ (state->m_expectedGrants.empty (), false, "Have expected grants"); std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front (); state->m_expectedGrants.pop_front (); NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected access grant is now"); m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first)); m_dcfManager->NotifyAckTimeoutStartNow (MicroSeconds (m_ackTimeoutValue + expected.first)); }
void BlockAckManager::UpdateAgreement (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient) { NS_LOG_FUNCTION (this << respHdr << recipient); uint8_t tid = respHdr->GetTid (); AgreementsI it = m_agreements.find (std::make_pair (recipient, tid)); if (it != m_agreements.end ()) { OriginatorBlockAckAgreement& agreement = it->second.first; agreement.SetBufferSize (respHdr->GetBufferSize () + 1); agreement.SetTimeout (respHdr->GetTimeout ()); agreement.SetAmsduSupport (respHdr->IsAmsduSupported ()); if (respHdr->IsImmediateBlockAck ()) { agreement.SetImmediateBlockAck (); } else { agreement.SetDelayedBlockAck (); } agreement.SetState (OriginatorBlockAckAgreement::ESTABLISHED); if (agreement.GetTimeout () != 0) { Time timeout = MicroSeconds (1024 * agreement.GetTimeout ()); agreement.m_inactivityEvent = Simulator::Schedule (timeout, &BlockAckManager::InactivityTimeout, this, recipient, tid); } } m_unblockPackets (recipient, tid); }
void DcfManagerTest::AddAccessRequestWithAckTimeout (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t from) { Simulator::Schedule (MicroSeconds (at) - Now (), &DcfManagerTest::DoAccessRequest, this, txTime, expectedGrantTime, m_dcfStates[from]); }
void DcfManagerTest::AddAccessRequestWithSuccessfullAck (uint64_t at, uint64_t txTime, uint64_t expectedGrantTime, uint32_t ackDelay, uint32_t from) { NS_ASSERT (ackDelay < m_ackTimeoutValue); Simulator::Schedule (MicroSeconds (at) - Now (), &DcfManagerTest::DoAccessRequest, this, txTime, expectedGrantTime, m_dcfStates[from]); AddAckTimeoutReset (expectedGrantTime + txTime + ackDelay); }
void DcfManagerTest::NotifyCollision (uint32_t i) { DcfStateTest *state = m_dcfStates[i]; NS_TEST_EXPECT_MSG_EQ (state->m_expectedCollision.empty (), false, "Have expected collisions"); struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front (); state->m_expectedCollision.pop_front (); NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.at), "Expected collision is now"); state->StartBackoffNow (expected.nSlots); }
void DcfManagerTest::NotifyChannelSwitching (uint32_t i) { DcfStateTest *state = m_dcfStates[i]; if (!state->m_expectedGrants.empty ()) { std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front (); state->m_expectedGrants.pop_front (); NS_TEST_EXPECT_MSG_EQ (Simulator::Now (), MicroSeconds (expected.second), "Expected grant is now"); } }
inline void ProcessTask() { usleep(IntHash(MicroSeconds()) % 1000000); if (ThrowException_) { TStatCounter::IncThrows(); throw NStl::exception(); } TStatCounter::IncProceed(); }
Time InterferenceHelper::GetEnergyDuration (double energyW) { Time now = Simulator::Now (); double noiseInterferenceW = 0.0; Time end = now; noiseInterferenceW = m_firstPower; for (NiChanges::const_iterator i = m_niChanges.begin (); i != m_niChanges.end (); i++) { noiseInterferenceW += i->GetDelta (); end = i->GetTime (); if (end < now) { continue; } if (noiseInterferenceW < energyW) { break; } } return end > now ? end - now : MicroSeconds (0); }
operator MicroSeconds() const { return MicroSeconds(milliSeconds * 1000); }
ui64 millisec() { return MicroSeconds() / (ui64)1000; }
MicroSeconds getMicroSeconds() const { return MicroSeconds(timeval.tv_usec); }
MicroSeconds operator-() const { return MicroSeconds(-microSeconds); }
void BlockAckManager::NotifyGotBlockAck (const CtrlBAckResponseHeader *blockAck, Mac48Address recipient) { NS_LOG_FUNCTION (this << blockAck << recipient); uint16_t sequenceFirstLost = 0; if (!blockAck->IsMultiTid ()) { uint8_t tid = blockAck->GetTidInfo (); if (ExistsAgreementInState (recipient, tid, OriginatorBlockAckAgreement::ESTABLISHED)) { bool foundFirstLost = false; AgreementsI it = m_agreements.find (std::make_pair (recipient, tid)); PacketQueueI queueEnd = it->second.second.end (); if (it->second.first.m_inactivityEvent.IsRunning ()) { /* Upon reception of a block ack frame, the inactivity timer at the originator must be reset. For more details see section 11.5.3 in IEEE802.11e standard */ it->second.first.m_inactivityEvent.Cancel (); Time timeout = MicroSeconds (1024 * it->second.first.GetTimeout ()); it->second.first.m_inactivityEvent = Simulator::Schedule (timeout, &BlockAckManager::InactivityTimeout, this, recipient, tid); } if (blockAck->IsBasic ()) { for (PacketQueueI queueIt = it->second.second.begin (); queueIt != queueEnd;) { if (blockAck->IsFragmentReceived ((*queueIt).hdr.GetSequenceNumber (), (*queueIt).hdr.GetFragmentNumber ())) { queueIt = it->second.second.erase (queueIt); } else { if (!foundFirstLost) { foundFirstLost = true; sequenceFirstLost = (*queueIt).hdr.GetSequenceNumber (); (*it).second.first.SetStartingSequence (sequenceFirstLost); } m_retryPackets.push_back (queueIt); queueIt++; } } } else if (blockAck->IsCompressed ()) { for (PacketQueueI queueIt = it->second.second.begin (); queueIt != queueEnd;) { if (blockAck->IsPacketReceived ((*queueIt).hdr.GetSequenceNumber ())) { uint16_t currentSeq = (*queueIt).hdr.GetSequenceNumber (); while (queueIt != queueEnd && (*queueIt).hdr.GetSequenceNumber () == currentSeq) { queueIt = it->second.second.erase (queueIt); } } else { if (!foundFirstLost) { foundFirstLost = true; sequenceFirstLost = (*queueIt).hdr.GetSequenceNumber (); (*it).second.first.SetStartingSequence (sequenceFirstLost); } m_retryPackets.push_back (queueIt); queueIt++; } } } uint16_t newSeq = m_txMiddle->GetNextSeqNumberByTidAndAddress (tid, recipient); if ((foundFirstLost && !SwitchToBlockAckIfNeeded (recipient, tid, sequenceFirstLost)) || (!foundFirstLost && !SwitchToBlockAckIfNeeded (recipient, tid, newSeq))) { it->second.first.SetState (OriginatorBlockAckAgreement::INACTIVE); } } } else { //NOT SUPPORTED FOR NOW NS_FATAL_ERROR ("Multi-tid block ack is not supported."); } }
void DcfManagerTest::AddAckTimeoutReset (uint64_t at) { Simulator::Schedule (MicroSeconds (at) - Now (), &DcfManager::NotifyAckTimeoutResetNow, m_dcfManager); }
Time MeshWifiBeacon::GetBeaconInterval () const { return MicroSeconds (m_header.GetBeaconIntervalUs ()); }
ui64 InterpolatedMicroSeconds() { return MicroSeconds(); }
double InterferenceHelper::CalculatePer (Ptr<const InterferenceHelper::Event> event, NiChanges *ni) const { double psr = 1.0; /* Packet Success Rate */ NiChanges::iterator j = ni->begin (); Time previous = (*j).GetTime (); WifiMode payloadMode = event->GetPayloadMode (); WifiPreamble preamble = event->GetPreambleType (); WifiMode MfHeaderMode ; if (preamble==WIFI_PREAMBLE_HT_MF) { MfHeaderMode = WifiPhy::GetMFPlcpHeaderMode (payloadMode, preamble); //return L-SIG mode } WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (payloadMode, preamble); Time plcpHeaderStart = (*j).GetTime () + MicroSeconds (WifiPhy::GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble)); //packet start time+ preamble Time plcpHsigHeaderStart=plcpHeaderStart+ MicroSeconds (WifiPhy::GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble));//packet start time+ preamble+L SIG Time plcpHtTrainingSymbolsStart = plcpHsigHeaderStart + MicroSeconds (WifiPhy::GetPlcpHtSigHeaderDurationMicroSeconds (payloadMode, preamble));//packet start time+ preamble+L SIG+HT SIG Time plcpPayloadStart =plcpHtTrainingSymbolsStart + MicroSeconds (WifiPhy::GetPlcpHtTrainingSymbolDurationMicroSeconds (payloadMode, preamble,event->GetTxVector())); //packet start time+ preamble+L SIG+HT SIG+Training double noiseInterferenceW = (*j).GetDelta (); double powerW = event->GetRxPowerW (); j++; while (ni->end () != j) { Time current = (*j).GetTime (); NS_ASSERT (current >= previous); //Case 1: Both prev and curr point to the payload if (previous >= plcpPayloadStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, payloadMode), current - previous, payloadMode); } //Case 2: previous is before payload else if (previous >= plcpHtTrainingSymbolsStart) { //Case 2a: current is after payload if (current >= plcpPayloadStart) { //Case 2ai and 2aii: All formats psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, payloadMode), current - plcpPayloadStart, payloadMode); } } //Case 3: previous is in HT-SIG: Non HT will not enter here since it didn't enter in the last two and they are all the same for non HT else if (previous >=plcpHsigHeaderStart) { //Case 3a: cuurent after payload start if (current >=plcpPayloadStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, payloadMode), current - plcpPayloadStart, payloadMode); psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - previous, headerMode); } //case 3b: current after HT training symbols start else if (current >=plcpHtTrainingSymbolsStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - previous, headerMode); } //Case 3c: current is with previous in HT sig else { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), current- previous, headerMode); } } //Case 4: previous in L-SIG: GF will not reach here because it will execute the previous if and exit else if (previous >= plcpHeaderStart) { //Case 4a: current after payload start if (current >=plcpPayloadStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, payloadMode), current - plcpPayloadStart, payloadMode); //Case 4ai: Non HT format (No HT-SIG or Training Symbols) if (preamble == WIFI_PREAMBLE_LONG || preamble == WIFI_PREAMBLE_SHORT) //plcpHtTrainingSymbolsStart==plcpHeaderStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpPayloadStart - previous, headerMode); } else{ psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - plcpHsigHeaderStart, headerMode); psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart - previous, MfHeaderMode); } } //Case 4b: current in HT training symbol. non HT will not come here since it went in previous if or if the previous ifis not true this will be not true else if (current >=plcpHtTrainingSymbolsStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - plcpHsigHeaderStart, headerMode); psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart - previous, MfHeaderMode); } //Case 4c: current in H sig.non HT will not come here since it went in previous if or if the previous ifis not true this will be not true else if (current >=plcpHsigHeaderStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), current - plcpHsigHeaderStart, headerMode); psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart - previous, MfHeaderMode); } //Case 4d: Current with prev in L SIG else { //Case 4di: Non HT format (No HT-SIG or Training Symbols) if (preamble == WIFI_PREAMBLE_LONG || preamble == WIFI_PREAMBLE_SHORT) //plcpHtTrainingSymbolsStart==plcpHeaderStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), current - previous, headerMode); } else { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), current - previous, MfHeaderMode); } } } //Case 5: previous is in the preamble works for all cases else { if (current >= plcpPayloadStart) { //for all psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, payloadMode), current - plcpPayloadStart, payloadMode); // Non HT format (No HT-SIG or Training Symbols) if (preamble == WIFI_PREAMBLE_LONG || preamble == WIFI_PREAMBLE_SHORT) psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpPayloadStart - plcpHeaderStart, headerMode); else // Greenfield or Mixed format psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - plcpHsigHeaderStart, headerMode); if (preamble == WIFI_PREAMBLE_HT_MF) psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart-plcpHeaderStart, MfHeaderMode); } else if (current >=plcpHtTrainingSymbolsStart ) { // Non HT format will not come here since it will execute prev if // Greenfield or Mixed format psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), plcpHtTrainingSymbolsStart - plcpHsigHeaderStart, headerMode); if (preamble == WIFI_PREAMBLE_HT_MF) psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart-plcpHeaderStart, MfHeaderMode); } //non HT will not come here else if (current >=plcpHsigHeaderStart) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), current- plcpHsigHeaderStart, headerMode); if (preamble != WIFI_PREAMBLE_HT_GF) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), plcpHsigHeaderStart-plcpHeaderStart, MfHeaderMode); } } // GF will not come here else if (current >= plcpHeaderStart) { if (preamble == WIFI_PREAMBLE_LONG || preamble == WIFI_PREAMBLE_SHORT) { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, headerMode), current - plcpHeaderStart, headerMode); } else { psr *= CalculateChunkSuccessRate (CalculateSnr (powerW, noiseInterferenceW, MfHeaderMode), current - plcpHeaderStart, MfHeaderMode); } } } noiseInterferenceW += (*j).GetDelta (); previous = (*j).GetTime (); j++; } double per = 1 - psr; return per; }