handle wifi action frames in high MACs
authorMirko Banchi <mk.banchi@gmail.com>
Wed, 03 Feb 2010 20:34:50 +0100
changeset 5953 9e400f6b8a2c
parent 5952 0588b01cd77e
child 5954 2b9e06875b69
handle wifi action frames in high MACs
src/devices/wifi/edca-txop-n.cc
src/devices/wifi/edca-txop-n.h
src/devices/wifi/qadhoc-wifi-mac.cc
src/devices/wifi/qadhoc-wifi-mac.h
src/devices/wifi/qap-wifi-mac.cc
src/devices/wifi/qap-wifi-mac.h
src/devices/wifi/qsta-wifi-mac.cc
src/devices/wifi/qsta-wifi-mac.h
--- a/src/devices/wifi/edca-txop-n.cc	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/edca-txop-n.cc	Wed Feb 03 20:34:50 2010 +0100
@@ -31,6 +31,7 @@
 #include "random-stream.h"
 #include "wifi-mac-queue.h"
 #include "msdu-aggregator.h"
+#include "mgt-headers.h"
 
 NS_LOG_COMPONENT_DEFINE ("EdcaTxopN");
 
@@ -699,4 +700,13 @@
   StartAccessIfNeeded ();
 }
 
+void
+EdcaTxopN::GotAddBaResponse (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient)
+{
+  NS_LOG_FUNCTION (this);
+  MY_DEBUG ("received AddBa response from "<<recipient);
+  //?
+  RestartAccessIfNeeded ();
+}
+
 } //namespace ns3
--- a/src/devices/wifi/edca-txop-n.h	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/edca-txop-n.h	Wed Feb 03 20:34:50 2010 +0100
@@ -45,6 +45,8 @@
 class WifiMacQueue;
 class RandomStream;
 class MsduAggregator;
+class MgtAddBaResponseHeader;
+
 
 /* This queue contains packets for a particular access class.
  * possibles access classes are:
@@ -110,6 +112,7 @@
   void GotCts (double snr, WifiMode txMode);
   void MissedCts (void);
   void GotAck (double snr, WifiMode txMode);
+  void GotAddBaResponse (const MgtAddBaResponseHeader *respHdr, Mac48Address recipient);
   void MissedAck (void);
   void StartNext (void);
   void Cancel (void);
--- a/src/devices/wifi/qadhoc-wifi-mac.cc	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qadhoc-wifi-mac.cc	Wed Feb 03 20:34:50 2010 +0100
@@ -354,7 +354,39 @@
     }
   else if (hdr->IsMgt ())
     {
-      //Handling action frames
+      if (hdr->IsAction ())
+        {
+          WifiActionHeader actionHdr;
+          packet->RemoveHeader (actionHdr);
+          if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+              actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_REQUEST)
+            {
+              MgtAddBaRequestHeader reqHdr;
+              packet->RemoveHeader (reqHdr);
+              SendAddBaResponse (&reqHdr, hdr->GetAddr2 ());
+            }
+          else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+                   actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_REQUEST)
+            {
+              MgtAddBaResponseHeader respHdr;
+              packet->RemoveHeader (respHdr);
+              m_queues[QosUtilsMapTidToAc (respHdr.GetTid ())]->GotAddBaResponse (&respHdr, hdr->GetAddr2 ());
+            }
+          else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+                   actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_DELBA)
+            {
+              MgtDelBaHeader delBaHdr;
+              packet->RemoveHeader (delBaHdr);
+              if (delBaHdr.IsByOriginator ())
+                {
+                  /* Block ack agreement tear down */
+                }
+              else
+                {
+                  /* We must notify correct queue tear down of agreement */
+                }
+            }
+        }
     }
 }
 
@@ -446,4 +478,59 @@
     }
 }
 
