src/internet/model/codel-queue.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Thu, 02 Oct 2014 21:17:48 -0700
changeset 10978 754c8256c35c
parent 10968 2d29fee2b7b8
child 10986 4d7338f5952d
permissions -rw-r--r--
TracedValue callback function signatures.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2012 Andrew McGregor
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    17
 *
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Codel, the COntrolled DELay Queueing discipline
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 * Based on ns2 simulation code presented by Kathie Nichols
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
 *
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
 * This port based on linux kernel code by
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
 * Authors:	Dave Täht <d@taht.net>
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
 *		Eric Dumazet <edumazet@google.com>
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
 *
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
 * Ported to ns-3 by: Andrew McGregor <andrewmcgr@gmail.com>
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
*/
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/log.h"
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ns3/enum.h"
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "ns3/uinteger.h"
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "ns3/abort.h"
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "codel-queue.h"
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10888
diff changeset
    34
namespace ns3 {
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10888
diff changeset
    36
NS_LOG_COMPONENT_DEFINE ("CoDelQueue");
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
/* borrowed from the linux kernel */
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    39
static inline uint32_t ReciprocalDivide (uint32_t A, uint32_t R)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    41
  return (uint32_t)(((uint64_t)A * R) >> 32);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
/* end kernel borrowings */
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    46
static uint32_t CoDelGetTime (void)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
  Time time = Simulator::Now ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
  uint64_t ns = time.GetNanoSeconds ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
  return ns >> CODEL_SHIFT;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
class CoDelTimestampTag : public Tag
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
public:
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
  CoDelTimestampTag ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
  static TypeId GetTypeId (void);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  virtual TypeId GetInstanceTypeId (void) const;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
  virtual uint32_t GetSerializedSize (void) const;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
  virtual void Serialize (TagBuffer i) const;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
  virtual void Deserialize (TagBuffer i);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
  virtual void Print (std::ostream &os) const;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  Time GetTxTime (void) const;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
private:
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  uint64_t m_creationTime;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
};
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
CoDelTimestampTag::CoDelTimestampTag ()
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  : m_creationTime (Simulator::Now ().GetTimeStep ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
TypeId
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
CoDelTimestampTag::GetTypeId (void)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    79
  static TypeId tid = TypeId ("ns3::CoDelTimestampTag")
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
    .SetParent<Tag> ()
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
    .AddConstructor<CoDelTimestampTag> ()
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
    .AddAttribute ("CreationTime",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
                   "The time at which the timestamp was created",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
                   StringValue ("0.0s"),
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
                   MakeTimeAccessor (&CoDelTimestampTag::GetTxTime),
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
                   MakeTimeChecker ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  ;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  return tid;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
}
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
    90
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
TypeId
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
CoDelTimestampTag::GetInstanceTypeId (void) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
  return GetTypeId ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
uint32_t
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
CoDelTimestampTag::GetSerializedSize (void) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  return 8;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
void
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
CoDelTimestampTag::Serialize (TagBuffer i) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  i.WriteU64 (m_creationTime);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
void
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
CoDelTimestampTag::Deserialize (TagBuffer i)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
  m_creationTime = i.ReadU64 ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
void
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
CoDelTimestampTag::Print (std::ostream &os) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  os << "CreationTime=" << m_creationTime;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
Time
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
CoDelTimestampTag::GetTxTime (void) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  return TimeStep (m_creationTime);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
NS_OBJECT_ENSURE_REGISTERED (CoDelQueue);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   125
TypeId CoDelQueue::GetTypeId (void)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  static TypeId tid = TypeId ("ns3::CoDelQueue")
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
    .SetParent<Queue> ()
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
    .AddConstructor<CoDelQueue> ()
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   130
    .AddAttribute ("Mode",
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
                   "Whether to use Bytes (see MaxBytes) or Packets (see MaxPackets) as the maximum queue size metric.",
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   132
                   EnumValue (QUEUE_MODE_BYTES),
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
                   MakeEnumAccessor (&CoDelQueue::SetMode),
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   134
                   MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   135
                                    QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   136
    .AddAttribute ("MaxPackets",
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
                   "The maximum number of packets accepted by this CoDelQueue.",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
                   UintegerValue (DEFAULT_CODEL_LIMIT),
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
                   MakeUintegerAccessor (&CoDelQueue::m_maxPackets),
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
                   MakeUintegerChecker<uint32_t> ())
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   141
    .AddAttribute ("MaxBytes",
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
                   "The maximum number of bytes accepted by this CoDelQueue.",
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   143
                   UintegerValue (1500 * DEFAULT_CODEL_LIMIT),
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
                   MakeUintegerAccessor (&CoDelQueue::m_maxBytes),
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
                   MakeUintegerChecker<uint32_t> ())
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   146
    .AddAttribute ("MinBytes",
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
                   "The CoDel algorithm minbytes parameter.",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
                   UintegerValue (1500),
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   149
                   MakeUintegerAccessor (&CoDelQueue::m_minBytes),
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
                   MakeUintegerChecker<uint32_t> ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
    .AddAttribute ("Interval",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
                   "The CoDel algorithm interval",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
                   StringValue ("100ms"),
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   154
                   MakeTimeAccessor (&CoDelQueue::m_interval),
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
                   MakeTimeChecker ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
    .AddAttribute ("Target",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
                   "The CoDel algorithm target queue delay",
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
                   StringValue ("5ms"),
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   159
                   MakeTimeAccessor (&CoDelQueue::m_target),
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
                   MakeTimeChecker ())
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   161
    .AddTraceSource ("Count",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   162
                     "CoDel count",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   163
                     MakeTraceSourceAccessor (&CoDelQueue::m_count),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   164
                     "ns3::TracedValue::Uint32Callback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   165
    .AddTraceSource ("DropCount",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   166
                     "CoDel drop count",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   167
                     MakeTraceSourceAccessor (&CoDelQueue::m_dropCount),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   168
                     "ns3::TracedValue::Uint32Callback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   169
    .AddTraceSource ("LastCount",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   170
                     "CoDel lastcount",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   171
                     MakeTraceSourceAccessor (&CoDelQueue::m_lastCount),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   172
                     "ns3::TracedValue::Uint32Callback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   173
    .AddTraceSource ("DropState",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   174
                     "Dropping state",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   175
                     MakeTraceSourceAccessor (&CoDelQueue::m_dropping),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   176
                     "ns3::TracedValue::BoolCallback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   177
    .AddTraceSource ("BytesInQueue",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   178
                     "Number of bytes in the queue",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   179
                     MakeTraceSourceAccessor (&CoDelQueue::m_bytesInQueue),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   180
                     "ns3::TracedValue::Uint32Callback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   181
    .AddTraceSource ("Sojourn",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   182
                     "Time in the queue",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   183
                     MakeTraceSourceAccessor (&CoDelQueue::m_sojourn),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   184
                     "ns3::Time::TracedValueCallback")
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   185
    .AddTraceSource ("DropNext",
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   186
                     "Time until next packet drop",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   187
                     MakeTraceSourceAccessor (&CoDelQueue::m_dropNext),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   188
                     "ns3::TracedValue::Uint32Callback")
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  ;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
  return tid;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   194
CoDelQueue::CoDelQueue ()
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   195
  : Queue (),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   196
    m_packets (),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   197
    m_maxBytes (),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   198
    m_bytesInQueue (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   199
    m_count (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   200
    m_dropCount (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   201
    m_lastCount (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   202
    m_dropping (false),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   203
    m_recInvSqrt (~0U >> REC_INV_SQRT_SHIFT),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   204
    m_firstAboveTime (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   205
    m_dropNext (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   206
    m_state1 (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   207
    m_state2 (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   208
    m_state3 (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   209
    m_states (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   210
    m_dropOverLimit (0),
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   211
    m_sojourn (0)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   213
  NS_LOG_FUNCTION (this);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
CoDelQueue::~CoDelQueue ()
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   218
  NS_LOG_FUNCTION (this);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
void
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   222
CoDelQueue::NewtonStep (void)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   224
  NS_LOG_FUNCTION (this);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   225
  uint32_t invsqrt = ((uint32_t) m_recInvSqrt) << REC_INV_SQRT_SHIFT;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   226
  uint32_t invsqrt2 = ((uint64_t) invsqrt * invsqrt) >> 32;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   227
  uint64_t val = (3ll << 32) - ((uint64_t) m_count * invsqrt2);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
  val >>= 2; /* avoid overflow */
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   230
  val = (val * invsqrt) >> (32 - 2 + 1);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   231
  m_recInvSqrt = val >> REC_INV_SQRT_SHIFT;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   234
uint32_t
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   235
CoDelQueue::ControlLaw (uint32_t t)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   237
  NS_LOG_FUNCTION (this);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   238
  return t + ReciprocalDivide (Time2CoDel (m_interval), m_recInvSqrt << REC_INV_SQRT_SHIFT);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
void
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   242
CoDelQueue::SetMode (CoDelQueue::QueueMode mode)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
  NS_LOG_FUNCTION (mode);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  m_mode = mode;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   248
CoDelQueue::QueueMode
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
CoDelQueue::GetMode (void)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   251
  NS_LOG_FUNCTION (this);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
  return m_mode;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   255
bool
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
CoDelQueue::DoEnqueue (Ptr<Packet> p)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
  NS_LOG_FUNCTION (this << p);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   260
  if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () + 1 > m_maxPackets))
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
      NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
      Drop (p);
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   264
      ++m_dropOverLimit;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
      return false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
    }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   268
  if (m_mode == QUEUE_MODE_BYTES && (m_bytesInQueue + p->GetSize () > m_maxBytes))
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
      NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
      Drop (p);
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   272
      ++m_dropOverLimit;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
      return false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
    }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   276
  // Tag packet with current time for DoDequeue() to compute sojourn time
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  CoDelTimestampTag tag;
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   278
  p->AddPacketTag (tag);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   279
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
  m_bytesInQueue += p->GetSize ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
  m_packets.push (p);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
  return true;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
bool
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   290
CoDelQueue::OkToDrop (Ptr<Packet> p, uint32_t now)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   292
  NS_LOG_FUNCTION (this);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
  CoDelTimestampTag tag;
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   294
  bool okToDrop;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
  p->FindFirstMatchingByteTag (tag);
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   296
  bool found = p->RemovePacketTag (tag);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   297
  NS_ASSERT_MSG (found, "found a packet without an input timestamp tag");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   298
  NS_UNUSED (found);    //silence compiler warning
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
  Time delta = Simulator::Now () - tag.GetTxTime ();
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   300
  NS_LOG_INFO ("Sojourn time " << delta.GetSeconds ());
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   301
  m_sojourn = delta;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   302
  uint32_t sojournTime = Time2CoDel (delta);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   303
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   304
  if (CoDelTimeBefore (sojournTime, Time2CoDel (m_target))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   305
      || m_bytesInQueue < m_minBytes)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
    {
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   307
      // went below so we'll stay below for at least q->interval
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   308
      NS_LOG_LOGIC ("Sojourn time is below target or number of bytes in queue is less than minBytes; packet should not be dropped");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   309
      m_firstAboveTime = 0;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
      return false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
    }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   312
  okToDrop = false;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   313
  if (m_firstAboveTime == 0)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
      /* just went above from below. If we stay above
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
       * for at least q->interval we'll say it's ok to drop
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
       */
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   318
      NS_LOG_LOGIC ("Sojourn time has just gone above target from below, need to stay above for at least q->interval before packet can be dropped. ");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   319
      m_firstAboveTime = now + Time2CoDel (m_interval);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   320
    }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   321
  else
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   322
  if (CoDelTimeAfter (now, m_firstAboveTime))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   323
    {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   324
      NS_LOG_LOGIC ("Sojourn time has been above target for at least q->interval; it's OK to (possibly) drop packet.");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   325
      okToDrop = true;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   326
      ++m_state1;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   327
    }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   328
  return okToDrop;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
Ptr<Packet>
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
CoDelQueue::DoDequeue (void)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
  NS_LOG_FUNCTION (this);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
  if (m_packets.empty ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
    {
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   338
      // Leave dropping state when queue is empty
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
      m_dropping = false;
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   340
      m_firstAboveTime = 0;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
      NS_LOG_LOGIC ("Queue empty");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
      return 0;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
    }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   344
  uint32_t now = CoDelGetTime ();
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
  Ptr<Packet> p = m_packets.front ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
  m_packets.pop ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
  m_bytesInQueue -= p->GetSize ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
  NS_LOG_LOGIC ("Popped " << p);
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   350
  NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ());
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   351
  NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   353
  // Determine if p should be dropped
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   354
  bool okToDrop = OkToDrop (p, now);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   355
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
  if (m_dropping)
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   357
    { // In the dropping state (sojourn time has gone above target and hasn't come down yet)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   358
      // Check if we can leave the dropping state or next drop should occur
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   359
      NS_LOG_LOGIC ("In dropping state, check if it's OK to leave or next drop should occur");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   360
      if (!okToDrop)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
        {
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   362
          /* sojourn time fell below target - leave dropping state */
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   363
          NS_LOG_LOGIC ("Sojourn time goes below target, it's OK to leave dropping state.");
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
          m_dropping = false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
        }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
      else
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   367
      if (CoDelTimeAfterEq (now, m_dropNext))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   368
        {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   369
          m_state2++;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   370
          while (m_dropping && CoDelTimeAfterEq (now, m_dropNext))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   371
            {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   372
              // It's time for the next drop. Drop the current packet and
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   373
              // dequeue the next. The dequeue might take us out of dropping
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   374
              // state. If not, schedule the next drop.
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   375
              // A large amount of packets in queue might result in drop
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   376
              // rates so high that the next drop should happen now,
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   377
              // hence the while loop.
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   378
              NS_LOG_LOGIC ("Sojourn time is still above target and it's time for next drop; dropping " << p);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   379
              Drop (p);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   380
              ++m_dropCount;
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
              ++m_count;
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   382
              NewtonStep ();
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
              if (m_packets.empty ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
                {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
                  m_dropping = false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
                  NS_LOG_LOGIC ("Queue empty");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
                  ++m_states;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
                  return 0;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
                }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
              p = m_packets.front ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
              m_packets.pop ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
              m_bytesInQueue -= p->GetSize ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
              NS_LOG_LOGIC ("Popped " << p);
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   395
              NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ());
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   396
              NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   398
              if (!OkToDrop (p, now))
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
                {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
                  /* leave dropping state */
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   401
                  NS_LOG_LOGIC ("Leaving dropping state");
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
                  m_dropping = false;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
                }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   404
              else
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
                {
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   406
                  /* schedule the next drop */
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   407
                  NS_LOG_LOGIC ("Running ControlLaw for input m_dropNext: " << (double)m_dropNext / 1000000);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   408
                  m_dropNext = ControlLaw (m_dropNext);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   409
                  NS_LOG_LOGIC ("Scheduled next drop at " << (double)m_dropNext / 1000000);
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
                }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
            }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   412
        }
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
    }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   414
  else
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   415
    {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   416
      // Not in the dropping state
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   417
      // Decide if we have to enter the dropping state and drop the first packet
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   418
      NS_LOG_LOGIC ("Not in dropping state; decide if we have to enter the state and drop the first packet");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   419
      if (okToDrop)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   420
        {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   421
          // Drop the first packet and enter dropping state unless the queue is empty
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   422
          NS_LOG_LOGIC ("Sojourn time goes above target, dropping the first packet " << p << " and entering the dropping state");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   423
          ++m_dropCount;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   424
          Drop (p);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   425
          if (m_packets.empty ())
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   426
            {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   427
              m_dropping = false;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   428
              okToDrop = false;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   429
              NS_LOG_LOGIC ("Queue empty");
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   430
              ++m_states;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   431
            }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   432
          else
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   433
            {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   434
              p = m_packets.front ();
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   435
              m_packets.pop ();
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   436
              m_bytesInQueue -= p->GetSize ();
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   438
              NS_LOG_LOGIC ("Popped " << p);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   439
              NS_LOG_LOGIC ("Number packets remaining " << m_packets.size ());
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   440
              NS_LOG_LOGIC ("Number bytes remaining " << m_bytesInQueue);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   441
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   442
              okToDrop = OkToDrop (p, now);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   443
              m_dropping = true;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   444
            }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   445
          ++m_state3;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   446
          /*
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   447
           * if min went above target close to when we last went below it
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   448
           * assume that the drop rate that controlled the queue on the
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   449
           * last cycle is a good starting point to control it now.
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   450
           */
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   451
          int delta = m_count - m_lastCount;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   452
          if (delta > 1 && CoDelTimeBefore (now - m_dropNext, 16 * Time2CoDel (m_interval)))
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   453
            {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   454
              m_count = delta;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   455
              NewtonStep ();
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   456
            }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   457
          else
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   458
            {
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   459
              m_count = 1;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   460
              m_recInvSqrt = ~0U >> REC_INV_SQRT_SHIFT;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   461
            }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   462
          m_lastCount = m_count;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   463
          NS_LOG_LOGIC ("Running ControlLaw for input now: " << (double)now);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   464
          m_dropNext = ControlLaw (now);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   465
          NS_LOG_LOGIC ("Scheduled next drop at " << (double)m_dropNext / 1000000 << " now " << (double)now / 1000000);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   466
        }
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   467
    }
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
  ++m_states;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
  return p;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
uint32_t
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
CoDelQueue::GetQueueSize (void)
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
{
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   475
  NS_LOG_FUNCTION (this);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   476
  if (GetMode () == QUEUE_MODE_BYTES)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
      return m_bytesInQueue;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
    }
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   480
  else if (GetMode () == QUEUE_MODE_PACKETS)
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
      return m_packets.size ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
    }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
  else
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
      NS_ABORT_MSG ("Unknown mode.");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
    }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   490
uint32_t
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   491
CoDelQueue::GetDropOverLimit (void)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   492
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   493
  return m_dropOverLimit;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   494
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   495
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   496
uint32_t
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   497
CoDelQueue::GetDropCount (void)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   498
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   499
  return m_dropCount;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   500
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   501
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   502
Time
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   503
CoDelQueue::GetTarget (void)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   504
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   505
  return m_target;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   506
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   507
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   508
Time
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   509
CoDelQueue::GetInterval (void)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   510
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   511
  return m_interval;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   512
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   513
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   514
uint32_t
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   515
CoDelQueue::GetDropNext (void)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   516
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   517
  return m_dropNext;
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   518
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   519
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
Ptr<const Packet>
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
CoDelQueue::DoPeek (void) const
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
{
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
  NS_LOG_FUNCTION (this);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
  if (m_packets.empty ())
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
    {
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
      NS_LOG_LOGIC ("Queue empty");
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
      return 0;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
    }
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
  Ptr<Packet> p = m_packets.front ();
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
  return p;
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
}
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
10888
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   539
bool
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   540
CoDelQueue::CoDelTimeAfter (uint32_t a, uint32_t b)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   541
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   542
  return  ((int)(a) - (int)(b) > 0);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   543
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   544
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   545
bool
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   546
CoDelQueue::CoDelTimeAfterEq (uint32_t a, uint32_t b)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   547
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   548
  return ((int)(a) - (int)(b) >= 0);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   549
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   550
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   551
bool
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   552
CoDelQueue::CoDelTimeBefore (uint32_t a, uint32_t b)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   553
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   554
  return  ((int)(a) - (int)(b) < 0);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   555
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   556
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   557
bool
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   558
CoDelQueue::CoDelTimeBeforeEq (uint32_t a, uint32_t b)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   559
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   560
  return ((int)(a) - (int)(b) <= 0);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   561
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   562
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   563
uint32_t
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   564
CoDelQueue::Time2CoDel (Time t)
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   565
{
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   566
  return (t.GetNanoSeconds () >> CODEL_SHIFT);
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   567
}
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   568
2f56d98aa9fa changes suggested in original code review, and aditional improvements made during 2014 GSoC project
Anh Nguyen <trucanh524@gmail.com>
parents: 10887
diff changeset
   569
10887
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
} // namespace ns3
c718786f4822 move CoDel queue model to internet module
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571