lsquic_alarmset.h revision f38b395a
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_alarmset.h -- A set of alarms
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_ALARM_H
750aadb33SDmitri Tikhonov#define LSQUIC_ALARM_H 1
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#include "lsquic_int_types.h"
1050aadb33SDmitri Tikhonov
115392f7a3SLiteSpeed Techenum alarm_id;
125392f7a3SLiteSpeed Techstruct lsquic_conn;
135392f7a3SLiteSpeed Tech
145392f7a3SLiteSpeed Techtypedef void (*lsquic_alarm_cb_f)(enum alarm_id, void *cb_ctx,
1550aadb33SDmitri Tikhonov                                  lsquic_time_t expiry, lsquic_time_t now);
1650aadb33SDmitri Tikhonov
1750aadb33SDmitri Tikhonovtypedef struct lsquic_alarm {
1850aadb33SDmitri Tikhonov    lsquic_alarm_cb_f           callback;
1950aadb33SDmitri Tikhonov    void                       *cb_ctx;
2050aadb33SDmitri Tikhonov} lsquic_alarm_t;
2150aadb33SDmitri Tikhonov
2250aadb33SDmitri Tikhonov
2350aadb33SDmitri Tikhonovenum alarm_id {
2450aadb33SDmitri Tikhonov    AL_HANDSHAKE,
255392f7a3SLiteSpeed Tech    AL_RETX_INIT,
265392f7a3SLiteSpeed Tech    AL_RETX_HSK = AL_RETX_INIT + PNS_HSK,
275392f7a3SLiteSpeed Tech    AL_RETX_APP = AL_RETX_INIT + PNS_APP,
2850aadb33SDmitri Tikhonov    AL_PING,
29b8fa6195SDmitri Tikhonov    AL_MTU_PROBE,
3050aadb33SDmitri Tikhonov    AL_IDLE,
31bc520ef7SDmitri Tikhonov    AL_ACK_APP,
325392f7a3SLiteSpeed Tech    AL_RET_CIDS,
335392f7a3SLiteSpeed Tech    AL_CID_THROT,
345392f7a3SLiteSpeed Tech    AL_PATH_CHAL,
355392f7a3SLiteSpeed Tech    AL_PATH_CHAL_0 = AL_PATH_CHAL,
365392f7a3SLiteSpeed Tech    AL_PATH_CHAL_1,
37fb73393fSDmitri Tikhonov    AL_PATH_CHAL_2,
38fb73393fSDmitri Tikhonov    AL_PATH_CHAL_3,
3965728dc5SDmitri Tikhonov    AL_SESS_TICKET,
409fc12041SDmitri Tikhonov    AL_BLOCKED_KA,      /* Blocked Keep-Alive */
41f38b395aSDmitri Tikhonov    AL_PACK_TOL,        /* Calculate packet tolerance */
4250aadb33SDmitri Tikhonov    MAX_LSQUIC_ALARMS
4350aadb33SDmitri Tikhonov};
4450aadb33SDmitri Tikhonov
4550aadb33SDmitri Tikhonov
4650aadb33SDmitri Tikhonovenum alarm_id_bit {
4750aadb33SDmitri Tikhonov    ALBIT_HANDSHAKE = 1 << AL_HANDSHAKE,
485392f7a3SLiteSpeed Tech    ALBIT_RETX_INIT = 1 << AL_RETX_INIT,
495392f7a3SLiteSpeed Tech    ALBIT_RETX_HSK  = 1 << AL_RETX_HSK,
505392f7a3SLiteSpeed Tech    ALBIT_RETX_APP  = 1 << AL_RETX_APP,
515392f7a3SLiteSpeed Tech    ALBIT_ACK_APP   = 1 << AL_ACK_APP,
5250aadb33SDmitri Tikhonov    ALBIT_PING      = 1 << AL_PING,
5350aadb33SDmitri Tikhonov    ALBIT_IDLE      = 1 << AL_IDLE,
545392f7a3SLiteSpeed Tech    ALBIT_RET_CIDS  = 1 << AL_RET_CIDS,
555392f7a3SLiteSpeed Tech    ALBIT_CID_THROT = 1 << AL_CID_THROT,
565392f7a3SLiteSpeed Tech    ALBIT_PATH_CHAL_0 = 1 << AL_PATH_CHAL_0,
575392f7a3SLiteSpeed Tech    ALBIT_PATH_CHAL_1 = 1 << AL_PATH_CHAL_1,
58fb73393fSDmitri Tikhonov    ALBIT_PATH_CHAL_2 = 1 << AL_PATH_CHAL_2,
59fb73393fSDmitri Tikhonov    ALBIT_PATH_CHAL_3 = 1 << AL_PATH_CHAL_3,
6065728dc5SDmitri Tikhonov    ALBIT_SESS_TICKET = 1 << AL_SESS_TICKET,
619fc12041SDmitri Tikhonov    ALBIT_BLOCKED_KA  = 1 << AL_BLOCKED_KA,
62b8fa6195SDmitri Tikhonov    ALBIT_MTU_PROBE = 1 << AL_MTU_PROBE,
63f38b395aSDmitri Tikhonov    ALBIT_PACK_TOL = 1 << AL_PACK_TOL,
6450aadb33SDmitri Tikhonov};
6550aadb33SDmitri Tikhonov
6650aadb33SDmitri Tikhonov
6750aadb33SDmitri Tikhonovtypedef struct lsquic_alarmset {
6850aadb33SDmitri Tikhonov    enum alarm_id_bit           as_armed_set;
6950aadb33SDmitri Tikhonov    lsquic_time_t               as_expiry[MAX_LSQUIC_ALARMS];
705392f7a3SLiteSpeed Tech    const struct lsquic_conn   *as_conn;    /* Used for logging */
7150aadb33SDmitri Tikhonov    struct lsquic_alarm         as_alarms[MAX_LSQUIC_ALARMS];
7250aadb33SDmitri Tikhonov} lsquic_alarmset_t;
7350aadb33SDmitri Tikhonov
7450aadb33SDmitri Tikhonov
7550aadb33SDmitri Tikhonovvoid
765392f7a3SLiteSpeed Techlsquic_alarmset_init (lsquic_alarmset_t *, const struct lsquic_conn *);
7750aadb33SDmitri Tikhonov
7850aadb33SDmitri Tikhonovvoid
7950aadb33SDmitri Tikhonovlsquic_alarmset_init_alarm (lsquic_alarmset_t *, enum alarm_id,
8050aadb33SDmitri Tikhonov                            lsquic_alarm_cb_f, void *cb_ctx);
8150aadb33SDmitri Tikhonov
8250aadb33SDmitri Tikhonov#define lsquic_alarmset_set(alarmset, al_id, exp) do {                  \
8350aadb33SDmitri Tikhonov    (alarmset)->as_armed_set |= 1 << (al_id);                           \
8450aadb33SDmitri Tikhonov    (alarmset)->as_expiry[al_id] = exp;                                 \
8550aadb33SDmitri Tikhonov} while (0)
8650aadb33SDmitri Tikhonov
8750aadb33SDmitri Tikhonov#define lsquic_alarmset_unset(alarmset, al_id) do {                     \
8850aadb33SDmitri Tikhonov    (alarmset)->as_armed_set &= ~(1 << (al_id));                        \
8950aadb33SDmitri Tikhonov} while (0)
9050aadb33SDmitri Tikhonov
9150aadb33SDmitri Tikhonov#define lsquic_alarmset_is_set(alarmset, al_id) \
9250aadb33SDmitri Tikhonov                            ((alarmset)->as_armed_set & (1 << (al_id)))
9350aadb33SDmitri Tikhonov
945392f7a3SLiteSpeed Tech#define lsquic_alarmset_are_set(alarmset, flags) \
955392f7a3SLiteSpeed Tech                            ((alarmset)->as_armed_set & (flags))
965392f7a3SLiteSpeed Tech
97f38b395aSDmitri Tikhonov#define lsquic_alarmset_is_inited(alarmset_, al_id_) (                  \
98f38b395aSDmitri Tikhonov    (alarmset_)->as_alarms[al_id_].callback)
99f38b395aSDmitri Tikhonov
10050aadb33SDmitri Tikhonov/* Timers "fire," alarms "ring." */
10150aadb33SDmitri Tikhonovvoid
10250aadb33SDmitri Tikhonovlsquic_alarmset_ring_expired (lsquic_alarmset_t *, lsquic_time_t now);
10350aadb33SDmitri Tikhonov
104e8bd737dSDmitri Tikhonovlsquic_time_t
1050adf085aSDmitri Tikhonovlsquic_alarmset_mintime (const lsquic_alarmset_t *, enum alarm_id *);
1060adf085aSDmitri Tikhonov
1070adf085aSDmitri Tikhonovextern const char *const lsquic_alid2str[];
108e8bd737dSDmitri Tikhonov
10950aadb33SDmitri Tikhonov#endif
110