test_cubic.c revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <assert.h> 3#include <stdio.h> 4#include <stdlib.h> 5#include <string.h> 6#include <sys/queue.h> 7#ifndef WIN32 8#include <unistd.h> 9#else 10#include <getopt.h> 11#endif 12 13#include "lsquic.h" 14#include "lsquic_int_types.h" 15#include "lsquic_cong_ctl.h" 16#include "lsquic_cubic.h" 17#include "lsquic_logger.h" 18#include "lsquic_hash.h" 19#include "lsquic_conn.h" 20#include "lsquic_sfcw.h" 21#include "lsquic_conn_flow.h" 22#include "lsquic_varint.h" 23#include "lsquic_hq.h" 24#include "lsquic_stream.h" 25#include "lsquic_rtt.h" 26#include "lsquic_conn_public.h" 27#include "lsquic_packet_common.h" 28#include "lsquic_packet_out.h" 29 30static const struct cong_ctl_if *const cci = &lsquic_cong_cubic_if; 31 32static void 33test_post_quiescence_explosion (void) 34{ 35 struct lsquic_cubic cubic; 36 lsquic_time_t const rtt = 10000; 37 lsquic_time_t t = 12345600; 38 struct lsquic_conn lconn = LSCONN_INITIALIZER_CIDLEN(lconn, 8); 39 struct lsquic_conn_public conn_pub = { .lconn = &lconn, }; 40 int i; 41 struct lsquic_packet_out packet_out; memset(&packet_out, 0, sizeof(packet_out)); 42 43 cci->cci_init(&cubic, &conn_pub, 0); 44 cubic.cu_ssthresh = cubic.cu_cwnd = 32 * 1370; 45 46 for (i = 0; i < 10; ++i) 47 { 48 packet_out.po_sent = t - rtt; 49 cci->cci_ack(&cubic, &packet_out, 1370, t, 0); 50 } 51 52 assert(cci->cci_get_cwnd(&cubic) == 47026); 53 54 t += 25 * 1000 * 1000; 55 cci->cci_was_quiet(&cubic, t, 0 /* bytes in flight (unused) */); 56 packet_out.po_sent = t - rtt; 57 cci->cci_ack(&cubic, &packet_out, 1370, t, 0); 58 assert(cci->cci_get_cwnd(&cubic) == 47060); 59 60 t += 2 * 1000 * 1000; 61 packet_out.po_sent = t - rtt; 62 cci->cci_ack(&cubic, &packet_out, 1370, t, 0); 63} 64 65 66static void 67test_post_quiescence_explosion2 (void) 68{ 69 struct lsquic_cubic cubic; 70 lsquic_time_t const rtt = 10000; 71 lsquic_time_t t = 12345600; 72 struct lsquic_conn lconn = LSCONN_INITIALIZER_CIDLEN(lconn, 8); 73 struct lsquic_conn_public conn_pub = { .lconn = &lconn, }; 74 int i; 75 struct lsquic_packet_out packet_out; memset(&packet_out, 0, sizeof(packet_out)); 76 77 cci->cci_init(&cubic, &conn_pub, 0); 78 cubic.cu_ssthresh = cubic.cu_cwnd = 32 * 1370; 79 80 for (i = 0; i < 10; ++i) 81 { 82 packet_out.po_sent = t - rtt; 83 cci->cci_ack(&cubic, &packet_out, 1370, t, 1); 84 } 85 86 assert(cci->cci_get_cwnd(&cubic) == 45300); 87 88 t += 25 * 1000 * 1000; 89 cci->cci_was_quiet(&cubic, t, 0 /* bytes in flight (unused) */); 90 packet_out.po_sent = t - rtt; 91 cci->cci_ack(&cubic, &packet_out, 1370, t, 0); 92 assert(cci->cci_get_cwnd(&cubic) == 46754); 93 94 t += 2 * 1000 * 1000; 95 packet_out.po_sent = t - rtt; 96 cci->cci_ack(&cubic, &packet_out, 1370, t, 1); 97} 98 99 100 101int 102main (int argc, char **argv) 103{ 104 int opt; 105 106 lsquic_log_to_fstream(stderr, LLTS_NONE); 107 108 while (-1 != (opt = getopt(argc, argv, "l:"))) 109 { 110 switch (opt) 111 { 112 case 'l': 113 lsquic_logger_lopt(optarg); 114 break; 115 default: 116 exit(EXIT_FAILURE); 117 break; 118 } 119 } 120 121 test_post_quiescence_explosion(); 122 test_post_quiescence_explosion2(); 123 124 exit(EXIT_SUCCESS); 125} 126