src/devices/wifi/wifi-mac-queue.cc
author Pavel Boyko <boyko@iitp.ru>
Tue, 16 Jun 2009 17:58:16 +0400
changeset 5074 355de6af8ea9
parent 4466 8edb50eea6cb
child 5952 0588b01cd77e
permissions -rw-r--r--
merged with nsnam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
     3
 * Copyright (c) 2005, 2009 INRIA
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
     4
 * Copyright (c) 2009 MIRKO BANCHI
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
    20
 * Author: Mirko Banchi <mk.banchi@gmail.com>
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
 */
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "ns3/simulator.h"
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/packet.h"
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    24
#include "ns3/uinteger.h"
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "wifi-mac-queue.h"
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
using namespace std;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
namespace ns3 {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
4102
3a5b1ed17edc Fix WifiMacQueue typeid registration
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2965
diff changeset
    32
NS_OBJECT_ENSURE_REGISTERED (WifiMacQueue);
3a5b1ed17edc Fix WifiMacQueue typeid registration
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2965
diff changeset
    33
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1977
diff changeset
    34
WifiMacQueue::Item::Item (Ptr<const Packet> packet, 
4466
8edb50eea6cb const cleanup
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4443
diff changeset
    35
                          const WifiMacHeader &hdr, 
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1977
diff changeset
    36
                          Time tstamp)
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
  : packet (packet), hdr (hdr), tstamp (tstamp)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
{}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    40
TypeId 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    41
WifiMacQueue::GetTypeId (void)
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    42
{
4102
3a5b1ed17edc Fix WifiMacQueue typeid registration
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2965
diff changeset
    43
  static TypeId tid = TypeId ("ns3::WifiMacQueue")
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    44
    .SetParent<Object> ()
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    45
    .AddConstructor<WifiMacQueue> ()
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
    46
    .AddAttribute ("MaxPacketNumber", "If a packet arrives when there are already this number of packets, it is dropped.",
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
    47
                   UintegerValue (400),
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    48
                   MakeUintegerAccessor (&WifiMacQueue::m_maxSize),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    49
                   MakeUintegerChecker<uint32_t> ())
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
    50
    .AddAttribute ("MaxDelay", "If a packet stays longer than this delay in the queue, it is dropped.",
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2524
diff changeset
    51
                   TimeValue (Seconds (10.0)),
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    52
                   MakeTimeAccessor (&WifiMacQueue::m_maxDelay),
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    53
                   MakeTimeChecker ())
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    54
    ;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    55
  return tid;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    56
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    57
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
WifiMacQueue::WifiMacQueue ()
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
  : m_size (0)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
{}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
WifiMacQueue::~WifiMacQueue ()
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
  Flush ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
void 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
WifiMacQueue::SetMaxSize (uint32_t maxSize)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
  m_maxSize = maxSize;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
}
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
    72
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
    73
void
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
WifiMacQueue::SetMaxDelay (Time delay)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  m_maxDelay = delay;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
}
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
    78
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    79
uint32_t 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    80
WifiMacQueue::GetMaxSize (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    81
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    82
  return m_maxSize;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    83
}
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
    84
2524
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    85
Time 
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    86
WifiMacQueue::GetMaxDelay (void) const
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    87
{
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    88
  return m_maxDelay;
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    89
}
db72c0e7743e port wifi model to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2159
diff changeset
    90
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
void 
4466
8edb50eea6cb const cleanup
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4443
diff changeset
    92
WifiMacQueue::Enqueue (Ptr<const Packet> packet, const WifiMacHeader &hdr)
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
  Cleanup ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
  if (m_size == m_maxSize) 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
    {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
      return;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
    }
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
  Time now = Simulator::Now ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
  m_queue.push_back (Item (packet, hdr, now));
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
  m_size++;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
}
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   103
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
void
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
WifiMacQueue::Cleanup (void)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
  if (m_queue.empty ()) 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
    {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
      return;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
    }
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
  Time now = Simulator::Now ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
  uint32_t n = 0;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
  PacketQueueI end = m_queue.begin ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
  for (PacketQueueI i = m_queue.begin (); i != m_queue.end (); i++) 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
    {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
      if (i->tstamp + m_maxDelay > now) 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
        {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
          end = i;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
          break;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
        }
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
      n++;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
    }
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
  m_size -= n;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
  m_queue.erase (m_queue.begin (), end);
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1977
diff changeset
   128
Ptr<const Packet>
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1977
diff changeset
   129
