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 " << (uint16_t) tid << " out of range");
31  switch (tid)
32  {
33  case 0:
34  return AC_BE;
35  break;
36  case 1:
37  return AC_BK;
38  break;
39  case 2:
40  return AC_BK;
41  break;
42  case 3:
43  return AC_BE;
44  break;
45  case 4:
46  return AC_VI;
47  break;
48  case 5:
49  return AC_VI;
50  break;
51  case 6:
52  return AC_VO;
53  break;
54  case 7:
55  return AC_VO;
56  break;
57  }
58  return AC_UNDEF;
59 }
60 
61 uint8_t
63 {
65  uint8_t tid = 8;
66  if (packet->PeekPacketTag (qos))
67  {
68  if (qos.GetPriority () < 8)
69  {
70  tid = qos.GetPriority ();
71  }
72  }
73  return tid;
74 }
75 
76 uint32_t
77 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
78 {
79  uint32_t integer = 0;
80  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
81  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
82  integer *= 16;
83  integer += (seqControl & 0x000f);
84  return integer;
85 }
86 
87 bool
88 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
89 {
90  NS_ASSERT (startingSeq < 4096);
91  NS_ASSERT (seqNumber < 4096);
92  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
93  return (distance >= 2048);
94 }
95 
102 uint8_t
104 {
105  NS_ASSERT (hdr.IsQosData () || packet != 0);
106  if (hdr.IsQosData ())
107  {
108  return hdr.GetQosTid ();
109  }
110  else if (hdr.IsBlockAckReq ())
111  {
112  CtrlBAckRequestHeader baReqHdr;
113  packet->PeekHeader (baReqHdr);
114  return baReqHdr.GetTidInfo ();
115  }
116  else if (hdr.IsBlockAck ())
117  {
118  CtrlBAckResponseHeader baRespHdr;
119  packet->PeekHeader (baRespHdr);
120  return baRespHdr.GetTidInfo ();
121  }
122  else if (hdr.IsMgt () && hdr.IsAction ())
123  {
124  Ptr<Packet> pkt = packet->Copy ();
125  WifiActionHeader actionHdr;
126  pkt->RemoveHeader (actionHdr);
127 
128  if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK)
129  {
130  switch (actionHdr.GetAction ().blockAck)
131  {
133  {
134  MgtAddBaResponseHeader reqHdr;
135  pkt->RemoveHeader (reqHdr);
136  return reqHdr.GetTid ();
137  }
139  {
140  MgtAddBaResponseHeader respHdr;
141  pkt->RemoveHeader (respHdr);
142  return respHdr.GetTid ();
143  }
145  {
146  MgtDelBaHeader delHdr;
147  pkt->RemoveHeader (delHdr);
148  return delHdr.GetTid ();
149  }
150  default:
151  {
152  NS_FATAL_ERROR ("Cannot extract Traffic ID from this BA action frame");
153  }
154  }
155  }
156  else
157  {
158  NS_FATAL_ERROR ("Cannot extract Traffic ID from this action frame");
159  }
160  }
161  else
162  {
163  NS_FATAL_ERROR ("Packet has no Traffic ID");
164  }
165 }
166 
167 
168 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:267
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
Definition: mgt-headers.h:625
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:88
bool IsBlockAck(void) const
Return true if the header is a Block ACK header.
CategoryValue GetCategory()
Return the category value.
Definition: mgt-headers.cc:888
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:62
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:836
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:277
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:103
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).
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
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:77
BlockAckActionValue blockAck
block ack
Definition: mgt-headers.h:701
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:890
Implement the header for management frames of type del block ack.
Definition: mgt-headers.h:1011
ActionValue GetAction()
Return the action value.
Definition: mgt-headers.cc:909
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.