src/devices/wifi/mac-tx-middle.cc
changeset 4399 3858687497ce
parent 4079 210d64d11998
child 4400 18ba3459e177
equal deleted inserted replaced
4398:a07440ab970c 4399:3858687497ce
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     2 /*
     3  * Copyright (c) 2005 INRIA
     3  * Copyright (c) 2005, 2009 INRIA
       
     4  * Copyright (c) 2009 MIRKO BANCHI
     4  *
     5  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as 
     7  * it under the terms of the GNU General Public License version 2 as 
     7  * published by the Free Software Foundation;
     8  * published by the Free Software Foundation;
     8  *
     9  *
    14  * You should have received a copy of the GNU General Public License
    15  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
       
    20  * Author: Mirko Banchi <mk.banchi@gmail.com>
    19  */
    21  */
    20 
    22 
    21 #include "ns3/assert.h"
    23 #include "ns3/assert.h"
    22 
    24 
    23 #include "mac-tx-middle.h"
    25 #include "mac-tx-middle.h"
    24 #include "wifi-mac-header.h"
    26 #include "wifi-mac-header.h"
    25 
    27 
    26 namespace ns3 {
    28 namespace ns3 {
    27 
    29 
    28 MacTxMiddle::MacTxMiddle ()
    30 MacTxMiddle::MacTxMiddle ()
       
    31   : m_sequence (0)
       
    32 {}
       
    33 
       
    34 MacTxMiddle::~MacTxMiddle ()
    29 {
    35 {
    30   m_sequence = 0;
    36   std::map<Mac48Address,uint16_t*>::iterator i = m_qosSequences.begin();
    31   for (uint8_t i = 0; i < 16; i++) 
    37   for (; i != m_qosSequences.end (); i++)
    32     {
    38     {
    33       m_qosSequences[i] = 0;
    39       delete [] i->second;
    34     }
    40     }
    35 }
    41 }
    36 
    42 
    37 uint16_t 
    43 uint16_t 
    38 MacTxMiddle::GetNextSequenceNumberfor (const WifiMacHeader *hdr)
    44 MacTxMiddle::GetNextSequenceNumberfor (const WifiMacHeader *hdr)
    41   if (hdr->IsQosData () &&
    47   if (hdr->IsQosData () &&
    42       !hdr->GetAddr1 ().IsGroup ()) 
    48       !hdr->GetAddr1 ().IsGroup ()) 
    43     {
    49     {
    44       uint8_t tid = hdr->GetQosTid ();
    50       uint8_t tid = hdr->GetQosTid ();
    45       NS_ASSERT (tid < 16);
    51       NS_ASSERT (tid < 16);
    46       retval = m_qosSequences[tid];
    52       std::map<Mac48Address, uint16_t*>::iterator it = m_qosSequences.find (hdr->GetAddr1 ());
    47       m_qosSequences[tid]++;
    53       if (it != m_qosSequences.end ())
    48       m_qosSequences[tid] %= 4096;
    54         {
       
    55           retval = it->second[tid];
       
    56           it->second[tid]++;
       
    57           it->second[tid] %= 4096;
       
    58         }
       
    59       else
       
    60         {
       
    61           retval = 0;
       
    62           std::pair <Mac48Address,uint16_t*> newSeq (hdr->GetAddr1 (), new uint16_t[16]);
       
    63           std::pair <std::map<Mac48Address,uint16_t*>::iterator,bool> newIns = m_qosSequences.insert (newSeq);
       
    64           NS_ASSERT(newIns.second == true);
       
    65           for (uint8_t i = 0; i < 16; i++)
       
    66             newIns.first->second[i] = 0;
       
    67           newIns.first->second[tid]++;
       
    68         }
    49     } 
    69     } 
    50   else 
    70   else 
    51     {
    71     {
    52       retval = m_sequence;
    72       retval = m_sequence;
    53       m_sequence++;
    73       m_sequence++;