A Discrete-Event Network Simulator
API
wifi-mac-queue-item.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  * Stefano Avallone <stavallo@unina.it>
22  */
23 
24 #include "ns3/simulator.h"
25 #include "ns3/packet.h"
26 #include "ns3/log.h"
27 #include "wifi-mac-queue-item.h"
28 #include "wifi-mac-trailer.h"
29 #include "wifi-utils.h"
30 #include "msdu-aggregator.h"
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("WifiMacQueueItem");
35 
37  : WifiMacQueueItem (p, header, Simulator::Now ())
38 {
39 }
40 
42  : m_packet (p),
43  m_header (header),
44  m_tstamp (tstamp),
45  m_queueAc (AC_UNDEF)
46 {
47  if (header.IsQosData () && header.IsQosAmsdu ())
48  {
50  }
51  m_inFlight = false;
52 }
53 
55 {
56 }
57 
60 {
61  return m_packet;
62 }
63 
64 const WifiMacHeader&
66 {
67  return m_header;
68 }
69 
72 {
73  return m_header;
74 }
75 
78 {
79  return m_header.GetAddr1 ();
80 }
81 
82 Time
84 {
85  return m_tstamp;
86 }
87 
88 uint32_t
90 {
91  return m_packet->GetSize ();
92 }
93 
94 uint32_t
96 {
98 }
99 
100 bool
102 {
104 }
105 
108 {
109  Ptr<Packet> mpdu = m_packet->Copy ();
110  mpdu->AddHeader (m_header);
111  AddWifiMacTrailer (mpdu);
112  return mpdu;
113 }
114 
115 void
117 {
118  NS_ASSERT (msdu != 0);
119  NS_LOG_FUNCTION (this << *msdu);
120  NS_ABORT_MSG_IF (!msdu->GetHeader ().IsQosData () || msdu->GetHeader ().IsQosAmsdu (),
121  "Only QoS data frames that do not contain an A-MSDU can be aggregated");
122 
123  if (m_msduList.empty ())
124  {
125  // An MSDU is going to be aggregated to this MPDU, hence this has to be an A-MSDU now
126  Ptr<const WifiMacQueueItem> firstMsdu = Create<const WifiMacQueueItem> (*this);
127  m_packet = Create<Packet> ();
128  DoAggregate (firstMsdu);
129 
131  // Set Address3 according to Table 9-26 of 802.11-2016
132  if (m_header.IsToDs () && !m_header.IsFromDs ())
133  {
134  // from STA to AP: BSSID is in Address1
136  }
137  else if (!m_header.IsToDs () && m_header.IsFromDs ())
138  {
139  // from AP to STA: BSSID is in Address2
141  }
142  // in the WDS case (ToDS = FromDS = 1), both Address 3 and Address 4 need
143  // to be set to the BSSID, but neither Address 1 nor Address 2 contain the
144  // BSSID. Hence, it is left up to the caller to set these Address fields.
145  }
146  DoAggregate (msdu);
147 }
148 
149 void
151 {
152  NS_LOG_FUNCTION (this << *msdu);
153 
154  // build the A-MSDU Subframe header
156  /*
157  * (See Table 9-26 of 802.11-2016)
158  *
159  * ToDS | FromDS | DA | SA
160  * 0 | 0 | Addr1 | Addr2
161  * 0 | 1 | Addr1 | Addr3
162  * 1 | 0 | Addr3 | Addr2
163  * 1 | 1 | Addr3 | Addr4
164  */
165  hdr.SetDestinationAddr (msdu->GetHeader ().IsToDs () ? msdu->GetHeader ().GetAddr3 ()
166  : msdu->GetHeader ().GetAddr1 ());
167  hdr.SetSourceAddr (!msdu->GetHeader ().IsFromDs () ? msdu->GetHeader ().GetAddr2 ()
168  : (!msdu->GetHeader ().IsToDs ()
169  ? msdu->GetHeader ().GetAddr3 ()
170  : msdu->GetHeader ().GetAddr4 ()));
171  hdr.SetLength (static_cast<uint16_t> (msdu->GetPacket ()->GetSize ()));
172 
173  m_msduList.push_back ({msdu->GetPacket (), hdr});
174 
175  // build the A-MSDU
177  Ptr<Packet> amsdu = m_packet->Copy ();
178 
179  // pad the previous A-MSDU subframe if the A-MSDU is not empty
180  if (m_packet->GetSize () > 0)
181  {
182  uint8_t padding = MsduAggregator::CalculatePadding (m_packet->GetSize ());
183 
184  if (padding)
185  {
186  amsdu->AddAtEnd (Create<Packet> (padding));
187  }
188  }
189 
190  // add A-MSDU subframe header and MSDU
191  Ptr<Packet> amsduSubframe = msdu->GetPacket ()->Copy ();
192  amsduSubframe->AddHeader (hdr);
193  amsdu->AddAtEnd (amsduSubframe);
194  m_packet = amsdu;
195 
196  /* "The expiration of the A-MSDU lifetime timer occurs only when the lifetime
197  * timer of all of the constituent MSDUs of the A-MSDU have expired" (Section
198  * 10.12 of 802.11-2016)
199  */
200  // The timestamp of the A-MSDU is the most recent among those of the MSDUs
201  m_tstamp = Max (m_tstamp, msdu->GetTimeStamp ());
202 }
203 
204 bool
206 {
207  return m_queueAc != AC_UNDEF;
208 }
209 
210 AcIndex
212 {
213  NS_ASSERT (IsQueued ());
214  return m_queueAc;
215 }
216 
219 {
220  NS_ASSERT (IsQueued ());
221  return m_queueIt;
222 }
223 
224 void
226 {
227  m_inFlight = true;
228 }
229 
230 void
232 {
233  m_inFlight = false;
234 }
235 
236 bool
238 {
239  return m_inFlight;
240 }
241 
244 {
245  return m_msduList.begin ();
246 }
247 
250 {
251  return m_msduList.end ();
252 }
253 
254 void
255 WifiMacQueueItem::Print (std::ostream& os) const
256 {
257  os << m_header.GetTypeString ()
258  << ", payloadSize=" << GetPacketSize ()
259  << ", to=" << m_header.GetAddr1 ()
260  << ", seqN=" << m_header.GetSequenceNumber ()
261  << ", duration/ID=" << m_header.GetDuration ()
262  << ", lifetime=" << (Simulator::Now () - m_tstamp).As (Time::US);
263  if (m_header.IsQosData ())
264  {
265  os << ", tid=" << +m_header.GetQosTid ();
266  if (m_header.IsQosNoAck ())
267  {
268  os << ", ack=NoAck";
269  }
270  else if (m_header.IsQosAck ())
271  {
272  os << ", ack=NormalAck";
273  }
274  else if (m_header.IsQosBlockAck ())
275  {
276  os << ", ack=BlockAck";
277  }
278  }
279  os << ", packet=" << m_packet
280  << ", queued=" << IsQueued ()
281  << ", inflight=" << IsInFlight ();
282 }
283 
284 std::ostream & operator << (std::ostream &os, const WifiMacQueueItem &item)
285 {
286  item.Print (os);
287  return os;
288 }
289 
290 } //namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::WifiMacQueueItem::~WifiMacQueueItem
virtual ~WifiMacQueueItem()
Definition: wifi-mac-queue-item.cc:54
ns3::WifiMacQueueItem::begin
DeaggregatedMsdusCI begin(void)
Get a constant iterator pointing to the first MSDU in the list of aggregated MSDUs.
Definition: wifi-mac-queue-item.cc:243
ns3::WifiMacQueueItem
WifiMacQueueItem stores (const) packets along with their Wifi MAC headers and the time when they were...
Definition: wifi-mac-queue-item.h:45
ns3::WifiMacQueueItem::Aggregate
void Aggregate(Ptr< const WifiMacQueueItem > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU).
Definition: wifi-mac-queue-item.cc:116
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::WifiMacQueueItem::GetPacket
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item.
Definition: wifi-mac-queue-item.cc:59
ns3::MsduAggregator::CalculatePadding
static uint8_t CalculatePadding(uint16_t amsduSize)
Calculate how much padding must be added to the end of an A-MSDU of the given size if a new MSDU is a...
Definition: msdu-aggregator.cc:160
ns3::WifiMacHeader::IsToDs
bool IsToDs(void) const
Definition: wifi-mac-header.cc:552
ns3::AmsduSubframeHeader::SetDestinationAddr
void SetDestinationAddr(Mac48Address to)
Set destination address function.
Definition: amsdu-subframe-header.cc:85
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3::AmsduSubframeHeader::SetLength
void SetLength(uint16_t length)
Set length function.
Definition: amsdu-subframe-header.cc:97
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMacHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const override
Definition: wifi-mac-header.cc:1155
ns3::WIFI_MAC_FCS_LENGTH
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
Definition: wifi-mac-trailer.h:31
ns3::WifiMacHeader::IsQosNoAck
bool IsQosNoAck(void) const
Return if the QoS Ack policy is No Ack.
Definition: wifi-mac-header.cc:808
ns3::WifiMacQueueItem::end
DeaggregatedMsdusCI end(void)
Get a constant iterator indicating past-the-last MSDU in the list of aggregated MSDUs.
Definition: wifi-mac-queue-item.cc:249
ns3::Time::US
@ US
microsecond
Definition: nstime.h:117
ns3::AmsduSubframeHeader
Headers for A-MSDU subframes.
Definition: amsdu-subframe-header.h:34
ns3::WifiMacQueueItem::GetQueueAc
AcIndex GetQueueAc(void) const
Get the AC of the queue this item is stored into.
Definition: wifi-mac-queue-item.cc:211
ns3::WifiMacHeader::IsQosBlockAck
bool IsQosBlockAck(void) const
Return if the QoS Ack policy is Block Ack.
Definition: wifi-mac-header.cc:801
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::WifiMacHeader::SetQosAmsdu
void SetQosAmsdu(void)
Set that A-MSDU is present.
Definition: wifi-mac-header.cc:386
wifi-mac-queue-item.h
ns3::WifiMacQueueItem::GetPacketSize
uint32_t GetPacketSize(void) const
Return the size in bytes of the packet or control header or management header stored by this item.
Definition: wifi-mac-queue-item.cc:89
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition: wifi-mac-header.cc:424
ns3::WifiMacQueueItem::WifiMacQueueItem
WifiMacQueueItem(Ptr< const Packet > p, const WifiMacHeader &header)
Create a Wifi MAC queue item containing a packet and a Wifi MAC header.
Definition: wifi-mac-queue-item.cc:36
ns3::WifiMacHeader::SetAddr3
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
Definition: wifi-mac-header.cc:120
ns3::WifiMacQueueItem::GetHeader
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Definition: wifi-mac-queue-item.cc:65
ns3::WifiMacHeader::GetTypeString
const char * GetTypeString(void) const
Return a string corresponds to the header type.
Definition: wifi-mac-header.cc:977
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition: wifi-mac-header.h:85
ns3::Ptr< const Packet >
ns3::WifiMacQueueItem::GetDestinationAddress
Mac48Address GetDestinationAddress(void) const
Return the destination address present in the header.
Definition: wifi-mac-queue-item.cc:77
ns3::Max
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:230
ns3::WifiMacQueueItem::ConstIterator
std::list< Ptr< WifiMacQueueItem > >::const_iterator ConstIterator
Const iterator typedef.
Definition: wifi-mac-queue-item.h:144
ns3::WifiMacQueueItem::GetProtocolDataUnit
Ptr< Packet > GetProtocolDataUnit(void) const
Get the MAC protocol data unit (MPDU) corresponding to this item (i.e.
Definition: wifi-mac-queue-item.cc:107
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
ns3::WifiMacHeader::IsFromDs
bool IsFromDs(void) const
Definition: wifi-mac-header.cc:546
ns3::WifiMacHeader::IsQosAmsdu
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
Definition: wifi-mac-header.cc:855
ns3::WifiMacQueueItem::IsInFlight
bool IsInFlight(void) const
Return true if this MPDU is in flight, false otherwise.
Definition: wifi-mac-queue-item.cc:237
ns3::WifiMacQueueItem::DoAggregate
void DoAggregate(Ptr< const WifiMacQueueItem > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU).
Definition: wifi-mac-queue-item.cc:150
ns3::WifiMacQueueItem::m_tstamp
Time m_tstamp
timestamp when the packet arrived at the queue
Definition: wifi-mac-queue-item.h:209
ns3::AC_UNDEF
@ AC_UNDEF
Total number of ACs.
Definition: qos-utils.h:85
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::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::WifiMacHeader::GetSequenceNumber
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
Definition: wifi-mac-header.cc:777
ns3::WifiMacQueueItem::m_msduList
DeaggregatedMsdus m_msduList
The list of aggregated MSDUs included in this MPDU.
Definition: wifi-mac-queue-item.h:210
NS_ABORT_MSG_IF
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
ns3::WifiMacHeader::GetFragmentNumber
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
Definition: wifi-mac-header.cc:783
ns3::WifiMacQueueItem::DeaggregatedMsdusCI
std::list< std::pair< Ptr< const Packet >, AmsduSubframeHeader > >::const_iterator DeaggregatedMsdusCI
DeaggregatedMsdusCI typedef.
Definition: wifi-mac-queue-item.h:128
msdu-aggregator.h
ns3::WifiMacQueueItem::SetInFlight
void SetInFlight(void)
Mark this MPDU as being in flight (only used if Block Ack agreement established).
Definition: wifi-mac-queue-item.cc:225
ns3::WifiMacHeader::GetQosTid
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Definition: wifi-mac-header.cc:862
ns3::WifiMacQueueItem::Print
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: wifi-mac-queue-item.cc:255
ns3::Packet::AddAtEnd
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
ns3::WifiMacQueueItem::IsQueued
bool IsQueued(void) const
Return true if this item is stored in some queue, false otherwise.
Definition: wifi-mac-queue-item.cc:205
ns3::AddWifiMacTrailer
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:122
wifi-utils.h
ns3::WifiMacQueueItem::GetTimeStamp
Time GetTimeStamp(void) const
Get the timestamp included in this item.
Definition: wifi-mac-queue-item.cc:83
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
ns3::MsduAggregator::Deaggregate
static WifiMacQueueItem::DeaggregatedMsdus Deaggregate(Ptr< Packet > aggregatedPacket)
Definition: msdu-aggregator.cc:231
ns3::Simulator
Control the scheduling of simulation events.
Definition: simulator.h:69
ns3::AcIndex
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:71
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::WifiMacHeader::GetDuration
Time GetDuration(void) const
Return the duration from the Duration/ID field (Time object).
Definition: wifi-mac-header.cc:765
ns3::WifiMacHeader::IsMoreFragments
bool IsMoreFragments(void) const
Return if the More Fragment bit is set.
Definition: wifi-mac-header.cc:795
ns3::WifiMacQueueItem::m_packet
Ptr< const Packet > m_packet
The packet (MSDU or A-MSDU) contained in this queue item.
Definition: wifi-mac-queue-item.h:207
ns3::WifiMacQueueItem::m_inFlight
bool m_inFlight
whether the MPDU is in flight
Definition: wifi-mac-queue-item.h:213
ns3::WifiMacQueueItem::IsFragment
bool IsFragment(void) const
Return true if this item contains an MSDU fragment, false otherwise.
Definition: wifi-mac-queue-item.cc:101
ns3::WifiMacQueueItem::GetQueueIterator
ConstIterator GetQueueIterator(void) const
Get a const iterator pointing to the position of the MPDU in the queue.
Definition: wifi-mac-queue-item.cc:218
ns3::WifiMacQueueItem::ResetInFlight
void ResetInFlight(void)
Mark this MPDU as not being in flight (only used if Block Ack agreement established).
Definition: wifi-mac-queue-item.cc:231
ns3::WifiMacQueueItem::GetSize
uint32_t GetSize(void) const
Return the size of the packet stored by this item, including header size and trailer size.
Definition: wifi-mac-queue-item.cc:95
ns3::WifiMacQueueItem::m_header
WifiMacHeader m_header
Wifi MAC header associated with the packet.
Definition: wifi-mac-queue-item.h:208
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
ns3::WifiMacHeader::GetAddr2
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
Definition: wifi-mac-header.cc:430
ns3::AmsduSubframeHeader::SetSourceAddr
void SetSourceAddr(Mac48Address to)
Set source address function.
Definition: amsdu-subframe-header.cc:91
wifi-mac-trailer.h
ns3::WifiMacQueueItem::m_queueIt
ConstIterator m_queueIt
Queue iterator pointing to this MPDU, if queued.
Definition: wifi-mac-queue-item.h:211
ns3::WifiMacHeader::IsQosAck
bool IsQosAck(void) const
Return if the QoS Ack policy is Normal Ack.
Definition: wifi-mac-header.cc:815
ns3::WifiMacQueueItem::m_queueAc
AcIndex m_queueAc
AC associated with the queue this MPDU is stored into.
Definition: wifi-mac-queue-item.h:212