wmp_specific.cc
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           WMPSNIFFER          --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: window1_glade.cc
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2012, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
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                 //XXX : TODO: COGLIONEEEEEEEEEE
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 }


ros_rt_wmp_sniffer
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:57