A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
32
MacTxMiddle::MacTxMiddle
()
33
: m_sequence (0)
34
{
35
NS_LOG_FUNCTION
(
this
);
36
}
37
38
MacTxMiddle::~MacTxMiddle
()
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
48
MacTxMiddle::GetNextSequenceNumberFor
(
const
WifiMacHeader
*hdr)
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
87
MacTxMiddle::PeekNextSequenceNumberFor
(
const
WifiMacHeader
*hdr)
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
114
MacTxMiddle::GetNextSeqNumberByTidAndAddress
(uint8_t tid,
Mac48Address
addr)
const
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
void
128
MacTxMiddle::SetSequenceNumberFor
(
const
WifiMacHeader
*hdr)
129
{
130
NS_LOG_FUNCTION
(
this
<< *hdr);
131
132
if
(hdr->
IsQosData
()
133
&& !hdr->
GetAddr1
().
IsGroup
())
134
{
135
uint8_t tid = hdr->
GetQosTid
();
136
NS_ASSERT
(tid < 16);
137
auto
it =
m_qosSequences
.find (hdr->
GetAddr1
());
138
NS_ASSERT
(it !=
m_qosSequences
.end ());
139
it->second[tid] = hdr->
GetSequenceNumber
();
140
}
141
else
142
{
143
m_sequence
= hdr->
GetSequenceNumber
();
144
}
145
}
146
147
}
//namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
mac-tx-middle.h
NS_ASSERT
#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
ns3::Mac48Address::IsGroup
bool IsGroup(void) const
Definition:
mac48-address.cc:164
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MacTxMiddle::PeekNextSequenceNumberFor
uint16_t PeekNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the Traffic ID and destination, but do not pick it (i....
Definition:
mac-tx-middle.cc:87
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:44
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition:
wifi-mac-header.cc:424
ns3::MacTxMiddle::~MacTxMiddle
~MacTxMiddle()
Definition:
mac-tx-middle.cc:38
wifi-mac-header.h
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition:
wifi-mac-header.h:85
ns3::MacTxMiddle::SetSequenceNumberFor
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...
Definition:
mac-tx-middle.cc:128
ns3::WifiMacHeader::IsQosData
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
Definition:
wifi-mac-header.cc:565
ns3::WifiMacHeader::GetSequenceNumber
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
Definition:
wifi-mac-header.cc:777
ns3::MacTxMiddle::GetNextSequenceNumberFor
uint16_t GetNextSequenceNumberFor(const WifiMacHeader *hdr)
Return the next sequence number for the given header.
Definition:
mac-tx-middle.cc:48
ns3::WifiMacHeader::GetQosTid
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Definition:
wifi-mac-header.cc:862
ns3::MacTxMiddle::MacTxMiddle
MacTxMiddle()
Definition:
mac-tx-middle.cc:32
ns3::MacTxMiddle::GetNextSeqNumberByTidAndAddress
uint16_t GetNextSeqNumberByTidAndAddress(uint8_t tid, Mac48Address addr) const
Return the next sequence number for the Traffic ID and destination.
Definition:
mac-tx-middle.cc:114
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition:
log-macros-enabled.h:244
ns3::MacTxMiddle::m_qosSequences
std::map< Mac48Address, uint16_t * > m_qosSequences
QOS sequences.
Definition:
mac-tx-middle.h:77
ns3::MacTxMiddle::m_sequence
uint16_t m_sequence
current sequence number
Definition:
mac-tx-middle.h:78
src
wifi
model
mac-tx-middle.cc
Generated on Fri Oct 1 2021 17:03:45 for ns-3 by
1.8.20