[PATCH] lib: Fix initial automated repeat-request

  • From: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Tue, 9 Oct 2018 10:03:34 +0200

This fixes rudimentary automated repeat-request ARQ to correctly
configure the both connection records and use the receiver seqno. The
rto variable is moved out of the connection record.

Signed-off-by: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
---
 src/lib/frct.c     | 18 ++++++++++++------
 src/lib/rxmwheel.c |  4 ++--
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/lib/frct.c b/src/lib/frct.c
index db3572e..e40806f 100644
--- a/src/lib/frct.c
+++ b/src/lib/frct.c
@@ -39,7 +39,6 @@ struct frct_cr {
         uint8_t  cflags;
         uint32_t seqno;
 
-        time_t   rto;     /* ms */
         time_t   act;     /* s */
         time_t   inact;   /* s */
 };
@@ -51,6 +50,8 @@ struct frcti {
         time_t           a;
         time_t           r;
 
+        time_t           rto; /* ms */
+
         struct frct_cr   snd_cr;
         struct frct_cr   rcv_cr;
 
@@ -110,10 +111,12 @@ static struct frcti * frcti_create(int fd)
         frcti->snd_cr.inact  = 3 * delta_t;
         frcti->snd_cr.act    = now.tv_sec - (frcti->snd_cr.inact + 1);
         /* Initial rto. FIXME: recalc using Karn algorithm. */
-        frcti->snd_cr.rto    = 120;
+        frcti->rto           = 120;
 
-        if (ai.flows[fd].spec.loss == 0)
+        if (ai.flows[fd].spec.loss == 0) {
                 frcti->snd_cr.cflags |= FRCTFRTX;
+                frcti->rcv_cr.cflags |= FRCTFRTX;
+        }
 
         frcti->rcv_cr.inact  = 2 * delta_t;
         frcti->rcv_cr.act    = now.tv_sec - (frcti->rcv_cr.inact + 1);
@@ -243,8 +246,11 @@ static int __frcti_snd(struct frcti *       frcti,
                 snd_cr->lwe++;
         } else if (now.tv_sec - rcv_cr->act <= rcv_cr->inact) {
                 rxmwheel_add(frcti, snd_cr->seqno, sdb);
-                pci->flags |= FRCT_ACK;
-                pci->ackno = hton32(rcv_cr->lwe);
+                if (rcv_cr->lwe != rcv_cr->seqno) {
+                        pci->flags |= FRCT_ACK;
+                        pci->ackno = hton32(rcv_cr->seqno);
+                        rcv_cr->lwe = rcv_cr->seqno;
+                }
         }
 
         snd_cr->seqno++;
@@ -299,7 +305,7 @@ static int __frcti_rcv(struct frcti *       frcti,
 
                 if (rcv_cr->cflags & FRCTFRTX) {
                         size_t pos = seqno & (RQ_SIZE - 1);
-                        if ((seqno - rcv_cr->seqno) > RQ_SIZE /* Out of rq. */
+                        if ((seqno - rcv_cr->lwe) > RQ_SIZE /* Out of rq. */
                             || frcti->rq[pos] != -1) /* Duplicate in rq. */
                                 goto drop_packet;
                         /* Queue. */
diff --git a/src/lib/rxmwheel.c b/src/lib/rxmwheel.c
index 697c6a4..afef743 100644
--- a/src/lib/rxmwheel.c
+++ b/src/lib/rxmwheel.c
@@ -201,7 +201,7 @@ static int rxmwheel_move(void)
                         r->tail = shm_du_buff_tail(sdb);
                         r->sdb  = sdb;
 
-                        newtime = ts_to_ms(now) + (snd_cr->rto << ++r->mul);
+                        newtime = ts_to_ms(now) + (f->frcti->rto << ++r->mul);
                         rslot   = (newtime >> RXMQ_R) & (RXMQ_SLOTS - 1);
 
                         list_add_tail(&r->next, &rw.wheel[rslot]);
@@ -239,7 +239,7 @@ static int rxmwheel_add(struct frcti *       frcti,
         r->tail  = shm_du_buff_tail(sdb);
         r->frcti = frcti;
 
-        slot = ((r->t0 + frcti->snd_cr.rto) >> RXMQ_R)
+        slot = ((r->t0 + frcti->rto) >> RXMQ_R)
                 & (RXMQ_SLOTS - 1);
 
         list_add_tail(&r->next, &rw.wheel[slot]);
-- 
2.19.0


Other related posts:

  • » [PATCH] lib: Fix initial automated repeat-request - Dimitri Staessens