src/devices/wifi/mac-low.cc
changeset 3596 6c39b712a535
parent 3208 1a754d09c4ba
child 3597 fe35e5be4b78
equal deleted inserted replaced
3585:0404af4cacf0 3596:6c39b712a535
    31 #include "wifi-mac.h"
    31 #include "wifi-mac.h"
    32 
    32 
    33 NS_LOG_COMPONENT_DEFINE ("MacLow");
    33 NS_LOG_COMPONENT_DEFINE ("MacLow");
    34 
    34 
    35 #define MY_DEBUG(x) \
    35 #define MY_DEBUG(x) \
    36   NS_LOG_DEBUG (m_mac->GetAddress () << " " << x)
    36   NS_LOG_DEBUG (m_self << " " << x)
    37 
    37 
    38 namespace ns3 {
    38 namespace ns3 {
    39 
    39 
    40 class SnrTag : public Tag
    40 class SnrTag : public Tag
    41 {
    41 {
   354 Ptr<WifiMac> 
   354 Ptr<WifiMac> 
   355 MacLow::GetMac (void)
   355 MacLow::GetMac (void)
   356 {
   356 {
   357   return m_mac;
   357   return m_mac;
   358 }
   358 }
       
   359 
       
   360 void 
       
   361 MacLow::SetAddress (Mac48Address ad)
       
   362 {
       
   363   m_self = ad;
       
   364 }
       
   365 void 
       
   366 MacLow::SetAckTimeout (Time ackTimeout)
       
   367 {
       
   368   m_ackTimeout = ackTimeout;
       
   369 }
       
   370 Mac48Address 
       
   371 MacLow::GetAddress (void) const
       
   372 {
       
   373   return m_self;
       
   374 }
       
   375 Time 
       
   376 MacLow::GetAckTimeout (void) const
       
   377 {
       
   378   return m_ackTimeout;
       
   379 }
       
   380 
   359 void 
   381 void 
   360 MacLow::SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback)
   382 MacLow::SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback)
   361 {
   383 {
   362   m_rxCallback = callback;
   384   m_rxCallback = callback;
   363 }
   385 }
   449        * period if the NAV at the STA receiving the RTS frame indicates that the medium is 
   471        * period if the NAV at the STA receiving the RTS frame indicates that the medium is 
   450        * idle. If the NAV at the STA receiving the RTS indicates the medium is not idle, 
   472        * idle. If the NAV at the STA receiving the RTS indicates the medium is not idle, 
   451        * that STA shall not respond to the RTS frame.
   473        * that STA shall not respond to the RTS frame.
   452        */
   474        */
   453       if (isPrevNavZero &&
   475       if (isPrevNavZero &&
   454           hdr.GetAddr1 () == m_mac->GetAddress ()) 
   476           hdr.GetAddr1 () == m_self) 
   455         {
   477         {
   456           MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
   478           MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS");
   457           NS_ASSERT (m_sendCtsEvent.IsExpired ());
   479           NS_ASSERT (m_sendCtsEvent.IsExpired ());
   458           WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   480           WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   459           station->ReportRxOk (rxSnr, txMode);
   481           station->ReportRxOk (rxSnr, txMode);
   468         {
   490         {
   469           MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS");
   491           MY_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS");
   470         }
   492         }
   471     } 
   493     } 
   472   else if (hdr.IsCts () &&
   494   else if (hdr.IsCts () &&
   473            hdr.GetAddr1 () == m_mac->GetAddress () &&
   495            hdr.GetAddr1 () == m_self &&
   474            m_ctsTimeoutEvent.IsRunning () &&
   496            m_ctsTimeoutEvent.IsRunning () &&
   475            m_currentPacket != 0) 
   497            m_currentPacket != 0) 
   476     {
   498     {
   477       MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   499       MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   478       SnrTag tag;
   500       SnrTag tag;
   489                                              hdr.GetAddr1 (),
   511                                              hdr.GetAddr1 (),
   490                                              hdr.GetDuration (),
   512                                              hdr.GetDuration (),
   491                                              txMode);
   513                                              txMode);
   492     } 
   514     } 
   493   else if (hdr.IsAck () &&
   515   else if (hdr.IsAck () &&
   494            hdr.GetAddr1 () == m_mac->GetAddress () &&
   516            hdr.GetAddr1 () == m_self &&
   495            (m_normalAckTimeoutEvent.IsRunning () || 
   517            (m_normalAckTimeoutEvent.IsRunning () || 
   496             m_fastAckTimeoutEvent.IsRunning () ||
   518             m_fastAckTimeoutEvent.IsRunning () ||
   497             m_superFastAckTimeoutEvent.IsRunning ()) &&
   519             m_superFastAckTimeoutEvent.IsRunning ()) &&
   498            m_txParams.MustWaitAck ()) 
   520            m_txParams.MustWaitAck ()) 
   499     {
   521     {
   528     } 
   550     } 
   529   else if (hdr.IsCtl ()) 
   551   else if (hdr.IsCtl ()) 
   530     {
   552     {
   531       MY_DEBUG ("rx drop " << hdr.GetTypeString ());
   553       MY_DEBUG ("rx drop " << hdr.GetTypeString ());
   532     } 
   554     } 
   533   else if (hdr.GetAddr1 () == m_mac->GetAddress ()) 
   555   else if (hdr.GetAddr1 () == m_self) 
   534     {
   556     {
   535       WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   557       WifiRemoteStation *station = GetStation (hdr.GetAddr2 ());
   536       station->ReportRxOk (rxSnr, txMode);
   558       station->ReportRxOk (rxSnr, txMode);
   537       
   559       
   538       if (hdr.IsQosData () && hdr.IsQosNoAck ()) 
   560       if (hdr.IsQosData () && hdr.IsQosNoAck ()) 
   623 MacLow::GetPifs (void) const
   645 MacLow::GetPifs (void) const
   624 {
   646 {
   625   return m_mac->GetPifs ();
   647   return m_mac->GetPifs ();
   626 }
   648 }
   627 Time
   649 Time
   628 MacLow::GetAckTimeout (void) const
       
   629 {
       
   630   return m_mac->GetAckTimeout ();
       
   631 }
       
   632 Time
       
   633 MacLow::GetCtsTimeout (void) const
   650 MacLow::GetCtsTimeout (void) const
   634 {
   651 {
   635   return m_mac->GetCtsTimeout ();
   652   return m_mac->GetCtsTimeout ();
   636 }
   653 }
   637 uint32_t 
   654 uint32_t 
   720       DoNavResetNow (duration);
   737       DoNavResetNow (duration);
   721       return;
   738       return;
   722     }
   739     }
   723   // XXX Note that we should also handle CF_END specially here
   740   // XXX Note that we should also handle CF_END specially here
   724   // but we don't for now because we do not generate them.
   741   // but we don't for now because we do not generate them.
   725   else if (hdr.GetAddr1 () != m_mac->GetAddress ())
   742   else if (hdr.GetAddr1 () != m_self)
   726     {
   743     {
   727       // see section 9.2.5.4 802.11-1999
   744       // see section 9.2.5.4 802.11-1999
   728       bool navUpdated = DoNavStartNow (duration);
   745       bool navUpdated = DoNavStartNow (duration);
   729       if (hdr.IsRts () && navUpdated)
   746       if (hdr.IsRts () && navUpdated)
   730         {
   747         {
   882   rts.SetType (WIFI_MAC_CTL_RTS);
   899   rts.SetType (WIFI_MAC_CTL_RTS);
   883   rts.SetDsNotFrom ();
   900   rts.SetDsNotFrom ();
   884   rts.SetDsNotTo ();
   901   rts.SetDsNotTo ();
   885   rts.SetNoMoreFragments ();
   902   rts.SetNoMoreFragments ();
   886   rts.SetAddr1 (m_currentHdr.GetAddr1 ());
   903   rts.SetAddr1 (m_currentHdr.GetAddr1 ());
   887   rts.SetAddr2 (m_mac->GetAddress ());
   904   rts.SetAddr2 (m_self);
   888   WifiMode rtsTxMode = GetRtsTxMode (m_currentPacket, &m_currentHdr);
   905   WifiMode rtsTxMode = GetRtsTxMode (m_currentPacket, &m_currentHdr);
   889   Time duration = Seconds (0);
   906   Time duration = Seconds (0);
   890   if (m_txParams.HasDurationId ()) 
   907   if (m_txParams.HasDurationId ()) 
   891     {
   908     {
   892       duration += m_txParams.GetDurationId ();
   909       duration += m_txParams.GetDurationId ();