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 "qos-utils.h"
23 #include "ns3/socket.h"
24 
25 namespace ns3 {
26 
27 AcIndex
28 QosUtilsMapTidToAc (uint8_t tid)
29 {
30  NS_ASSERT_MSG (tid < 8, "Tid " << +tid << " out of range");
31  switch (tid)
32  {
33  case 0:
34  case 3:
35  return AC_BE;
36  break;
37  case 1:
38  case 2:
39  return AC_BK;
40  break;
41  case 4:
42  case 5:
43  return AC_VI;
44  break;
45  case 6:
46  case 7:
47  return AC_VO;
48  break;
49  }
50  return AC_UNDEF;
51 }
52 
53 uint8_t
55 {
57  uint8_t tid = 8;
58  if (packet->PeekPacketTag (qos))
59  {
60  if (qos.GetPriority () < 8)
61  {
62  tid = qos.GetPriority ();
63  }
64  }
65  return tid;
66 }
67 
68 uint32_t
69 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
70 {
71  uint32_t integer = 0;
72  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
73  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
74  integer *= 16;
75  integer += (seqControl & 0x000f);
76  return integer;
77 }
78 
79 bool
80 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
81 {
82  NS_ASSERT (startingSeq < 4096);
83  NS_ASSERT (seqNumber < 4096);
84  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
85  return (distance >= 2048);
86 }
87 
94 uint8_t
96 {
97  NS_ASSERT (hdr.IsQosData () || packet != 0);
98  if (hdr.IsQosData ())
99  {
100  return hdr.GetQosTid ();
101  }
102  else if (hdr.IsBlockAckReq ())
103  {
104  CtrlBAckRequestHeader baReqHdr;
105  packet->PeekHeader (baReqHdr);
106  return baReqHdr.GetTidInfo ();
107  }
108  else if (hdr.IsBlockAck ())
109  {
110  CtrlBAckResponseHeader baRespHdr;
111  packet->PeekHeader (baRespHdr);
112  return baRespHdr.GetTidInfo ();
113  }
114  else if (hdr.IsMgt () && hdr.IsAction ())
115  {
116  Ptr<Packet> pkt = packet->Copy ();
117  WifiActionHeader actionHdr;
118  pkt->RemoveHeader (actionHdr);
119 
120  if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK)
121  {
122  switch (actionHdr.GetAction ().blockAck)
123  {
125  {
126  MgtAddBaResponseHeader reqHdr;
127  pkt->RemoveHeader (reqHdr);
128  return reqHdr.GetTid ();
129  }
131  {
132  MgtAddBaResponseHeader respHdr;
133  pkt->RemoveHeader (respHdr);
134  return respHdr.GetTid ();
135  }
137  {
138  MgtDelBaHeader delHdr;
139  pkt->RemoveHeader (delHdr);
140  return delHdr.GetTid ();
141  }
142  default:
143  {
144  NS_FATAL_ERROR ("Cannot extract Traffic ID from this BA action frame");
145  }
146  }
147  }
148  else
149  {
150  NS_FATAL_ERROR ("Cannot extract Traffic ID from this action frame");
151  }
152  }
153  else
154  {
155  NS_FATAL_ERROR ("Packet has no Traffic ID");
156  }
157 }
158 
159 
160 } //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:850
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:80
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:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:54
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Background.
Definition: qos-utils.h:43
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:28
Headers for Block ack response.
Definition: ctrl-headers.h:190
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:95
uint8_t GetPriority(void) const
Get the tag'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:69
BlockAckActionValue blockAck
block ack
Definition: mgt-headers.h:926
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:1115
Implement the header for management frames of type del block ack.
Definition: mgt-headers.h:1236
ActionValue GetAction()
Return the action value.
Headers for Block ack request.
Definition: ctrl-headers.h:50
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:38
Implements the IEEE 802.11 MAC header.