From 840f95eaa36e46f51a9f9cab85d1e82b2424f2ec Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 16 Sep 2019 15:06:57 +0200 Subject: [PATCH] Satisfying donar --- src/algo_thunder.c | 35 +++++++++++++++++++---------------- src/test.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/test.c diff --git a/src/algo_thunder.c b/src/algo_thunder.c index 33a5ec4..1500534 100644 --- a/src/algo_thunder.c +++ b/src/algo_thunder.c @@ -122,7 +122,7 @@ int schedule(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct bu if (protect == thunderc->total_links) mili_sec = compute_delta (&thunderc->prev_link_time, UINT16_MAX); - printf("send packet on link %d with delta=%ld\n", thunderc->selected_link, mili_sec); + //printf("send packet on link %d with delta=%ld\n", thunderc->selected_link, mili_sec); // 5. We create the array struct link_info *li = &new_ap->fmt.content.link_monitoring_thunder.links_status; for (int i = 0; i < thunderc->total_links; i++) { @@ -170,7 +170,7 @@ void on_block (struct evt_core_ctx* ctx, void* raw) { struct block_info* bi = raw; struct thunder_ctx* thunderc = bi->app_ctx->misc; - if (thunderc->received_pkts_on_link[bi->i] >= bi->missing) goto release; + if (bi->is_timeout && thunderc->received_pkts_on_link[bi->i] >= bi->missing) goto release; if (thunderc->blacklisted[bi->i] >= bi->missing) goto release; printf("%s\n", bi->reason); @@ -217,7 +217,7 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b uint64_t mili_sec = compute_delta (&thunderc->prev_rcv_link_time, UINT16_MAX); for (int i = 0; i < thunderc->total_links; i++) { - if (thunderc->received_pkts_on_link[i] == 0) continue; + if (thunderc->received_pkts_on_link[i] <= 1) continue; thunderc->rcv_delta_t_per_link[i] += mili_sec; } thunderc->rcv_delta_t_per_link[link_id] = 0; @@ -232,6 +232,7 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b uint64_t expected = i <= link_id ? thunderc->received_pkts_on_link[link_id] : thunderc->received_pkts_on_link[link_id] - 1; if (thunderc->received_pkts_on_link[i] != expected) continue; + if (thunderc->received_pkts_on_link[i] <= 1) continue; remote_delta = li[i].delta_t; local_delta = thunderc->rcv_delta_t_per_link[i]; @@ -243,34 +244,36 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b } //printf("----> %ld vs %ld for i=%d, link_id=%d, owd_difference=%ld, smallest=%ld, remote=%ld, local=%ld\n", thunderc->received_pkts_on_link[i], expected, i, link_id, owd_difference, smallest_owdd, local_delta, remote_delta); + //printf(" owd_difference = %ld, max=%ld, min=%ld\n", owd_difference, thunderc->allowed_jitter_ms, -thunderc->allowed_jitter_ms); if (owd_difference <= thunderc->allowed_jitter_ms && owd_difference >= -thunderc->allowed_jitter_ms) continue; - struct block_info *bi = malloc(sizeof(struct block_info)); - bi->app_ctx = app_ctx; bi->is_timeout = 1; - bi->is_timeout = 0; - bi->app_ctx = app_ctx; - sprintf(bi->reason, "Erreur"); + struct block_info bi = {0}; + bi.app_ctx = app_ctx; + bi.is_timeout = 0; + bi.app_ctx = app_ctx; + sprintf(bi.reason, "Erreur"); if (owd_difference < -thunderc->allowed_jitter_ms) { - bi->i = i; - bi->missing = expected; - sprintf(bi->reason, " Packet Too Late - Blocked link %d owd_diff=%ld, local_delta=%ld, remote_delta=%ld", i, owd_difference, local_delta, remote_delta); + bi.i = i; + bi.missing = expected; + sprintf(bi.reason, " Packet Too Late - Blocked non current link %d owd_diff=%ld, local_delta=%ld, remote_delta=%ld", i, owd_difference, local_delta, remote_delta); } else if (owd_difference > thunderc->allowed_jitter_ms) { - bi->i = link_id; - bi->missing = thunderc->received_pkts_on_link[link_id]; - sprintf(bi->reason, " Packet Too Late - Blocked link %d owd_diff=%ld, local_delta=%ld, remote_delta=%ld", link_id, owd_difference, local_delta, remote_delta); + bi.i = link_id; + bi.missing = thunderc->received_pkts_on_link[link_id]; + sprintf(bi.reason, " Packet Too Late - Blocked current link %d owd_diff=%ld, local_delta=%ld, remote_delta=%ld", link_id, owd_difference, local_delta, remote_delta); } else { fprintf(stderr, "Algorithm is wrong\n"); exit(EXIT_FAILURE); } - on_block(ctx, bi); + on_block(ctx, &bi); } // 2.5 Compute link jitter + //printf("retained owd: %ld\n", biggest_owdd); int64_t current_link_jitter = biggest_owdd; for (int i = 0; i < thunderc->total_links; i++) { - thunderc->estimated_sent[i] = li[i].delta_t + current_link_jitter; + thunderc->estimated_sent[i] = li[i].delta_t /*+ current_link_jitter*/; } // 3. Disable links that miss packets diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..f91ac8d --- /dev/null +++ b/src/test.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include "proxy.h" + +int main(int argc, char** argv) { + setvbuf(stdout, NULL, _IONBF, 0); + printf("~ udpecho ~\n"); + + + int64_t sorted_estimation[MAX_LINKS]; + uint64_t sorted_occurencies; + struct thunder_ctx thunderc = {0}; + thunderc.total_links = 8; + thunderc.estimated_sent[0] = 221; + thunderc.estimated_sent[1] = 110; + thunderc.estimated_sent[2] = 0; + thunderc.estimated_sent[3] = 522; + thunderc.estimated_sent[4] = 522; + thunderc.estimated_sent[5] = 443; + thunderc.estimated_sent[6] = 333; + thunderc.estimated_sent[7] = 333; + + get_estimation (&thunderc, sorted_estimation, &sorted_occurencies); + printf("sorted_occurencies = %ld, vals=", sorted_occurencies); + for (int i = 0; i < sorted_occurencies; i++) { + printf("%ld,", sorted_estimation[i]); + } + printf("\n"); + +}