Improve algorithm logging

This commit is contained in:
Quentin Dufour 2019-03-27 11:48:09 +01:00
parent bb60aeaef3
commit 6a22df4ac1

View file

@ -72,6 +72,20 @@ co_error:
exit(EXIT_FAILURE);
}
void show_link_availability(struct rr_ctx* rr) {
printf("Links availability: my_links[");
for (int i = 0; i < 8; i++) {
if (rr->my_links & 1 << i) printf("U");
else printf("-");
}
printf("], rem_links[");
for (int i = 0; i < 8; i++) {
if (rr->remote_links & 1 << i) printf("U");
else printf("-");
}
printf("]\n");
}
int set_timeout(struct evt_core_ctx* evts, uint64_t milli_sec, struct waited_pkt* wpkt) {
struct timespec now;
struct itimerspec timer_config;
@ -121,12 +135,6 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo,
if (bp->ip.ap.str.id > rr->my_links_ver) {
rr->my_links = bp->ip.ap.str.bitfield;
rr->my_links_ver = bp->ip.ap.str.id;
printf("Links availability: [");
for (int i = 0; i < 8; i++) {
if (rr->my_links & 1 << i) printf("U");
else printf("-");
}
printf("]\n");
}
// 2. If packet arrived too late, we discard it
@ -161,6 +169,10 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo,
char buffer[16];
url_get_port (buffer, fdinfo->url);
int link_num = atoi(buffer) - 7500; // @FIXME Hardcoded
if (!(rr->remote_links & 1 << link_num)) {
printf("Activate link=%d\n", link_num);
show_link_availability (rr);
}
rr->remote_links |= 1 << link_num; // Make sure that the link is marked as working
}
@ -322,7 +334,8 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
while(1) {
if (max-- < 0) break;
rr->current_link = (rr->current_link + 1) % 10;
if (!(rr->my_links & (1 << rr->current_link))) continue;
//if (!(rr->my_links & (1 << rr->current_link))) continue;
if (!(rr->remote_links & (1 << rr->current_link))) continue;
sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + rr->current_link); //@FIXME Hardcoded
//printf("-- Trying %s\n", url);
to_fdinfo = evt_core_get_from_url (ctx, url);
@ -391,6 +404,8 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
printf("Timer reached for packet %d\n", pkt->id);
// !BLACKLIST LINK
printf("Blacklist link=%d\n", pkt->link_num);
show_link_availability (rr);
rr->remote_links &= 0xff ^ 1 << pkt->link_num;
while (ring_lt(rr->recv_id, pkt->id)) {