From ca8eddc0add4611c735e78d1ddc635a222e192b9 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 27 Mar 2019 18:27:44 +0100 Subject: [PATCH] Some improvement on RR algo --- src/algo_rr.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index 82396e8..302565e 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -13,6 +13,7 @@ struct waited_pkt { struct deferred_pkt { int link_fd; int idx; + uint16_t id; uint8_t on; }; @@ -175,6 +176,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, int idx_real = bp->ip.ap.str.id % PACKET_BUFFER_SIZE; if (rr->wait[idx_real].on && rr->wait[idx_real].id != bp->ip.ap.str.id) { fprintf(stderr, "Waiting array is full, BUG\n"); + exit(EXIT_FAILURE); } else if (!rr->wait[idx_real].on) { rr->wait[idx_real].on = 1; rr->wait[idx_real].id = bp->ip.ap.str.id; @@ -183,10 +185,18 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, } // 5. We queue the packet - rr->real[idx_real].on = 1; - rr->real[idx_real].idx = idx_real; - rr->real[idx_real].link_fd = fdinfo->fd; - mv_buffer_rtoa(app_ctx, fdinfo, &rr->real[idx_real].idx); + if (rr->real[idx_real].on && rr->real[idx_real].id != bp->ip.ap.str.id) { + fprintf(stderr, "Real array is full, BUG\n"); + exit(EXIT_FAILURE); + } else if (!rr->real[idx_real].on) { + rr->real[idx_real].on = 1; + rr->real[idx_real].idx = idx_real; + rr->real[idx_real].link_fd = fdinfo->fd; + mv_buffer_rtoa(app_ctx, fdinfo, &rr->real[idx_real].idx); + } else { + fprintf(stdout, "Packet %d already received (current: %d)\n", bp->ip.ap.str.id, rr->recv_id); + mv_buffer_wtof (app_ctx, fdinfo); + } } void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct deferred_pkt* dp) { @@ -198,18 +208,20 @@ void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct // 1. Marked the packet as handled dp->on = 0; - // 2. Get the buffer + // 2. Get the buffer and update rr state struct buffer_packet* bp = get_app_buffer (app_ctx, &dp->idx); + int idx_real = bp->ip.ap.str.id % PACKET_BUFFER_SIZE; + rr->wait[idx_real].on = 0; //printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id); // 3. We update our cursor rr->recv_id = bp->ip.ap.str.id; // 4. We free the buffer if it's a control packet and quit - if (bp->ip.ap.str.flags & PKT_CONTROL) { + /*if (bp->ip.ap.str.flags & PKT_CONTROL) { mv_buffer_atof (app_ctx, &dp->idx); return; - } + }*/ // 5. Find its target sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);