bbr.h 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
#ifndef PRRT_BBR_H
#define PRRT_BBR_H

#include <stdint.h>
#include "stdbool.h"
#include "types/packet.h"
#include "clock.h"
#include "types/channelStateInformation.h"
#include "types/packetTracking.h"
#include "types/rateSample.h"
#include "../util/windowedFilter.h"

#define PROBE_GAIN 1.25
#define DRAIN_GAIN 0.75
#define RTpropFilterLen 10000000    //10s
#define BBRHighGain ((((float)2885) / 1000) + 1)
#define BBRGainCycleLen 8
#define ProbeRTTDuration 200000 //200ms
#define RTprop_Inf UINT32_MAX

enum bbr_state {
    STARTUP,
    DRAIN,
    PROBE_BW,
    PROBE_RTT
};

typedef struct bbr {
    pthread_mutex_t lock;

    prrtByteCount_t mps;
    prrtByteCount_t min_pipe_cwnd;
    prrtByteCount_t initial_cwnd;
    prrtTimedelta_t rtprop;
    prrtTimestamp_t rtprop_stamp;
    prrtTimestamp_t probe_rtt_done_stamp;
    bool probe_rtt_round_done;
    bool packet_conservation;
    prrtByteCount_t prior_cwnd;
    prrtByteCount_t cwnd;
    prrtByteCount_t target_cwnd;
    bool idle_restart;

    enum bbr_state state;

    double pacing_gain;
    float cwnd_gain;

    bool filled_pipe;
    prrtByteCount_t full_bw;
    uint32_t full_bw_count;

    double pacing_rate;
    bool has_seen_rtt;

    uint32_t next_round_delivered;
    bool round_start;
    uint32_t round_count;

    uint32_t next_rtt_delivered;
    uint32_t rtt_count;
    bool rtprop_expired;

    bool is_loss_recovery;
    prrtTimestamp_t loss_recovery_stamp;

    prrtTimestamp_t cycle_stamp;
    uint8_t cycle_index;
    float* pacing_gain_cycle;

    prrtByteCount_t send_quantum;

    prrtDeliveryRate_t bw;

    WindowedFilter* btlBwFilter;
} BBR;

BBR* BBR_Init(prrtByteCount_t maximum_payload_size);
void BBR_OnACK(BBR* bbr, PrrtChannelStateInformation* csi, PrrtRateSample* rs, PrrtPacketTracking* packetTracking, prrtTimedelta_t rtt);
void BBR_OnSpuriousLoss(BBR *bbr, PrrtPacketTracking *tracking);
void BBR_OnRTOLoss(BBR *bbr);
void BBR_OnLossExit(BBR *bbr);
void BBR_destroy(BBR* bbr);

double BBR_getPacingRate(BBR* bbr);
prrtByteCount_t BBR_getCwnd(BBR* bbr);
prrtDeliveryRate_t BBR_getBtlBw(BBR* bbr);
uint32_t BBR_getState(BBR* bbr);
prrtByteCount_t BBR_getFullBw(BBR* bbr);
double BBR_getPacingGain(BBR* bbr);
uint32_t BBR_getCycleIndex(BBR* bbr);
bool BBR_getFilledPipe(BBR* bbr);
uint32_t BBR_getRTProp(BBR* bbr);
prrtByteCount_t BBR_getInflight(BBR* bbr);
prrtByteCount_t BBR_getSendQuantum(BBR* bbr);
bool BBR_getRoundStart(BBR* bbr);

#endif //PRRT_BBR_H