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 "ns3/queue-item.h"
24 #include "qos-utils.h"
25 #include "wifi-mac-header.h"
26 #include "mgt-headers.h"
27 #include "ctrl-headers.h"
28 
29 namespace ns3 {
30 
31 std::size_t
33 {
34  uint8_t buffer[7];
35  addressTidPair.first.CopyTo (buffer);
36  buffer[6] = addressTidPair.second;
37 
38  std::string s (buffer, buffer + 7);
39  return std::hash<std::string>{} (s);
40 }
41 
42 std::size_t
44 {
45  uint8_t buffer[6];
46  address.CopyTo (buffer);
47 
48  std::string s (buffer, buffer + 6);
49  return std::hash<std::string>{} (s);
50 }
51 
52 AcIndex
53 QosUtilsMapTidToAc (uint8_t tid)
54 {
55  NS_ASSERT_MSG (tid < 8, "Tid " << +tid << " out of range");
56  switch (tid)
57  {
58  case 0:
59  case 3:
60  return AC_BE;
61  break;
62  case 1:
63  case 2:
64  return AC_BK;
65  break;
66  case 4:
67  case 5:
68  return AC_VI;
69  break;
70  case 6:
71  case 7:
72  return AC_VO;
73  break;
74  }
75  return AC_UNDEF;
76 }
77 
78 uint8_t
80 {
82  uint8_t tid = 8;
83  if (packet->PeekPacketTag (qos))
84  {
85  if (qos.GetPriority () < 8)
86  {
87  tid = qos.GetPriority ();
88  }
89  }
90  return tid;
91 }
92 
93 uint32_t
94 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
95 {
96  uint32_t integer = 0;
97  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
98  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
99  integer *= 16;
100  integer += (seqControl & 0x000f);
101  return integer;
102 }
103 
104 bool
105 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
106 {
107  NS_ASSERT (startingSeq < 4096);
108  NS_ASSERT (seqNumber < 4096);
109  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
110  return (distance >= 2048);
111 }
112 
119 uint8_t
121 {
122  NS_ASSERT (hdr.IsQosData () || packet != 0);
123  if (hdr.IsQosData ())
124  {
125  return hdr.GetQosTid ();
126  }
127  else if (hdr.IsBlockAckReq ())
128  {
129  CtrlBAckRequestHeader baReqHdr;
130  packet->PeekHeader (baReqHdr);
131  return baReqHdr.GetTidInfo ();
132  }
133  else if (hdr.IsBlockAck ())
134  {
135  CtrlBAckResponseHeader baRespHdr;
136  packet->PeekHeader (baRespHdr);
137  return baRespHdr.GetTidInfo ();
138  }
139  else if (hdr.IsMgt () && hdr.IsAction ())
140  {
141  Ptr<Packet> pkt = packet->Copy ();
142  WifiActionHeader actionHdr;
143  pkt->RemoveHeader (actionHdr);
144 
145  if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK)
146  {
147  switch (actionHdr.GetAction ().blockAck)
148  {
150  {
151  MgtAddBaRequestHeader reqHdr;
152  pkt->RemoveHeader (reqHdr);
153  return reqHdr.GetTid ();
154  }
156  {
157  MgtAddBaResponseHeader respHdr;
158  pkt->RemoveHeader (respHdr);
159  return respHdr.GetTid ();
160  }
162  {
163  MgtDelBaHeader delHdr;
164  pkt->RemoveHeader (delHdr);
165  return delHdr.GetTid ();
166  }
167  default:
168  {
169  NS_FATAL_ERROR ("Cannot extract Traffic ID from this BA action frame");
170  }
171  }
172  }
173  else
174  {
175  NS_FATAL_ERROR ("Cannot extract Traffic ID from this action frame");
176  }
177  }
178  else
179  {
180  NS_FATAL_ERROR ("Packet has no Traffic ID");
181  }
182 }
183 
184 uint8_t
186 {
187  uint8_t dscp, priority = 0;
188  if (item->GetUint8Value (QueueItem::IP_DSFIELD, dscp))
189  {
190  // if the QoS map element is implemented, it should be used here
191  // to set the priority.
192  // User priority is set to the three most significant bits of the DS field
193  priority = dscp >> 5;
194  }
195 
196  // replace the priority tag
197  SocketPriorityTag priorityTag;
198  priorityTag.SetPriority (priority);
199  item->GetPacket ()->ReplacePacketTag (priorityTag);
200 
201  // if the admission control were implemented, here we should check whether
202  // the access category assigned to the packet should be downgraded
203 
204  return static_cast<uint8_t> (QosUtilsMapTidToAc (priority));
205 }
206 
207 
208 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
std::pair< Mac48Address, uint8_t > WifiAddressTidPair
(MAC address, TID) pair
Definition: qos-utils.h:31
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:57
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
Definition: mgt-headers.h:856
Implement the header for management frames of type Add Block Ack request.
Definition: mgt-headers.h:989
uint8_t GetPriority(void) const
Get the tag&#39;s priority.
Definition: socket.cc:848
#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:165
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:105
CategoryValue GetCategory()
Return the category value.
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
bool IsBlockAck(void) const
Return true if the header is a BlockAck header.
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a QoS tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:79
uint8_t GetTid(void) const
Return the Traffic ID (TID).
bool IsBlockAckReq(void) const
Return true if the header is a BlockAckRequest header.
bool IsAction(void) const
Return true if the header is an Action header.
Video.
Definition: qos-utils.h:64
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:970
indicates whether the socket has a priority set.
Definition: socket.h:1308
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:53
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
Best Effort.
Definition: qos-utils.h:60
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Headers for BlockAck response.
Definition: ctrl-headers.h:199
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
uint8_t SelectQueueByDSField(Ptr< QueueItem > item)
Determine the TX queue for a given packet.
Definition: qos-utils.cc:185
Background.
Definition: qos-utils.h:62
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
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
Definition: qos-utils.cc:120
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
Definition: queue-item.cc:57
#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:88
uint8_t GetTid(void) const
Return the Traffic ID (TID).
Voice.
Definition: qos-utils.h:66
bool IsMgt(void) const
Return true if the Type is Management.
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:94
BlockAckActionValue blockAck
block ack
Definition: mgt-headers.h:932
Implement the header for management frames of type Add Block Ack response.
Definition: mgt-headers.h:1121
std::size_t operator()(const WifiAddressTidPair &addressTidPair) const
Definition: qos-utils.cc:32
Implement the header for management frames of type Delete Block Ack.
Definition: mgt-headers.h:1242
std::size_t operator()(const Mac48Address &address) const
Definition: qos-utils.cc:43
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data...
uint8_t GetTid(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:978
ActionValue GetAction()
Return the action value.
Headers for BlockAckRequest.
Definition: ctrl-headers.h:47
void SetPriority(uint8_t priority)
Set the tag&#39;s priority.
Definition: socket.cc:842
Implements the IEEE 802.11 MAC header.