| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "../../../src/rist-rtt-mute.h" |
| 9 |
|
| 10 |
#include <stdint.h> |
| 11 |
#include <stdio.h> |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#define DROP 500 |
| 16 |
#define RESTORE 400 |
| 17 |
#define SETTLE 3 |
| 18 |
|
| 19 |
static int failures; |
| 20 |
|
| 21 |
static void expect(const char *name, enum rist_rtt_mute_action got, |
| 22 |
enum rist_rtt_mute_action want, bool muted, bool want_muted) |
| 23 |
{ |
| 24 |
if (got != want || muted != want_muted) { |
| 25 |
fprintf(stderr, "FAIL: %s -> action %d muted %d (want action %d muted %d)\n", |
| 26 |
name, got, muted, want, want_muted); |
| 27 |
failures++; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
static void check(const char *name, bool got, bool want) |
| 32 |
{ |
| 33 |
if (got != want) { |
| 34 |
fprintf(stderr, "FAIL: %s -> %d (want %d)\n", name, got, want); |
| 35 |
failures++; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
static void check_weight(const char *name, uint32_t got, uint32_t want) |
| 40 |
{ |
| 41 |
if (got != want) { |
| 42 |
fprintf(stderr, "FAIL: %s -> %u (want %u)\n", name, got, want); |
| 43 |
failures++; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
int main(void) |
| 48 |
{ |
| 49 |
|
| 50 |
{ |
| 51 |
struct rist_rtt_mute_state st = {0}; |
| 52 |
enum rist_rtt_mute_action a = RIST_RTT_MUTE_NONE; |
| 53 |
for (uint64_t t = 0; t < 10; t++) |
| 54 |
a = rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, t); |
| 55 |
expect("stays_active_below_ceiling", a, RIST_RTT_MUTE_NONE, st.muted, false); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
{ |
| 60 |
struct rist_rtt_mute_state st = {0}; |
| 61 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 0); |
| 62 |
enum rist_rtt_mute_action a = |
| 63 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 1); |
| 64 |
expect("no_drop_before_settle", a, RIST_RTT_MUTE_NONE, st.muted, false); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
{ |
| 69 |
struct rist_rtt_mute_state st = {0}; |
| 70 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 0); |
| 71 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 1); |
| 72 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 2); |
| 73 |
enum rist_rtt_mute_action a = |
| 74 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 3); |
| 75 |
expect("drop_after_settle", a, RIST_RTT_MUTE_DROP, st.muted, true); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
{ |
| 80 |
struct rist_rtt_mute_state st = {0}; |
| 81 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 0); |
| 82 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 1); |
| 83 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, 2); |
| 84 |
enum rist_rtt_mute_action a = |
| 85 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, SETTLE, SETTLE, 3); |
| 86 |
expect("dip_resets_dwell", a, RIST_RTT_MUTE_NONE, st.muted, false); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
{ |
| 91 |
struct rist_rtt_mute_state st = { .muted = true }; |
| 92 |
enum rist_rtt_mute_action a = RIST_RTT_MUTE_NONE; |
| 93 |
for (uint64_t t = 0; t < 10; t++) |
| 94 |
a = rist_rtt_mute_step(&st, 450, DROP, RESTORE, SETTLE, SETTLE, t); |
| 95 |
expect("no_restore_in_hysteresis_band", a, RIST_RTT_MUTE_NONE, st.muted, true); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
{ |
| 100 |
struct rist_rtt_mute_state st = { .muted = true }; |
| 101 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, 0); |
| 102 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, 1); |
| 103 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, 2); |
| 104 |
enum rist_rtt_mute_action a = |
| 105 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, SETTLE, SETTLE, 3); |
| 106 |
expect("restore_after_settle", a, RIST_RTT_MUTE_RESTORE, st.muted, false); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
{ |
| 111 |
struct rist_rtt_mute_state st = { .muted = true }; |
| 112 |
enum rist_rtt_mute_action a = |
| 113 |
rist_rtt_mute_step(&st, 9999, 0, RESTORE, SETTLE, SETTLE, 0); |
| 114 |
expect("disabled_forces_restore", a, RIST_RTT_MUTE_RESTORE, st.muted, false); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
{ |
| 119 |
struct rist_rtt_mute_state st = {0}; |
| 120 |
enum rist_rtt_mute_action a = |
| 121 |
rist_rtt_mute_step(&st, 9999, 0, RESTORE, SETTLE, SETTLE, 0); |
| 122 |
expect("disabled_active_noop", a, RIST_RTT_MUTE_NONE, st.muted, false); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
{ |
| 129 |
struct rist_rtt_mute_state st = {0}; |
| 130 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, 1, 5, 0); |
| 131 |
enum rist_rtt_mute_action a = |
| 132 |
rist_rtt_mute_step(&st, 900, DROP, RESTORE, 1, 5, 1); |
| 133 |
expect("asymmetric_fast_drop", a, RIST_RTT_MUTE_DROP, st.muted, true); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
rist_rtt_mute_step(&st, 100, DROP, RESTORE, 1, 5, 2); |
| 138 |
a = rist_rtt_mute_step(&st, 100, DROP, RESTORE, 1, 5, 5); |
| 139 |
expect("asymmetric_slow_restore_hold", a, RIST_RTT_MUTE_NONE, st.muted, true); |
| 140 |
|
| 141 |
|
| 142 |
a = rist_rtt_mute_step(&st, 100, DROP, RESTORE, 1, 5, 7); |
| 143 |
expect("asymmetric_slow_restore_fires", a, RIST_RTT_MUTE_RESTORE, st.muted, false); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
{ |
| 149 |
|
| 150 |
|
| 151 |
check("handover_rejects_small_margin", |
| 152 |
rist_rtt_sole_carrier_handover(126, 85, 10, 3, 2), false); |
| 153 |
|
| 154 |
check("handover_accepts_clear_margin", |
| 155 |
rist_rtt_sole_carrier_handover(1162, 406, 10, 3, 2), true); |
| 156 |
|
| 157 |
check("handover_holds_until_min", |
| 158 |
rist_rtt_sole_carrier_handover(1162, 406, 2, 3, 2), false); |
| 159 |
|
| 160 |
check("handover_boundaries", |
| 161 |
rist_rtt_sole_carrier_handover(800, 400, 3, 3, 2), true); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
{ |
| 166 |
|
| 167 |
check_weight("ramp_absent", rist_rtt_ramped_weight(10, 0, 100, 50), 10); |
| 168 |
check_weight("ramp_complete", rist_rtt_ramped_weight(10, 0 + 1, 100, 201), 10); |
| 169 |
|
| 170 |
check_weight("ramp_quarter", rist_rtt_ramped_weight(10, 100, 100, 125), 2); |
| 171 |
check_weight("ramp_half", rist_rtt_ramped_weight(10, 100, 100, 150), 5); |
| 172 |
check_weight("ramp_end", rist_rtt_ramped_weight(10, 100, 100, 200), 10); |
| 173 |
|
| 174 |
check_weight("ramp_floor_is_one", rist_rtt_ramped_weight(10, 100, 100, 101), 1); |
| 175 |
|
| 176 |
check_weight("ramp_skips_weight_one", rist_rtt_ramped_weight(1, 100, 100, 150), 1); |
| 177 |
check_weight("ramp_skips_duplicate", rist_rtt_ramped_weight(0, 100, 100, 150), 0); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
{ |
| 182 |
|
| 183 |
check("trickle_within_buffer", rist_rtt_trickle_useful(400, 1800), true); |
| 184 |
|
| 185 |
check("trickle_at_cutoff", rist_rtt_trickle_useful(3600, 1800), true); |
| 186 |
check("trickle_past_cutoff", rist_rtt_trickle_useful(3602, 1800), false); |
| 187 |
|
| 188 |
check("trickle_collapsed_leg", rist_rtt_trickle_useful(33000, 1800), false); |
| 189 |
|
| 190 |
check("trickle_unknown_buffer", rist_rtt_trickle_useful(33000, 0), true); |
| 191 |
} |
| 192 |
|
| 193 |
if (failures == 0) { |
| 194 |
printf("OK\n"); |
| 195 |
return 0; |
| 196 |
} |
| 197 |
fprintf(stderr, "Total failures: %d\n", failures); |
| 198 |
return 1; |
| 199 |
} |