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 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("WifiMacQueueItem");
34 
36  : WifiMacQueueItem (p, header, Simulator::Now ())
37 {
38 }
39 
41  : m_packet (p),
42  m_header (header),
43  m_tstamp (tstamp)
44 {
45  if (header.IsQosData () && header.IsQosAmsdu ())
46  {
48  }
49 }
50 
52 {
53 }
54 
57 {
58  return m_packet;
59 }
60 
61 const WifiMacHeader&
63 {
64  return m_header;
65 }
66 
69 {
70  return m_header;
71 }
72 
75 {
76  return m_header.GetAddr1 ();
77 }
78 
79 Time
81 {
82  return m_tstamp;
83 }
84 
85 uint32_t
87 {
89 }
90 
93 {
94  Ptr<Packet> mpdu = m_packet->Copy ();
95  mpdu->AddHeader (m_header);
96  AddWifiMacTrailer (mpdu);
97  return mpdu;
98 }
99 
100 void
102 {
103  NS_ASSERT (msdu != 0);
104  NS_LOG_FUNCTION (this << *msdu);
105  NS_ABORT_MSG_IF (!msdu->GetHeader ().IsQosData () || msdu->GetHeader ().IsQosAmsdu (),
106  "Only QoS data frames that do not contain an A-MSDU can be aggregated");
107 
108  if (m_msduList.empty ())
109  {
110  // An MSDU is going to be aggregated to this MPDU, hence this has to be an A-MSDU now
111  Ptr<const WifiMacQueueItem> firstMsdu = Create<const WifiMacQueueItem> (*this);
112  m_packet = Create<Packet> ();
113  DoAggregate (firstMsdu);
114 
116  // Set Address3 according to Table 9-26 of 802.11-2016
117  if (m_header.IsToDs () && !m_header.IsFromDs ())
118  {
119  // from STA to AP: BSSID is in Address1
121  }
122  else if (!m_header.IsToDs () && m_header.IsFromDs ())
123  {
124  // from AP to STA: BSSID is in Address2
126  }
127  // in the WDS case (ToDS = FromDS = 1), both Address 3 and Address 4 need
128  // to be set to the BSSID, but neither Address 1 nor Address 2 contain the
129  // BSSID. Hence, it is left up to the caller to set these Address fields.
130  }
131  DoAggregate (msdu);
132 }
133 
134 void
136 {
137  NS_LOG_FUNCTION (this << *msdu);
138 
139  // build the A-MSDU Subframe header
141  /*
142  * (See Table 9-26 of 802.11-2016)
143  *
144  * ToDS | FromDS | DA | SA
145  * 0 | 0 | Addr1 | Addr2
146  * 0 | 1 | Addr1 | Addr3
147  * 1 | 0 | Addr3 | Addr2
148  * 1 | 1 | Addr3 | Addr4
149  */
150  hdr.SetDestinationAddr (msdu->GetHeader ().IsToDs () ? msdu->GetHeader ().GetAddr3 ()
151  : msdu->GetHeader ().GetAddr1 ());
152  hdr.SetSourceAddr (!msdu->GetHeader ().IsFromDs () ? msdu->GetHeader ().GetAddr2 ()
153  : (!msdu->GetHeader ().IsToDs ()
154  ? msdu->GetHeader ().GetAddr3 ()
155  : msdu->GetHeader ().GetAddr4 ()));
156  hdr.SetLength (static_cast<uint16_t> (msdu->GetPacket ()->GetSize ()));
157 
158  m_msduList.push_back ({msdu->GetPacket (), hdr});
159 
160  // build the A-MSDU
162  Ptr<Packet> amsdu = m_packet->Copy ();
163 
164  // pad the previous A-MSDU subframe if the A-MSDU is not empty
165  if (m_packet->GetSize () > 0)
166  {
167  uint8_t padding = MsduAggregator::CalculatePadding (m_packet->GetSize ());
168 
169  if (padding)
170  {
171  amsdu->AddAtEnd (Create<Packet> (padding));
172  }
173  }
174 
175  // add A-MSDU subframe header and MSDU
176  Ptr<Packet> amsduSubframe = msdu->GetPacket ()->Copy ();
177  amsduSubframe->AddHeader (hdr);
178  amsdu->AddAtEnd (amsduSubframe);
179  m_packet = amsdu;
180 
181  /* "The expiration of the A-MSDU lifetime timer occurs only when the lifetime
182  * timer of all of the constituent MSDUs of the A-MSDU have expired" (Section
183  * 10.12 of 802.11-2016)
184  */
185  // The timestamp of the A-MSDU is the most recent among those of the MSDUs
186  m_tstamp = Max (m_tstamp, msdu->GetTimeStamp ());
187 }
188 
189 
192 {
193  return m_msduList.begin ();
194 }
195 
198 {
199  return m_msduList.end ();
200 }
201 
202 void
203 WifiMacQueueItem::Print (std::ostream& os) const
204 {
205  os << "size=" << m_packet->GetSize ()
206  << ", to=" << m_header.GetAddr1 ()
207  << ", seqN=" << m_header.GetSequenceNumber ()
208  << ", lifetime=" << (Simulator::Now () - m_tstamp).GetMicroSeconds () << "us";
209  if (m_header.IsQosData ())
210  {
211  os << ", tid=" << +m_header.GetQosTid ();
212  if (m_header.IsQosNoAck ())
213  {
214  os << ", ack=NoAck";
215  }
216  else if (m_header.IsQosAck ())
217  {
218  os << ", ack=NormalAck";
219  }
220  else if (m_header.IsQosBlockAck ())
221  {
222  os << ", ack=BlockAck";
223  }
224  }
225 }
226 
227 std::ostream & operator << (std::ostream &os, const WifiMacQueueItem &item)
228 {
229  item.Print (os);
230  return os;
231 }
232 
233 } //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
MsduAggregator::DeaggregatedMsdusCI begin(void)
Get a constant iterator pointing to the first MSDU in the list of aggregated MSDUs.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Control the scheduling of simulation events.
Definition: simulator.h:68
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
void AddWifiMacTrailer(Ptr< Packet > packet)
Add FCS trailer to a packet.
Definition: wifi-utils.cc:231
virtual void Print(std::ostream &os) const
Print the item contents.
uint32_t GetSize(void) const
Return the size of the packet stored by this item, including header size and trailer size...
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
Time GetTimeStamp(void) const
Get the timestamp included in this item.
static const uint16_t WIFI_MAC_FCS_LENGTH
The length in octects of the IEEE 802.11 MAC FCS field.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
static DeaggregatedMsdus Deaggregate(Ptr< Packet > aggregatedPacket)
Mac48Address GetDestinationAddress(void) const
Return the destination address present in the header.
MsduAggregator::DeaggregatedMsdusCI end(void)
Get a constant iterator indicating past-the-last MSDU in the list of aggregated MSDUs.
void SetSourceAddr(Mac48Address to)
Set source address function.
Ptr< const Packet > m_packet
The packet (MSDU or A-MSDU) contained in this queue item.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Definition: packet.cc:335
std::list< std::pair< Ptr< const Packet >, AmsduSubframeHeader > >::const_iterator DeaggregatedMsdusCI
DeaggregatedMsdusCI typedef.
WifiMacQueueItem stores (const) packets along with their Wifi MAC headers and the time when they were...
const WifiMacHeader & GetHeader(void) const
Get the header stored in this item.
Time m_tstamp
timestamp when the packet arrived at the queue
bool IsQosNoAck(void) const
Return if the QoS Ack policy is No Ack.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
MsduAggregator::DeaggregatedMsdus m_msduList
The list of aggregated MSDUs included in this MPDU.
bool IsFromDs(void) const
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
WifiMacHeader m_header
Wifi MAC header associated with the packet.
void Aggregate(Ptr< const WifiMacQueueItem > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU)...
void SetLength(uint16_t length)
Set length function.
bool IsQosAck(void) const
Return if the QoS Ack policy is Normal Ack.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ptr< const Packet > GetPacket(void) const
Get the packet stored in this item.
Ptr< Packet > GetProtocolDataUnit(void) const
Get the MAC protocol data unit (MPDU) corresponding to this item (i.e.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
WifiMacQueueItem(Ptr< const Packet > p, const WifiMacHeader &header)
Create a Wifi MAC queue item containing a packet and a Wifi MAC header.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
an EUI-48 address
Definition: mac48-address.h:43
Headers for A-MSDU subframes.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
void SetDestinationAddr(Mac48Address to)
Set destination address function.
bool IsQosBlockAck(void) const
Return if the QoS Ack policy is Block Ack.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
uint32_t GetSerializedSize(void) const
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...
void DoAggregate(Ptr< const WifiMacQueueItem > msdu)
Aggregate the MSDU contained in the given MPDU to this MPDU (thus constituting an A-MSDU)...
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data...
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:309
void SetQosAmsdu(void)
Set that A-MSDU is present.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
Implements the IEEE 802.11 MAC header.
bool IsToDs(void) const