Rework code

This commit is contained in:
Quentin 2019-09-19 14:37:29 +02:00
parent 422f1845c9
commit 07287db40d
2 changed files with 32 additions and 85 deletions

View file

@ -210,28 +210,6 @@ int is_in_order(struct thunder_ctx* thunderc, uint8_t link_id) {
return 1;
}
void update_owdd(struct thunder_ctx* thunderc, uint8_t link_id, struct link_info *li) {
if (!is_in_order(thunderc, link_id)) return; // Packet is out of order, computing OWDD makes no sense
for (int i = 0; i < thunderc->total_links; i++) {
int64_t remote_delta = 0, local_delta = 0, owd_difference = 0;
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 || thunderc->received_pkts_on_link[i] <= 1) {
thunderc->owdd[i] = INT64_MAX;
} else if (thunderc->received_pkts_on_link[i] > expected) {
fprintf(stderr, "We must consider in order packets only. This code path should not be triggered and proove that algo is wrong\n");
exit(EXIT_FAILURE);
}
remote_delta = li[i].delta_t;
local_delta = thunderc->rcv_delta_t_per_link[i];
owd_difference = remote_delta - local_delta;
thunderc->owdd[i] = owd_difference;
}
}
void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
struct thunder_ctx* thunderc = app_ctx->misc;
@ -242,12 +220,6 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b
exit(EXIT_FAILURE);
}
/*
if (ap->fmt.headers.flags & FLAG_RESET) {
for (int i = 0; i < MAX_LINKS; i++) thunderc->received_pkts_on_link[i] = 1;
}
*/
// 1. Update link info
int link_id = url_get_port_int(fdinfo->url) - 7500;
thunderc->received_pkts_on_link[link_id] += ap->fmt.content.link_monitoring_thunder.to_increment;
@ -261,47 +233,10 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b
}
thunderc->rcv_delta_t_per_link[link_id] = 0;
update_owdd(thunderc, link_id, li);
for (int i = 0; i < thunderc->total_links; i++) {
int64_t remote_delta = 0, local_delta = 0, owd_difference = 0;
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];
owd_difference = remote_delta - local_delta;
if (owd_difference <= thunderc->allowed_jitter_ms && owd_difference >= -thunderc->allowed_jitter_ms) continue;
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 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 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);
}
// 3. Disable links that miss packets
for (uint8_t i = 0; i < thunderc->total_links; i++) {
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; // Nothing to do, all packets have been received
int64_t timeout = thunderc->allowed_jitter_ms - li[i].delta_t;
struct block_info *bi = malloc(sizeof(struct block_info));
@ -310,26 +245,22 @@ void classify(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct b
sprintf(bi->reason, " Missing Packet - Timeout for link %d after %ldms (expected: %ld, seen: %ld)", i, timeout, expected, thunderc->received_pkts_on_link[i]);
if (timeout <= 0) {
on_block(ctx, bi);
//printf(" Missing Packet - Blocked link %d (expected: %ld, seen: %ld)\n", i, expected, thunderc->received_pkts_on_link[i]);
continue;
}
set_timeout (ctx, timeout, bi, on_block);
if (ctx->verbose > 1) {
fprintf(stderr, " [algo_thunder] Set timeout on link %d of %ld ms (packets expected: %ld, seen: %ld)\n",
i, timeout, expected, thunderc->received_pkts_on_link[i]);
}
}
if (ctx->verbose > 1) fprintf(stderr, " [algo_thunder] Classify done\n");
uint64_t ts = compute_delta (&thunderc->start_time, UINT64_MAX, 0);
printf("[%ld] Blacklisted links: ", ts);
for (int i = 0; i < thunderc->total_links; i++) {
if (is_blacklisted (thunderc, i)) printf("_");
else printf("U");
if (thunderc->scheduler_activated) {
uint64_t ts = compute_delta (&thunderc->start_time, UINT64_MAX, 0);
printf("[%ld] Blacklisted links: ", ts);
for (int i = 0; i < thunderc->total_links; i++) {
if (is_blacklisted (thunderc, i)) printf("_");
else printf("U");
}
printf("\n");
}
printf("\n");
}
struct unpad_info {

View file

@ -101,21 +101,37 @@ int main_on_err(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo);
#define MAX_LINKS 64
struct thunder_ctx {
uint16_t recv_id;
uint16_t emit_id;
uint8_t selected_link;
// shared/global parameters
uint8_t total_links;
struct timespec start_time;
// scheduler parameters
uint8_t selected_link;
uint64_t blacklisted[MAX_LINKS];
// classifier send side parameters
struct timespec prev_link_time;
uint8_t to_increment[MAX_LINKS];
uint64_t delta_t_per_link[MAX_LINKS];
uint64_t sent_pkts_on_link[MAX_LINKS];
// classifier receive side parameters
uint64_t rcv_delta_t_per_link[MAX_LINKS];
uint64_t received_pkts_on_link[MAX_LINKS];
uint64_t sent_pkts_on_link[MAX_LINKS];
uint64_t blacklisted[MAX_LINKS];
int64_t estimated_sent[MAX_LINKS];
struct timespec prev_rcv_link_time;
int64_t owdd[MAX_LINKS];
// uint16_t received_delta_by_links[MAX_LINKS][MAX_LINKS];
// struct timespec last_received_on_link[MAX_LINKS];
// prepare/adapt parameters
uint16_t recv_id;
uint16_t emit_id;
// pad/unpad parameter
size_t monit_pkt_size;
// user parameters
int64_t allowed_jitter_ms;
int scheduler_activated;
struct timespec prev_link_time, prev_rcv_link_time, start_time;
};
void get_estimation(struct thunder_ctx* thunderc, int64_t* sorted_estimation, uint64_t* sorted_occurencies);