A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mac-tx-middle.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 
23 #include "ns3/assert.h"
24 
25 #include "mac-tx-middle.h"
26 #include "wifi-mac-header.h"
27 
28 namespace ns3 {
29 
31  : m_sequence (0)
32 {
33 }
34 
36 {
37  for (std::map<Mac48Address,uint16_t*>::iterator i = m_qosSequences.begin (); i != m_qosSequences.end (); i++)
38  {
39  delete [] i->second;
40  }
41 }
42 
43 uint16_t
45 {
46  uint16_t retval;
47  if (hdr->IsQosData ()
48  && !hdr->GetAddr1 ().IsGroup ())
49  {
50  uint8_t tid = hdr->GetQosTid ();
51  NS_ASSERT (tid < 16);
52  std::map<Mac48Address, uint16_t*>::iterator it = m_qosSequences.find (hdr->GetAddr1 ());
53  if (it != m_qosSequences.end ())
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  {
67  newIns.first->second[i] = 0;
68  }
69  newIns.first->second[tid]++;
70  }
71  }
72  else
73  {
74  retval = m_sequence;
75  m_sequence++;
76  m_sequence %= 4096;
77  }
78  return retval;
79 }
80 
81 uint16_t
83 {
84  NS_ASSERT (tid < 16);
85  uint16_t seq = 0;
86  std::map <Mac48Address,uint16_t*>::const_iterator it = m_qosSequences.find (addr);
87  if (it != m_qosSequences.end ())
88  {
89  return it->second[tid];
90  }
91  return seq;
92 }
93 
94 } // namespace ns3
uint16_t m_sequence
Definition: mac-tx-middle.h:63
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
uint16_t GetNextSequenceNumberfor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
bool IsGroup(void) const
std::map< Mac48Address, uint16_t * > m_qosSequences
Definition: mac-tx-middle.h:62
an EUI-48 address
Definition: mac48-address.h:41
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
Implements the IEEE 802.11 MAC header.