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 (std::map<Mac48Address, uint16_t*>::const_iterator i = m_qosSequences.begin();
44  i != m_qosSequences.end();
45  i++)
46  {
47  delete[] i->second;
48  }
49 }
50 
51 uint16_t
53 {
54  NS_LOG_FUNCTION(this);
55  uint16_t retval;
56  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
57  {
58  uint8_t tid = hdr->GetQosTid();
59  NS_ASSERT(tid < 16);
60  std::map<Mac48Address, uint16_t*>::const_iterator it = m_qosSequences.find(hdr->GetAddr1());
61  if (it != m_qosSequences.end())
62  {
63  retval = it->second[tid];
64  it->second[tid]++;
65  it->second[tid] %= 4096;
66  }
67  else
68  {
69  retval = 0;
70  std::pair<Mac48Address, uint16_t*> newSeq(hdr->GetAddr1(), new uint16_t[16]);
71  std::pair<std::map<Mac48Address, uint16_t*>::const_iterator, bool> newIns =
72  m_qosSequences.insert(newSeq);
73  NS_ASSERT(newIns.second == true);
74  for (uint8_t i = 0; i < 16; i++)
75  {
76  newIns.first->second[i] = 0;
77  }
78  newIns.first->second[tid]++;
79  }
80  }
81  else
82  {
83  retval = m_sequence;
84  m_sequence++;
85  m_sequence %= 4096;
86  }
87  return retval;
88 }
89 
90 uint16_t
92 {
93  NS_LOG_FUNCTION(this);
94  uint16_t retval;
95  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
96  {
97  uint8_t tid = hdr->GetQosTid();
98  NS_ASSERT(tid < 16);
99  std::map<Mac48Address, uint16_t*>::const_iterator it = m_qosSequences.find(hdr->GetAddr1());
100  if (it != m_qosSequences.end())
101  {
102  retval = it->second[tid];
103  }
104  else
105  {
106  retval = 0;
107  }
108  }
109  else
110  {
111  retval = m_sequence;
112  }
113  return retval;
114 }
115 
116 uint16_t
118 {
119  NS_LOG_FUNCTION(this);
120  NS_ASSERT(tid < 16);
121  uint16_t seq = 0;
122  std::map<Mac48Address, uint16_t*>::const_iterator it = m_qosSequences.find(addr);
123  if (it != m_qosSequences.end())
124  {
125  return it->second[tid];
126  }
127  return seq;
128 }
129 
130 void
132 {
133  NS_LOG_FUNCTION(this << *hdr);
134 
135  if (hdr->IsQosData() && !hdr->GetAddr1().IsGroup())
136  {
137  uint8_t tid = hdr->GetQosTid();
138  NS_ASSERT(tid < 16);
139  auto it = m_qosSequences.find(hdr->GetAddr1());
140  NS_ASSERT(it != m_qosSequences.end());
141  it->second[tid] = hdr->GetSequenceNumber();
142  }
143  else
144  {
145  m_sequence = hdr->GetSequenceNumber();
146  }
147 }
148 
149 } // 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.