+
+void
+QadhocWifiMac::SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator)
+{
+  NS_LOG_FUNCTION (this);
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetAddr1 (originator);
+  hdr.SetAddr2 (m_low->GetAddress ());
+  hdr.SetAddr3 (m_low->GetAddress ());
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+
+  MgtAddBaResponseHeader respHdr;
+  StatusCode code;
+  code.SetSuccess ();
+  respHdr.SetStatusCode (code);
+  //Here a control about queues type?
+  respHdr.SetAmsduSupport (reqHdr->IsAmsduSupported ());
+
+  if (reqHdr->IsImmediateBlockAck ())
+    {
+      respHdr.SetImmediateBlockAck ();
+    }
+  else
+    {
+      respHdr.SetDelayedBlockAck ();
+    }
+  respHdr.SetTid (reqHdr->GetTid ());
+  /* For now there's not no control about limit of reception.
+     We assume that receiver has no limit on reception.
+     However we assume that a receiver sets a bufferSize in order to satisfy
+     next equation:
+     (bufferSize + 1) % 16 = 0
+     So if a recipient is able to buffer a packet, it should be also able to buffer
+     all possible packet's fragments.
+     See section 7.3.1.14 in IEEE802.11e for more details. */
+  respHdr.SetBufferSize (1023);
+  respHdr.SetTimeout (reqHdr->GetTimeout ());
+
+  WifiActionHeader actionHdr;
+  WifiActionHeader::ActionValue action;
+  action.blockAck = WifiActionHeader::BLOCK_ACK_ADDBA_RESPONSE;
+  actionHdr.SetAction (WifiActionHeader::BLOCK_ACK, action);
+
+  Ptr<Packet> packet = Create<Packet> ();
+  packet->AddHeader (respHdr);
+  packet->AddHeader (actionHdr);
+  
+  /* ns3::MacLow have to buffer all correctly received packet for this block ack session */
+  //m_low->CreateIngoingAgreement (&respHdr, originator, reqHdr->GetStartingSequence ());
+
+  //Better a management queue? 
+  m_queues[QosUtilsMapTidToAc (reqHdr->GetTid ())]->PushFront (packet, hdr);
+}
 } //namespace ns3
--- a/src/devices/wifi/qadhoc-wifi-mac.h	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qadhoc-wifi-mac.h	Wed Feb 03 20:34:50 2010 +0100
@@ -38,6 +38,7 @@
 class DcfManager;
 class MacLow;
 class MacRxMiddle;
+class MgtAddBaRequestHeader;
 
 class QadhocWifiMac : public WifiMac
 {
@@ -82,7 +83,8 @@
   void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to);
   QadhocWifiMac &operator = (const QadhocWifiMac &);
   QadhocWifiMac (const QadhocWifiMac &);
-
+  void SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator);
+  
   /**
   * When an A-MSDU is received, is deaggregated by this method and all extracted packets are
   * forwarded up.
--- a/src/devices/wifi/qap-wifi-mac.cc	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qap-wifi-mac.cc	Wed Feb 03 20:34:50 2010 +0100
@@ -673,7 +673,40 @@
           else if (hdr->IsReassocReq ()) 
             {
               /* we don't support reassoc frames for now */
-            } 
+            }
+          else if (hdr->IsAction ())
+            {
+              WifiActionHeader actionHdr;
+              packet->RemoveHeader (actionHdr);
+              if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+                  actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_REQUEST)
+                {
+                  MgtAddBaRequestHeader reqHdr;
+                  packet->RemoveHeader (reqHdr);
+                  SendAddBaResponse (&reqHdr, hdr->GetAddr2 ());
+                }
+              else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+                       actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_RESPONSE)
+                {
+                  MgtAddBaResponseHeader respHdr;
+                  packet->RemoveHeader (respHdr);
+                  m_queues[QosUtilsMapTidToAc (respHdr.GetTid ())]->GotAddBaResponse (&respHdr, hdr->GetAddr2 ());
+                }
+              else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+                       actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_DELBA)
+                {
+                  MgtDelBaHeader delBaHdr;
+                  packet->RemoveHeader (delBaHdr);
+                  if (delBaHdr.IsByOriginator ())
+                    {
+                      /* Block ack agreement tear down */
+                    }
+                  else
+                    {
+                      /* We must notify correct queue tear down of agreement */
+                    }
+                }
+            }
           else if (hdr->IsAuthentication () ||
                    hdr->IsDeauthentication ()) 
                  {
@@ -799,4 +832,59 @@
   WifiMac::DoStart ();
 }
 
