Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "wmp_config.h"
00037 #include <math.h>
00038 #include "misc.h"
00039
00040 #include "core/include/frames.h"
00041 #include <stdio.h>
00042 char * wmp_get_frame_tail_pointer(wmpFrame * t, int n_nodes){
00043 char * tkn_data_ptr =(char*)t;
00044 if (t->hdr.type==TOKEN){
00045 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Token)+n_nodes*n_nodes);
00046 }
00047 else if (t->hdr.type==AUTHORIZATION){
00048 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Authorization));
00049 }else if (t->hdr.type==MESSAGE){
00050 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Message)+t->msg.len);
00051 }else {
00052 fprintf(stderr,"Unknown frame type in get_tail_pointer, (s:%lu), exiting\n",t->hdr.serial);
00053 }
00054 return tkn_data_ptr;
00055 }
00056
00057 char * wmp_get_frame_routing_pointer(wmpFrame * t, int n_nodes){
00058 char * tkn_data_ptr = (char*) t;
00059 if (t->hdr.type == TOKEN) {
00060 tkn_data_ptr += (sizeof(Token_Hdr) + sizeof(Token));
00061 } else if (t->hdr.type == AUTHORIZATION) {
00062 tkn_data_ptr += (sizeof(Token_Hdr) + sizeof(Authorization));
00063 } else if (t->hdr.type == MESSAGE) {
00064 tkn_data_ptr += (sizeof(Token_Hdr) + sizeof(Message));
00065 } else if (t->hdr.type == DROP_TOKEN) {
00066 tkn_data_ptr += (sizeof(Token_Hdr) + sizeof(Drop));
00067 } else {
00068 fprintf(stderr,
00069 "Unknown frame type in get_routing_pointer (s:%lu), exiting\n",
00070 t->hdr.serial);
00071 }
00072 return tkn_data_ptr;
00073 }
00074
00075 int valid_frame(wmpFrame * p, int nbytes, int num_nodes) {
00076 int res = 0;
00077 if (nbytes < sizeof (Token_Hdr)) {
00078 res +=1;
00079 }
00080 if (p->hdr.from < 0 ||
00081 p->hdr.to < 0 ||
00082 p->hdr.from >= num_nodes ||
00083 p->hdr.to >= num_nodes) {
00084 res +=10;
00085 }
00086 if (res) {
00087 fprintf(stderr, "***** WARNING DISCARDING FRAME %d serial %d from %d to %d size:%d th_size:%d reason:%d\n", p->hdr.type,
00088 (int)p->hdr.serial, p->hdr.from, p->hdr.to, nbytes,sizeof (Token_Hdr), res);
00089 }
00090 return (!res);
00091 }
00092
00093
00094 int wmp_get_frame_total_lenght(wmpFrame * t, int n_nodes){
00095 int size=sizeof(Token_Hdr);
00096 #ifdef WMP_ROUTING_tree
00097 size += n_nodes;
00098 if (t->hdr.type==TOKEN){
00099 size+=sizeof(Token)+2*n_nodes;
00100 } else if (t->hdr.type==AUTHORIZATION){
00101 size+=sizeof(Authorization);
00102 } else if (t->hdr.type==MESSAGE){
00103 size+=sizeof(Message)+t->msg.len;
00104 } else if (t->hdr.type==DROP_TOKEN){
00105 size+=sizeof(Drop);
00106 } else {
00107 size+=0;
00108 }
00109 #else
00110 if (t->hdr.type==TOKEN){
00111 size+=sizeof(Token)+n_nodes*n_nodes;
00112 } else if (t->hdr.type==AUTHORIZATION){
00113 size+=sizeof(Authorization);
00114 } else if (t->hdr.type == MESSAGE) {
00115 if (mBitsIsSet(t->msg.type, AURA_MSG)) {
00116 size += sizeof(Message) + t->msg.len;
00117 } else {
00118 size += sizeof(Authorization);
00119 }
00120 } else if (t->hdr.type==DROP_TOKEN){
00121 size+=sizeof(Drop);
00122 } else {
00123 size+=0;
00124 }
00125 #endif
00126 #ifdef ENABLE_BC_SUPPORT
00127 if (t->hdr.bc_type!=0){
00128
00129 size+=t->hdr.bc_len;
00130 }
00131 #endif
00132 return size;
00133 }
00134
00135
00136
00137 char * wmp_get_message_data_pointer(wmpFrame * t){
00138 char * tkn_data_ptr =(char*)t;
00139 if (t->hdr.type!=MESSAGE) return NULL;
00140 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Message));
00141 return tkn_data_ptr;
00142 }
00143
00144 int key(Message * p){
00145 int val = 0;
00146 char * m = (char *) p;
00147 for (int i=0; i < p->len ; i++){
00148 val += *((m+sizeof(Message))+i);
00149 }
00150 return (p->src*10000 + p->dest * 1000 + 100 * p->len + 10 * p->priority + val);
00151 };
00152
00153 char * wmp_get_frame_routing_pointer_tree(wmpFrame * t, int n_nodes){
00154 char * tkn_data_ptr =(char*)t;
00155 if (t->hdr.type==TOKEN){
00156 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Token));
00157 }
00158 else if (t->hdr.type==AUTHORIZATION){
00159 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Authorization));
00160 }else if (t->hdr.type==MESSAGE){
00161 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Message));
00162 }else if (t->hdr.type==DROP_TOKEN) {
00163 tkn_data_ptr+=(sizeof(Token_Hdr)+sizeof(Drop));
00164 }else{
00165 fprintf(stderr,"Unknown frame type in get_routing_pointer (s:%lu), exiting\n",t->hdr.serial);
00166 }
00167 return tkn_data_ptr;
00168 }