From 2f101f268fe5a0d076706523eb46c2c6e9044af1 Mon Sep 17 00:00:00 2001 From: Mirko Banchi Date: Fri, 24 Apr 2009 09:10:14 +0200 Subject: [PATCH] new methods to look in the packet queue --- src/devices/wifi/wifi-mac-queue.cc | 112 +++++++++++++++++++++++++++-- src/devices/wifi/wifi-mac-queue.h | 52 +++++++++++--- 2 files changed, 151 insertions(+), 13 deletions(-) diff --git a/src/devices/wifi/wifi-mac-queue.cc b/src/devices/wifi/wifi-mac-queue.cc index ab7d5e30b..186749c7d 100644 --- a/src/devices/wifi/wifi-mac-queue.cc +++ b/src/devices/wifi/wifi-mac-queue.cc @@ -1,6 +1,7 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2005 INRIA + * Copyright (c) 2005, 2009 INRIA + * Copyright (c) 2009 MIRKO BANCHI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -16,8 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Mathieu Lacage + * Author: Mirko Banchi */ - #include "ns3/simulator.h" #include "ns3/packet.h" #include "ns3/uinteger.h" @@ -30,7 +31,6 @@ namespace ns3 { NS_OBJECT_ENSURE_REGISTERED (WifiMacQueue); - WifiMacQueue::Item::Item (Ptr packet, WifiMacHeader const &hdr, Time tstamp) @@ -69,16 +69,19 @@ WifiMacQueue::SetMaxSize (uint32_t maxSize) { m_maxSize = maxSize; } -void + +void WifiMacQueue::SetMaxDelay (Time delay) { m_maxDelay = delay; } + uint32_t WifiMacQueue::GetMaxSize (void) const { return m_maxSize; } + Time WifiMacQueue::GetMaxDelay (void) const { @@ -97,6 +100,7 @@ WifiMacQueue::Enqueue (Ptr packet, WifiMacHeader const &hdr) m_queue.push_back (Item (packet, hdr, now)); m_size++; } + void WifiMacQueue::Cleanup (void) { @@ -136,6 +140,72 @@ WifiMacQueue::Dequeue (WifiMacHeader *hdr) return 0; } +Ptr +WifiMacQueue::Peek (WifiMacHeader *hdr) +{ + Cleanup (); + if (!m_queue.empty ()) + { + Item i = m_queue.front (); + *hdr = i.hdr; + return i.packet; + } + return 0; +} + +Ptr +WifiMacQueue::DequeueByTidAndAddress (WifiMacHeader *hdr, uint8_t tid, + WifiMacHeader::AddressType index, Mac48Address dest) +{ + Cleanup (); + Ptr packet = 0; + if (!m_queue.empty ()) + { + PacketQueueI it; + NS_ASSERT (index <= 4); + for (it = m_queue.begin (); it != m_queue.end (); ++it) + { + if (it->hdr.IsQosData ()) + { + if (GetAddressForPacket (index, it) == dest && + it->hdr.GetQosTid () == tid) + { + packet = it->packet; + *hdr = it->hdr; + m_queue.erase (it); + m_size--; + break; + } + } + } + } + return packet; +} + +Ptr +WifiMacQueue::PeekByTidAndAddress (WifiMacHeader *hdr, uint8_t tid, + WifiMacHeader::AddressType index, Mac48Address dest) +{ + Cleanup (); + if (!m_queue.empty ()) + { + PacketQueueI it; + NS_ASSERT (index <= 4); + for (it = m_queue.begin (); it != m_queue.end (); ++it) + { + if (it->hdr.IsQosData ()) + { + if (GetAddressForPacket (index, it) == dest && + it->hdr.GetQosTid () == tid) + { + *hdr = it->hdr; + return it->packet; + } + } + } + } + return 0; +} bool WifiMacQueue::IsEmpty (void) @@ -144,7 +214,6 @@ WifiMacQueue::IsEmpty (void) return m_queue.empty (); } - uint32_t WifiMacQueue::GetSize (void) { @@ -158,4 +227,37 @@ WifiMacQueue::Flush (void) m_size = 0; } +Mac48Address +WifiMacQueue::GetAddressForPacket (uint8_t index, PacketQueueI it) +{ + if (index == WifiMacHeader::ADDR1) + { + return it->hdr.GetAddr1 (); + } + if (index == WifiMacHeader::ADDR2) + { + return it->hdr.GetAddr2 (); + } + if (index == WifiMacHeader::ADDR3) + { + return it->hdr.GetAddr3 (); + } + return 0; +} + +bool +WifiMacQueue::Remove (Ptr packet) +{ + PacketQueueI it = m_queue.begin (); + for (; it != m_queue.end (); it++) + { + if (it->packet == packet) + { + m_queue.erase (it); + return true; + } + } + return false; +} + } // namespace ns3 diff --git a/src/devices/wifi/wifi-mac-queue.h b/src/devices/wifi/wifi-mac-queue.h index ec77506a4..20498c7a0 100644 --- a/src/devices/wifi/wifi-mac-queue.h +++ b/src/devices/wifi/wifi-mac-queue.h @@ -1,6 +1,7 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2005 INRIA + * Copyright (c) 2005, 2009 INRIA + * Copyright (c) 2009 MIRKO BANCHI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -16,11 +17,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Mathieu Lacage + * Author: Mirko Banchi */ #ifndef WIFI_MAC_QUEUE_H #define WIFI_MAC_QUEUE_H -#include +#include #include #include "ns3/packet.h" #include "ns3/nstime.h" @@ -60,25 +62,60 @@ public: void Enqueue (Ptr packet, WifiMacHeader const &hdr); Ptr Dequeue (WifiMacHeader *hdr); - + Ptr Peek (WifiMacHeader *hdr); + /** + * Searchs and returns, if is present in this queue, first packet having + * address indicated by index equals to addr, and tid + * equals to tid. This method removes the packet from this queue. + * Is typically used by ns3::EdcaTxopN in order to perform correct MSDU + * aggregation (A-MSDU). + */ + Ptr DequeueByTidAndAddress (WifiMacHeader *hdr, + uint8_t tid, + WifiMacHeader::AddressType index, + Mac48Address addr); + /** + * Searchs and returns, if is present in this queue, first packet having + * address indicated by index equals to addr, and tid + * equals to tid. This method doesn't remove the packet from this queue. + * Is typically used by ns3::EdcaTxopN in order to perform correct MSDU + * aggregation (A-MSDU). + */ + Ptr PeekByTidAndAddress (WifiMacHeader *hdr, + uint8_t tid, + WifiMacHeader::AddressType index, + Mac48Address addr); + /** + * If exists, removes packet from queue and returns true. Otherwise it + * takes no effects and return false. Deletion of the packet is + * performed in linear time (O(n)). + */ + bool Remove (Ptr packet); + void Flush (void); bool IsEmpty (void); uint32_t GetSize (void); private: + struct Item; + + typedef std::list PacketQueue; + typedef std::list::reverse_iterator PacketQueueRI; + typedef std::list::iterator PacketQueueI; + void Cleanup (void); + Mac48Address GetAddressForPacket (uint8_t index, PacketQueueI); + struct Item { Item (Ptr packet, - WifiMacHeader const&hdr, + WifiMacHeader const &hdr, Time tstamp); Ptr packet; WifiMacHeader hdr; Time tstamp; }; - typedef std::deque PacketQueue; - typedef std::deque::reverse_iterator PacketQueueRI; - typedef std::deque::iterator PacketQueueI; + PacketQueue m_queue; WifiMacParameters *m_parameters; uint32_t m_size; @@ -88,5 +125,4 @@ private: } // namespace ns3 - #endif /* WIFI_MAC_QUEUE_H */