+void
+QapWifiMac::SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator)
+{
+  NS_LOG_FUNCTION (this);
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetAddr1 (originator);
+  hdr.SetAddr2 (m_low->GetAddress ());
+  hdr.SetAddr3 (m_low->GetAddress ());
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+
+  MgtAddBaResponseHeader respHdr;
+  StatusCode code;
+  code.SetSuccess ();
+  respHdr.SetStatusCode (code);
+  //Here a control about queues type?
+  respHdr.SetAmsduSupport (reqHdr->IsAmsduSupported ());
+  
+  if (reqHdr->IsImmediateBlockAck ())
+    {
+      respHdr.SetImmediateBlockAck ();
+    }
+  else
+    {
+      respHdr.SetDelayedBlockAck ();
+    }
+  respHdr.SetTid (reqHdr->GetTid ());
+  /* For now there's not no control about limit of reception.
+     We assume that receiver has no limit on reception.
+     However we assume that a receiver sets a bufferSize in order to satisfy
+     next equation:
+     (bufferSize + 1) % 16 = 0
+     So if a recipient is able to buffer a packet, it should be also able to buffer
+     all possible packet's fragments.
+     See section 7.3.1.14 in IEEE802.11e for more details. */
+  respHdr.SetBufferSize (1023);
+  respHdr.SetTimeout (reqHdr->GetTimeout ());
+
+  WifiActionHeader actionHdr;
+  WifiActionHeader::ActionValue action;
+  action.blockAck = WifiActionHeader::BLOCK_ACK_ADDBA_RESPONSE;
+  actionHdr.SetAction (WifiActionHeader::BLOCK_ACK, action);
+
+  Ptr<Packet> packet = Create<Packet> ();
+  packet->AddHeader (respHdr);
+  packet->AddHeader (actionHdr);
+  
+  /* ns3::MacLow have to buffer all correctly received packet for this block ack session */
+  //m_low->CreateIngoingAgreement (&respHdr, originator, reqHdr->GetStartingSequence ());
+
+  //Better a management queue? 
+  m_queues[QosUtilsMapTidToAc (reqHdr->GetTid ())]->PushFront (packet, hdr);
+}
+
 }  //namespace ns3
--- a/src/devices/wifi/qap-wifi-mac.h	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qap-wifi-mac.h	Wed Feb 03 20:34:50 2010 +0100
@@ -47,6 +47,7 @@
 class DcfManager;
 class AmsduSubframeHeader;
 class MsduAggregator;
+class MgtAddBaRequestHeader;
 
 class QapWifiMac : public WifiMac
 {
@@ -103,6 +104,7 @@
   void TxFailed (const WifiMacHeader& hdr);
   void SendProbeResp (Mac48Address to);
   void SendAssocResp (Mac48Address to, bool success);
+  void SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator);
   void SendOneBeacon (void);
   SupportedRates GetSupportedRates (void) const;
   void SetBeaconGeneration (bool enable);
--- a/src/devices/wifi/qsta-wifi-mac.cc	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qsta-wifi-mac.cc	Wed Feb 03 20:34:50 2010 +0100
@@ -674,6 +674,39 @@
             }
         }
     }
