Type Parameters:
E - type of elements in this queue, extending CDPQEntry
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

public class CoDelPriorityBlockingQueue<E extends CDPQEntry>extends PriBlockingQueue<E>
CoDel (Controlled Delay) implementation with priority-based queue management.

Extends CoDelBlockingQueue to add priority-based dropping functionality. Implements enhanced CoDel algorithm with configurable priority thresholds and per-priority statistics.

Provides priority-aware packet dropping where higher priority packets are protected from dropping during congestion events. Includes comprehensive statistics tracking and performance monitoring for different priority levels.

Input methods are overridden to add timestamps for delay calculation. Output methods implement AQM behavior with enhanced statistics tracking for priority-based operations.

See Also:
  • Field Details

    • _first_above_time

      private long _first_above_time
      Time when we'll declare we're above target (0 if below). Part of the CoDel sample-code state, locked by this queue.
    • _drop_next

      private long _drop_next
      Time to drop next packet.
    • _count

      private int _count
      Packets dropped since going into drop state.
    • _dropping

      private boolean _dropping
      True if in drop state.
    • _now

      private volatile long _now
      Per-request global for ease of use, locked by this.
    • _lastDroppedPriority

      private int _lastDroppedPriority
      Last dropped priority.
    • __id

      static final AtomicLong __id
      Unique ID generator for instances.
    • _id

      private final long _id
      Instance ID.
    • CODEL_RATES

      private static final long[] CODEL_RATES
      Rate windows kept for the backlog statistics.
    • DEFAULT_CODEL_TARGET

      private static final int DEFAULT_CODEL_TARGET
      Quote: Below a target of 5 ms, utilization suffers for some conditions and traffic loads; above 5 ms there is very little or no improvement in utilization.

      I2P: Lowered to 5ms for reduced latency in high-performance scenarios.

      See Also:
    • PROP_CODEL_TARGET

      public static final String PROP_CODEL_TARGET
      Property key for CoDel target delay.
      See Also:
    • _target

      private volatile long _target
      CoDel target delay in ms.
    • DEFAULT_CODEL_INTERVAL

      private static final int DEFAULT_CODEL_INTERVAL
      Quote: A setting of 100 ms works well across a range of RTTs from 10 ms to 1 second

      I2P: Lowered to 50ms for faster reaction to congestion.

      See Also:
    • PROP_CODEL_INTERVAL

      public static final String PROP_CODEL_INTERVAL
      Property key for CoDel interval.
      See Also:
    • _interval

      private volatile long _interval
      CoDel interval in ms.
    • STAT_DROP

      private final String STAT_DROP
      RateStat name for dropped messages.
    • INSTANCES

      Active instances for dynamic tuning — weak refs prevent leak when tunnels expire.
    • STAT_DELAY

      private final String STAT_DELAY
      Stat name for delay tracking.
    • MIN_PRIORITY

      public static final int MIN_PRIORITY
      Minimum priority.
      See Also:
    • PRIORITIES

      private static final int[] PRIORITIES
      Priority values assigned to the job classes.
    • DONT_DROP_PRIORITY

      public static final int DONT_DROP_PRIORITY
      Priorities at or above this value are never dropped.
      See Also:
    • BACKLOG_TIME

      private static final long BACKLOG_TIME
      How long a job may wait before it counts as backlog, in ms.
  • Constructor Details

    • CoDelPriorityBlockingQueue

      public CoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity)
      CoDel priority blocking queue with default target and interval.
      Parameters:
      ctx - the I2P application context
      name - a name for this queue instance
      initialCapacity - the initial capacity for the priority queue
    • CoDelPriorityBlockingQueue

      public CoDelPriorityBlockingQueue(I2PAppContext ctx, String name, int initialCapacity, int target, int interval)
      Creates a queue and registers the per-priority drop stats and the delay stat under the given queue name, so the tuning page can graph them per queue.
      Parameters:
      ctx - context supplying the stat manager the stats are created in
      name - the queue's short name, used as the stat name prefix
      initialCapacity - the number of entries to size the internal array for
      target - CoDel target delay in ms, the queueing delay the controller aims for
      interval - CoDel interval in ms, how long to sample before deciding to drop
  • Method Details

    • dispose

      public void dispose()
      Remove this instance from the tuning list.
    • expungeStaleInstances

      public static void expungeStaleInstances()
      Remove cleared (GC'd) weak references from the list.
    • updateAllTargets

      public static void updateAllTargets(long target)
      Update the target delay for all active instances.
      Parameters:
      target - the new target delay in ms
    • updateAllIntervals

      public static void updateAllIntervals(long interval)
      Update the interval for all active instances.
      Parameters:
      interval - the new interval in ms
    • delayDescription

      public static String delayDescription(String queueName)
      Description for a queue's mean delay stat.

      Names the queue because several queues publish the same measure: OBGW and UDP-Sender both come through here, and IBGW, UDP-Receiver and UDP-MessageReceiver register theirs by hand. A single shared description left five graphs in the list called "Average queue delay (ms)", indistinguishable from one another.

      Parameters:
      queueName - the queue's short name, as used in its stat names
      Returns:
      the stat description, which names the queue so that queues sharing this measure are distinguishable on the tuning page
    • dropDescription

      public static String dropDescription(String queueName, int priority)
      Description for a queue's per-priority drop-delay stat.

      Names the queue as well as the priority, for the same reason: without it codel.OBGW.drop.0 and codel.UDP-Sender.drop.0 were two graphs with the same name.

      Parameters:
      queueName - the queue's short name, as used in its stat names
      priority - the CoDel priority band
      Returns:
      the stat description, naming both the queue and the priority band so their drop-delay graphs are distinguishable
    • getTarget

      public long getTarget()
      The CoDel target queuing delay, the delay considered acceptable before the queue is judged congested.
      Returns:
      the target delay in ms
    • setTarget

      public void setTarget(long target)
      Current CoDel target delay in ms.
      Parameters:
      target - the new target delay in ms
    • getInterval

      public long getInterval()
      The CoDel measuring interval, the sliding window over which the minimum queuing delay is observed.
      Returns:
      the interval in ms
    • setInterval

      public void setInterval(long interval)
      Current CoDel interval in ms.
      Parameters:
      interval - the new interval in ms
    • clear

      public void clear()
      Clear the queue and reset CoDel state.
      Specified by:
      clear in interface Collection<E extends CDPQEntry>
      Overrides:
      clear in class PriorityBlockingQueue<E extends CDPQEntry>
    • take

      public E take() throws InterruptedException
      Take the next element, applying CoDel drops as needed.
      Specified by:
      take in interface BlockingQueue<E extends CDPQEntry>
      Overrides:
      take in class PriorityBlockingQueue<E extends CDPQEntry>
      Throws:
      InterruptedException
    • poll

      public E poll()
      Poll the next element, applying CoDel drops as needed.
      Specified by:
      poll in interface Queue<E extends CDPQEntry>
      Overrides:
      poll in class PriorityBlockingQueue<E extends CDPQEntry>
    • drainTo

      public int drainTo(Collection<? super E> c)
      Updates stats and possibly drops while draining.
      Specified by:
      drainTo in interface BlockingQueue<E extends CDPQEntry>
      Overrides:
      drainTo in class PriorityBlockingQueue<E extends CDPQEntry>
    • drainTo

      public int drainTo(Collection<? super E> c, int maxElements)
      Updates stats and possibly drops while draining.
      Specified by:
      drainTo in interface BlockingQueue<E extends CDPQEntry>
      Overrides:
      drainTo in class PriorityBlockingQueue<E extends CDPQEntry>
    • drainAllTo

      public int drainAllTo(Collection<? super E> c)
      Drains all, without updating stats or dropping.
      Parameters:
      c - the collection to drain into
      Returns:
      the number of elements drained
    • isBacklogged

      public boolean isBacklogged()
      Has the head of the queue been waiting too long, or is the queue too big?
      Overrides:
      isBacklogged in class PriBlockingQueue<E extends CDPQEntry>
      Returns:
      true if the head has waited out the backlog delay, the queue is already dropping, or the backlog size limit has been reached
    • timestamp

      protected void timestamp(E o)
      Timestamp the added element.
      Overrides:
      timestamp in class PriBlockingQueue<E extends CDPQEntry>
      Parameters:
      o - the element to timestamp
    • updateVars

      private boolean updateVars(E entry)
      Caller must synch on this.
      Parameters:
      entry - may be null
      Returns:
      true if the sojourn time has stayed above target for at least the interval, making it OK to drop
    • getCurrentTime

      private void getCurrentTime()
      Takes the current time for the backlog measurement.
    • deque

      private E deque() throws InterruptedException
      Dequeue the next element, applying CoDel drops as needed.
      Returns:
      if null, call again
      Throws:
      InterruptedException - if interrupted while waiting for the next element
    • codel

      private E codel(E rv)
      Apply CoDel control to the given entry, dropping if needed.
      Parameters:
      rv - may be null
      Returns:
      rv or a subsequent entry or null if dropped
    • drop

      private void drop(E entry)
      Drops a job that waited too long in the backlog.
      Parameters:
      entry - the job to drop
    • control_law

      private void control_law(long t)
      Caller must synch on this.
      Parameters:
      t - the time, in ms, to schedule the next drop from