757 { |
757 { |
758 CtrlBAckRequestHeader blockAckReq; |
758 CtrlBAckRequestHeader blockAckReq; |
759 packet->RemoveHeader (blockAckReq); |
759 packet->RemoveHeader (blockAckReq); |
760 if (!blockAckReq.IsMultiTid ()) |
760 if (!blockAckReq.IsMultiTid ()) |
761 { |
761 { |
762 AgreementsI it = m_bAckAgreements.find (std::make_pair (hdr.GetAddr2 (), blockAckReq.GetTidInfo ())); |
762 uint8_t tid = blockAckReq.GetTidInfo (); |
|
763 AgreementsI it = m_bAckAgreements.find (std::make_pair (hdr.GetAddr2 (), tid)); |
763 if (it != m_bAckAgreements.end ()) |
764 if (it != m_bAckAgreements.end ()) |
764 { |
765 { |
|
766 //Update block ack cache |
|
767 BlockAckCachesI i = m_bAckCaches.find (std::make_pair (hdr.GetAddr2 (), tid)); |
|
768 NS_ASSERT (i != m_bAckCaches.end ()); |
|
769 (*i).second.UpdateWithBlockAckReq (blockAckReq.GetStartingSequence ()); |
|
770 |
765 NS_ASSERT (m_sendAckEvent.IsExpired ()); |
771 NS_ASSERT (m_sendAckEvent.IsExpired ()); |
766 /* See section 11.5.3 in IEEE802.11 for mean of this timer */ |
772 /* See section 11.5.3 in IEEE802.11 for mean of this timer */ |
767 ResetBlockAckInactivityTimerIfNeeded (it->second.first); |
773 ResetBlockAckInactivityTimerIfNeeded (it->second.first); |
768 if ((*it).second.first.IsImmediateBlockAck ()) |
774 if ((*it).second.first.IsImmediateBlockAck ()) |
769 { |
775 { |
1540 std::list<BufferedPacket> buffer (0); |
1552 std::list<BufferedPacket> buffer (0); |
1541 AgreementKey key (originator, respHdr->GetTid ()); |
1553 AgreementKey key (originator, respHdr->GetTid ()); |
1542 AgreementValue value (agreement, buffer); |
1554 AgreementValue value (agreement, buffer); |
1543 m_bAckAgreements.insert (std::make_pair (key, value)); |
1555 m_bAckAgreements.insert (std::make_pair (key, value)); |
1544 |
1556 |
|
1557 BlockAckCache cache; |
|
1558 cache.Init (startingSeq, respHdr->GetBufferSize () + 1); |
|
1559 m_bAckCaches.insert (std::make_pair (key, cache)); |
|
1560 |
1545 if (respHdr->GetTimeout () != 0) |
1561 if (respHdr->GetTimeout () != 0) |
1546 { |
1562 { |
1547 AgreementsI it = m_bAckAgreements.find (std::make_pair (originator, respHdr->GetTid ())); |
1563 AgreementsI it = m_bAckAgreements.find (std::make_pair (originator, respHdr->GetTid ())); |
1548 Time timeout = MicroSeconds (1024 * agreement.GetTimeout ()); |
1564 Time timeout = MicroSeconds (1024 * agreement.GetTimeout ()); |
1549 |
1565 |
1724 CtrlBAckResponseHeader blockAck; |
1744 CtrlBAckResponseHeader blockAck; |
1725 uint8_t tid; |
1745 uint8_t tid; |
1726 bool immediate = false; |
1746 bool immediate = false; |
1727 if (!reqHdr.IsMultiTid ()) |
1747 if (!reqHdr.IsMultiTid ()) |
1728 { |
1748 { |
1729 blockAck.SetStartingSequence (reqHdr.GetStartingSequence ()); |
|
1730 blockAck.SetTidInfo (reqHdr.GetTidInfo ()); |
|
1731 |
|
1732 tid = reqHdr.GetTidInfo (); |
1749 tid = reqHdr.GetTidInfo (); |
1733 AgreementsI it; |
1750 AgreementsI it = m_bAckAgreements.find (std::make_pair (originator, tid)); |
1734 it = m_bAckAgreements.find (std::make_pair (originator, tid)); |
|
1735 if (it != m_bAckAgreements.end ()) |
1751 if (it != m_bAckAgreements.end ()) |
1736 { |
1752 { |
|
1753 blockAck.SetStartingSequence (reqHdr.GetStartingSequence ()); |
|
1754 blockAck.SetTidInfo (tid); |
1737 immediate = (*it).second.first.IsImmediateBlockAck (); |
1755 immediate = (*it).second.first.IsImmediateBlockAck (); |
1738 uint16_t startingSeqCtrl = reqHdr.GetStartingSequenceControl (); |
|
1739 |
|
1740 /* All packets with smaller sequence than starting sequence control must be passed up to Wifimac |
|
1741 * See 9.10.3 in IEEE8022.11e standard. |
|
1742 */ |
|
1743 RxCompleteBufferedPacketsWithSmallerSequence ((startingSeqCtrl>>4)&0x0fff, originator, tid); |
|
1744 |
|
1745 std::list<BufferedPacket>::iterator i = (*it).second.second.begin (); |
|
1746 |
|
1747 /* For more details about next operations see section 9.10.4 of IEEE802.11e standard */ |
|
1748 if (reqHdr.IsBasic ()) |
1756 if (reqHdr.IsBasic ()) |
1749 { |
1757 { |
1750 blockAck.SetType (BASIC_BLOCK_ACK); |
1758 blockAck.SetType (BASIC_BLOCK_ACK); |
1751 uint16_t guard = startingSeqCtrl; |
|
1752 std::list<BufferedPacket>::iterator lastComplete = (*it).second.second.begin (); |
|
1753 for (; i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl (); i++) |
|
1754 { |
|
1755 blockAck.SetReceivedFragment ((*i).second.GetSequenceNumber (), |
|
1756 (*i).second.GetFragmentNumber ()); |
|
1757 /* Section 9.10.4 in IEEE802.11n: the recipient shall pass up to WifiMac the |
|
1758 * MSDUs and A-MSDUs starting with the starting sequence number |
|
1759 * sequentially until there is an incomplete MSDU or A-MSDU in the buffer */ |
|
1760 if (!(*i).second.IsMoreFragments ()) |
|
1761 { |
|
1762 while (lastComplete != i) |
|
1763 { |
|
1764 m_rxCallback ((*lastComplete).first, &(*lastComplete).second); |
|
1765 lastComplete++; |
|
1766 } |
|
1767 m_rxCallback ((*lastComplete).first, &(*lastComplete).second); |
|
1768 lastComplete++; |
|
1769 } |
|
1770 guard = (*i).second.IsMoreFragments () ? (guard + 1) : (guard + 16) & 0xfff0; |
|
1771 } |
|
1772 (*it).second.first.SetStartingSequence ((guard>>4)&0x0fff); |
|
1773 /* All packets already forwarded to WifiMac must be removed from buffer: |
|
1774 [begin (), lastComplete) */ |
|
1775 (*it).second.second.erase ((*it).second.second.begin (), lastComplete); |
|
1776 for (i = lastComplete; i != (*it).second.second.end (); i++) |
|
1777 { |
|
1778 blockAck.SetReceivedFragment ((*i).second.GetSequenceNumber (), |
|
1779 (*i).second.GetFragmentNumber ()); |
|
1780 } |
|
1781 } |
1759 } |
1782 else if (reqHdr.IsCompressed ()) |
1760 else if (reqHdr.IsCompressed ()) |
1783 { |
1761 { |
1784 blockAck.SetType (COMPRESSED_BLOCK_ACK); |
1762 blockAck.SetType (COMPRESSED_BLOCK_ACK); |
1785 uint16_t guard = startingSeqCtrl; |
|
1786 std::list<BufferedPacket>::iterator lastComplete = (*it).second.second.begin (); |
|
1787 for (; i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl (); i++) |
|
1788 { |
|
1789 if (!(*i).second.IsMoreFragments ()) |
|
1790 { |
|
1791 blockAck.SetReceivedPacket ((*i).second.GetSequenceNumber ()); |
|
1792 while (lastComplete != i) |
|
1793 { |
|
1794 m_rxCallback ((*lastComplete).first, &(*lastComplete).second); |
|
1795 lastComplete++; |
|
1796 } |
|
1797 m_rxCallback ((*lastComplete).first, &(*lastComplete).second); |
|
1798 lastComplete++; |
|
1799 } |
|
1800 guard = (*i).second.IsMoreFragments () ? (guard + 1) : (guard + 16) & 0xfff0; |
|
1801 } |
|
1802 (*it).second.first.SetStartingSequence ((guard>>4)&0x0fff); |
|
1803 /* All packets already forwarded to WifiMac must be removed from buffer: |
|
1804 [begin (), lastcomplete) */ |
|
1805 (*it).second.second.erase ((*it).second.second.begin (), lastComplete); |
|
1806 i = lastComplete; |
|
1807 if (i != (*it).second.second.end ()) |
|
1808 { |
|
1809 guard = (*i).second.GetSequenceControl () & 0xfff0; |
|
1810 } |
|
1811 for (; i != (*it).second.second.end ();) |
|
1812 { |
|
1813 for (; i != (*it).second.second.end () && guard == (*i).second.GetSequenceControl (); i++) |
|
1814 { |
|
1815 if (!(*i).second.IsMoreFragments ()) |
|
1816 { |
|
1817 guard = (guard + 16) & 0xfff0; |
|
1818 blockAck.SetReceivedPacket ((*i).second.GetSequenceNumber ()); |
|
1819 } |
|
1820 else |
|
1821 { |
|
1822 guard += 1; |
|
1823 } |
|
1824 } |
|
1825 while (i != (*it).second.second.end () && ((guard >> 4) & 0x0fff) == (*i).second.GetSequenceNumber ()) |
|
1826 { |
|
1827 i++; |
|
1828 } |
|
1829 if (i != (*it).second.second.end ()) |
|
1830 { |
|
1831 guard = (*i).second.GetSequenceControl () & 0xfff0; |
|
1832 } |
|
1833 } |
|
1834 } |
1763 } |
|
1764 BlockAckCachesI i = m_bAckCaches.find (std::make_pair (originator, tid)); |
|
1765 NS_ASSERT (i != m_bAckCaches.end ()); |
|
1766 (*i).second.FillBlockAckBitmap (&blockAck); |
|
1767 |
|
1768 /* All packets with smaller sequence than starting sequence control must be passed up to Wifimac |
|
1769 * See 9.10.3 in IEEE8022.11e standard. |
|
1770 */ |
|
1771 RxCompleteBufferedPacketsWithSmallerSequence (reqHdr.GetStartingSequence (), originator, tid); |
|
1772 RxCompleteBufferedPacketsUntilFirstLost (originator, tid); |
1835 } |
1773 } |
1836 else |
1774 else |
1837 { |
1775 { |
1838 NS_LOG_DEBUG ("there's not a valid block ack agreement with "<<originator); |
1776 NS_LOG_DEBUG ("there's not a valid block ack agreement with "<<originator); |
1839 } |
1777 } |