src/devices/wifi/mac-low.cc
changeset 6065 0f012e7d9128
parent 5846 f7a4e1b3f632
child 6068 a2127017ecb4
equal deleted inserted replaced
6064:ddec96840ebd 6065:0f012e7d9128
    22 #include "ns3/packet.h"
    22 #include "ns3/packet.h"
    23 #include "ns3/simulator.h"
    23 #include "ns3/simulator.h"
    24 #include "ns3/tag.h"
    24 #include "ns3/tag.h"
    25 #include "ns3/log.h"
    25 #include "ns3/log.h"
    26 #include "ns3/node.h"
    26 #include "ns3/node.h"
       
    27 #include "ns3/double.h"
    27 
    28 
    28 #include "mac-low.h"
    29 #include "mac-low.h"
    29 #include "wifi-phy.h"
    30 #include "wifi-phy.h"
    30 #include "wifi-mac-trailer.h"
    31 #include "wifi-mac-trailer.h"
    31 
    32 
   573       if (isPrevNavZero &&
   574       if (isPrevNavZero &&
   574           hdr.GetAddr1 () == m_self) 
   575           hdr.GetAddr1 () == m_self) 
   575         {
   576         {
   576           NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
   577           NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
   577           NS_ASSERT (m_sendCtsEvent.IsExpired ());
   578           NS_ASSERT (m_sendCtsEvent.IsExpired ());
   578           WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   579           m_stationManager->ReportRxOk (hdr.GetAddr2 (), &hdr, 
   579           station->ReportRxOk (rxSnr, txMode);
   580                                         rxSnr, txMode);
   580           m_sendCtsEvent = Simulator::Schedule (GetSifs (),
   581           m_sendCtsEvent = Simulator::Schedule (GetSifs (),
   581                                                 &MacLow::SendCtsAfterRts, this,
   582                                                 &MacLow::SendCtsAfterRts, this,
   582                                                 hdr.GetAddr2 (), 
   583                                                 hdr.GetAddr2 (), 
   583                                                 hdr.GetDuration (),
   584                                                 hdr.GetDuration (),
   584                                                 txMode,
   585                                                 txMode,
   595            m_currentPacket != 0) 
   596            m_currentPacket != 0) 
   596     {
   597     {
   597       NS_LOG_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   598       NS_LOG_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   598       SnrTag tag;
   599       SnrTag tag;
   599       packet->RemovePacketTag (tag);
   600       packet->RemovePacketTag (tag);
   600       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   601       m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr,
   601       station->ReportRxOk (rxSnr, txMode);
   602                                     rxSnr, txMode);
   602       station->ReportRtsOk (rxSnr, txMode, tag.Get ());
   603       m_stationManager->ReportRtsOk (m_currentHdr.GetAddr1 (), &m_currentHdr,
       
   604                                      rxSnr, txMode, tag.Get ());
   603       
   605       
   604       m_ctsTimeoutEvent.Cancel ();
   606       m_ctsTimeoutEvent.Cancel ();
   605       NotifyCtsTimeoutResetNow ();
   607       NotifyCtsTimeoutResetNow ();
   606       m_listener->GotCts (rxSnr, txMode);
   608       m_listener->GotCts (rxSnr, txMode);
   607       NS_ASSERT (m_sendDataEvent.IsExpired ());
   609       NS_ASSERT (m_sendDataEvent.IsExpired ());
   619            m_txParams.MustWaitAck ()) 
   621            m_txParams.MustWaitAck ()) 
   620     {
   622     {
   621       NS_LOG_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
   623       NS_LOG_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
   622       SnrTag tag;
   624       SnrTag tag;
   623       packet->RemovePacketTag (tag);
   625       packet->RemovePacketTag (tag);
   624       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   626       m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr,
   625       station->ReportRxOk (rxSnr, txMode);
   627                                     rxSnr, txMode);
   626       station->ReportDataOk (rxSnr, txMode, tag.Get ());
   628       m_stationManager->ReportDataOk (m_currentHdr.GetAddr1 (), &m_currentHdr,
       
   629                                       rxSnr, txMode, tag.Get ());
   627       bool gotAck = false;
   630       bool gotAck = false;
   628       if (m_txParams.MustWaitNormalAck () &&
   631       if (m_txParams.MustWaitNormalAck () &&
   629           m_normalAckTimeoutEvent.IsRunning ()) 
   632           m_normalAckTimeoutEvent.IsRunning ()) 
   630         {
   633         {
   631           m_normalAckTimeoutEvent.Cancel ();
   634           m_normalAckTimeoutEvent.Cancel ();
   653     {
   656     {
   654       NS_LOG_DEBUG ("rx drop " << hdr.GetTypeString ());
   657       NS_LOG_DEBUG ("rx drop " << hdr.GetTypeString ());
   655     } 
   658     } 
   656   else if (hdr.GetAddr1 () == m_self) 
   659   else if (hdr.GetAddr1 () == m_self) 
   657     {
   660     {
   658       WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   661       m_stationManager->ReportRxOk (hdr.GetAddr2 (), &hdr,
   659       station->ReportRxOk (rxSnr, txMode);
   662                                     rxSnr, txMode);
   660       
   663       
   661       if (hdr.IsQosData () && hdr.IsQosNoAck ()) 
   664       if (hdr.IsQosData () && hdr.IsQosNoAck ()) 
   662         {
   665         {
   663           NS_LOG_DEBUG ("rx unicast/noAck from="<<hdr.GetAddr2 ());
   666           NS_LOG_DEBUG ("rx unicast/noAck from="<<hdr.GetAddr2 ());
   664         } 
   667         } 
   741 
   744 
   742 WifiMode
   745 WifiMode
   743 MacLow::GetRtsTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const
   746 MacLow::GetRtsTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const
   744 {
   747 {
   745   Mac48Address to = hdr->GetAddr1 ();
   748   Mac48Address to = hdr->GetAddr1 ();
   746   return GetStation (to)->GetRtsMode (packet);
   749   return m_stationManager->GetRtsMode (to, hdr, packet);
   747 }
   750 }
   748 WifiMode
   751 WifiMode
   749 MacLow::GetDataTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const
   752 MacLow::GetDataTxMode (Ptr<const Packet> packet, const WifiMacHeader *hdr) const
   750 {
   753 {
   751   Mac48Address to = hdr->GetAddr1 ();
   754   Mac48Address to = hdr->GetAddr1 ();
   752   WifiMacTrailer fcs;
   755   WifiMacTrailer fcs;
   753   uint32_t size =  packet->GetSize () + hdr->GetSize () + fcs.GetSerializedSize ();
   756   uint32_t size =  packet->GetSize () + hdr->GetSize () + fcs.GetSerializedSize ();
   754   return GetStation (to)->GetDataMode (packet, size);
   757   return m_stationManager->GetDataMode (to, hdr, packet, size);
   755 }
   758 }
   756 
   759 
   757 WifiMode
   760 WifiMode
   758 MacLow::GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const
   761 MacLow::GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const
   759 {
   762 {
   760   return GetStation (to)->GetCtsMode (rtsTxMode);
   763   return m_stationManager->GetCtsMode (to, rtsTxMode);
   761 }
   764 }
   762 WifiMode
   765 WifiMode
   763 MacLow::GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const
   766 MacLow::GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const
   764 {
   767 {
   765   return GetStation (to)->GetAckMode (dataTxMode);
   768   return m_stationManager->GetAckMode (to, dataTxMode);
   766 }
   769 }
   767 
   770 
   768 
   771 
   769 Time
   772 Time
   770 MacLow::CalculateOverallTxTime (Ptr<const Packet> packet,
   773 MacLow::CalculateOverallTxTime (Ptr<const Packet> packet,
   935   NS_LOG_FUNCTION (this);
   938   NS_LOG_FUNCTION (this);
   936   NS_LOG_DEBUG ("cts timeout");
   939   NS_LOG_DEBUG ("cts timeout");
   937   // XXX: should check that there was no rx start before now.
   940   // XXX: should check that there was no rx start before now.
   938   // we should restart a new cts timeout now until the expected
   941   // we should restart a new cts timeout now until the expected
   939   // end of rx if there was a rx start before now.
   942   // end of rx if there was a rx start before now.
   940   WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   943   m_stationManager->ReportRtsFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
   941   station->ReportRtsFailed ();
       
   942   m_currentPacket = 0;
   944   m_currentPacket = 0;
   943   MacLowTransmissionListener *listener = m_listener;
   945   MacLowTransmissionListener *listener = m_listener;
   944   m_listener = 0;
   946   m_listener = 0;
   945   listener->MissedCts ();
   947   listener->MissedCts ();
   946 }
   948 }
   950   NS_LOG_FUNCTION (this);
   952   NS_LOG_FUNCTION (this);
   951   NS_LOG_DEBUG ("normal ack timeout");
   953   NS_LOG_DEBUG ("normal ack timeout");
   952   // XXX: should check that there was no rx start before now.
   954   // XXX: should check that there was no rx start before now.
   953   // we should restart a new ack timeout now until the expected
   955   // we should restart a new ack timeout now until the expected
   954   // end of rx if there was a rx start before now.
   956   // end of rx if there was a rx start before now.
   955   WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   957   m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
   956   station->ReportDataFailed ();
       
   957   MacLowTransmissionListener *listener = m_listener;
   958   MacLowTransmissionListener *listener = m_listener;
   958   m_listener = 0;
   959   m_listener = 0;
   959   listener->MissedAck ();
   960   listener->MissedAck ();
   960 }
   961 }
   961 void
   962 void
   962 MacLow::FastAckTimeout (void)
   963 MacLow::FastAckTimeout (void)
   963 {
   964 {
   964   NS_LOG_FUNCTION (this);
   965   NS_LOG_FUNCTION (this);
   965   WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   966   m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
   966   station->ReportDataFailed ();
       
   967   MacLowTransmissionListener *listener = m_listener;
   967   MacLowTransmissionListener *listener = m_listener;
   968   m_listener = 0;
   968   m_listener = 0;
   969   if (m_phy->IsStateIdle ()) 
   969   if (m_phy->IsStateIdle ()) 
   970     {
   970     {
   971       NS_LOG_DEBUG ("fast Ack idle missed");
   971       NS_LOG_DEBUG ("fast Ack idle missed");
   978 }
   978 }
   979 void
   979 void
   980 MacLow::SuperFastAckTimeout ()
   980 MacLow::SuperFastAckTimeout ()
   981 {
   981 {
   982   NS_LOG_FUNCTION (this);
   982   NS_LOG_FUNCTION (this);
   983   WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   983   m_stationManager->ReportDataFailed (m_currentHdr.GetAddr1 (), &m_currentHdr);
   984   station->ReportDataFailed ();
       
   985   MacLowTransmissionListener *listener = m_listener;
   984   MacLowTransmissionListener *listener = m_listener;
   986   m_listener = 0;
   985   m_listener = 0;
   987   if (m_phy->IsStateIdle ()) 
   986   if (m_phy->IsStateIdle ()) 
   988     {
   987     {
   989       NS_LOG_DEBUG ("super fast Ack failed");
   988       NS_LOG_DEBUG ("super fast Ack failed");
  1136     {
  1135     {
  1137       return false;
  1136       return false;
  1138     }
  1137     }
  1139 }
  1138 }
  1140 
  1139 
  1141 WifiRemoteStation *
       
  1142 MacLow::GetStation (Mac48Address ad) const
       
  1143 {
       
  1144   return m_stationManager->Lookup (ad);
       
  1145 }
       
  1146 
       
  1147 void
  1140 void
  1148 MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, double rtsSnr)
  1141 MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, double rtsSnr)
  1149 {
  1142 {
  1150   NS_LOG_FUNCTION (this << source << duration << rtsTxMode << rtsSnr);
  1143   NS_LOG_FUNCTION (this << source << duration << rtsTxMode << rtsSnr);
  1151   /* send a CTS when you receive a RTS 
  1144   /* send a CTS when you receive a RTS