shared facility for qos support
authorMirko Banchi <mk.banchi@gmail.com>
Fri, 24 Apr 2009 09:16:28 +0200
changeset 4404 e10005ac0701
parent 4403 54141b0e8f9f
child 4405 938c96b15fa7
shared facility for qos support
src/devices/wifi/qos-tag.cc
src/devices/wifi/qos-tag.h
src/devices/wifi/qos-utils.cc
src/devices/wifi/qos-utils.h
src/devices/wifi/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/qos-tag.cc	Fri Apr 24 09:16:28 2009 +0200
@@ -0,0 +1,85 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 MIRKO BANCHI
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Mirko Banchi <mk.banchi@gmail.com>
+ */
+#include "qos-tag.h"
+#include "ns3/tag.h"
+#include "ns3/uinteger.h"
+
+namespace ns3 {
+
+TypeId 
+QosTag::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::QosTag")
+    .SetParent<Tag> ()
+    .AddConstructor<QosTag> ()
+    .AddAttribute ("tid", "The tid that indicates AC which packet belongs",
+                   UintegerValue (0),
+                   MakeUintegerAccessor (&QosTag::Get),
+                   MakeUintegerChecker<uint8_t> ())
+    ;
+  return tid;
+}
+
+TypeId
+QosTag::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+QosTag::QosTag()
+{}
+
+uint32_t 
+QosTag::GetSerializedSize (void) const
+{
+  return 1;
+}
+
+void
+QosTag::Serialize (TagBuffer i) const
+{
+  i.WriteU8 (m_tid);
+}
+
+void
+QosTag::Deserialize (TagBuffer i)
+{
+  m_tid = i.ReadU8 ();
+}
+
+void
+QosTag::Set (uint8_t tid)
+{
+  m_tid = tid;
+}
+
+uint8_t
+QosTag::Get () const
+{
+  return m_tid;
+}
+
+void
+QosTag::Print (std::ostream &os) const
+{
+  os << "Tid=" << m_tid;
+}
+
+} //namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/qos-tag.h	Fri Apr 24 09:16:28 2009 +0200
@@ -0,0 +1,49 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 MIRKO BANCHI
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Mirko Banchi <mk.banchi@gmail.com>
+ */
+#ifndef QOS_TAG_H
+#define QOS_TAG_H
+
+#include "ns3/packet.h"
+
+namespace ns3 {
+
+class Tag;
+
+class QosTag : public Tag
+{
+public:
+  static TypeId GetTypeId (void);
+  virtual TypeId GetInstanceTypeId (void) const;
+  
+  QosTag ();
+  virtual void Serialize (TagBuffer i) const;
+  virtual void Deserialize (TagBuffer i);
+  virtual uint32_t GetSerializedSize () const;
+  virtual void Print (std::ostream &os) const;
+
+  uint8_t Get (void) const;
+  void Set (uint8_t tid);
+private:
+  uint8_t m_tid;
+};
+
+} //namespace ns3
+
+#endif /* QOS_TAG_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/qos-utils.cc	Fri Apr 24 09:16:28 2009 +0200
@@ -0,0 +1,72 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 MIRKO BANCHI
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Mirko Banchi <mk.banchi@gmail.com>
+ */
+#include "qos-utils.h"
+#include "qos-tag.h"
+
+namespace ns3 {
+
+AccessClass
+QosUtilsMapTidToAc (uint8_t tid)
+{
+  switch (tid) {
+  case 0 :
+    return AC_BE;
+    break;
+  case 1 :
+    return AC_BK;
+    break;
+  case 2 :
+    return AC_BK;
+    break;
+  case 3 :
+    return AC_BE;
+    break;
+  case 4 :
+    return AC_VI;
+    break;
+  case 5 :
+    return AC_VI;
+    break;
+  case 6 :
+    return AC_VO;
+    break;
+  case 7 : 
+    return AC_VO;
+    break;
+  }
+  return AC_UNDEF;
+}
+
+uint8_t
+QosUtilsGetTidForPacket (Ptr<const Packet> packet)
+{
+  QosTag qos;
+  uint8_t tid = 8;
+  if (packet->FindFirstMatchingTag (qos))
+    {
+      if (qos.Get () < 8)
+        {
+          tid = qos.Get ();
+        }
+    }
+  return tid;
+}
+
+} //namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/wifi/qos-utils.h	Fri Apr 24 09:16:28 2009 +0200
@@ -0,0 +1,49 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 MIRKO BANCHI
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as 
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Mirko Banchi <mk.banchi@gmail.com>
+ */
+#ifndef QOS_UTILS_H
+#define QOS_UTILS_H
+
+#include "ns3/uinteger.h"
+#include "ns3/ptr.h"
+#include "ns3/packet.h"
+
+namespace ns3 {
+
+enum AccessClass {
+  AC_VO = 0,
+  AC_VI = 1,
+  AC_BE = 2,
+  AC_BK = 3,
+  AC_UNDEF
+};
+
+/* Maps TID (Traffic ID) to Access classes.
+ * For more details see table 9-1 of IEEE802.11 standard.
+ */
+AccessClass QosUtilsMapTidToAc (uint8_t tid);
+
+/* If a qos tag is attached to the packet, returns a value < 8.
+   A value >= 8 is returned otherwise.
+ */
+uint8_t QosUtilsGetTidForPacket (Ptr<const Packet> packet);
+
+} //namespace ns3
+
+#endif /* QOS_UTILS_H */
--- a/src/devices/wifi/wscript	Fri Apr 24 09:11:48 2009 +0200
+++ b/src/devices/wifi/wscript	Fri Apr 24 09:16:28 2009 +0200
@@ -46,6 +46,8 @@
         'cara-wifi-manager.cc',
         'constant-rate-wifi-manager.cc',
         'wifi-test.cc',
+        'qos-tag.cc',
+        'qos-utils.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'wifi'