Class MtuDiscovery

java.lang.Object
io.github.mahmoudimus.quic.connection.MtuDiscovery

public final class MtuDiscovery extends Object
Datagram packetization layer path MTU discovery (DPLPMTUD, RFC 8899): probes larger packets in the application data space by binary search, and detects MTU black holes from the pattern of lost packets. Times are nanoseconds.

Probes are padded PING packets of the size pollTransmit(long, long) returns; an acknowledged probe raises the MTU, and a probe lost three times lowers the next size tried. Lost probes do not count as congestion.

Threads. Not thread-safe; owned by one connection.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Ends the current loss burst and checks for a black hole.
    A copy with the same MTU, search and black hole state, for a new path that is presumably the same network (a NAT rebinding), as quinn clones it.
    int
    The current MTU.
    disabled(int mtu, int minMtu)
    Disabled discovery: the MTU stays fixed, except that a black hole still lowers it to the minimum.
    enabled(int initialMtu, int minMtu, int peerMaxUdpPayloadSize, MtuDiscoveryConfig config)
    Enabled discovery.
    long
    The packet number of the probe in flight.
    boolean
    onAcked(SpaceId space, long pn, int length)
    Records an acknowledged packet.
    void
    onNonProbeLost(long pn, int length)
    Records a lost packet that was not a probe.
    void
    onPeerMaxUdpPayloadSizeReceived(int peerMaxUdpPayloadSize)
    Applies the peer's max_udp_payload_size, which caps the MTU and the search.
    void
    Records that the in-flight probe was lost.
    int
    pollTransmit(long now, long nextPacketNumber)
    The size of the next probe to send, if one is due.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • enabled

      public static MtuDiscovery enabled(int initialMtu, int minMtu, int peerMaxUdpPayloadSize, MtuDiscoveryConfig config)
      Enabled discovery.
      Parameters:
      initialMtu - the MTU to start from, at least minMtu
      minMtu - the MTU the path is assumed to support, 1200 for QUIC
      peerMaxUdpPayloadSize - the peer's max_udp_payload_size if already known (after a migration), or -1
      config - the configuration
      Returns:
      the discovery state
    • disabled

      public static MtuDiscovery disabled(int mtu, int minMtu)
      Disabled discovery: the MTU stays fixed, except that a black hole still lowers it to the minimum.
      Parameters:
      mtu - the fixed MTU
      minMtu - the minimum MTU
      Returns:
      the discovery state
    • copy

      public MtuDiscovery copy()
      A copy with the same MTU, search and black hole state, for a new path that is presumably the same network (a NAT rebinding), as quinn clones it.
      Returns:
      the copy
    • currentMtu

      public int currentMtu()
      The current MTU.
      Returns:
      the largest UDP payload to send
    • pollTransmit

      public int pollTransmit(long now, long nextPacketNumber)
      The size of the next probe to send, if one is due.
      Parameters:
      now - the current time
      nextPacketNumber - the number the probe packet will have
      Returns:
      the probe's UDP payload size, or -1 if no probe should be sent now
    • onPeerMaxUdpPayloadSizeReceived

      public void onPeerMaxUdpPayloadSizeReceived(int peerMaxUdpPayloadSize)
      Applies the peer's max_udp_payload_size, which caps the MTU and the search. It must arrive before probing starts.
      Parameters:
      peerMaxUdpPayloadSize - the transport parameter
    • onAcked

      public boolean onAcked(SpaceId space, long pn, int length)
      Records an acknowledged packet.
      Parameters:
      space - the packet's space; probes are only sent in the application data space
      pn - the packet number
      length - the packet's size
      Returns:
      true if it was the in-flight probe, which raised the MTU
    • inFlightMtuProbe

      public long inFlightMtuProbe()
      The packet number of the probe in flight.
      Returns:
      the packet number, or -1 if none
    • onProbeLost

      public void onProbeLost()
      Records that the in-flight probe was lost.
    • onNonProbeLost

      public void onNonProbeLost(long pn, int length)
      Records a lost packet that was not a probe. Call blackHoleDetected(long) once the losses of a batch are recorded.
      Parameters:
      pn - the packet number
      length - the packet's size
    • blackHoleDetected

      public boolean blackHoleDetected(long now)
      Ends the current loss burst and checks for a black hole. On a black hole the MTU drops to the minimum and discovery pauses for the cooldown.
      Parameters:
      now - the current time
      Returns:
      true if a black hole was detected