A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * Author: Mirko Banchi <mk.banchi@gmail.com>
19  * Author: Cecchi Niccolò <insa@igeek.it>
20  */
21 #include "qos-utils.h"
22 #include "qos-tag.h"
23 
24 namespace ns3 {
25 
26 AcIndex
27 QosUtilsMapTidToAc (uint8_t tid)
28 {
29  switch (tid)
30  {
31  case 0:
32  return AC_BE;
33  break;
34  case 1:
35  return AC_BK;
36  break;
37  case 2:
38  return AC_BK;
39  break;
40  case 3:
41  return AC_BE;
42  break;
43  case 4:
44  return AC_VI;
45  break;
46  case 5:
47  return AC_VI;
48  break;
49  case 6:
50  return AC_VO;
51  break;
52  case 7:
53  return AC_VO;
54  break;
55  }
56  return AC_UNDEF;
57 }
58 
59 uint8_t
61 {
62  QosTag qos;
63  uint8_t tid = 8;
64  if (packet->PeekPacketTag (qos))
65  {
66  if (qos.GetTid () < 8)
67  {
68  tid = qos.GetTid ();
69  }
70  }
71  return tid;
72 }
73 
74 uint32_t
75 QosUtilsMapSeqControlToUniqueInteger (uint16_t seqControl, uint16_t endSequence)
76 {
77  uint32_t integer = 0;
78  uint16_t numberSeq = (seqControl >> 4) & 0x0fff;
79  integer = (4096 - (endSequence + 1) + numberSeq) % 4096;
80  integer *= 16;
81  integer += (seqControl & 0x000f);
82  return integer;
83 }
84 
85 bool
86 QosUtilsIsOldPacket (uint16_t startingSeq, uint16_t seqNumber)
87 {
88  NS_ASSERT (startingSeq < 4096);
89  NS_ASSERT (seqNumber < 4096);
90  uint16_t distance = ((seqNumber - startingSeq) + 4096) % 4096;
91  return (distance >= 2048);
92 }
93 
94 } // namespace ns3
#define NS_ASSERT(condition)
Definition: assert.h:64
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:86
Video.
Definition: qos-utils.h:42
Voice.
Definition: qos-utils.h:44
Best Effort.
Definition: qos-utils.h:38
uint8_t QosUtilsGetTidForPacket(Ptr< const Packet > packet)
If a qos tag is attached to the packet, returns a value < 8.
Definition: qos-utils.cc:60
Background.
Definition: qos-utils.h:40
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:863
AcIndex QosUtilsMapTidToAc(uint8_t tid)
Maps TID (Traffic ID) to Access classes.
Definition: qos-utils.cc:27
The aim of the QosTag is to provide means for an Application to specify the TID which will be used by...
Definition: qos-tag.h:61
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:75
uint8_t GetTid(void) const
Return the Type ID.
Definition: qos-tag.cc:89
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:35