summaryrefslogtreecommitdiff
path: root/src/lib/frct.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/frct.c')
-rw-r--r--src/lib/frct.c125
1 files changed, 23 insertions, 102 deletions
diff --git a/src/lib/frct.c b/src/lib/frct.c
index 0f3173c5..db3572e3 100644
--- a/src/lib/frct.c
+++ b/src/lib/frct.c
@@ -31,16 +31,13 @@
#define TW_RESOLUTION 1 /* ms */
#define FRCT_PCILEN (sizeof(struct frct_pci))
-#define FRCT_CRCLEN (sizeof(uint32_t))
struct frct_cr {
- bool drf;
uint32_t lwe;
uint32_t rwe;
- uint32_t seqno;
- bool conf;
uint8_t cflags;
+ uint32_t seqno;
time_t rto; /* ms */
time_t act; /* s */
@@ -67,15 +64,12 @@ enum frct_flags {
FRCT_ACK = 0x03, /* ACK field valid */
FRCT_FC = 0x08, /* FC window valid */
FRCT_RDVZ = 0x10, /* Rendez-vous */
- FRCT_CFG = 0x20, /* Configuration */
- FRCT_MFGM = 0x40, /* More fragments */
- FRCT_CRC = 0x80, /* CRC present */
+ FRCT_MFGM = 0x20, /* More fragments */
+ FRCT_CRC = 0x40, /* CRC present */
};
struct frct_pci {
- uint8_t flags;
-
- uint8_t cflags;
+ uint16_t flags;
uint16_t window;
@@ -85,8 +79,7 @@ struct frct_pci {
#include <rxmwheel.c>
-static struct frcti * frcti_create(int fd,
- qoscube_t qc)
+static struct frcti * frcti_create(int fd)
{
struct frcti * frcti;
time_t delta_t;
@@ -114,16 +107,15 @@ static struct frcti * frcti_create(int fd,
delta_t = (frcti->mpl + frcti->a + frcti->r) / 1000;
- if (qc == QOS_CUBE_DATA)
- frcti->snd_cr.cflags |= FRCTFRTX;
-
- frcti->snd_cr.conf = true;
- frcti->snd_cr.inact = 3 * delta_t + 1;
+ 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->rcv_cr.inact = 2 * delta_t + 1;
+ if (ai.flows[fd].spec.loss == 0)
+ frcti->snd_cr.cflags |= FRCTFRTX;
+
+ frcti->rcv_cr.inact = 2 * delta_t;
frcti->rcv_cr.act = now.tv_sec - (frcti->rcv_cr.inact + 1);
return frcti;
@@ -138,7 +130,7 @@ static void frcti_destroy(struct frcti * frcti)
{
/*
* FIXME: In case of reliable transmission we should
- * make sure everything is acked.
+ * make sure everything we sent is acked.
*/
rxmwheel_clear(frcti->fd);
@@ -148,24 +140,6 @@ static void frcti_destroy(struct frcti * frcti)
free(frcti);
}
-static int frcti_setconf(struct frcti * frcti,
- uint16_t flags)
-{
- assert(frcti);
-
- pthread_rwlock_wrlock(&frcti->lock);
-
- if (frcti->snd_cr.cflags != flags) {
- frcti->snd_cr.cflags = flags;
- frcti->snd_cr.conf = true;
- frcti->snd_cr.drf = true;
- }
-
- pthread_rwlock_unlock(&frcti->lock);
-
- return 0;
-}
-
static uint16_t frcti_getconf(struct frcti * frcti)
{
uint16_t ret;
@@ -203,14 +177,6 @@ static ssize_t __frcti_queued_pdu(struct frcti * frcti)
pos = frcti->rcv_cr.lwe & (RQ_SIZE - 1);
idx = frcti->rq[pos];
if (idx != -1) {
- struct shm_du_buff * sdb;
- struct frct_pci * pci;
-
- sdb = shm_rdrbuff_get(ai.rdrb, idx);
- pci = (struct frct_pci *) shm_du_buff_head(sdb) - 1;
- if (pci->flags & FRCT_CFG)
- frcti->rcv_cr.cflags = pci->cflags;
-
++frcti->rcv_cr.lwe;
frcti->rq[pos] = -1;
}
@@ -220,22 +186,6 @@ static ssize_t __frcti_queued_pdu(struct frcti * frcti)
return idx;
}
-static int frct_chk_crc(uint8_t * head,
- uint8_t * tail)
-{
- uint32_t crc;
-
- mem_hash(HASH_CRC32, &crc, head, tail - head);
-
- return crc == *((uint32_t *) tail);
-}
-
-static void frct_add_crc(uint8_t * head,
- uint8_t * tail)
-{
- mem_hash(HASH_CRC32, tail, head, tail - head);
-}
-
static struct frct_pci * frcti_alloc_head(struct shm_du_buff * sdb)
{
struct frct_pci * pci;
@@ -272,38 +222,20 @@ static int __frcti_snd(struct frcti * frcti,
pci->flags |= FRCT_DATA;
- if (snd_cr->cflags & FRCTFERRCHCK) {
- uint8_t * tail = shm_du_buff_tail_alloc(sdb, FRCT_CRCLEN);
- if (tail == NULL) {
- pthread_rwlock_unlock(&frcti->lock);
- return -1;
- }
-
- frct_add_crc((uint8_t *) pci, tail);
-
- pci->flags |= FRCT_CRC;
- }
-
/* Set DRF if there are no unacknowledged packets. */
if (snd_cr->seqno == snd_cr->lwe)
pci->flags |= FRCT_DRF;
- if (snd_cr->conf) {
- /* FIXME: This packet must be acked! */
- pci->flags |= FRCT_CFG;
- pci->cflags = snd_cr->cflags;
- }
-
/* Choose a new sequence number if sender inactivity expired. */
if (now.tv_sec - snd_cr->act > snd_cr->inact) {
/* There are no unacknowledged packets. */
assert(snd_cr->seqno == snd_cr->lwe);
#ifdef CONFIG_OUROBOROS_DEBUG
- frcti->snd_cr.seqno = 0;
+ snd_cr->seqno = 0;
#else
random_buffer(&snd_cr->seqno, sizeof(snd_cr->seqno));
#endif
- frcti->snd_cr.lwe = frcti->snd_cr.seqno;
+ frcti->snd_cr.lwe = snd_cr->seqno;
}
pci->seqno = hton32(snd_cr->seqno);
@@ -317,14 +249,13 @@ static int __frcti_snd(struct frcti * frcti,
snd_cr->seqno++;
snd_cr->act = now.tv_sec;
- snd_cr->conf = false;
pthread_rwlock_unlock(&frcti->lock);
return 0;
}
-/* Returns 0 when idx contains an SDU for the application. */
+/* Returns 0 when idx contains a packet for the application. */
static int __frcti_rcv(struct frcti * frcti,
struct shm_du_buff * sdb)
{
@@ -349,43 +280,33 @@ static int __frcti_rcv(struct frcti * frcti,
idx = shm_du_buff_get_idx(sdb);
- /* PDU may be corrupted. */
- if (pci->flags & FRCT_CRC) {
- uint8_t * tail = shm_du_buff_tail_release(sdb, FRCT_CRCLEN);
- if (frct_chk_crc((uint8_t *) pci, tail))
- goto drop_packet;
- }
-
seqno = ntoh32(pci->seqno);
/* Check if receiver inactivity is true. */
if (now.tv_sec - rcv_cr->act > rcv_cr->inact) {
/* Inactive receiver, check for DRF. */
if (pci->flags & FRCT_DRF) /* New run. */
- rcv_cr->lwe = seqno - 1;
+ rcv_cr->seqno = seqno;
else
goto drop_packet;
}
- if (seqno == rcv_cr->lwe + 1) {
- rcv_cr->lwe = seqno;
- /* Check for online reconfiguration. */
- if (pci->flags & FRCT_CFG)
- rcv_cr->cflags = pci->cflags;
+ if (seqno == rcv_cr->seqno) {
+ ++rcv_cr->seqno;
} else { /* Out of order. */
- if ((int32_t)(seqno - rcv_cr->lwe) <= 0) /* Duplicate. */
+ if ((int32_t)(seqno - rcv_cr->seqno) < 0) /* Duplicate. */
goto drop_packet;
if (rcv_cr->cflags & FRCTFRTX) {
size_t pos = seqno & (RQ_SIZE - 1);
- if ((seqno - rcv_cr->lwe) > RQ_SIZE /* Out of rq. */
+ if ((seqno - rcv_cr->seqno) > RQ_SIZE /* Out of rq. */
|| frcti->rq[pos] != -1) /* Duplicate in rq. */
goto drop_packet;
/* Queue. */
frcti->rq[pos] = idx;
ret = -EAGAIN;
} else {
- rcv_cr->lwe = seqno;
+ rcv_cr->seqno = seqno;
}
}
@@ -398,18 +319,18 @@ static int __frcti_rcv(struct frcti * frcti,
rcv_cr->act = now.tv_sec;
+ pthread_rwlock_unlock(&frcti->lock);
+
if (!(pci->flags & FRCT_DATA))
shm_rdrbuff_remove(ai.rdrb, idx);
- pthread_rwlock_unlock(&frcti->lock);
-
rxmwheel_move();
return ret;
drop_packet:
- shm_rdrbuff_remove(ai.rdrb, idx);
pthread_rwlock_unlock(&frcti->lock);
+ shm_rdrbuff_remove(ai.rdrb, idx);
rxmwheel_move();
return -EAGAIN;
}