+  else if (hdr->IsAction ())
+    {
+      WifiActionHeader actionHdr;
+      packet->RemoveHeader (actionHdr);
+      if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+          actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_REQUEST)
+        {
+          MgtAddBaRequestHeader reqHdr;
+          packet->RemoveHeader (reqHdr);
+          SendAddBaResponse (&reqHdr, hdr->GetAddr2 ());
+        }
+      else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+               actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_ADDBA_RESPONSE)
+        {
+          MgtAddBaResponseHeader respHdr;
+          packet->RemoveHeader (respHdr);
+          m_queues[QosUtilsMapTidToAc (respHdr.GetTid ())]->GotAddBaResponse (&respHdr, hdr->GetAddr2 ());
+        }
+      else if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK &&
+               actionHdr.GetAction().blockAck == WifiActionHeader::BLOCK_ACK_DELBA)
+        {
+          MgtDelBaHeader delBaHdr;
+          packet->RemoveHeader (delBaHdr);
+          if (delBaHdr.IsByOriginator ())
+            {
+              /* Block ack agreement tear down */
+            }
+          else
+            {
+              /* We must notify correct queue tear down of agreement */
+            }
+        }
+    }
 }
 
 SupportedRates
@@ -775,5 +808,59 @@
     }
 }
 
+void
+QstaWifiMac::SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator)
+{
+  NS_LOG_FUNCTION (this);
+  WifiMacHeader hdr;
+  hdr.SetAction ();
+  hdr.SetAddr1 (originator);
+  hdr.SetAddr2 (m_low->GetAddress ());
+  hdr.SetAddr3 (m_low->GetAddress ());
+  hdr.SetDsNotFrom ();
+  hdr.SetDsNotTo ();
+
+  MgtAddBaResponseHeader respHdr;
+  StatusCode code;
+  code.SetSuccess ();
+  respHdr.SetStatusCode (code);
+  //Here a control about queues type?
+  respHdr.SetAmsduSupport (reqHdr->IsAmsduSupported ());
+
+  if (reqHdr->IsImmediateBlockAck ())
+    {
+      respHdr.SetImmediateBlockAck ();
+    }
+  else
+    {
+      respHdr.SetDelayedBlockAck ();
+    }
+  respHdr.SetTid (reqHdr->GetTid ());
+  /* For now there's not no control about limit of reception.
+     We assume that receiver has no limit on reception.
+     However we assume that a receiver sets a bufferSize in order to satisfy
+     next equation:
+     (bufferSize + 1) % 16 = 0
+     So if a recipient is able to buffer a packet, it should be also able to buffer
+     all possible packet's fragments.
+     See section 7.3.1.14 in IEEE802.11e for more details. */
+  respHdr.SetBufferSize (1023);
+  respHdr.SetTimeout (reqHdr->GetTimeout ());
+
+  WifiActionHeader actionHdr;
+  WifiActionHeader::ActionValue action;
+  action.blockAck = WifiActionHeader::BLOCK_ACK_ADDBA_RESPONSE;
+  actionHdr.SetAction (WifiActionHeader::BLOCK_ACK, action);
+
+  Ptr<Packet> packet = Create<Packet> ();
+  packet->AddHeader (respHdr);
+  packet->AddHeader (actionHdr);
+  
+  /* ns3::MacLow have to buffer all correctly received packet for this block ack session */
+  //m_low->CreateIngoingAgreement (&respHdr, originator, reqHdr->GetStartingSequence ());
+
+  //Better a management queue? 
+  m_queues[QosUtilsMapTidToAc (reqHdr->GetTid ())]->PushFront (packet, hdr);
+}
 
 }  //namespace ns3
--- a/src/devices/wifi/qsta-wifi-mac.h	Wed Feb 03 20:34:49 2010 +0100
+++ b/src/devices/wifi/qsta-wifi-mac.h	Wed Feb 03 20:34:50 2010 +0100
@@ -45,6 +45,7 @@
 class WifiMacHeader;
 class AmsduSubframeHeader;
 class MsduAggregator;
+class MgtAddBaRequestHeader;
 
 class QstaWifiMac : public WifiMac
 {
@@ -100,6 +101,7 @@
   void ProbeRequestTimeout (void);
   void SendAssociationRequest (void);
   void SendProbeRequest (void);
+  void SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr, Mac48Address originator);
   void TryToEnsureAssociated (void);
   bool IsAssociated (void) const;
   bool IsWaitAssocResp (void) const;