From 1f379ea2094fd75f55920327d5c1f5dc362870e9 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 9 Oct 2012 16:09:33 +1030 Subject: [PATCH] Add and preserve QOS bit flags in packet header --- commandline.c | 1 + constants.h | 8 ++------ overlay.c | 9 ++++++--- overlay_mdp.c | 10 +++++++--- overlay_packetformats.c | 4 ++-- overlay_payload.c | 9 ++++++++- serval.h | 1 + tests/routing | 2 ++ 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/commandline.c b/commandline.c index 36ed9a29..e0175c24 100644 --- a/commandline.c +++ b/commandline.c @@ -797,6 +797,7 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option * mdp.out.src.port=port; bcopy(srcsid,mdp.out.src.sid,SID_SIZE); bcopy(ping_sid,&mdp.out.dst.sid[0],SID_SIZE); + mdp.out.queue=OQ_MESH_MANAGEMENT; /* Set port to well known echo port (from /etc/services) */ mdp.out.dst.port=7; mdp.out.payload_length=4+8; diff --git a/constants.h b/constants.h index 7a713076..5c94c47e 100644 --- a/constants.h +++ b/constants.h @@ -204,12 +204,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. time. #define OF_CRYPTO_PARANOID 0x0c Encrypted and digitally signed frame, with final destination address also encrypted. */ -/* Data compression */ -#define OF_COMPRESS_BITS 0x03 -#define OF_COMPRESS_NONE 0x00 -#define OF_COMPRESS_GZIP 0x01 /* Frame compressed with gzip */ -#define OF_COMPRESS_BZIP2 0x02 /* bzip2 */ -#define OF_COMPRESS_RESERVED 0x03 /* Reserved for another compression system */ +/* QOS packet queue bits */ +#define OF_QUEUE_BITS 0x03 #define RFS_PLUS250 0xfa #define RFS_PLUS456 0xfb diff --git a/overlay.c b/overlay.c index c9dcf283..da213be5 100644 --- a/overlay.c +++ b/overlay.c @@ -103,16 +103,19 @@ int overlayServerMode() for(i=0;iqueue; + /* Get source and destination addresses */ if (f->destination) bcopy(f->destination->sid,mdp.in.dst.sid,SID_SIZE); @@ -910,9 +912,11 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP, break; } - // TODO include priority in packet header - frame->queue=OQ_ORDINARY; - /* Make sure voice traffic gets priority */ + frame->queue=mdp->out.queue; + if (frame->queue==0) + frame->queue = OQ_ORDINARY; + + /* Make sure only voice traffic gets priority */ if ((frame->type&OF_TYPE_BITS)==OF_TYPE_DATA_VOICE) { frame->queue=OQ_ISOCHRONOUS_VOICE; rhizome_saw_voice_traffic(); diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 8268881f..e150c07b 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -92,8 +92,6 @@ int overlay_forward_payload(struct overlay_frame *f){ if (!qf) return WHY("Could not clone frame for queuing"); - // TODO include priority in packet header - qf->queue=OQ_ORDINARY; /* Make sure voice traffic gets priority */ if ((qf->type&OF_TYPE_BITS)==OF_TYPE_DATA_VOICE) { qf->queue=OQ_ISOCHRONOUS_VOICE; @@ -224,6 +222,8 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s break; } + f.queue = (f.modifiers & OF_QUEUE_BITS) +1; + /* Get time to live */ f.ttl=ob_get(b); diff --git a/overlay_payload.c b/overlay_payload.c index 89c1f343..13cc1d21 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -24,6 +24,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. static int op_append_type(struct overlay_buffer *headers, struct overlay_frame *p) { unsigned char c[3]; + // pack the QOS queue into the modifiers + int q_bits = p->queue; + if (q_bits>0) q_bits--; + if (q_bits>3) q_bits=3; + + p->modifiers = (p->modifiers & ~OF_QUEUE_BITS)|q_bits; + switch(p->type&OF_TYPE_FLAG_BITS) { case OF_TYPE_FLAG_NORMAL: @@ -195,7 +202,7 @@ int overlay_payload_enqueue(struct overlay_frame *p) return WHYF("Destination %s is unreachable (%d)", alloca_tohex_sid(p->destination->sid), r); } - if (p->queue<0||p->queue>=OQ_MAX) + if (p->queue>=OQ_MAX) return WHY("Invalid queue specified"); overlay_txqueue *queue = &overlay_tx[p->queue]; diff --git a/serval.h b/serval.h index c9be22f7..ca6bf897 100644 --- a/serval.h +++ b/serval.h @@ -723,6 +723,7 @@ typedef struct overlay_mdp_data_frame { uint16_t payload_length; // temporary hack to improve reliability before implementing per-packet nack's int send_copies; + int queue; unsigned char payload[MDP_MTU-100]; } overlay_mdp_data_frame; diff --git a/tests/routing b/tests/routing index f5fd20a6..0d76652f 100755 --- a/tests/routing +++ b/tests/routing @@ -60,6 +60,7 @@ doc_single_link="Start 2 instances on one link" test_single_link() { set_instance +A executeOk_servald mdp ping $SIDB 3 + tfw_cat --stdout --stderr } setup_multihop_linear() { @@ -77,6 +78,7 @@ test_multihop_linear() { wait_until --sleep=0.25 instances_see_each_other +A +B +C +D set_instance +A executeOk_servald mdp ping $SIDD 3 + tfw_cat --stdout --stderr } runTests "$@"