427 m_sendCtsEvent.Cancel (); |
425 m_sendCtsEvent.Cancel (); |
428 m_sendAckEvent.Cancel (); |
426 m_sendAckEvent.Cancel (); |
429 m_sendDataEvent.Cancel (); |
427 m_sendDataEvent.Cancel (); |
430 m_waitSifsEvent.Cancel (); |
428 m_waitSifsEvent.Cancel (); |
431 m_endTxNoAckEvent.Cancel (); |
429 m_endTxNoAckEvent.Cancel (); |
432 m_waitRifsEvent.Cancel(); |
430 m_waitRifsEvent.Cancel(); |
433 m_phy = 0; |
431 m_phy = 0; |
434 m_stationManager = 0; |
432 m_stationManager = 0; |
435 if (m_phyMacLowListener != 0) |
433 if (m_phyMacLowListener != 0) |
436 { |
434 { |
437 delete m_phyMacLowListener; |
435 delete m_phyMacLowListener; |
521 m_phy = phy; |
519 m_phy = phy; |
522 m_phy->SetReceiveOkCallback (MakeCallback (&MacLow::DeaggregateAmpduAndReceive, this)); |
520 m_phy->SetReceiveOkCallback (MakeCallback (&MacLow::DeaggregateAmpduAndReceive, this)); |
523 m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, this)); |
521 m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, this)); |
524 SetupPhyMacLowListener (phy); |
522 SetupPhyMacLowListener (phy); |
525 } |
523 } |
|
524 |
526 Ptr<WifiPhy> |
525 Ptr<WifiPhy> |
527 MacLow::GetPhy (void) const |
526 MacLow::GetPhy (void) const |
528 { |
527 { |
529 return m_phy; |
528 return m_phy; |
530 } |
529 } |
|
530 |
531 void |
531 void |
532 MacLow::ResetPhy (void) |
532 MacLow::ResetPhy (void) |
533 { |
533 { |
534 m_phy->SetReceiveOkCallback (MakeNullCallback<void,Ptr<Packet>, double, WifiTxVector, enum WifiPreamble> ()); |
534 m_phy->SetReceiveOkCallback (MakeNullCallback<void,Ptr<Packet>, double, WifiTxVector, enum WifiPreamble> ()); |
535 m_phy->SetReceiveErrorCallback (MakeNullCallback<void,Ptr<const Packet>, double> ()); |
535 m_phy->SetReceiveErrorCallback (MakeNullCallback<void,Ptr<const Packet>, double> ()); |
536 RemovePhyMacLowListener (m_phy); |
536 RemovePhyMacLowListener (m_phy); |
537 m_phy = 0; |
537 m_phy = 0; |
538 } |
538 } |
|
539 |
539 void |
540 void |
540 MacLow::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> manager) |
541 MacLow::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> manager) |
541 { |
542 { |
542 m_stationManager = manager; |
543 m_stationManager = manager; |
543 } |
544 } |
545 void |
546 void |
546 MacLow::SetAddress (Mac48Address ad) |
547 MacLow::SetAddress (Mac48Address ad) |
547 { |
548 { |
548 m_self = ad; |
549 m_self = ad; |
549 } |
550 } |
|
551 |
550 void |
552 void |
551 MacLow::SetAckTimeout (Time ackTimeout) |
553 MacLow::SetAckTimeout (Time ackTimeout) |
552 { |
554 { |
553 m_ackTimeout = ackTimeout; |
555 m_ackTimeout = ackTimeout; |
554 } |
556 } |
|
557 |
555 void |
558 void |
556 MacLow::SetBasicBlockAckTimeout (Time blockAckTimeout) |
559 MacLow::SetBasicBlockAckTimeout (Time blockAckTimeout) |
557 { |
560 { |
558 m_basicBlockAckTimeout = blockAckTimeout; |
561 m_basicBlockAckTimeout = blockAckTimeout; |
559 } |
562 } |
|
563 |
560 void |
564 void |
561 MacLow::SetCompressedBlockAckTimeout (Time blockAckTimeout) |
565 MacLow::SetCompressedBlockAckTimeout (Time blockAckTimeout) |
562 { |
566 { |
563 m_compressedBlockAckTimeout = blockAckTimeout; |
567 m_compressedBlockAckTimeout = blockAckTimeout; |
564 } |
568 } |
|
569 |
565 void |
570 void |
566 MacLow::SetCtsToSelfSupported (bool enable) |
571 MacLow::SetCtsToSelfSupported (bool enable) |
567 { |
572 { |
568 m_ctsToSelfSupported = enable; |
573 m_ctsToSelfSupported = enable; |
569 } |
574 } |
|
575 |
570 bool |
576 bool |
571 MacLow::GetCtsToSelfSupported () const |
577 MacLow::GetCtsToSelfSupported () const |
572 { |
578 { |
573 return m_ctsToSelfSupported; |
579 return m_ctsToSelfSupported; |
574 } |
580 } |
|
581 |
575 void |
582 void |
576 MacLow::SetCtsTimeout (Time ctsTimeout) |
583 MacLow::SetCtsTimeout (Time ctsTimeout) |
577 { |
584 { |
578 m_ctsTimeout = ctsTimeout; |
585 m_ctsTimeout = ctsTimeout; |
579 } |
586 } |
|
587 |
580 void |
588 void |
581 MacLow::SetSifs (Time sifs) |
589 MacLow::SetSifs (Time sifs) |
582 { |
590 { |
583 m_sifs = sifs; |
591 m_sifs = sifs; |
584 } |
592 } |
|
593 |
585 void |
594 void |
586 MacLow::SetSlotTime (Time slotTime) |
595 MacLow::SetSlotTime (Time slotTime) |
587 { |
596 { |
588 m_slotTime = slotTime; |
597 m_slotTime = slotTime; |
589 } |
598 } |
|
599 |
590 void |
600 void |
591 MacLow::SetPifs (Time pifs) |
601 MacLow::SetPifs (Time pifs) |
592 { |
602 { |
593 m_pifs = pifs; |
603 m_pifs = pifs; |
594 } |
604 } |
|
605 |
595 void |
606 void |
596 MacLow::SetRifs (Time rifs) |
607 MacLow::SetRifs (Time rifs) |
597 { |
608 { |
598 m_rifs = rifs; |
609 m_rifs = rifs; |
599 } |
610 } |
|
611 |
600 void |
612 void |
601 MacLow::SetBssid (Mac48Address bssid) |
613 MacLow::SetBssid (Mac48Address bssid) |
602 { |
614 { |
603 m_bssid = bssid; |
615 m_bssid = bssid; |
604 } |
616 } |
|
617 |
605 void |
618 void |
606 MacLow::SetPromisc (void) |
619 MacLow::SetPromisc (void) |
607 { |
620 { |
608 m_promisc = true; |
621 m_promisc = true; |
609 } |
622 } |
|
623 |
610 Mac48Address |
624 Mac48Address |
611 MacLow::GetAddress (void) const |
625 MacLow::GetAddress (void) const |
612 { |
626 { |
613 return m_self; |
627 return m_self; |
614 } |
628 } |
|
629 |
615 Time |
630 Time |
616 MacLow::GetAckTimeout (void) const |
631 MacLow::GetAckTimeout (void) const |
617 { |
632 { |
618 return m_ackTimeout; |
633 return m_ackTimeout; |
619 } |
634 } |
|
635 |
620 Time |
636 Time |
621 MacLow::GetBasicBlockAckTimeout () const |
637 MacLow::GetBasicBlockAckTimeout () const |
622 { |
638 { |
623 return m_basicBlockAckTimeout; |
639 return m_basicBlockAckTimeout; |
624 } |
640 } |
|
641 |
625 Time |
642 Time |
626 MacLow::GetCompressedBlockAckTimeout () const |
643 MacLow::GetCompressedBlockAckTimeout () const |
627 { |
644 { |
628 return m_compressedBlockAckTimeout; |
645 return m_compressedBlockAckTimeout; |
629 } |
646 } |
|
647 |
630 Time |
648 Time |
631 MacLow::GetCtsTimeout (void) const |
649 MacLow::GetCtsTimeout (void) const |
632 { |
650 { |
633 return m_ctsTimeout; |
651 return m_ctsTimeout; |
634 } |
652 } |
|
653 |
635 Time |
654 Time |
636 MacLow::GetSifs (void) const |
655 MacLow::GetSifs (void) const |
637 { |
656 { |
638 return m_sifs; |
657 return m_sifs; |
639 } |
658 } |
|
659 |
640 Time |
660 Time |
641 MacLow::GetRifs (void) const |
661 MacLow::GetRifs (void) const |
642 { |
662 { |
643 return m_rifs; |
663 return m_rifs; |
644 } |
664 } |
|
665 |
645 Time |
666 Time |
646 MacLow::GetSlotTime (void) const |
667 MacLow::GetSlotTime (void) const |
647 { |
668 { |
648 return m_slotTime; |
669 return m_slotTime; |
649 } |
670 } |
|
671 |
650 Time |
672 Time |
651 MacLow::GetPifs (void) const |
673 MacLow::GetPifs (void) const |
652 { |
674 { |
653 return m_pifs; |
675 return m_pifs; |
654 } |
676 } |
|
677 |
655 Mac48Address |
678 Mac48Address |
656 MacLow::GetBssid (void) const |
679 MacLow::GetBssid (void) const |
657 { |
680 { |
658 return m_bssid; |
681 return m_bssid; |
659 } |
682 } |
|
683 |
660 bool |
684 bool |
661 MacLow::IsPromisc (void) const |
685 MacLow::IsPromisc (void) const |
662 { |
686 { |
663 return m_promisc; |
687 return m_promisc; |
664 } |
688 } |
665 |
689 |
666 void |
690 void |
667 MacLow::SetRxCallback (Callback<void,Ptr<Packet>,const WifiMacHeader *> callback) |
691 MacLow::SetRxCallback (Callback<void, Ptr<Packet>, const WifiMacHeader *> callback) |
668 { |
692 { |
669 m_rxCallback = callback; |
693 m_rxCallback = callback; |
670 } |
694 } |
|
695 |
671 void |
696 void |
672 MacLow::RegisterDcfListener (MacLowDcfListener *listener) |
697 MacLow::RegisterDcfListener (MacLowDcfListener *listener) |
673 { |
698 { |
674 m_dcfListeners.push_back (listener); |
699 m_dcfListeners.push_back (listener); |
675 } |
700 } |
703 * - ctsTimeout |
728 * - ctsTimeout |
704 * - sendDataAfterCTS |
729 * - sendDataAfterCTS |
705 * expired. This means that one of these timers is still |
730 * expired. This means that one of these timers is still |
706 * running. They are all cancelled below anyway by the |
731 * running. They are all cancelled below anyway by the |
707 * call to CancelAllEvents (because of at least one |
732 * call to CancelAllEvents (because of at least one |
708 * of these two timer) which will trigger a call to the |
733 * of these two timers) which will trigger a call to the |
709 * previous listener's cancel method. |
734 * previous listener's cancel method. |
710 * |
735 * |
711 * This typically happens because the high-priority |
736 * This typically happens because the high-priority |
712 * QapScheduler has taken access to the channel from |
737 * QapScheduler has taken access to the channel from |
713 * one of the Edca of the QAP. |
738 * one of the Edca of the QAP. |
714 */ |
739 */ |
715 m_currentHdr = *hdr; |
740 m_currentHdr = *hdr; |
716 CancelAllEvents (); |
741 CancelAllEvents (); |
717 m_listener = listener; |
742 m_listener = listener; |
718 m_txParams = params; |
743 m_txParams = params; |
719 |
|
720 //NS_ASSERT (m_phy->IsStateIdle ()); |
|
721 |
744 |
722 if(m_aggregateQueue->GetSize () == 0) |
745 if(m_aggregateQueue->GetSize () == 0) |
723 { |
746 { |
724 m_currentPacket = packet->Copy (); |
747 m_currentPacket = packet->Copy (); |
725 m_ampdu = IsAmpdu (m_currentPacket, m_currentHdr); |
748 m_ampdu = IsAmpdu (m_currentPacket, m_currentHdr); |
756 } |
779 } |
757 |
780 |
758 /* When this method completes, we have taken ownership of the medium. */ |
781 /* When this method completes, we have taken ownership of the medium. */ |
759 NS_ASSERT (m_phy->IsStateTx ()); |
782 NS_ASSERT (m_phy->IsStateTx ()); |
760 } |
783 } |
|
784 |
761 bool |
785 bool |
762 MacLow::NeedCtsToSelf (void) |
786 MacLow::NeedCtsToSelf (void) |
763 { |
787 { |
764 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
788 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
765 return m_stationManager->NeedCtsToSelf (dataTxVector); |
789 return m_stationManager->NeedCtsToSelf (dataTxVector); |
766 } |
790 } |
|
791 |
767 void |
792 void |
768 MacLow::ReceiveError (Ptr<const Packet> packet, double rxSnr) |
793 MacLow::ReceiveError (Ptr<const Packet> packet, double rxSnr) |
769 { |
794 { |
770 NS_LOG_FUNCTION (this << packet << rxSnr); |
795 NS_LOG_FUNCTION (this << packet << rxSnr); |
771 NS_LOG_DEBUG ("rx failed "); |
796 NS_LOG_DEBUG ("rx failed "); |
773 Ptr<Packet> pkt = packet->Copy(); |
798 Ptr<Packet> pkt = packet->Copy(); |
774 bool isInAmpdu = pkt->RemovePacketTag(ampdu); |
799 bool isInAmpdu = pkt->RemovePacketTag(ampdu); |
775 |
800 |
776 if(isInAmpdu && m_receivedAtLeastOneMpdu && (ampdu.GetNoOfMpdus() == 1)) |
801 if(isInAmpdu && m_receivedAtLeastOneMpdu && (ampdu.GetNoOfMpdus() == 1)) |
777 { |
802 { |
778 MpduAggregator::DeaggregatedMpdus packets = MpduAggregator::Deaggregate (pkt); |
803 MpduAggregator::DeaggregatedMpdus packets = MpduAggregator::Deaggregate (pkt); |
779 MpduAggregator::DeaggregatedMpdusCI n = packets.begin (); |
804 MpduAggregator::DeaggregatedMpdusCI n = packets.begin (); |
780 WifiMacHeader hdr; |
805 WifiMacHeader hdr; |
781 (*n).first->PeekHeader(hdr); |
806 (*n).first->PeekHeader(hdr); |
782 if(hdr.IsQosData()) |
807 if(hdr.IsQosData()) |
783 { |
808 { |
784 NS_LOG_DEBUG ("last a-mpdu subframe detected/sendImmediateBlockAck from=" << hdr.GetAddr2 ()); |
809 NS_LOG_DEBUG ("last a-mpdu subframe detected/sendImmediateBlockAck from=" << hdr.GetAddr2 ()); |
785 m_sendAckEvent = Simulator::Schedule (GetSifs (), |
810 m_sendAckEvent = Simulator::Schedule (GetSifs (), |
786 &MacLow::SendBlockAckAfterAmpdu, this, |
811 &MacLow::SendBlockAckAfterAmpdu, this, |
787 hdr.GetQosTid(), |
812 hdr.GetQosTid (), |
788 hdr.GetAddr2 (), |
813 hdr.GetAddr2 (), |
789 hdr.GetDuration (), |
814 hdr.GetDuration (), |
790 m_currentTxVector); |
815 m_currentTxVector); |
791 } |
816 } |
792 else if (hdr.IsBlockAckReq()) |
817 else if (hdr.IsBlockAckReq()) |
793 { |
818 { |
794 NS_LOG_DEBUG("last a-mpdu subframe is BAR"); |
819 NS_LOG_DEBUG("last a-mpdu subframe is BAR"); |
795 } |
820 } |
796 m_receivedAtLeastOneMpdu = false; |
821 m_receivedAtLeastOneMpdu = false; |
797 } |
822 } |
798 else if (m_txParams.MustWaitFastAck ()) |
823 else if (m_txParams.MustWaitFastAck ()) |
799 { |
824 { |
800 NS_ASSERT (m_fastAckFailedTimeoutEvent.IsExpired ()); |
825 NS_ASSERT (m_fastAckFailedTimeoutEvent.IsExpired ()); |
891 { |
916 { |
892 if (ampduSubframe) |
917 if (ampduSubframe) |
893 { |
918 { |
894 NS_FATAL_ERROR ("Received CTS as part of an A-MPDU"); |
919 NS_FATAL_ERROR ("Received CTS as part of an A-MPDU"); |
895 } |
920 } |
|
921 |
896 NS_LOG_DEBUG ("receive cts from=" << m_currentHdr.GetAddr1 ()); |
922 NS_LOG_DEBUG ("receive cts from=" << m_currentHdr.GetAddr1 ()); |
|
923 |
897 SnrTag tag; |
924 SnrTag tag; |
898 packet->RemovePacketTag (tag); |
925 packet->RemovePacketTag (tag); |
899 m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
926 m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
900 rxSnr, txVector.GetMode ()); |
927 rxSnr, txVector.GetMode ()); |
901 m_stationManager->ReportRtsOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
928 m_stationManager->ReportRtsOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
923 m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
950 m_stationManager->ReportRxOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
924 rxSnr, txVector.GetMode ()); |
951 rxSnr, txVector.GetMode ()); |
925 m_stationManager->ReportDataOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
952 m_stationManager->ReportDataOk (m_currentHdr.GetAddr1 (), &m_currentHdr, |
926 rxSnr, txVector.GetMode (), tag.Get ()); |
953 rxSnr, txVector.GetMode (), tag.Get ()); |
927 |
954 |
928 FlushAggregateQueue(); |
955 FlushAggregateQueue (); |
929 bool gotAck = false; |
956 bool gotAck = false; |
|
957 |
930 if (m_txParams.MustWaitNormalAck () |
958 if (m_txParams.MustWaitNormalAck () |
931 && m_normalAckTimeoutEvent.IsRunning ()) |
959 && m_normalAckTimeoutEvent.IsRunning ()) |
932 { |
960 { |
933 m_normalAckTimeoutEvent.Cancel (); |
961 m_normalAckTimeoutEvent.Cancel (); |
934 NotifyAckTimeoutResetNow (); |
962 NotifyAckTimeoutResetNow (); |
1182 //Not implemented |
1211 //Not implemented |
1183 NS_ASSERT (false); |
1212 NS_ASSERT (false); |
1184 } |
1213 } |
1185 return hdr.GetSize () + blockAck.GetSerializedSize () + 4; |
1214 return hdr.GetSize () + blockAck.GetSerializedSize () + 4; |
1186 } |
1215 } |
|
1216 |
1187 uint32_t |
1217 uint32_t |
1188 MacLow::GetRtsSize (void) const |
1218 MacLow::GetRtsSize (void) const |
1189 { |
1219 { |
1190 WifiMacHeader rts; |
1220 WifiMacHeader rts; |
1191 rts.SetType (WIFI_MAC_CTL_RTS); |
1221 rts.SetType (WIFI_MAC_CTL_RTS); |
1192 return rts.GetSize () + 4; |
1222 return rts.GetSize () + 4; |
1193 } |
1223 } |
|
1224 |
1194 Time |
1225 Time |
1195 MacLow::GetAckDuration (Mac48Address to, WifiTxVector dataTxVector) const |
1226 MacLow::GetAckDuration (Mac48Address to, WifiTxVector dataTxVector) const |
1196 { |
1227 { |
1197 WifiTxVector ackTxVector = GetAckTxVectorForData (to, dataTxVector.GetMode ()); |
1228 WifiTxVector ackTxVector = GetAckTxVectorForData (to, dataTxVector.GetMode ()); |
1198 return GetAckDuration (ackTxVector); |
1229 return GetAckDuration (ackTxVector); |
1199 } |
1230 } |
|
1231 |
1200 Time |
1232 Time |
1201 MacLow::GetAckDuration (WifiTxVector ackTxVector) const |
1233 MacLow::GetAckDuration (WifiTxVector ackTxVector) const |
1202 { |
1234 { |
1203 NS_ASSERT (ackTxVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT); // ACK should always use non-HT PPDU (HT PPDU cases not supported yet) |
1235 NS_ASSERT (ackTxVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT); // ACK should always use non-HT PPDU (HT PPDU cases not supported yet) |
1204 return m_phy->CalculateTxDuration (GetAckSize (), ackTxVector, WIFI_PREAMBLE_LONG, m_phy->GetFrequency(), 0, 0); |
1236 return m_phy->CalculateTxDuration (GetAckSize (), ackTxVector, WIFI_PREAMBLE_LONG, m_phy->GetFrequency(), 0, 0); |
1205 } |
1237 } |
|
1238 |
1206 Time |
1239 Time |
1207 MacLow::GetBlockAckDuration (Mac48Address to, WifiTxVector blockAckReqTxVector, enum BlockAckType type) const |
1240 MacLow::GetBlockAckDuration (Mac48Address to, WifiTxVector blockAckReqTxVector, enum BlockAckType type) const |
1208 { |
1241 { |
1209 /* |
1242 /* |
1210 * For immediate Basic BlockAck we should transmit the frame with the same WifiMode |
1243 * For immediate Basic BlockAck we should transmit the frame with the same WifiMode |
1211 * as the BlockAckReq. |
1244 * as the BlockAckReq. |
1212 */ |
1245 */ |
1213 WifiPreamble preamble; |
1246 WifiPreamble preamble; |
1214 if (blockAckReqTxVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT && type == BASIC_BLOCK_ACK) |
1247 if (blockAckReqTxVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT && type == BASIC_BLOCK_ACK) |
1215 preamble= WIFI_PREAMBLE_HT_MF; |
1248 preamble = WIFI_PREAMBLE_HT_MF; |
1216 else |
1249 else |
1217 preamble=WIFI_PREAMBLE_LONG; |
1250 preamble = WIFI_PREAMBLE_LONG; |
1218 return m_phy->CalculateTxDuration (GetBlockAckSize (type), blockAckReqTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1251 return m_phy->CalculateTxDuration (GetBlockAckSize (type), blockAckReqTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1219 } |
1252 } |
|
1253 |
1220 Time |
1254 Time |
1221 MacLow::GetCtsDuration (Mac48Address to, WifiTxVector rtsTxVector) const |
1255 MacLow::GetCtsDuration (Mac48Address to, WifiTxVector rtsTxVector) const |
1222 { |
1256 { |
1223 WifiTxVector ctsTxVector = GetCtsTxVectorForRts (to, rtsTxVector.GetMode ()); |
1257 WifiTxVector ctsTxVector = GetCtsTxVectorForRts (to, rtsTxVector.GetMode ()); |
1224 return GetCtsDuration (ctsTxVector); |
1258 return GetCtsDuration (ctsTxVector); |
1226 |
1260 |
1227 Time |
1261 Time |
1228 MacLow::GetCtsDuration (WifiTxVector ctsTxVector) const |
1262 MacLow::GetCtsDuration (WifiTxVector ctsTxVector) const |
1229 { |
1263 { |
1230 NS_ASSERT (ctsTxVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT); // CTS should always use non-HT PPDU (HT PPDU cases not supported yet) |
1264 NS_ASSERT (ctsTxVector.GetMode ().GetModulationClass () != WIFI_MOD_CLASS_HT); // CTS should always use non-HT PPDU (HT PPDU cases not supported yet) |
1231 return m_phy->CalculateTxDuration (GetCtsSize (), ctsTxVector, WIFI_PREAMBLE_LONG, m_phy->GetFrequency(), 0, 0); |
1265 return m_phy->CalculateTxDuration (GetCtsSize (), ctsTxVector, WIFI_PREAMBLE_LONG, m_phy->GetFrequency (), 0, 0); |
1232 } |
1266 } |
|
1267 |
1233 uint32_t |
1268 uint32_t |
1234 MacLow::GetCtsSize (void) const |
1269 MacLow::GetCtsSize (void) const |
1235 { |
1270 { |
1236 WifiMacHeader cts; |
1271 WifiMacHeader cts; |
1237 cts.SetType (WIFI_MAC_CTL_CTS); |
1272 cts.SetType (WIFI_MAC_CTL_CTS); |
1238 return cts.GetSize () + 4; |
1273 return cts.GetSize () + 4; |
1239 } |
1274 } |
|
1275 |
1240 uint32_t |
1276 uint32_t |
1241 MacLow::GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1277 MacLow::GetSize (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1242 { |
1278 { |
1243 uint32_t size; |
1279 uint32_t size; |
1244 WifiMacTrailer fcs; |
1280 WifiMacTrailer fcs; |
1259 MacLow::GetRtsTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1295 MacLow::GetRtsTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1260 { |
1296 { |
1261 Mac48Address to = hdr->GetAddr1 (); |
1297 Mac48Address to = hdr->GetAddr1 (); |
1262 return m_stationManager->GetRtsTxVector (to, hdr, packet); |
1298 return m_stationManager->GetRtsTxVector (to, hdr, packet); |
1263 } |
1299 } |
|
1300 |
1264 WifiTxVector |
1301 WifiTxVector |
1265 MacLow::GetDataTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1302 MacLow::GetDataTxVector (Ptr<const Packet> packet, const WifiMacHeader *hdr) const |
1266 { |
1303 { |
1267 Mac48Address to = hdr->GetAddr1 (); |
1304 Mac48Address to = hdr->GetAddr1 (); |
1268 WifiMacTrailer fcs; |
1305 WifiMacTrailer fcs; |
1269 uint32_t size = packet->GetSize ()+ hdr->GetSize () + fcs.GetSerializedSize (); |
1306 uint32_t size = packet->GetSize ()+ hdr->GetSize () + fcs.GetSerializedSize (); |
1270 //size is not used in anything!! will not worry about aggregation |
1307 //size is not used in anything!! will not worry about aggregation |
1271 return m_stationManager->GetDataTxVector (to, hdr, packet, size); |
1308 return m_stationManager->GetDataTxVector (to, hdr, packet, size); |
1272 } |
1309 } |
|
1310 |
1273 WifiTxVector |
1311 WifiTxVector |
1274 MacLow::GetCtsTxVector (Mac48Address to, WifiMode rtsTxMode) const |
1312 MacLow::GetCtsTxVector (Mac48Address to, WifiMode rtsTxMode) const |
1275 { |
1313 { |
1276 return m_stationManager->GetCtsTxVector (to, rtsTxMode); |
1314 return m_stationManager->GetCtsTxVector (to, rtsTxMode); |
1277 } |
1315 } |
|
1316 |
1278 WifiTxVector |
1317 WifiTxVector |
1279 MacLow::GetAckTxVector (Mac48Address to, WifiMode dataTxMode) const |
1318 MacLow::GetAckTxVector (Mac48Address to, WifiMode dataTxMode) const |
1280 { |
1319 { |
1281 return m_stationManager->GetAckTxVector (to, dataTxMode); |
1320 return m_stationManager->GetAckTxVector (to, dataTxMode); |
1282 } |
1321 } |
|
1322 |
1283 WifiTxVector |
1323 WifiTxVector |
1284 MacLow::GetBlockAckTxVector (Mac48Address to, WifiMode dataTxMode) const |
1324 MacLow::GetBlockAckTxVector (Mac48Address to, WifiMode dataTxMode) const |
1285 { |
1325 { |
1286 return m_stationManager->GetBlockAckTxVector (to, dataTxMode); |
1326 return m_stationManager->GetBlockAckTxVector (to, dataTxMode); |
1287 } |
1327 } |
1289 WifiTxVector |
1329 WifiTxVector |
1290 MacLow::GetCtsTxVectorForRts (Mac48Address to, WifiMode rtsTxMode) const |
1330 MacLow::GetCtsTxVectorForRts (Mac48Address to, WifiMode rtsTxMode) const |
1291 { |
1331 { |
1292 return GetCtsTxVector (to, rtsTxMode); |
1332 return GetCtsTxVector (to, rtsTxMode); |
1293 } |
1333 } |
|
1334 |
1294 WifiTxVector |
1335 WifiTxVector |
1295 MacLow::GetAckTxVectorForData (Mac48Address to, WifiMode dataTxMode) const |
1336 MacLow::GetAckTxVectorForData (Mac48Address to, WifiMode dataTxMode) const |
1296 { |
1337 { |
1297 return GetAckTxVector (to, dataTxMode); |
1338 return GetAckTxVector (to, dataTxMode); |
1298 } |
1339 } |
1299 |
|
1300 |
1340 |
1301 Time |
1341 Time |
1302 MacLow::CalculateOverallTxTime (Ptr<const Packet> packet, |
1342 MacLow::CalculateOverallTxTime (Ptr<const Packet> packet, |
1303 const WifiMacHeader* hdr, |
1343 const WifiMacHeader* hdr, |
1304 const MacLowTransmissionParameters& params) const |
1344 const MacLowTransmissionParameters& params) const |
1316 else |
1356 else |
1317 { |
1357 { |
1318 //Otherwise, RTS should always use non-HT PPDU (HT PPDU cases not supported yet) |
1358 //Otherwise, RTS should always use non-HT PPDU (HT PPDU cases not supported yet) |
1319 preamble = WIFI_PREAMBLE_LONG; |
1359 preamble = WIFI_PREAMBLE_LONG; |
1320 } |
1360 } |
1321 txTime += m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1361 txTime += m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1322 txTime += GetCtsDuration (hdr->GetAddr1 (), rtsTxVector); |
1362 txTime += GetCtsDuration (hdr->GetAddr1 (), rtsTxVector); |
1323 txTime += Time (GetSifs () * 2); |
1363 txTime += Time (GetSifs () * 2); |
1324 } |
1364 } |
1325 WifiTxVector dataTxVector = GetDataTxVector (packet, hdr); |
1365 WifiTxVector dataTxVector = GetDataTxVector (packet, hdr); |
1326 if (m_phy->GetGreenfield () && m_stationManager->GetGreenfieldSupported (m_currentHdr.GetAddr1 ())) |
1366 if (m_phy->GetGreenfield () && m_stationManager->GetGreenfieldSupported (m_currentHdr.GetAddr1 ())) |
1327 preamble = WIFI_PREAMBLE_HT_GF; |
1367 preamble = WIFI_PREAMBLE_HT_GF; |
1328 else if (dataTxVector.GetMode().GetModulationClass () == WIFI_MOD_CLASS_HT) |
1368 else if (dataTxVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT) |
1329 preamble = WIFI_PREAMBLE_HT_MF; |
1369 preamble = WIFI_PREAMBLE_HT_MF; |
1330 else |
1370 else |
1331 preamble = WIFI_PREAMBLE_LONG; |
1371 preamble = WIFI_PREAMBLE_LONG; |
1332 uint32_t dataSize = GetSize (packet, hdr); |
1372 uint32_t dataSize = GetSize (packet, hdr); |
1333 txTime += m_phy->CalculateTxDuration (dataSize, dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1373 txTime += m_phy->CalculateTxDuration (dataSize, dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1334 if (params.MustWaitAck ()) |
1374 if (params.MustWaitAck ()) |
1335 { |
1375 { |
1336 txTime += GetSifs (); |
1376 txTime += GetSifs (); |
1337 txTime += GetAckDuration (hdr->GetAddr1 (), dataTxVector); |
1377 txTime += GetAckDuration (hdr->GetAddr1 (), dataTxVector); |
1338 } |
1378 } |
1392 */ |
1432 */ |
1393 WifiMacHeader cts; |
1433 WifiMacHeader cts; |
1394 cts.SetType (WIFI_MAC_CTL_CTS); |
1434 cts.SetType (WIFI_MAC_CTL_CTS); |
1395 WifiTxVector txVector=GetRtsTxVector (packet, &hdr); |
1435 WifiTxVector txVector=GetRtsTxVector (packet, &hdr); |
1396 Time navCounterResetCtsMissedDelay = |
1436 Time navCounterResetCtsMissedDelay = |
1397 m_phy->CalculateTxDuration (cts.GetSerializedSize (), txVector, preamble, m_phy->GetFrequency(), 0, 0) + |
1437 m_phy->CalculateTxDuration (cts.GetSerializedSize (), txVector, preamble, m_phy->GetFrequency (), 0, 0) + |
1398 Time (2 * GetSifs ()) + Time (2 * GetSlotTime ()); |
1438 Time (2 * GetSifs ()) + Time (2 * GetSlotTime ()); |
1399 m_navCounterResetCtsMissed = Simulator::Schedule (navCounterResetCtsMissedDelay, |
1439 m_navCounterResetCtsMissed = Simulator::Schedule (navCounterResetCtsMissedDelay, |
1400 &MacLow::NavCounterResetCtsMissed, this, |
1440 &MacLow::NavCounterResetCtsMissed, this, |
1401 Simulator::Now ()); |
1441 Simulator::Now ()); |
1402 } |
1442 } |
1437 m_lastNavDuration = duration; |
1478 m_lastNavDuration = duration; |
1438 return true; |
1479 return true; |
1439 } |
1480 } |
1440 return false; |
1481 return false; |
1441 } |
1482 } |
|
1483 |
1442 void |
1484 void |
1443 MacLow::NotifyAckTimeoutStartNow (Time duration) |
1485 MacLow::NotifyAckTimeoutStartNow (Time duration) |
1444 { |
1486 { |
1445 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1487 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1446 { |
1488 { |
1447 (*i)->AckTimeoutStart (duration); |
1489 (*i)->AckTimeoutStart (duration); |
1448 } |
1490 } |
1449 } |
1491 } |
|
1492 |
1450 void |
1493 void |
1451 MacLow::NotifyAckTimeoutResetNow () |
1494 MacLow::NotifyAckTimeoutResetNow () |
1452 { |
1495 { |
1453 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1496 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1454 { |
1497 { |
1455 (*i)->AckTimeoutReset (); |
1498 (*i)->AckTimeoutReset (); |
1456 } |
1499 } |
1457 } |
1500 } |
|
1501 |
1458 void |
1502 void |
1459 MacLow::NotifyCtsTimeoutStartNow (Time duration) |
1503 MacLow::NotifyCtsTimeoutStartNow (Time duration) |
1460 { |
1504 { |
1461 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1505 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1462 { |
1506 { |
1463 (*i)->CtsTimeoutStart (duration); |
1507 (*i)->CtsTimeoutStart (duration); |
1464 } |
1508 } |
1465 } |
1509 } |
|
1510 |
1466 void |
1511 void |
1467 MacLow::NotifyCtsTimeoutResetNow () |
1512 MacLow::NotifyCtsTimeoutResetNow () |
1468 { |
1513 { |
1469 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1514 for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) |
1470 { |
1515 { |
1525 else |
1570 else |
1526 { |
1571 { |
1527 Simulator::Schedule (delay, &MacLow::SendPacket, this, newPacket, txVector, preamble, packetType); |
1572 Simulator::Schedule (delay, &MacLow::SendPacket, this, newPacket, txVector, preamble, packetType); |
1528 } |
1573 } |
1529 if(queueSize > 1) |
1574 if(queueSize > 1) |
1530 delay = delay + m_phy->CalculateTxDuration (GetSize (newPacket, &newHdr), txVector, preamble, m_phy->GetFrequency(), packetType, 0); |
1575 delay = delay + m_phy->CalculateTxDuration (GetSize (newPacket, &newHdr), txVector, preamble, m_phy->GetFrequency (), packetType, 0); |
1531 preamble = WIFI_PREAMBLE_NONE; |
1576 preamble = WIFI_PREAMBLE_NONE; |
1532 } |
1577 } |
1533 } |
1578 } |
1534 } |
1579 } |
1535 |
1580 |
1657 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
1706 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
1658 duration += GetSifs (); |
1707 duration += GetSifs (); |
1659 duration += GetCtsDuration (m_currentHdr.GetAddr1 (), rtsTxVector); |
1708 duration += GetCtsDuration (m_currentHdr.GetAddr1 (), rtsTxVector); |
1660 duration += GetSifs (); |
1709 duration += GetSifs (); |
1661 duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), |
1710 duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), |
1662 dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1711 dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1663 duration += GetSifs (); |
1712 duration += GetSifs (); |
1664 if (m_txParams.MustWaitBasicBlockAck ()) |
1713 if (m_txParams.MustWaitBasicBlockAck ()) |
1665 { |
1714 { |
1666 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2(), dataTxVector.GetMode ()); |
1715 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1667 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, BASIC_BLOCK_ACK); |
1716 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, BASIC_BLOCK_ACK); |
1668 } |
1717 } |
1669 else if (m_txParams.MustWaitCompressedBlockAck ()) |
1718 else if (m_txParams.MustWaitCompressedBlockAck ()) |
1670 { |
1719 { |
1671 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2(), dataTxVector.GetMode ()); |
1720 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1672 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
1721 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
1673 } |
1722 } |
1674 else if (m_txParams.MustWaitAck ()) |
1723 else if (m_txParams.MustWaitAck ()) |
1675 { |
1724 { |
1676 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1725 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1677 } |
1726 } |
1678 if (m_txParams.HasNextPacket ()) |
1727 if (m_txParams.HasNextPacket ()) |
1679 { |
1728 { |
1680 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1729 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1681 dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1730 dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1682 if (m_txParams.MustWaitAck ()) |
1731 if (m_txParams.MustWaitAck ()) |
1683 { |
1732 { |
1684 duration += GetSifs (); |
1733 duration += GetSifs (); |
1685 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1734 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1686 } |
1735 } |
1687 } |
1736 } |
1688 } |
1737 } |
1689 rts.SetDuration (duration); |
1738 rts.SetDuration (duration); |
1690 |
1739 |
1691 Time txDuration = m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1740 Time txDuration = m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1692 Time timerDelay = txDuration + GetCtsTimeout (); |
1741 Time timerDelay = txDuration + GetCtsTimeout (); |
1693 |
1742 |
1694 NS_ASSERT (m_ctsTimeoutEvent.IsExpired ()); |
1743 NS_ASSERT (m_ctsTimeoutEvent.IsExpired ()); |
1695 NotifyCtsTimeoutStartNow (timerDelay); |
1744 NotifyCtsTimeoutStartNow (timerDelay); |
1696 m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this); |
1745 m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this); |
1714 else if (dataTxVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT) |
1763 else if (dataTxVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT) |
1715 preamble = WIFI_PREAMBLE_HT_MF; |
1764 preamble = WIFI_PREAMBLE_HT_MF; |
1716 else |
1765 else |
1717 preamble = WIFI_PREAMBLE_LONG; |
1766 preamble = WIFI_PREAMBLE_LONG; |
1718 |
1767 |
1719 Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1768 Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1720 if (m_txParams.MustWaitNormalAck ()) |
1769 if (m_txParams.MustWaitNormalAck ()) |
1721 { |
1770 { |
1722 Time timerDelay = txDuration + GetAckTimeout (); |
1771 Time timerDelay = txDuration + GetAckTimeout (); |
1723 NS_ASSERT (m_normalAckTimeoutEvent.IsExpired ()); |
1772 NS_ASSERT (m_normalAckTimeoutEvent.IsExpired ()); |
1724 NotifyAckTimeoutStartNow (timerDelay); |
1773 NotifyAckTimeoutStartNow (timerDelay); |
1819 } |
1868 } |
1820 if (m_txParams.HasNextPacket ()) |
1869 if (m_txParams.HasNextPacket ()) |
1821 { |
1870 { |
1822 duration += GetSifs (); |
1871 duration += GetSifs (); |
1823 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1872 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1824 dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1873 dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1825 if (m_txParams.MustWaitAck ()) |
1874 if (m_txParams.MustWaitAck ()) |
1826 { |
1875 { |
1827 duration += GetSifs (); |
1876 duration += GetSifs (); |
1828 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1877 duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
1829 } |
1878 } |
1883 else |
1932 else |
1884 { |
1933 { |
1885 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
1934 WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr); |
1886 duration += GetSifs (); |
1935 duration += GetSifs (); |
1887 duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket,&m_currentHdr), |
1936 duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket,&m_currentHdr), |
1888 dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1937 dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1889 if (m_txParams.MustWaitBasicBlockAck ()) |
1938 if (m_txParams.MustWaitBasicBlockAck ()) |
1890 { |
1939 { |
1891 |
1940 |
1892 duration += GetSifs (); |
1941 duration += GetSifs (); |
1893 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1942 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1906 } |
1955 } |
1907 if (m_txParams.HasNextPacket ()) |
1956 if (m_txParams.HasNextPacket ()) |
1908 { |
1957 { |
1909 duration += GetSifs (); |
1958 duration += GetSifs (); |
1910 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1959 duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), |
1911 dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1960 dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1912 if (m_txParams.MustWaitCompressedBlockAck ()) |
1961 if (m_txParams.MustWaitCompressedBlockAck ()) |
1913 { |
1962 { |
1914 duration += GetSifs (); |
1963 duration += GetSifs (); |
1915 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1964 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
1916 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
1965 duration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
1930 WifiMacTrailer fcs; |
1979 WifiMacTrailer fcs; |
1931 packet->AddTrailer (fcs); |
1980 packet->AddTrailer (fcs); |
1932 |
1981 |
1933 ForwardDown (packet, &cts, ctsTxVector,preamble); |
1982 ForwardDown (packet, &cts, ctsTxVector,preamble); |
1934 |
1983 |
1935 Time txDuration = m_phy->CalculateTxDuration (GetCtsSize (), ctsTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
1984 Time txDuration = m_phy->CalculateTxDuration (GetCtsSize (), ctsTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
1936 txDuration += GetSifs (); |
1985 txDuration += GetSifs (); |
1937 NS_ASSERT (m_sendDataEvent.IsExpired ()); |
1986 NS_ASSERT (m_sendDataEvent.IsExpired ()); |
1938 |
1987 |
1939 m_sendDataEvent = Simulator::Schedule (txDuration, |
1988 m_sendDataEvent = Simulator::Schedule (txDuration, |
1940 &MacLow::SendDataAfterCts, this, |
1989 &MacLow::SendDataAfterCts, this, |
1989 { |
2038 { |
1990 for (std::vector<Item>::size_type i = 0; i != m_txPackets.size(); i++) |
2039 for (std::vector<Item>::size_type i = 0; i != m_txPackets.size(); i++) |
1991 { |
2040 { |
1992 uint8_t tid = GetTid (m_txPackets.at(i).packet, m_txPackets.at(i).hdr); |
2041 uint8_t tid = GetTid (m_txPackets.at(i).packet, m_txPackets.at(i).hdr); |
1993 AcIndex ac = QosUtilsMapTidToAc (tid); |
2042 AcIndex ac = QosUtilsMapTidToAc (tid); |
1994 std::map<AcIndex, MacLowAggregationCapableTransmissionListener*>::const_iterator listenerIt= m_edcaListeners.find(ac); |
2043 std::map<AcIndex, MacLowAggregationCapableTransmissionListener*>::const_iterator listenerIt = m_edcaListeners.find (ac); |
1995 |
2044 |
1996 listenerIt->second->CompleteMpduTx (m_txPackets.at(i).packet, m_txPackets.at(i).hdr, m_txPackets.at(i).timestamp); |
2045 listenerIt->second->CompleteMpduTx (m_txPackets.at(i).packet, m_txPackets.at(i).hdr, m_txPackets.at(i).timestamp); |
1997 } |
2046 } |
1998 m_txPackets.clear (); |
2047 m_txPackets.clear (); |
1999 } |
2048 } |
2027 newDuration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
2076 newDuration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
2028 } |
2077 } |
2029 if (m_txParams.HasNextPacket ()) |
2078 if (m_txParams.HasNextPacket ()) |
2030 { |
2079 { |
2031 newDuration += GetSifs (); |
2080 newDuration += GetSifs (); |
2032 newDuration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
2081 newDuration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
2033 if (m_txParams.MustWaitCompressedBlockAck ()) |
2082 if (m_txParams.MustWaitCompressedBlockAck ()) |
2034 { |
2083 { |
2035 newDuration += GetSifs (); |
2084 newDuration += GetSifs (); |
2036 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
2085 WifiTxVector blockAckReqTxVector = GetBlockAckTxVector (m_currentHdr.GetAddr2 (), dataTxVector.GetMode ()); |
2037 newDuration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
2086 newDuration += GetBlockAckDuration (m_currentHdr.GetAddr1 (), blockAckReqTxVector, COMPRESSED_BLOCK_ACK); |
2041 newDuration += GetSifs (); |
2090 newDuration += GetSifs (); |
2042 newDuration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
2091 newDuration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); |
2043 } |
2092 } |
2044 } |
2093 } |
2045 |
2094 |
2046 Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr),dataTxVector, preamble, m_phy->GetFrequency(), 0, 0); |
2095 Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), dataTxVector, preamble, m_phy->GetFrequency (), 0, 0); |
2047 duration -= txDuration; |
2096 duration -= txDuration; |
2048 duration -= GetSifs (); |
2097 duration -= GetSifs (); |
2049 |
2098 |
2050 duration = std::max (duration, newDuration); |
2099 duration = std::max (duration, newDuration); |
2051 NS_ASSERT (duration >= MicroSeconds (0)); |
2100 NS_ASSERT (duration >= MicroSeconds (0)); |
2142 if (!QosUtilsIsOldPacket ((*it).second.first.GetStartingSequence (), seqNumber)) |
2191 if (!QosUtilsIsOldPacket ((*it).second.first.GetStartingSequence (), seqNumber)) |
2143 { |
2192 { |
2144 StoreMpduIfNeeded (packet, hdr); |
2193 StoreMpduIfNeeded (packet, hdr); |
2145 if (!IsInWindow(hdr.GetSequenceNumber (), (*it).second.first.GetStartingSequence (), (*it).second.first.GetBufferSize ())) |
2194 if (!IsInWindow(hdr.GetSequenceNumber (), (*it).second.first.GetStartingSequence (), (*it).second.first.GetBufferSize ())) |
2146 { |
2195 { |
2147 uint16_t delta = (seqNumber - (*it).second.first.GetWinEnd()+ 4096) % 4096; |
2196 uint16_t delta = (seqNumber - (*it).second.first.GetWinEnd() + 4096) % 4096; |
2148 if (delta > 1) |
2197 if (delta > 1) |
2149 { |
2198 { |
2150 (*it).second.first.SetWinEnd (seqNumber); |
2199 (*it).second.first.SetWinEnd (seqNumber); |
2151 int16_t winEnd = (*it).second.first.GetWinEnd (); |
2200 int16_t winEnd = (*it).second.first.GetWinEnd (); |
2152 int16_t bufferSize = (*it).second.first.GetBufferSize (); |
2201 int16_t bufferSize = (*it).second.first.GetBufferSize (); |
2154 (*it).second.first.SetStartingSequence (sum); |
2203 (*it).second.first.SetStartingSequence (sum); |
2155 RxCompleteBufferedPacketsWithSmallerSequence ((*it).second.first.GetStartingSequence (), originator, tid); |
2204 RxCompleteBufferedPacketsWithSmallerSequence ((*it).second.first.GetStartingSequence (), originator, tid); |
2156 } |
2205 } |
2157 } |
2206 } |
2158 RxCompleteBufferedPacketsUntilFirstLost (originator, tid); //forwards up packets starting from winstart and set winstart to last +1 |
2207 RxCompleteBufferedPacketsUntilFirstLost (originator, tid); //forwards up packets starting from winstart and set winstart to last +1 |
2159 (*it).second.first.SetWinEnd(((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize()-1)%4096); |
2208 (*it).second.first.SetWinEnd (((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize() - 1) % 4096); |
2160 } |
2209 } |
2161 return true; |
2210 return true; |
2162 } |
2211 } |
2163 return false; |
2212 return false; |
2164 } |
2213 } |
2165 else |
2214 else |
2166 return StoreMpduIfNeeded (packet,hdr); |
2215 return StoreMpduIfNeeded (packet, hdr); |
2167 } |
2216 } |
2168 |
2217 |
2169 bool |
2218 bool |
2170 MacLow::StoreMpduIfNeeded (Ptr<Packet> packet, WifiMacHeader hdr) |
2219 MacLow::StoreMpduIfNeeded (Ptr<Packet> packet, WifiMacHeader hdr) |
2171 { |
2220 { |
2476 } |
2525 } |
2477 else |
2526 else |
2478 { |
2527 { |
2479 if (!QosUtilsIsOldPacket ((*it).second.first.GetStartingSequence(), reqHdr.GetStartingSequence ())) |
2528 if (!QosUtilsIsOldPacket ((*it).second.first.GetStartingSequence(), reqHdr.GetStartingSequence ())) |
2480 { |
2529 { |
2481 (*it).second.first.SetStartingSequence(reqHdr.GetStartingSequence ()); |
2530 (*it).second.first.SetStartingSequence (reqHdr.GetStartingSequence ()); |
2482 (*it).second.first.SetWinEnd(((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize()-1) % 4096); |
2531 (*it).second.first.SetWinEnd (((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize() - 1) % 4096); |
2483 RxCompleteBufferedPacketsWithSmallerSequence (reqHdr.GetStartingSequence (), originator, tid); |
2532 RxCompleteBufferedPacketsWithSmallerSequence (reqHdr.GetStartingSequence (), originator, tid); |
2484 RxCompleteBufferedPacketsUntilFirstLost (originator, tid); |
2533 RxCompleteBufferedPacketsUntilFirstLost (originator, tid); |
2485 (*it).second.first.SetWinEnd(((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize()-1) % 4096); |
2534 (*it).second.first.SetWinEnd (((*it).second.first.GetStartingSequence()+(*it).second.first.GetBufferSize() - 1) % 4096); |
2486 } |
2535 } |
2487 } |
2536 } |
2488 } |
2537 } |
2489 else |
2538 else |
2490 { |
2539 { |
2506 { |
2555 { |
2507 NS_ASSERT (agreement.m_inactivityEvent.IsRunning ()); |
2556 NS_ASSERT (agreement.m_inactivityEvent.IsRunning ()); |
2508 agreement.m_inactivityEvent.Cancel (); |
2557 agreement.m_inactivityEvent.Cancel (); |
2509 Time timeout = MicroSeconds (1024 * agreement.GetTimeout ()); |
2558 Time timeout = MicroSeconds (1024 * agreement.GetTimeout ()); |
2510 AcIndex ac = QosUtilsMapTidToAc (agreement.GetTid ()); |
2559 AcIndex ac = QosUtilsMapTidToAc (agreement.GetTid ()); |
2511 //std::map<AcIndex, MacLowTransmissionListener*>::iterator it = m_edcaListeners.find (ac); |
|
2512 //NS_ASSERT (it != m_edcaListeners.end ()); |
|
2513 |
|
2514 agreement.m_inactivityEvent = Simulator::Schedule (timeout, |
2560 agreement.m_inactivityEvent = Simulator::Schedule (timeout, |
2515 &MacLowAggregationCapableTransmissionListener::BlockAckInactivityTimeout, |
2561 &MacLowAggregationCapableTransmissionListener::BlockAckInactivityTimeout, |
2516 m_edcaListeners[ac], |
2562 m_edcaListeners[ac], |
2517 agreement.GetPeer (), |
2563 agreement.GetPeer (), |
2518 agreement.GetTid ()); |
2564 agreement.GetTid ()); |
2539 bool normalAck = false; |
2585 bool normalAck = false; |
2540 bool ampduSubframe = false; |
2586 bool ampduSubframe = false; |
2541 if (aggregatedPacket->RemovePacketTag(ampdu)) |
2587 if (aggregatedPacket->RemovePacketTag(ampdu)) |
2542 { |
2588 { |
2543 ampduSubframe = true; |
2589 ampduSubframe = true; |
2544 MpduAggregator::DeaggregatedMpdus packets = MpduAggregator::Deaggregate (aggregatedPacket); |
2590 MpduAggregator::DeaggregatedMpdus packets = MpduAggregator::Deaggregate (aggregatedPacket); |
2545 MpduAggregator::DeaggregatedMpdusCI n = packets.begin (); |
2591 MpduAggregator::DeaggregatedMpdusCI n = packets.begin (); |
2546 |
2592 |
2547 WifiMacHeader firsthdr; |
2593 WifiMacHeader firsthdr; |
2548 (*n).first->PeekHeader(firsthdr); |
2594 (*n).first->PeekHeader (firsthdr); |
2549 NS_LOG_DEBUG ("duration/id=" << firsthdr.GetDuration ()); |
2595 NS_LOG_DEBUG ("duration/id=" << firsthdr.GetDuration ()); |
2550 NotifyNav ((*n).first, firsthdr, preamble); |
2596 NotifyNav ((*n).first, firsthdr, preamble); |
|
2597 |
2551 if (firsthdr.GetAddr1 () == m_self) |
2598 if (firsthdr.GetAddr1 () == m_self) |
2552 { |
2599 { |
2553 m_receivedAtLeastOneMpdu = true; |
2600 m_receivedAtLeastOneMpdu = true; |
2554 if (firsthdr.IsAck () || firsthdr.IsBlockAck () || firsthdr.IsBlockAckReq ()) |
2601 if (firsthdr.IsAck () || firsthdr.IsBlockAck () || firsthdr.IsBlockAckReq ()) |
2555 ReceiveOk ((*n).first, rxSnr, txVector, preamble, ampduSubframe); |
2602 ReceiveOk ((*n).first, rxSnr, txVector, preamble, ampduSubframe); |
2556 else if (firsthdr.IsData () || firsthdr.IsQosData ()) |
2603 else if (firsthdr.IsData () || firsthdr.IsQosData ()) |
2557 { |
2604 { |
2558 NS_LOG_DEBUG ("Deaagregate packet with sequence=" << firsthdr.GetSequenceNumber ()); |
2605 NS_LOG_DEBUG ("Deaggregate packet with sequence=" << firsthdr.GetSequenceNumber ()); |
2559 ReceiveOk ((*n).first, rxSnr, txVector, preamble, ampduSubframe); |
2606 ReceiveOk ((*n).first, rxSnr, txVector, preamble, ampduSubframe); |
2560 if (firsthdr.IsQosAck ()) |
2607 if (firsthdr.IsQosAck ()) |
2561 { |
2608 { |
2562 NS_LOG_DEBUG ("Normal Ack"); |
2609 NS_LOG_DEBUG ("Normal Ack"); |
2563 normalAck = true; |
2610 normalAck = true; |
2582 /* See section 11.5.3 in IEEE 802.11 for mean of this timer */ |
2629 /* See section 11.5.3 in IEEE 802.11 for mean of this timer */ |
2583 ResetBlockAckInactivityTimerIfNeeded (it->second.first); |
2630 ResetBlockAckInactivityTimerIfNeeded (it->second.first); |
2584 NS_LOG_DEBUG ("rx A-MPDU/sendImmediateBlockAck from=" << firsthdr.GetAddr2 ()); |
2631 NS_LOG_DEBUG ("rx A-MPDU/sendImmediateBlockAck from=" << firsthdr.GetAddr2 ()); |
2585 m_sendAckEvent = Simulator::Schedule (GetSifs (), |
2632 m_sendAckEvent = Simulator::Schedule (GetSifs (), |
2586 &MacLow::SendBlockAckAfterAmpdu, this, |
2633 &MacLow::SendBlockAckAfterAmpdu, this, |
2587 firsthdr.GetQosTid(), |
2634 firsthdr.GetQosTid (), |
2588 firsthdr.GetAddr2 (), |
2635 firsthdr.GetAddr2 (), |
2589 firsthdr.GetDuration (), |
2636 firsthdr.GetDuration (), |
2590 txVector); |
2637 txVector); |
2591 } |
2638 } |
2592 else |
2639 else |
2616 |
2663 |
2617 if (peekedPacket == 0) |
2664 if (peekedPacket == 0) |
2618 return true; |
2665 return true; |
2619 |
2666 |
2620 //An HT STA shall not transmit a PPDU that has a duration that is greater than aPPDUMaxTime (10 milliseconds) |
2667 //An HT STA shall not transmit a PPDU that has a duration that is greater than aPPDUMaxTime (10 milliseconds) |
2621 if(m_phy->CalculateTxDuration (aggregatedPacket->GetSize () + peekedPacket->GetSize () + peekedHdr.GetSize () + WIFI_MAC_FCS_LENGTH, dataTxVector, preamble, m_phy->GetFrequency(), 0, 0) > MilliSeconds(10)) |
2668 if(m_phy->CalculateTxDuration (aggregatedPacket->GetSize () + peekedPacket->GetSize () + peekedHdr.GetSize () + WIFI_MAC_FCS_LENGTH, dataTxVector, preamble, m_phy->GetFrequency (), 0, 0) > MilliSeconds(10)) |
2622 return true; |
2669 return true; |
2623 |
2670 |
2624 if (!m_mpduAggregator->CanBeAggregated (peekedPacket->GetSize () + peekedHdr.GetSize () + WIFI_MAC_FCS_LENGTH, aggregatedPacket, size)) |
2671 if (!m_mpduAggregator->CanBeAggregated (peekedPacket->GetSize () + peekedHdr.GetSize () + WIFI_MAC_FCS_LENGTH, aggregatedPacket, size)) |
2625 return true; |
2672 return true; |
2626 |
2673 |
2790 //find what will the sequence number be so that we don't send more than 64 packets apart |
2837 //find what will the sequence number be so that we don't send more than 64 packets apart |
2791 currentSequenceNumber = listenerIt->second->PeekNextSequenceNumberfor (&peekedHdr); |
2838 currentSequenceNumber = listenerIt->second->PeekNextSequenceNumberfor (&peekedHdr); |
2792 |
2839 |
2793 if (listenerIt->second->GetMsduAggregator () != 0) |
2840 if (listenerIt->second->GetMsduAggregator () != 0) |
2794 { |
2841 { |
2795 tempPacket = PerformMsduAggregation(peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, blockAckSize); |
2842 tempPacket = PerformMsduAggregation (peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, blockAckSize); |
2796 if (tempPacket != 0) //MSDU aggregation |
2843 if (tempPacket != 0) //MSDU aggregation |
2797 peekedPacket = tempPacket->Copy(); |
2844 peekedPacket = tempPacket->Copy(); |
2798 } |
2845 } |
2799 } |
2846 } |
2800 } |
2847 } |
2810 //find what will the sequence number be so that we don't send more than 64 packets apart |
2857 //find what will the sequence number be so that we don't send more than 64 packets apart |
2811 currentSequenceNumber = listenerIt->second->PeekNextSequenceNumberfor (&peekedHdr); |
2858 currentSequenceNumber = listenerIt->second->PeekNextSequenceNumberfor (&peekedHdr); |
2812 |
2859 |
2813 if (listenerIt->second->GetMsduAggregator () != 0 && IsInWindow (currentSequenceNumber, startingSequenceNumber, 64)) |
2860 if (listenerIt->second->GetMsduAggregator () != 0 && IsInWindow (currentSequenceNumber, startingSequenceNumber, 64)) |
2814 { |
2861 { |
2815 tempPacket = PerformMsduAggregation(peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, blockAckSize); |
2862 tempPacket = PerformMsduAggregation (peekedPacket, &peekedHdr, &tstamp, currentAggregatedPacket, blockAckSize); |
2816 if (tempPacket != 0) //MSDU aggregation |
2863 if (tempPacket != 0) //MSDU aggregation |
2817 peekedPacket = tempPacket->Copy(); |
2864 peekedPacket = tempPacket->Copy(); |
2818 } |
2865 } |
2819 } |
2866 } |
2820 } |
2867 } |
2893 Ptr<Packet> currentAmsduPacket = Create<Packet> (); |
2940 Ptr<Packet> currentAmsduPacket = Create<Packet> (); |
2894 Ptr<Packet> tempPacket = Create<Packet> (); |
2941 Ptr<Packet> tempPacket = Create<Packet> (); |
2895 |
2942 |
2896 Ptr<WifiMacQueue> queue; |
2943 Ptr<WifiMacQueue> queue; |
2897 AcIndex ac = QosUtilsMapTidToAc (GetTid (packet, *hdr)); |
2944 AcIndex ac = QosUtilsMapTidToAc (GetTid (packet, *hdr)); |
2898 std::map<AcIndex, MacLowAggregationCapableTransmissionListener*>::const_iterator listenerIt= m_edcaListeners.find(ac); |
2945 std::map<AcIndex, MacLowAggregationCapableTransmissionListener*>::const_iterator listenerIt = m_edcaListeners.find (ac); |
2899 NS_ASSERT (listenerIt != m_edcaListeners.end ()); |
2946 NS_ASSERT (listenerIt != m_edcaListeners.end ()); |
2900 queue = listenerIt->second->GetQueue(); |
2947 queue = listenerIt->second->GetQueue(); |
2901 |
2948 |
2902 listenerIt->second->GetMsduAggregator ()->Aggregate (packet, currentAmsduPacket, |
2949 listenerIt->second->GetMsduAggregator ()->Aggregate (packet, currentAmsduPacket, |
2903 listenerIt->second->GetSrcAddressForAggregation (*hdr), |
2950 listenerIt->second->GetSrcAddressForAggregation (*hdr), |