A Discrete-Event Network Simulator
API
qos-utils.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
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: Mirko Banchi <mk.banchi@gmail.com>
19  * Cecchi Niccolò <insa@igeek.it>
20  */
21 
22 #include "ns3/socket.h"
23 #include "qos-utils.h"
24 #include "wifi-mac-header.h"
25 #include "mgt-headers.h"
26 #include "ctrl-headers.h"
27 
28 namespace ns3 {
29 
30 AcIndex
31 QosUtilsMapTidToAc (uint8_t tid)
32 {
33  NS_ASSERT_MSG (tid < 8, "Tid " << +tid << " out of range");
34  switch (tid)
35  {
36  case 0:
37  case 3:
38  return AC_BE;
39  break;
40  case 1:
41  case 2:
42  return AC_BK;
43  break;
44  case 4:
45  case 5:
46  return AC_VI;
47  break;
48  case 6:
49  case 7:
50  return AC_VO;
51  break;
52  }
53  return AC_UNDEF;
54 }
55 
56 uint8_t
58 {
60  uint8_t tid = 8;
61  if (packet->PeekPacketTag (qos))
62  {
63  if (qos.GetPriority () < 8)
64  {
65  tid = qos.GetPriority ();
66  }
67  }
68  return tid;
69 }
70 
71 uint32_t
72 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
73 {
74  uint32_t integer = 0;
75  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
76  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
77  integer *= 16;
78  integer += (seqControl & 0x000f);
79  return integer;
80 }
81 
82 bool
83 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
84 {
85  NS_ASSERT (startingSeq < 4096);
86  NS_ASSERT (seqNumber < 4096);
87  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
88  return (distance >= 2048);
89 }
90 
97 uint8_t
99 {
100  NS_ASSERT (hdr.IsQosData () || packet != 0);
101  if (hdr.IsQosData ())
102  {
103  return hdr.GetQosTid ();
104  }
105  else if (hdr.IsBlockAckReq ())
106  {
107  CtrlBAckRequestHeader baReqHdr;
108  packet->PeekHeader (baReqHdr);
109  return baReqHdr.GetTidInfo ();
110  }
111  else if (hdr.IsBlockAck ())
112  {
113  CtrlBAckResponseHeader baRespHdr;
114  packet->PeekHeader (baRespHdr);
115  return baRespHdr.GetTidInfo ();
116  }
117  else if (hdr.IsMgt () && hdr.IsAction ())
118  {
119  Ptr<Packet> pkt = packet->Copy ();
120  WifiActionHeader actionHdr;
121  pkt->RemoveHeader (actionHdr);
122 
123  if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK)
124  {
125  switch (actionHdr.GetAction ().blockAck)
126  {
128  {
129  MgtAddBaResponseHeader reqHdr;
130  pkt->RemoveHeader (reqHdr);
131  return reqHdr.GetTid ();
132  }
134  {
135  MgtAddBaResponseHeader respHdr;
136  pkt->RemoveHeader (respHdr);
137  return respHdr.GetTid ();
138  }
140  {
141  MgtDelBaHeader delHdr;
142  pkt->RemoveHeader (delHdr);
143  return delHdr.GetTid ();
144  }
145  default:
146  {
147  NS_FATAL_ERROR ("Cannot extract Traffic ID from this BA action frame");
148  }
149  }
150  }
151  else
152  {
153  NS_FATAL_ERROR ("Cannot extract Traffic ID from this action frame");
154  }
155  }
156  else
157  {
158  NS_FATAL_ERROR ("Packet has no Traffic ID");
159  }
160 }
161 
162 
163 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
Definition: mgt-headers.h:864
bool IsAction() const
Return true if the header is an Action header.
#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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet. ...
Definition: qos-utils.cc:83
bool IsBlockAck(void) const
Return true if the header is a Block ACK header.
CategoryValue GetCategory()
Return the category value.
Video.
Definition: qos-utils.h:44
Voice.
Definition: qos-utils.h:46
Best Effort.
Definition: qos-utils.h:40
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:57
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Background.
Definition: qos-utils.h:42
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:874
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
indicates whether the socket has a priority set.
Definition: socket.h:1303
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:31
Headers for Block ack response.
Definition: ctrl-headers.h:181
bool IsMgt(void) const
Return true if the Type is Management.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetTid(void) const
Return the Traffic ID (TID).
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
Definition: qos-utils.cc:98
uint8_t GetPriority(void) const
Get the tag&#39;s priority.
Definition: socket.cc:854
uint8_t GetTid(void) const
Return the Traffic ID (TID).
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
uint32_t QosUtilsMapSeqControlToUniqueInteger(uint16_t seqControl, uint16_t endSequence)
Next function is useful to correctly sort buffered packets under block ack.
Definition: qos-utils.cc:72
BlockAckActionValue blockAck
block ack
Definition: mgt-headers.h:940
bool IsBlockAckReq(void) const
Return true if the header is a Block ACK Request header.
Implement the header for management frames of type add block ack response.
Definition: mgt-headers.h:1129
Implement the header for management frames of type del block ack.
Definition: mgt-headers.h:1250
ActionValue GetAction()
Return the action value.
Headers for Block ack request.
Definition: ctrl-headers.h:41
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:37
Implements the IEEE 802.11 MAC header.