A Discrete-Event Network Simulator
API
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  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  * Ghada Badawy <gbadawy@gmail.com>
22  */
23 
24 #include "ns3/log.h"
25 #include "mac-tx-middle.h"
26 #include "wifi-mac-header.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("MacTxMiddle");
31 
33  : m_sequence (0)
34 {
35  NS_LOG_FUNCTION (this);
36 }
37 
39 {
40  NS_LOG_FUNCTION (this);
41  for (std::map<Mac48Address,uint16_t*>::const_iterator i = m_qosSequences.begin (); i != m_qosSequences.end (); i++)
42  {
43  delete [] i->second;
44  }
45 }
46 
47 uint16_t
49 {
50  NS_LOG_FUNCTION (this);
51  uint16_t retval;
52  if (hdr->IsQosData ()
53  && !hdr->GetAddr1 ().IsGroup ())
54  {
55  uint8_t tid = hdr->GetQosTid ();
56  NS_ASSERT (tid < 16);
57  std::map<Mac48Address, uint16_t*>::const_iterator it = m_qosSequences.find (hdr->GetAddr1 ());
58  if (it != m_qosSequences.end ())
59  {
60  retval = it->second[tid];
61  it->second[tid]++;
62  it->second[tid] %= 4096;
63  }
64  else
65  {
66  retval = 0;
67  std::pair <Mac48Address,uint16_t*> newSeq (hdr->GetAddr1 (), new uint16_t[16]);
68  std::pair <std::map<Mac48Address,uint16_t*>::const_iterator,bool> newIns = m_qosSequences.insert (newSeq);
69  NS_ASSERT (newIns.second == true);
70  for (uint8_t i = 0; i < 16; i++)
71  {
72  newIns.first->second[i] = 0;
73  }
74  newIns.first->second[tid]++;
75  }
76  }
77  else
78  {
79  retval = m_sequence;
80  m_sequence++;
81  m_sequence %= 4096;
82  }
83  return retval;
84 }
85 
86 uint16_t
88 {
89  NS_LOG_FUNCTION (this);
90  uint16_t retval;
91  if (hdr->IsQosData ()
92  && !hdr->GetAddr1 ().IsGroup ())
93  {
94  uint8_t tid = hdr->GetQosTid ();
95  NS_ASSERT (tid < 16);
96  std::map<Mac48Address, uint16_t*>::const_iterator 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  std::map <Mac48Address,uint16_t*>::const_iterator it = m_qosSequences.find (addr);
120  if (it != m_qosSequences.end ())
121  {
122  return it->second[tid];
123  }
124  return seq;
125 }
126 
127 } //namespace ns3
uint16_t m_sequence
current sequence number
Definition: mac-tx-middle.h:72
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< Mac48Address, uint16_t * > m_qosSequences
QOS sequences.
Definition: mac-tx-middle.h:71
an EUI-48 address
Definition: mac48-address.h:43
bool IsGroup(void) const
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i...
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
Implements the IEEE 802.11 MAC header.