A Discrete-Event Network Simulator
API
mac-tx-middle.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005, 2009 INRIA
3  * Copyright (c) 2009 MIRKO BANCHI
4  *
5  * 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  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * 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  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Mirko Banchi <mk.banchi@gmail.com>
20  * Ghada Badawy <gbadawy@gmail.com>
21  */
22 
23 #include "mac-tx-middle.h"
24 
25 #include "wifi-mac-header.h"
26 
27 #include "ns3/log.h"
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("MacTxMiddle");
33 
35  : m_sequence(0)
36 {
37  NS_LOG_FUNCTION(this);
38 }
39 
41 {
42  NS_LOG_FUNCTION(this);
43  for (auto i = m_qosSequences.begin(); i != m_qosSequences.end(); i++)
44  {
45  delete[] i->second;
46  }
47 }
48 
49 uint16_t
51 {
52  NS_LOG_FUNCTION(this);
53  uint16_t retval;
54  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
55  {
56  uint8_t tid = hdr->GetQosTid();
57  NS_ASSERT(tid < 16);
58  auto it = m_qosSequences.find(hdr->GetAddr1());
59  if (it != m_qosSequences.end())
60  {
61  retval = it->second[tid];
62  it->second[tid]++;
63  it->second[tid] %= 4096;
64  }
65  else
66  {
67  retval = 0;
68  std::pair<Mac48Address, uint16_t*> newSeq(hdr->GetAddr1(), new uint16_t[16]);
69  auto newIns = m_qosSequences.insert(newSeq);
70  NS_ASSERT(newIns.second == true);
71  for (uint8_t i = 0; i < 16; i++)
72  {
73  newIns.first->second[i] = 0;
74  }
75  newIns.first->second[tid]++;
76  }
77  }
78  else
79  {
80  retval = m_sequence;
81  m_sequence++;
82  m_sequence %= 4096;
83  }
84  return retval;
85 }
86 
87 uint16_t
89 {
90  NS_LOG_FUNCTION(this);
91  uint16_t retval;
92  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
93  {
94  uint8_t tid = hdr->GetQosTid();
95  NS_ASSERT(tid < 16);
96  auto it = m_qosSequences.find(hdr->GetAddr1());
97  if (it != m_qosSequences.end())
98  {
99  retval = it->second[tid];
100  }
101  else
102  {
103  retval = 0;
104  }
105  }
106  else
107  {
108  retval = m_sequence;
109  }
110  return retval;
111 }
112 
113 uint16_t
115 {
116  NS_LOG_FUNCTION(this);
117  NS_ASSERT(tid < 16);
118  uint16_t seq = 0;
119  auto it = m_qosSequences.find(addr);
120  if (it != m_qosSequences.end())
121  {
122  return it->second[tid];
123  }
124  return seq;
125 }
126 
127 void
129 {
130  NS_LOG_FUNCTION(this << *hdr);
131 
132  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
133  {
134  uint8_t tid = hdr->GetQosTid();
135  NS_ASSERT(tid < 16);
136  auto it = m_qosSequences.find(hdr->GetAddr1());
137  NS_ASSERT(it != m_qosSequences.end());
138  it->second[tid] = hdr->GetSequenceNumber();
139  }
140  else
141  {
142  m_sequence = hdr->GetSequenceNumber();
143  }
144 }
145 
146 } // namespace ns3
an EUI-48 address
Definition: mac48-address.h:46
bool IsGroup() const
void SetSequenceNumberFor(const WifiMacHeader *hdr)
Set the sequence number of the given MAC header as the next sequence number for the Traffic ID and de...
std::map< Mac48Address, uint16_t * > m_qosSequences
QOS sequences.
Definition: mac-tx-middle.h:79
uint16_t m_sequence
current sequence number
Definition: mac-tx-middle.h:80
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i....
Implements the IEEE 802.11 MAC header.
uint8_t GetQosTid() const
Return the Traffic ID of a QoS header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
uint16_t GetSequenceNumber() const
Return the sequence number of the header.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.