From 27a454ef722d4bc81f301e51dd9f9f4fdf02480e Mon Sep 17 00:00:00 2001 From: gardners Date: Mon, 5 Sep 2011 12:49:37 +0930 Subject: [PATCH] Initial implementation of frame enqueuing. Queues require maxLength to be initalised to set congestion threshold. --- mphlr.h | 6 ++++-- overlay.c | 6 ++++-- overlay_payload.c | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/mphlr.h b/mphlr.h index df8ad419..35debafe 100644 --- a/mphlr.h +++ b/mphlr.h @@ -550,8 +550,9 @@ int ob_unlimitsize(overlay_buffer *b); typedef struct overlay_txqueue { struct overlay_frame *first; struct overlay_frame *last; - int length; - int maxLength; + int length; /* # frames in queue */ + int maxLength; /* max # frames in queue before we consider ourselves congested */ + /* Latency target in ms for this traffic class. Frames older than the latency target will get dropped. */ int latencyTarget; @@ -776,4 +777,5 @@ int overlay_frame_set_me_as_source(overlay_frame *f); int overlay_update_sequence_number(); int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags); int overlayServerMode(); +int overlay_payload_enqueue(int q,overlay_frame *p); diff --git a/overlay.c b/overlay.c index 2d108580..3867e489 100644 --- a/overlay.c +++ b/overlay.c @@ -209,8 +209,10 @@ int overlay_frame_process(int interface,overlay_frame *f) if (overlay_get_nexthop(f->destination,f->nexthop,&len)) return WHY("Could not find next hop for host - dropping frame"); f->ttl--; - - /* Queue frame for dispatch */ + + /* Queue frame for dispatch. + Don't forget to put packet in the correct queue based on type. + (e.g., mesh management, voice, video, ordinary or opportunistic). */ WHY("forwarding of frames not implemented"); /* If the frame was a broadcast frame, then we need to hang around diff --git a/overlay_payload.c b/overlay_payload.c index 90711a34..c4e8644d 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -136,9 +136,27 @@ overlay_buffer *overlay_payload_unpackage(overlay_frame *b) { int overlay_payload_enqueue(int q,overlay_frame *p) { /* Add payload p to queue q. + + Queues get scanned from first to last, so we should append new entries + on the end of the queue. + + Complain if there are too many frames in the queue. */ - return WHY("not implemented"); + if (q<0||q>=OQ_MAX) return WHY("Invalid queue specified"); + if (!p) return WHY("Cannot queue NULL"); + + if (overlay_tx[q].length>=overlay_tx[q].maxLength) return WHY("Queue congested"); + + overlay_frame *l=overlay_tx[q].last; + if (l) l->next=p; + p->prev=l; + p->next=NULL; + overlay_tx[q].last=p; + if (!overlay_tx[q].first) overlay_tx[q].first=p; + overlay_tx[q].length++; + + return 0; } int op_free(overlay_frame *p)