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 
96 } //namespace ns3
#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
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
Video.
Definition: qos-utils.h:43
Voice.
Definition: qos-utils.h:45
Best Effort.
Definition: qos-utils.h:39
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
Background.
Definition: qos-utils.h:41
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:846
indicates whether the socket has a priority set.
Definition: socket.h:1304
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:28
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetPriority(void) const
Get the tag's priority.
Definition: socket.cc:854
#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
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
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:36