|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Freie Universität Berlin |
| 3 | + * |
| 4 | + * This file is subject to the terms and conditions of the GNU Lesser |
| 5 | + * General Public License v2.1. See the file LICENSE in the top level |
| 6 | + * directory for more details. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * @{ |
| 11 | + * |
| 12 | + * @file |
| 13 | + * @author Martine S. Lenders <[email protected]> |
| 14 | + */ |
| 15 | + |
| 16 | +#include <assert.h> |
| 17 | +#include <stdlib.h> |
| 18 | +#include <string.h> |
| 19 | + |
| 20 | +#include "clist.h" |
| 21 | +#include "congure/test.h" |
| 22 | +#include "fmt.h" |
| 23 | +#include "shell.h" |
| 24 | + |
| 25 | +#include "congure_impl.h" |
| 26 | + |
| 27 | +#define SHELL_BUFSIZE 512U |
| 28 | + |
| 29 | +static char _line_buf[SHELL_BUFSIZE]; |
| 30 | + |
| 31 | +static int _json_statham(int argc, char **argv); |
| 32 | +static int _set_mss(int argc, char **argv); |
| 33 | +static int _set_cwnd(int argc, char **argv); |
| 34 | +static int _set_ssthresh(int argc, char **argv); |
| 35 | +static int _get_fr_calls(int argc, char **argv); |
| 36 | +static int _set_same_wnd_adv_res(int argc, char **argv); |
| 37 | + |
| 38 | +static congure_reno_snd_t _congure_state; |
| 39 | +static const shell_command_t shell_commands[] = { |
| 40 | + { "state", "Prints current CongURE state object as JSON", _json_statham }, |
| 41 | + { "set_cwnd", "Set cwnd member for CongURE state object", _set_cwnd }, |
| 42 | + { "set_mss", "Set new MSS for CongURE state object", _set_mss }, |
| 43 | + { "set_ssthresh", "Set ssthresh member for CongURE state object", |
| 44 | + _set_ssthresh }, |
| 45 | + { "get_ff_calls", |
| 46 | + "Get the number of calls to fast_retransmit callback of CongURE state " |
| 47 | + "object", _get_fr_calls }, |
| 48 | + { "set_same_wnd_adv", |
| 49 | + "Set the result for the same_window_advertised callback of CongURE state " |
| 50 | + "object", _set_same_wnd_adv_res }, |
| 51 | + { NULL, NULL, NULL } |
| 52 | +}; |
| 53 | + |
| 54 | +int main(void) |
| 55 | +{ |
| 56 | + shell_run(shell_commands, _line_buf, SHELL_BUFSIZE); |
| 57 | + return 0; |
| 58 | +} |
| 59 | + |
| 60 | +congure_test_snd_t *congure_test_get_state(void) |
| 61 | +{ |
| 62 | + return &_congure_state; |
| 63 | +} |
| 64 | + |
| 65 | +#define PRINT_FIELD_PTR(obj_ptr, field) \ |
| 66 | + print_str("\"" #field "\":\"0x"); \ |
| 67 | + print_u32_hex((intptr_t)((obj_ptr)->field)); \ |
| 68 | + print_str("\",") |
| 69 | + |
| 70 | +#define PRINT_FIELD_UINT(obj, field) \ |
| 71 | + print_str("\"" #field "\":"); \ |
| 72 | + print_u32_dec((obj).field); \ |
| 73 | + print_str(",") |
| 74 | + |
| 75 | +static void _print_congure_reno_consts(const congure_reno_snd_consts_t *consts) |
| 76 | +{ |
| 77 | + print_str("\"consts\":"); |
| 78 | + |
| 79 | + if (consts) { |
| 80 | + print_str("{"); |
| 81 | + PRINT_FIELD_PTR(consts, fr); |
| 82 | + PRINT_FIELD_PTR(consts, same_wnd_adv); |
| 83 | + PRINT_FIELD_PTR(consts, ss_cwnd_inc); |
| 84 | + PRINT_FIELD_PTR(consts, ca_cwnd_inc); |
| 85 | + PRINT_FIELD_PTR(consts, fr_cwnd_dec); |
| 86 | + PRINT_FIELD_UINT(*consts, init_mss); |
| 87 | + PRINT_FIELD_UINT(*consts, cwnd_upper); |
| 88 | + PRINT_FIELD_UINT(*consts, cwnd_lower); |
| 89 | + PRINT_FIELD_UINT(*consts, init_ssthresh); |
| 90 | + PRINT_FIELD_UINT(*consts, frthresh); |
| 91 | + print_str("},"); |
| 92 | + } |
| 93 | + else { |
| 94 | + print_str("null,"); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +static int _json_statham(int argc, char **argv) |
| 99 | +{ |
| 100 | + (void)argc; |
| 101 | + (void)argv; |
| 102 | + print_str("{"); |
| 103 | + |
| 104 | + PRINT_FIELD_UINT(_congure_state.super, cwnd); |
| 105 | + _print_congure_reno_consts(_congure_state.consts); |
| 106 | + PRINT_FIELD_UINT(_congure_state, mss); |
| 107 | + PRINT_FIELD_UINT(_congure_state, last_ack); |
| 108 | + PRINT_FIELD_UINT(_congure_state, ssthresh); |
| 109 | + PRINT_FIELD_UINT(_congure_state, in_flight_size); |
| 110 | + PRINT_FIELD_UINT(_congure_state, dup_acks); |
| 111 | + |
| 112 | + print_str("}\n"); |
| 113 | + return 0; |
| 114 | +} |
| 115 | + |
| 116 | +static int _set_mss(int argc, char **argv) |
| 117 | +{ |
| 118 | + uint32_t tmp; |
| 119 | + |
| 120 | + if (argc < 2) { |
| 121 | + print_str("{\"error\":\"`mss` argument expected\"}"); |
| 122 | + return 1; |
| 123 | + } |
| 124 | + tmp = scn_u32_dec(argv[1], strlen(argv[1])); |
| 125 | + if (tmp > CONGURE_WND_SIZE_MAX) { |
| 126 | + print_str("{\"error\":\"`mss` not 16 bit wide\"}\n"); |
| 127 | + } |
| 128 | + congure_reno_set_mss(&_congure_state, (congure_wnd_size_t)tmp); |
| 129 | + return 0; |
| 130 | +} |
| 131 | + |
| 132 | +static int _set_cwnd(int argc, char **argv) |
| 133 | +{ |
| 134 | + uint32_t tmp; |
| 135 | + |
| 136 | + if (argc < 2) { |
| 137 | + print_str("{\"error\":\"`cwnd` argument expected\"}"); |
| 138 | + return 1; |
| 139 | + } |
| 140 | + tmp = scn_u32_dec(argv[1], strlen(argv[1])); |
| 141 | + if (tmp > CONGURE_WND_SIZE_MAX) { |
| 142 | + print_str("{\"error\":\"`cwnd` not 16 bit wide\"}\n"); |
| 143 | + } |
| 144 | + _congure_state.super.cwnd = (congure_wnd_size_t)tmp; |
| 145 | + return 0; |
| 146 | +} |
| 147 | + |
| 148 | +static int _set_ssthresh(int argc, char **argv) |
| 149 | +{ |
| 150 | + uint32_t tmp; |
| 151 | + |
| 152 | + if (argc < 2) { |
| 153 | + print_str("{\"error\":\"`ssthresh` argument expected\"}"); |
| 154 | + return 1; |
| 155 | + } |
| 156 | + tmp = scn_u32_dec(argv[1], strlen(argv[1])); |
| 157 | + if (tmp > CONGURE_WND_SIZE_MAX) { |
| 158 | + print_str("{\"error\":\"`ssthresh` not 16 bit wide\"}\n"); |
| 159 | + } |
| 160 | + _congure_state.ssthresh = (congure_wnd_size_t)tmp; |
| 161 | + return 0; |
| 162 | +} |
| 163 | + |
| 164 | +static int _get_fr_calls(int argc, char **argv) |
| 165 | +{ |
| 166 | + (void)argc; |
| 167 | + (void)argv; |
| 168 | + |
| 169 | + print_str("{\"fr_calls\":"); |
| 170 | + print_u32_dec(congure_reno_test_get_fr_calls()); |
| 171 | + print_str("}\n"); |
| 172 | + return 0; |
| 173 | +} |
| 174 | + |
| 175 | +static int _set_same_wnd_adv_res(int argc, char **argv) |
| 176 | +{ |
| 177 | + if (argc < 2) { |
| 178 | + print_str("{\"error\":\"`value` argument expected\"}"); |
| 179 | + return 1; |
| 180 | + } |
| 181 | + congure_reno_test_set_same_wnd_adv_res( |
| 182 | + (bool)scn_u32_dec(argv[1], strlen(argv[1])) |
| 183 | + ); |
| 184 | + return 0; |
| 185 | +} |
| 186 | + |
| 187 | +/** @} */ |
0 commit comments