WifiMacQueue::Dequeue (WifiMacHeader *hdr)
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
  Cleanup ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
  if (!m_queue.empty ()) 
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
    {
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
      Item i = m_queue.front ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
      m_queue.pop_front ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
      m_size--;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
      *hdr = i.hdr;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
      return i.packet;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
    }
2159
20f882e85b4a port to Ptr<Packet> branch
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1977
diff changeset
   140
  return 0;
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   143
Ptr<const Packet>
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   144
WifiMacQueue::Peek (WifiMacHeader *hdr)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   145
{
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   146
  Cleanup ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   147
  if (!m_queue.empty ()) 
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   148
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   149
      Item i = m_queue.front ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   150
      *hdr = i.hdr;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   151
      return i.packet;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   152
    }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   153
  return 0;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   154
}
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   155
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   156
Ptr<const Packet>
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   157
WifiMacQueue::DequeueByTidAndAddress (WifiMacHeader *hdr, uint8_t tid, 
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   158
                                      WifiMacHeader::AddressType type, Mac48Address dest)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   159
{
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   160
  Cleanup ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   161
  Ptr<const Packet> packet = 0;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   162
  if (!m_queue.empty ())
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   163
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   164
      PacketQueueI it;
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   165
      NS_ASSERT (type <= 4);
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   166
      for (it = m_queue.begin (); it != m_queue.end (); ++it)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   167
        {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   168
          if (it->hdr.IsQosData ())
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   169
            {
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   170
              if (GetAddressForPacket (type, it) == dest &&
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   171
                  it->hdr.GetQosTid () == tid)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   172
                {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   173
                  packet = it->packet;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   174
                  *hdr = it->hdr;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   175
                  m_queue.erase (it);
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   176
                  m_size--;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   177
                  break;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   178
                }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   179
            }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   180
        }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   181
    }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   182
  return packet;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   183
}
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   184
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   185
Ptr<const Packet>
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   186
WifiMacQueue::PeekByTidAndAddress (WifiMacHeader *hdr, uint8_t tid, 
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   187
                                   WifiMacHeader::AddressType type, Mac48Address dest)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   188
{
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   189
  Cleanup ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   190
  if (!m_queue.empty ())
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   191
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   192
      PacketQueueI it;
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   193
      NS_ASSERT (type <= 4);
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   194
      for (it = m_queue.begin (); it != m_queue.end (); ++it)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   195
        {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   196
          if (it->hdr.IsQosData ())
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   197
            {
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   198
              if (GetAddressForPacket (type, it) == dest &&
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   199
                  it->hdr.GetQosTid () == tid)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   200
                {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   201
                  *hdr = it->hdr;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   202
                  return it->packet;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   203
                }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   204
            }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   205
        }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   206
    }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   207
  return 0;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   208
}
1924
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
bool
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
WifiMacQueue::IsEmpty (void)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
  Cleanup ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
  return m_queue.empty ();
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
uint32_t
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
WifiMacQueue::GetSize (void)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
  return m_size;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
void
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
WifiMacQueue::Flush (void)
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
{
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
  m_queue.erase (m_queue.begin (), m_queue.end ());
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
  m_size = 0;
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
}
0471fb5a3df8 add WifiMacQueue to build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   230
Mac48Address
4443
b6f14f95c8af mismatching type
Mirko Banchi <mk.banchi@gmail.com>
parents: 4403
diff changeset
   231
WifiMacQueue::GetAddressForPacket (enum WifiMacHeader::AddressType type, PacketQueueI it)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   232
{
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   233
  if (type == WifiMacHeader::ADDR1)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   234
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   235
      return it->hdr.GetAddr1 ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   236
    }
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   237
  if (type == WifiMacHeader::ADDR2)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   238
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   239
      return it->hdr.GetAddr2 ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   240
    }
4403
54141b0e8f9f rename 'index' variable to 'type'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4402
diff changeset
   241
  if (type == WifiMacHeader::ADDR3)
4402
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   242
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   243
      return it->hdr.GetAddr3 ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   244
    }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   245
  return 0;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   246
}
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   247
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   248
bool
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   249
WifiMacQueue::Remove (Ptr<const Packet> packet)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   250
{
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   251
  PacketQueueI it = m_queue.begin ();
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   252
  for (; it != m_queue.end (); it++)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   253
    {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   254
      if (it->packet == packet)
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   255
        {
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   256
          m_queue.erase (it);
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   257
          return true;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   258
        }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   259
    }
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   260
  return false;
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   261
}
f6243535620f new methods to look in the packet queue
Mirko Banchi <mk.banchi@gmail.com>
parents: 4102
diff changeset
   262
1977
4303409f3d8e remove uneeded trailing ';'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1924
diff changeset
   263
} // namespace ns3