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
00037 #include "wmp_config.h"
00038 #include "core/include/frames.h"
00039 #include "core/include/wmp_com.h"
00040
00041
00042
00043 int timer_initied=0;
00044
00045 extern void print_matrix(char* txt, char **lqm);
00046 extern void print_vector(char*txt, char *t);
00047 extern void tree_get_next_tree(char * cp);
00048 extern void tree_create_lqm_from_tree(char ** lqm, char * tree);
00049 extern void tree_create_tree_from_lqm(char * tree, char ** lqm);
00050 extern int tree_which_best(char * t1, char * t2);
00051
00052 void decode_routing_info_pap(wmpFrame *p){
00053 int i, all_reached;
00054 char * cp;
00055 p->tkn.new_token=0;
00056
00057 cp = wmp_get_frame_routing_pointer_status(p);
00058 for (i=0;i<status.N_NODES;i++){
00059 nstat_set_byte(i,cp[i]);
00060 }
00061
00062 all_reached = 1;
00063 for (i = 0; i < status.N_NODES; i++) {
00064 if (i != status.id){
00065 all_reached = all_reached && nstat_isReached(i);
00066 }
00067 }
00068
00069 if (all_reached){
00070 cp = wmp_get_frame_routing_pointer_new_tree(p);
00071 tree_get_next_tree(cp);
00072 tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00073 } else{
00074 cp = wmp_get_frame_routing_pointer(p);
00075 tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00076 }
00077
00078 lqm_calculate_distances();
00079 }
00080
00081
00082
00083 void encode_routing_info_pap(wmpFrame * p) {
00084 int i;
00085 char * cp_s;
00086 char * cp;
00087 char * cp_nt;
00088
00089
00090
00091 cp = wmp_get_frame_routing_pointer(p);
00092
00093
00094 print_matrix("before", lqm_get_ptr());
00095 tree_create_tree_from_lqm(cp, lqm_get_ptr());
00096 print_matrix("after", lqm_get_ptr());
00097 print_vector("done",cp);
00098 cp_s = wmp_get_frame_routing_pointer_status(p);
00099 for (i = 0; i < status.N_NODES; i++) {
00100 cp_s[i] = nstat_get_byte(i);
00101 }
00102
00103 cp_nt = wmp_get_frame_routing_pointer_new_tree(p);
00104
00105
00106 if (p->tkn.new_token && status.lastRecvdType != TOKEN) {
00107
00108
00109 memcpy(cp_nt,cp,status.N_NODES);
00110 }
00111
00112 tree_get_next_tree(cp_nt);
00113
00114 if (p->tkn.new_token) {
00115
00116 if (tree_which_best(cp,cp_nt)==2){
00117 memcpy(cp, cp_nt, status.N_NODES);
00118 }
00119 }
00120 print_vector("done2",cp);
00121 }
00122
00123 void encode_routing_info_atp_mtp(wmpFrame * p){
00124
00125 char * cp = wmp_get_frame_routing_pointer(p);
00126 tree_create_tree_from_lqm(cp,lqm_get_ptr());
00127 }
00128
00129 void decode_routing_info_atp_mtp(wmpFrame * p){
00130
00131 char * cp = wmp_get_frame_routing_pointer(p);
00132 tree_create_lqm_from_tree(lqm_get_ptr(),cp);
00133 }
00134
00135 void decode_routing_info(wmpFrame * p){
00136
00137 if (p->hdr.type == TOKEN){
00138 decode_routing_info_pap(p);
00139 } else if (p->hdr.type != DROP_TOKEN){
00140 decode_routing_info_atp_mtp(p);
00141 }
00142 }
00143
00144 void encode_routing_info(wmpFrame * p){
00145
00146 if (p->hdr.type == TOKEN){
00147 encode_routing_info_pap(p);
00148 } else if (p->hdr.type != DROP_TOKEN){
00149 encode_routing_info_atp_mtp(p);
00150 }
00151 }