diff --git a/src/devices/wifi/qos-blocked-destinations.cc b/src/devices/wifi/qos-blocked-destinations.cc new file mode 100644 index 000000000..10a906b82 --- /dev/null +++ b/src/devices/wifi/qos-blocked-destinations.cc @@ -0,0 +1,66 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mirko Banchi + */ +#include "qos-blocked-destinations.h" + +namespace ns3 { + +QosBlockedDestinations::QosBlockedDestinations () +{} + +QosBlockedDestinations::~QosBlockedDestinations () +{} + +bool +QosBlockedDestinations::IsBlocked (Mac48Address dest, uint8_t tid) const +{ + for (BlockedPacketsCI i = m_blockedQosPackets.begin (); i != m_blockedQosPackets.end (); i++) + { + if (i->first == dest && i->second == tid) + { + return true; + } + } + return false; +} + +void +QosBlockedDestinations::Block (Mac48Address dest, uint8_t tid) +{ + if (!IsBlocked (dest, tid)) + { + m_blockedQosPackets.push_back (std::make_pair (dest, tid)); + } +} + +void +QosBlockedDestinations::Unblock (Mac48Address dest, uint8_t tid) +{ + for (BlockedPacketsI i = m_blockedQosPackets.begin (); i != m_blockedQosPackets.end (); i++) + { + if (i->first == dest && i->second == tid) + { + m_blockedQosPackets.erase (i); + break; + } + } +} + +} //namespace ns3 \ No newline at end of file diff --git a/src/devices/wifi/qos-blocked-destinations.h b/src/devices/wifi/qos-blocked-destinations.h new file mode 100644 index 000000000..35b2cf45f --- /dev/null +++ b/src/devices/wifi/qos-blocked-destinations.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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 + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mirko Banchi + */ +#ifndef QOS_BLOCKED_DESTINATIONS_H +#define QOS_BLOCKED_DESTINATIONS_H + +#include +#include "ns3/mac48-address.h" + +namespace ns3 { + +class QosBlockedDestinations +{ +public: + QosBlockedDestinations (); + ~QosBlockedDestinations (); + + void Block (Mac48Address dest, uint8_t tid); + void Unblock (Mac48Address dest, uint8_t tid); + bool IsBlocked (Mac48Address dest, uint8_t tid) const; + +private: + typedef std::list > BlockedPackets; + typedef std::list >::iterator BlockedPacketsI; + typedef std::list >::const_iterator BlockedPacketsCI; + BlockedPackets m_blockedQosPackets; +}; + +} //namespace ns3 + +#endif /* QOS_BLOCKED_DESTINATIONS_H */ diff --git a/src/devices/wifi/wifi-mac-queue.cc b/src/devices/wifi/wifi-mac-queue.cc index 79ad8c07a..95073b103 100644 --- a/src/devices/wifi/wifi-mac-queue.cc +++ b/src/devices/wifi/wifi-mac-queue.cc @@ -24,6 +24,7 @@ #include "ns3/uinteger.h" #include "wifi-mac-queue.h" +#include "qos-blocked-destinations.h" using namespace std; @@ -298,4 +299,44 @@ WifiMacQueue::GetNPacketsByTidAndAddress (uint8_t tid, WifiMacHeader::AddressTyp return nPackets; } +Ptr +WifiMacQueue::DequeueFirstAvailable (WifiMacHeader *hdr, Time ×tamp, + const QosBlockedDestinations *blockedPackets) +{ + Cleanup (); + Ptr packet = 0; + for (PacketQueueI it = m_queue.begin (); it != m_queue.end (); it++) + { + if (!it->hdr.IsQosData () || + !blockedPackets->IsBlocked (it->hdr.GetAddr1 (), it->hdr.GetQosTid ())) + { + *hdr = it->hdr; + timestamp = it->tstamp; + packet = it->packet; + m_queue.erase (it); + m_size--; + return packet; + } + } + return packet; +} + +Ptr +WifiMacQueue::PeekFirstAvailable (WifiMacHeader *hdr, Time ×tamp, + const QosBlockedDestinations *blockedPackets) +{ + Cleanup (); + for (PacketQueueI it = m_queue.begin (); it != m_queue.end (); it++) + { + if (!it->hdr.IsQosData () || + !blockedPackets->IsBlocked (it->hdr.GetAddr1 (), it->hdr.GetQosTid ())) + { + *hdr = it->hdr; + timestamp = it->tstamp; + return it->packet; + } + } + return 0; +} + } // namespace ns3 diff --git a/src/devices/wifi/wifi-mac-queue.h b/src/devices/wifi/wifi-mac-queue.h index 2c4fa23db..fb1cad8c6 100644 --- a/src/devices/wifi/wifi-mac-queue.h +++ b/src/devices/wifi/wifi-mac-queue.h @@ -32,6 +32,7 @@ namespace ns3 { class WifiMacParameters; +class QosBlockedDestinations; /** * \brief a 802.11e-specific queue. @@ -99,12 +100,26 @@ public: uint32_t GetNPacketsByTidAndAddress (uint8_t tid, WifiMacHeader::AddressType type, Mac48Address addr); - + /** + * Returns first available packet for transmission. A packet could be no available + * if it's a QoS packet with a tid and an address1 fields equal to tid and addr + * respectively that index a pending agreement in the BlockAckManager object. + * So that packet must not be transmitted until reception of an ADDBA response frame from station + * addressed by addr. This method removes the packet from queue. + */ + Ptr DequeueFirstAvailable (WifiMacHeader *hdr, + Time &tStamp, + const QosBlockedDestinations *blockedPackets); + /** + * Returns first available packet for transmission. The packet isn't removed from queue. + */ + Ptr PeekFirstAvailable (WifiMacHeader *hdr, + Time &tStamp, + const QosBlockedDestinations *blockedPackets); void Flush (void); bool IsEmpty (void); uint32_t GetSize (void); - private: struct Item; diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index 25a21872e..2608630e7 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -57,6 +57,7 @@ def build(bld): 'originator-block-ack-agreement.cc', 'dcf.cc', 'ctrl-headers.cc', + 'qos-blocked-destinations.cc', 'block-ack-agreement.cc', 'block-ack-manager.cc', ]