From d5d09d37d8e3271e2286f1dcc57c7839a8f4e1a4 Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sat, 2 Apr 2011 04:24:47 -0500 Subject: [PATCH] Merged Qasim's old tree (Fall 2010) with the newer ns3 code base. Commits 6668 to 6681. --- src/mesh/model/dot11s/airtime-metric.cc | 2 ++ src/mesh/model/dot11s/hwmp-protocol.cc | 3 ++ src/mesh/model/dot11s/peer-link.cc | 18 +++++++++-- src/mesh/model/dot11s/peer-link.h | 9 ++++-- .../dot11s/peer-management-protocol-mac.cc | 4 +-- .../model/dot11s/peer-management-protocol.cc | 8 ++--- .../model/dot11s/peer-management-protocol.h | 4 +-- src/visualizer/model/pyviz.cc | 4 +++ src/visualizer/visualizer/core.py | 1 + src/wifi/model/dca-txop.cc | 17 ++++++++++- src/wifi/model/mac-low.cc | 30 ++++++++++++++++--- src/wifi/model/mac-low.h | 2 +- src/wifi/model/wifi-remote-station-manager.cc | 24 +++++++++++---- src/wifi/model/wifi-remote-station-manager.h | 9 ++++-- src/wifi/wscript | 1 + 15 files changed, 109 insertions(+), 27 deletions(-) diff --git a/src/mesh/model/dot11s/airtime-metric.cc b/src/mesh/model/dot11s/airtime-metric.cc index 86e81833..1ced1842 100644 --- a/src/mesh/model/dot11s/airtime-metric.cc +++ b/src/mesh/model/dot11s/airtime-metric.cc @@ -95,6 +95,8 @@ AirtimeLinkMetricCalculator::CalculateMetric (Mac48Address peerAddress, PtrGetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), mode, WIFI_PREAMBLE_LONG) ).GetMicroSeconds () / (10.24 * (1.0 - failAvg))); + + //metric = (uint32_t) mac->GetStationManager ()->GetInfo (peerAddress).GetPacketTimeAvg (); return metric; } } //namespace dot11s diff --git a/src/mesh/model/dot11s/hwmp-protocol.cc b/src/mesh/model/dot11s/hwmp-protocol.cc index b32390eb..9c1eca6b 100644 --- a/src/mesh/model/dot11s/hwmp-protocol.cc +++ b/src/mesh/model/dot11s/hwmp-protocol.cc @@ -364,6 +364,9 @@ HwmpProtocol::ForwardUnicast (uint32_t sourceIface, const Mac48Address source, result = m_rtable->LookupReactiveExpired (destination); if (ShouldSendPreq (destination)) { + NS_LOG_ERROR("Source " << source << " sending preq for destination " << destination << "\n"); + // Accepted preq from address" << from << ", preq:" << preq); + uint32_t originator_seqno = GetNextHwmpSeqno (); uint32_t dst_seqno = 0; if (result.retransmitter != Mac48Address::GetBroadcast ()) diff --git a/src/mesh/model/dot11s/peer-link.cc b/src/mesh/model/dot11s/peer-link.cc index 6e38ed46..ae8253e8 100644 --- a/src/mesh/model/dot11s/peer-link.cc +++ b/src/mesh/model/dot11s/peer-link.cc @@ -101,7 +101,11 @@ PeerLink::PeerLink () : m_packetFail (0), m_state (IDLE), m_retryCounter (0), - m_maxPacketFail (3) + m_maxPacketFail (3), + m_packetSuccessCount (0), + m_packetSuccessBytes (0), + m_packetFailCount (0), + m_packetFailBytes (0) { } PeerLink::~PeerLink () @@ -162,14 +166,18 @@ PeerLink::BeaconLoss () StateMachine (CNCL); } void -PeerLink::TransmissionSuccess () +PeerLink::TransmissionSuccess (uint32_t size) { m_packetFail = 0; + m_packetSuccessCount ++; + m_packetSuccessBytes += size; } void -PeerLink::TransmissionFailure () +PeerLink::TransmissionFailure (uint32_t size) { m_packetFail ++; + m_packetFailCount ++; + m_packetFailBytes += size; if (m_packetFail == m_maxPacketFail) { StateMachine (CNCL); @@ -699,6 +707,10 @@ PeerLink::Report (std::ostream & os) const "localLinkId=\"" << m_localLinkId << "\"" << std::endl << "peerLinkId=\"" << m_peerLinkId << "\"" << std::endl << "assocId=\"" << m_assocId << "\"" << std::endl << + "FrameSuccessCount=\"" << m_packetSuccessCount << "\"" << std::endl << + "FrameSuccessBytes=\"" << m_packetSuccessBytes << "\"" << std::endl << + "FrameFailCount=\"" << m_packetFailCount << "\"" << std::endl << + "FrameFailBytes=\"" << m_packetFailBytes << "\"" << std::endl << "/>" << std::endl; } } // namespace dot11s diff --git a/src/mesh/model/dot11s/peer-link.h b/src/mesh/model/dot11s/peer-link.h index 2db0afb3..fb79ccfd 100644 --- a/src/mesh/model/dot11s/peer-link.h +++ b/src/mesh/model/dot11s/peer-link.h @@ -100,8 +100,8 @@ class PeerLink : public Object /// Set callback void MLMESetSignalStatusCallback (SignalStatusCallback); /// Reports about transmission success/failure - void TransmissionSuccess (); - void TransmissionFailure (); + void TransmissionSuccess (uint32_t size); + void TransmissionFailure (uint32_t size); //\} ///\brief Statistics void Report (std::ostream & os) const; @@ -254,6 +254,11 @@ class PeerLink : public Object //\} /// How to report my status change SignalStatusCallback m_linkStatusCallback; + + uint32_t m_packetSuccessCount; + uint32_t m_packetSuccessBytes; + uint32_t m_packetFailCount; + uint32_t m_packetFailBytes; }; } // namespace dot11s diff --git a/src/mesh/model/dot11s/peer-management-protocol-mac.cc b/src/mesh/model/dot11s/peer-management-protocol-mac.cc index d8a13c19..0b04b037 100644 --- a/src/mesh/model/dot11s/peer-management-protocol-mac.cc +++ b/src/mesh/model/dot11s/peer-management-protocol-mac.cc @@ -52,12 +52,12 @@ PeerManagementProtocolMac::SetParent (Ptr parent) void PeerManagementProtocolMac::TxError (WifiMacHeader const &hdr) { - m_protocol->TransmissionFailure (m_ifIndex, hdr.GetAddr1 ()); + m_protocol->TransmissionFailure (m_ifIndex, hdr.GetAddr1 (), hdr.GetSize ()); } void PeerManagementProtocolMac::TxOk (WifiMacHeader const &hdr) { - m_protocol->TransmissionSuccess (m_ifIndex, hdr.GetAddr1 ()); + m_protocol->TransmissionSuccess (m_ifIndex, hdr.GetAddr1 (), hdr.GetSize ()); } bool PeerManagementProtocolMac::Receive (Ptr const_packet, const WifiMacHeader & header) diff --git a/src/mesh/model/dot11s/peer-management-protocol.cc b/src/mesh/model/dot11s/peer-management-protocol.cc index 0be167bf..2b02a9ad 100644 --- a/src/mesh/model/dot11s/peer-management-protocol.cc +++ b/src/mesh/model/dot11s/peer-management-protocol.cc @@ -237,23 +237,23 @@ PeerManagementProtocol::ConfigurationMismatch (uint32_t interface, Mac48Address } } void -PeerManagementProtocol::TransmissionFailure (uint32_t interface, Mac48Address peerAddress) +PeerManagementProtocol::TransmissionFailure (uint32_t interface, Mac48Address peerAddress, uint32_t size) { NS_LOG_DEBUG("transmission failed between "< peerLink = FindPeerLink(interface, peerAddress); if (peerLink != 0) { - peerLink->TransmissionFailure (); + peerLink->TransmissionFailure (size); } } void -PeerManagementProtocol::TransmissionSuccess (uint32_t interface, Mac48Address peerAddress) +PeerManagementProtocol::TransmissionSuccess (uint32_t interface, Mac48Address peerAddress, uint32_t size) { NS_LOG_DEBUG("transmission success "< peerLink = FindPeerLink(interface, peerAddress); if (peerLink != 0) { - peerLink->TransmissionSuccess (); + peerLink->TransmissionSuccess (size); } } Ptr diff --git a/src/mesh/model/dot11s/peer-management-protocol.h b/src/mesh/model/dot11s/peer-management-protocol.h index 3efb1e66..20a98b79 100644 --- a/src/mesh/model/dot11s/peer-management-protocol.h +++ b/src/mesh/model/dot11s/peer-management-protocol.h @@ -116,11 +116,11 @@ class PeerManagementProtocol : public Object /** * \brief Cancels peer link due to successive transmission failures */ - void TransmissionFailure (uint32_t interface, const Mac48Address peerAddress); + void TransmissionFailure (uint32_t interface, const Mac48Address peerAddress, uint32_t size); /** * \brief resets transmission failure statistics */ - void TransmissionSuccess (uint32_t interface, const Mac48Address peerAddress); + void TransmissionSuccess (uint32_t interface, const Mac48Address peerAddress, uint32_t size); /** * \brief Checks if there is established link */ diff --git a/src/visualizer/model/pyviz.cc b/src/visualizer/model/pyviz.cc index 2e9a4cc8..fd5798b0 100644 --- a/src/visualizer/model/pyviz.cc +++ b/src/visualizer/model/pyviz.cc @@ -598,6 +598,8 @@ PyViz::TraceNetDevTxWifi (std::string context, Ptr packet) { destinationAddress = hdr.GetAddr3 (); } + + NS_LOG_FUNCTION(context<<"Addr1: " << hdr.GetAddr1()<<"Addr2: " << hdr.GetAddr2()<<"Addr3: " << hdr.GetAddr3()<<"Addr4: " << hdr.GetAddr4()<<"\n\n"); TraceNetDevTxCommon (context, packet, destinationAddress); } @@ -769,6 +771,8 @@ PyViz::TraceNetDevRxWifi (std::string context, Ptr packet) sourceAddress = hdr.GetAddr4 (); } + NS_LOG_FUNCTION(context<<"Addr1: " << hdr.GetAddr1()<<"Addr2: " << hdr.GetAddr2()<<"Addr3: " << hdr.GetAddr3()<<"Addr4: " << hdr.GetAddr4()<<"\n\n"); + TraceNetDevRxCommon (context, packet, sourceAddress); } diff --git a/src/visualizer/visualizer/core.py b/src/visualizer/visualizer/core.py index c505cb07..7e309d65 100644 --- a/src/visualizer/visualizer/core.py +++ b/src/visualizer/visualizer/core.py @@ -917,6 +917,7 @@ def _update_transmissions_view(self): rx_bytes += transmission.bytes count += 1 transmissions_average[key] = rx_bytes, count + # print "[Joel] Transmitter: ", transmission.transmitter.GetId(), ", Receiver: ", transmission.receiver.GetId(), "Bytes: ", transmission.bytes, "\n" old_arrows = self._transmission_arrows for arrow, label in old_arrows: diff --git a/src/wifi/model/dca-txop.cc b/src/wifi/model/dca-txop.cc index ffc78e9e..efd473b7 100644 --- a/src/wifi/model/dca-txop.cc +++ b/src/wifi/model/dca-txop.cc @@ -33,6 +33,7 @@ #include "wifi-mac-trailer.h" #include "wifi-mac.h" #include "random-stream.h" +#include "tsf-tag.h" NS_LOG_COMPONENT_DEFINE ("DcaTxop"); @@ -225,7 +226,21 @@ DcaTxop::Queue (Ptr packet, const WifiMacHeader &hdr) uint32_t fullPacketSize = hdr.GetSerializedSize () + packet->GetSize () + fcs.GetSerializedSize (); m_stationManager->PrepareForQueue (hdr.GetAddr1 (), &hdr, packet, fullPacketSize); - m_queue->Enqueue (packet, hdr); + + Ptr p = packet->Copy (); + if (hdr.IsData () && !hdr.GetAddr1 ().IsBroadcast () && !hdr.IsAck ()) + { + TsfTag tag; + p->RemovePacketTag (tag); + + tag.SetQueueTime (Simulator::Now ()); + tag.SetAckTime (Seconds (0.0)); + p->AddPacketTag (tag); + + NS_LOG_DEBUG ("==> Packet Queue Time : " << tag.GetQueueTime ().GetMicroSeconds ()); + } + + m_queue->Enqueue (p, hdr); StartAccessIfNeeded (); } diff --git a/src/wifi/model/mac-low.cc b/src/wifi/model/mac-low.cc index 08406a47..c305508d 100644 --- a/src/wifi/model/mac-low.cc +++ b/src/wifi/model/mac-low.cc @@ -33,6 +33,7 @@ #include "wifi-mac-trailer.h" #include "qos-utils.h" #include "edca-txop-n.h" +#include "tsf-tag.h" NS_LOG_COMPONENT_DEFINE ("MacLow"); @@ -714,10 +715,15 @@ MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamb NS_LOG_DEBUG ("receive ack from="<RemovePacketTag (tag); + + TsfTag t; + if (packet->RemovePacketTag (t)) + NS_LOG_DEBUG ("*** TSF diff: " << (t.GetAckTime () - t.GetQueueTime ()).GetMicroSeconds ()); + m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, rxSnr, txMode); m_stationManager->ReportDataOk (m_currentHdr.GetAddr1 (), &m_currentHdr, - rxSnr, txMode, tag.Get ()); + rxSnr, txMode, tag.Get (), t.Get ()); bool gotAck = false; if (m_txParams.MustWaitNormalAck () && m_normalAckTimeoutEvent.IsRunning ()) @@ -824,7 +830,8 @@ MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamb hdr.GetAddr2 (), hdr.GetDuration (), txMode, - rxSnr); + rxSnr, + packet); } else if (hdr.IsQosBlockAck ()) { @@ -856,12 +863,14 @@ MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamb { NS_LOG_DEBUG ("rx unicast/sendAck from=" << hdr.GetAddr2 ()); NS_ASSERT (m_sendAckEvent.IsExpired ()); + m_sendAckEvent = Simulator::Schedule (GetSifs (), &MacLow::SendAckAfterData, this, hdr.GetAddr2 (), hdr.GetDuration (), txMode, - rxSnr); + rxSnr, + packet); } goto rxPacket; } @@ -1471,7 +1480,7 @@ MacLow::FastAckFailedTimeout (void) } void -MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMode, double dataSnr) +MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMode, double dataSnr, Ptr p) { NS_LOG_FUNCTION (this); /* send an ACK when you receive @@ -1499,6 +1508,19 @@ MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMod tag.Set (dataSnr); packet->AddPacketTag (tag); + TsfTag t; + bool succ = p->RemovePacketTag (t); + + if (succ) + { + t.SetAckTime (Simulator::Now ()); + NS_LOG_DEBUG ("==> Setting ACK time to " << t.GetAckTime ()); + packet->AddPacketTag (t); + + //packet->PrintPacketTags (std::cout); + } + + ForwardDown (packet, &ack, ackTxMode); } diff --git a/src/wifi/model/mac-low.h b/src/wifi/model/mac-low.h index 64f4608a..4e208936 100644 --- a/src/wifi/model/mac-low.h +++ b/src/wifi/model/mac-low.h @@ -526,7 +526,7 @@ class MacLow : public Object { void BlockAckTimeout (void); void CtsTimeout (void); void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); - void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); + void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr, Ptr p); void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode); void WaitSifsAfterEndTx (void); diff --git a/src/wifi/model/wifi-remote-station-manager.cc b/src/wifi/model/wifi-remote-station-manager.cc index 49e72795..1f66dfdf 100644 --- a/src/wifi/model/wifi-remote-station-manager.cc +++ b/src/wifi/model/wifi-remote-station-manager.cc @@ -408,17 +408,17 @@ WifiRemoteStationManager::ReportRtsOk (Mac48Address address, const WifiMacHeader { NS_ASSERT (!address.IsGroup ()); WifiRemoteStation *station = Lookup (address, header); - station->m_state->m_info.NotifyTxSuccess (station->m_ssrc); + station->m_state->m_info.NotifyTxSuccess (station->m_ssrc, 0); station->m_ssrc = 0; DoReportRtsOk (station, ctsSnr, ctsMode, rtsSnr); } void WifiRemoteStationManager::ReportDataOk (Mac48Address address, const WifiMacHeader *header, - double ackSnr, WifiMode ackMode, double dataSnr) + double ackSnr, WifiMode ackMode, double dataSnr, double packetTime) { NS_ASSERT (!address.IsGroup ()); WifiRemoteStation *station = Lookup (address, header); - station->m_state->m_info.NotifyTxSuccess (station->m_slrc); + station->m_state->m_info.NotifyTxSuccess (station->m_slrc, packetTime); station->m_slrc = 0; DoReportDataOk (station, ackSnr, ackMode, dataSnr); } @@ -813,7 +813,8 @@ WifiRemoteStationManager::GetNSupported (const WifiRemoteStation *station) const WifiRemoteStationInfo::WifiRemoteStationInfo () : m_memoryTime (Seconds (1.0)), m_lastUpdate (Seconds (0.0)), - m_failAvg (0.0) + m_failAvg (0.0), + m_packetTimeAvg (0.0) {} double @@ -827,17 +828,22 @@ WifiRemoteStationInfo::CalculateAveragingCoefficient () } void -WifiRemoteStationInfo::NotifyTxSuccess (uint32_t retryCounter) +WifiRemoteStationInfo::NotifyTxSuccess (uint32_t retryCounter, double packetTime) { double coefficient = CalculateAveragingCoefficient (); m_failAvg = (double)retryCounter / (1 + (double) retryCounter) * (1.0 - coefficient) + coefficient * m_failAvg; + if (packetTime > 0) + m_packetTimeAvg = packetTime * (1.0 - coefficient) + coefficient * m_packetTimeAvg; + NS_LOG_DEBUG (retryCounter); } void -WifiRemoteStationInfo::NotifyTxFailed () +WifiRemoteStationInfo::NotifyTxFailed (/*double packetTime*/) { double coefficient = CalculateAveragingCoefficient (); m_failAvg = (1.0 - coefficient) + coefficient * m_failAvg; + //if (packetTime > 0) + //m_packetTimeAvg = coefficient * m_packetTimeAvg; } double @@ -845,4 +851,10 @@ WifiRemoteStationInfo::GetFrameErrorRate () const { return m_failAvg; } + +double +WifiRemoteStationInfo::GetPacketTimeAvg () const +{ + return m_packetTimeAvg; +} } // namespace ns3 diff --git a/src/wifi/model/wifi-remote-station-manager.h b/src/wifi/model/wifi-remote-station-manager.h index fb3f5848..70fcc3e2 100644 --- a/src/wifi/model/wifi-remote-station-manager.h +++ b/src/wifi/model/wifi-remote-station-manager.h @@ -52,11 +52,12 @@ class WifiRemoteStationInfo * \param retryCounter is slrc or ssrc value at the moment of * success transmission. */ - void NotifyTxSuccess (uint32_t retryCounter); + void NotifyTxSuccess (uint32_t retryCounter, double packetTime); /// Updates average frame error rate when final data or RTS has failed. void NotifyTxFailed (); /// Returns frame error rate (probability that frame is corrupted due to transmission error). double GetFrameErrorRate () const; + double GetPacketTimeAvg () const; private: /** * \brief Calculate averaging coefficient for frame error rate. Depends on time of the last update. @@ -70,6 +71,9 @@ class WifiRemoteStationInfo Time m_lastUpdate; /// moving percentage of failed frames double m_failAvg; + + /// moving average of packet queue time + backoff time + transmission time + ack delay + double m_packetTimeAvg; }; /** @@ -187,7 +191,7 @@ class WifiRemoteStationManager : public Object * we just sent. */ void ReportDataOk (Mac48Address address, const WifiMacHeader *header, - double ackSnr, WifiMode ackMode, double dataSnr); + double ackSnr, WifiMode ackMode, double dataSnr, double packetTime); /** * Should be invoked after calling ReportRtsFailed if * NeedRtsRetransmission returns false @@ -394,6 +398,7 @@ class WifiRemoteStationManager : public Object WifiMode GetControlAnswerMode (Mac48Address address, WifiMode reqMode); uint32_t GetNFragments (Ptr packet); + typedef std::vector Stations; typedef std::vector StationStates; diff --git a/src/wifi/wscript b/src/wifi/wscript index cc3557f4..368310cf 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -48,6 +48,7 @@ def build(bld): 'model/cara-wifi-manager.cc', 'model/minstrel-wifi-manager.cc', 'model/qos-tag.cc', + 'model/tsf-tag.cc', 'model/qos-utils.cc', 'model/edca-txop-n.cc', 'model/msdu-aggregator.cc',