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 AcIndex
32 QosUtilsMapTidToAc (uint8_t tid)
33 {
34  NS_ASSERT_MSG (tid < 8, "Tid " << +tid << " out of range");
35  switch (tid)
36  {
37  case 0:
38  case 3:
39  return AC_BE;
40  break;
41  case 1:
42  case 2:
43  return AC_BK;
44  break;
45  case 4:
46  case 5:
47  return AC_VI;
48  break;
49  case 6:
50  case 7:
51  return AC_VO;
52  break;
53  }
54  return AC_UNDEF;
55 }
56 
57 uint8_t
59 {
61  uint8_t tid = 8;
62  if (packet->PeekPacketTag (qos))
63  {
64  if (qos.GetPriority () < 8)
65  {
66  tid = qos.GetPriority ();
67  }
68  }
69  return tid;
70 }
71 
72 uint32_t
73 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
74 {
75  uint32_t integer = 0;
76  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
77  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
78  integer *= 16;
79  integer += (seqControl & 0x000f);
80  return integer;
81 }
82 
83 bool
84 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
85 {
86  NS_ASSERT (startingSeq < 4096);
87  NS_ASSERT (seqNumber < 4096);
88  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
89  return (distance >= 2048);
90 }
91 
98 uint8_t
100 {
101  NS_ASSERT (hdr.IsQosData () || packet != 0);
102  if (hdr.IsQosData ())
103  {
104  return hdr.GetQosTid ();
105  }
106  else if (hdr.IsBlockAckReq ())
107  {
108  CtrlBAckRequestHeader baReqHdr;
109  packet->PeekHeader (baReqHdr);
110  return baReqHdr.GetTidInfo ();
111  }
112  else if (hdr.IsBlockAck ())
113  {
114  CtrlBAckResponseHeader baRespHdr;
115  packet->PeekHeader (baRespHdr);
116  return baRespHdr.GetTidInfo ();
117  }
118  else if (hdr.IsMgt () && hdr.IsAction ())
119  {
120  Ptr<Packet> pkt = packet->Copy ();
121  WifiActionHeader actionHdr;
122  pkt->RemoveHeader (actionHdr);
123 
124  if (actionHdr.GetCategory () == WifiActionHeader::BLOCK_ACK)
125  {
126  switch (actionHdr.GetAction ().blockAck)
127  {
129  {
130  MgtAddBaRequestHeader reqHdr;
131  pkt->RemoveHeader (reqHdr);
132  return reqHdr.GetTid ();
133  }
135  {
136  MgtAddBaResponseHeader respHdr;
137  pkt->RemoveHeader (respHdr);
138  return respHdr.GetTid ();
139  }
141  {
142  MgtDelBaHeader delHdr;
143  pkt->RemoveHeader (delHdr);
144  return delHdr.GetTid ();
145  }
146  default:
147  {
148  NS_FATAL_ERROR ("Cannot extract Traffic ID from this BA action frame");
149  }
150  }
151  }
152  else
153  {
154  NS_FATAL_ERROR ("Cannot extract Traffic ID from this action frame");
155  }
156  }
157  else
158  {
159  NS_FATAL_ERROR ("Packet has no Traffic ID");
160  }
161 }
162 
163 uint8_t
165 {
166  uint8_t dscp, priority = 0;
167  if (item->GetUint8Value (QueueItem::IP_DSFIELD, dscp))
168  {
169  // if the QoS map element is implemented, it should be used here
170  // to set the priority.
171  // User priority is set to the three most significant bits of the DS field
172  priority = dscp >> 5;
173  }
174 
175  // replace the priority tag
176  SocketPriorityTag priorityTag;
177  priorityTag.SetPriority (priority);
178  item->GetPacket ()->ReplacePacketTag (priorityTag);
179 
180  // if the admission control were implemented, here we should check whether
181  // the access category assigned to the packet should be downgraded
182 
183  return static_cast<uint8_t> (QosUtilsMapTidToAc (priority));
184 }
185 
186 
187 } //namespace ns3
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
Definition: mgt-headers.h:864
Implement the header for management frames of type add block ack request.
Definition: mgt-headers.h:997
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: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:84
CategoryValue GetCategory()
Return the category value.
Ptr< Packet > GetPacket(void) const
Definition: queue-item.cc:42
Video.
Definition: qos-utils.h:45
Voice.
Definition: qos-utils.h:47
Best Effort.
Definition: qos-utils.h:41
uint8_t GetTidInfo(void) const
Return the Traffic ID (TID).
bool IsBlockAck(void) const
Return true if the header is a Block ACK 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:58
uint8_t GetTid(void) const
Return the Traffic ID (TID).
bool IsBlockAckReq(void) const
Return true if the header is a Block ACK Request header.
Background.
Definition: qos-utils.h:43
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:877
indicates whether the socket has a priority set.
Definition: socket.h:1307
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:32
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Headers for Block ack response.
Definition: ctrl-headers.h:193
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t SelectQueueByDSField(Ptr< QueueItem > item)
Determine the tx queue for a given packet.
Definition: qos-utils.cc:164
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint8_t GetTid(Ptr< const Packet > packet, const WifiMacHeader hdr)
Extraction operator for TypeId.
Definition: qos-utils.cc:99
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
uint8_t GetTid(void) const
Return the Traffic ID (TID).
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:73
BlockAckActionValue blockAck
block ack
Definition: mgt-headers.h:940
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
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS DATA...
bool IsAction() const
Return true if the header is an Action header.
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:885
ActionValue GetAction()
Return the action value.
Headers for Block ack request.
Definition: ctrl-headers.h:41
void SetPriority(uint8_t priority)
Set the tag&#39;s priority.
Definition: socket.cc:842
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.