lsquic_cubic.h revision bfc7bfd8
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_cubic.h -- CUBIC congestion control protocol.
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_CUBIC_H
750aadb33SDmitri Tikhonov#define LSQUIC_CUBIC_H 1
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonovstruct lsquic_cubic {
1050aadb33SDmitri Tikhonov    lsquic_time_t   cu_min_delay;
1150aadb33SDmitri Tikhonov    lsquic_time_t   cu_epoch_start;
12bfc7bfd8SDmitri Tikhonov    double          cu_K;
13bfc7bfd8SDmitri Tikhonov    unsigned long   cu_origin_point;
14bfc7bfd8SDmitri Tikhonov    unsigned long   cu_last_max_cwnd;
15bfc7bfd8SDmitri Tikhonov    unsigned long   cu_cwnd;
16bfc7bfd8SDmitri Tikhonov    unsigned long   cu_tcp_cwnd;
17bfc7bfd8SDmitri Tikhonov    unsigned long   cu_ssthresh;
1850aadb33SDmitri Tikhonov    lsquic_cid_t    cu_cid;            /* Used for logging */
1950aadb33SDmitri Tikhonov    enum cubic_flags {
2050aadb33SDmitri Tikhonov        CU_TCP_FRIENDLY = (1 << 0),
2150aadb33SDmitri Tikhonov    }               cu_flags;
22bfc7bfd8SDmitri Tikhonov    unsigned        cu_sampling_rate;
2350aadb33SDmitri Tikhonov    lsquic_time_t   cu_last_logged;
2450aadb33SDmitri Tikhonov};
2550aadb33SDmitri Tikhonov
26bfc7bfd8SDmitri Tikhonov#define DEFAULT_CUBIC_FLAGS (CU_TCP_FRIENDLY)
27bfc7bfd8SDmitri Tikhonov
28bfc7bfd8SDmitri Tikhonov#define TCP_MSS 1460
2950aadb33SDmitri Tikhonov
3050aadb33SDmitri Tikhonovvoid
3150aadb33SDmitri Tikhonovlsquic_cubic_init_ext (struct lsquic_cubic *, lsquic_cid_t, enum cubic_flags);
3250aadb33SDmitri Tikhonov
3350aadb33SDmitri Tikhonov#define lsquic_cubic_init(cubic, cid) \
3450aadb33SDmitri Tikhonov            lsquic_cubic_init_ext(cubic, cid, DEFAULT_CUBIC_FLAGS)
3550aadb33SDmitri Tikhonov
3650aadb33SDmitri Tikhonovvoid
3750aadb33SDmitri Tikhonovlsquic_cubic_ack (struct lsquic_cubic *cubic, lsquic_time_t now,
38bfc7bfd8SDmitri Tikhonov                  lsquic_time_t rtt, int app_limited, unsigned n_bytes);
3950aadb33SDmitri Tikhonov
4050aadb33SDmitri Tikhonovvoid
4150aadb33SDmitri Tikhonovlsquic_cubic_loss (struct lsquic_cubic *cubic);
4250aadb33SDmitri Tikhonov
4350aadb33SDmitri Tikhonovvoid
4450aadb33SDmitri Tikhonovlsquic_cubic_timeout (struct lsquic_cubic *cubic);
4550aadb33SDmitri Tikhonov
46bfc7bfd8SDmitri Tikhonovvoid
47bfc7bfd8SDmitri Tikhonovlsquic_cubic_was_quiet (struct lsquic_cubic *, lsquic_time_t now);
48bfc7bfd8SDmitri Tikhonov
4950aadb33SDmitri Tikhonov#define lsquic_cubic_get_cwnd(c) (+(c)->cu_cwnd)
5050aadb33SDmitri Tikhonov
5150aadb33SDmitri Tikhonov#define lsquic_cubic_in_slow_start(cubic) \
5250aadb33SDmitri Tikhonov                        ((cubic)->cu_cwnd < (cubic)->cu_ssthresh)
5350aadb33SDmitri Tikhonov
5450aadb33SDmitri Tikhonov#endif
55