📄 olsr.c
字号:
count++; twohop_neighbors=twohop_neighbors->neighbor_2_next; } a_neighbor->neighbor_2_nocov=count; *two_hop_count= *two_hop_count+count; } }}/*--------------------------------------------------------------------------*/struct neighbor_entry *olsr_find_maximum_covered(int willingness) //"willingness" is added by Y.Ge, define which willingness of the neighbor we should look in this round{ olsr_u16_t maximum=0; olsr_u8_t index; struct neighborhash *neighbor_hash_table; struct neighbor_entry *a_neighbor; struct neighbor_entry *mpr_candidate=NULL; neighbor_hash_table=neighbortable.neighborhash; for (index=0;index<HASHSIZE;index++) { for(a_neighbor=neighbor_hash_table[index].neighbor_forw;a_neighbor!=(struct neighbor_entry *)&neighbor_hash_table[index];a_neighbor=a_neighbor->neighbor_forw) { /* if(maximum<a_neighbor->neighbor_2_nocov) */ //commented by Y.Ge /* added by Y.Ge * choose the certain willingness neighbor * as MPR */ if((maximum<a_neighbor->neighbor_2_nocov) && (a_neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_willingness == willingness)) { maximum=a_neighbor->neighbor_2_nocov; mpr_candidate=a_neighbor; } } } return (mpr_candidate);}/*----------------------------------------------------------------------------*/voidolsr_calculate_mpr() { /*This function calculates the mpr neighbor*/ olsr_u16_t two_hop_covered_count=0; olsr_u16_t two_hop_count=0; struct neighbor_2_list_entry *two_hop_list=NULL; struct neighbor_2_list_entry *tmp; struct neighbor_entry *mprs; struct iface_addr_list_entry *will_always_neighbor=NULL; //added by Y.Ge struct iface_addr_list_entry *will_always_tmp; //added by Y.Ge int i, should_try_next=0; //added by Y.Ge /*************** added by Y.Ge *************/ /* first, re-set the status in the main_addr_neigh_table*/ olsr_clear_main_addr_neigh_table_mpr_status(); /*************** end of revision ***********/ olsr_calculate_neighbors(&two_hop_count); two_hop_list=olsr_find_2_hop_neighbors_with_1_link(); /*************** added by Y.Ge *************/ /* select neighbor who's wilingness is WILL_ALWAYS as MPR */ /* * the function is added after "olsr_find_2_hop_neighbors_with_1_link()" * because the neighbor_2_covered status is initialized in * olsr_find_2_hop_neighbors_with_1_link() */ will_always_neighbor = olsr_find_will_always_neighbor(); if (debug_level >3) { printf ("\n\n-------------- Node is selecting MPRs! ----------\n"); printf ("my two hop neighbor count is: %d\n", two_hop_count); printf ("I have following neighbor as my WILL_ALWAYS neighbor:\n"); fprintf (y_file,"\n\n-------------- Node is selecting MPRs! ----------\n"); fprintf (y_file,"my two hop neighbor count is: %d\n", two_hop_count); fprintf (y_file,"I have following neighbor as my WILL_ALWAYS neighbor:\n"); } while(will_always_neighbor != NULL) { if (debug_level >3) { printf ("WILL_ALWAYS neighbor: %s\n", convert_address_to_string(&will_always_neighbor->neighbor_iface->neighbor_addr)); fprintf (y_file,"WILL_ALWAYS neighbor: %s\n", convert_address_to_string(&will_always_neighbor->neighbor_iface->neighbor_addr)); } olsr_chosen_mpr(will_always_neighbor->neighbor_iface, &two_hop_covered_count); will_always_tmp = will_always_neighbor; will_always_neighbor = will_always_neighbor->iface_addr_next; free (will_always_tmp); } /*************** end of revission *************/ /*--------------------*/ if(debug_level > 3) { printf(" AFTER choose WILL_ALWAYS neighbor as mpr, Two hop count: %d\n",two_hop_count); printf("\nnow looking at 2-hop-neighbors that only have one link. these nodes are:\n"); fprintf(y_file," AFTER choose WILL_ALWAYS neighbor as mpr, Two hop count: %d\n",two_hop_count); fprintf(y_file,"\nnow looking at 2-hop-neighbors that only have one link. these nodes are:\n"); } /*--------------------*/ while(two_hop_list!=NULL) { if (debug_level > 3) { printf ("1-LINK-2-HOP-NEIGHBOR:%s\n",convert_address_to_string(&two_hop_list->neighbor_2->neighbor_2_nblist->neighbor->neighbor_addr)); fprintf (y_file,"1-LINK-2-HOP-NEIGHBOR:%s\n",convert_address_to_string(&two_hop_list->neighbor_2->neighbor_2_nblist->neighbor->neighbor_addr)); } olsr_chosen_mpr(two_hop_list->neighbor_2->neighbor_2_nblist->neighbor,&two_hop_covered_count); tmp=two_hop_list; two_hop_list=two_hop_list->neighbor_2_next;; free(tmp); } /*---------------------*/ if(debug_level > 3) { printf(" AFTER select 1-link-2-hop-neighbor, Two hops covered: %d\n",two_hop_covered_count); printf(" \nnow looking at remaining 2-hop-neighbors\n"); fprintf(y_file," AFTER select 1-link-2-hop-neighbor, Two hops covered: %d\n",two_hop_covered_count); fprintf(y_file," \nnow looking at remaining 2-hop-neighbors\n"); } /*---------------------*/ /*while(two_hop_covered_count<two_hop_count) { mprs=olsr_find_maximum_covered(); if (mprs!=NULL) { olsr_chosen_mpr(mprs,&two_hop_covered_count); } }*/ //commented by Y.Ge, see the following /************** added by Y.Ge *************/ /* * do based on the OLSR RFC - choose the one that has the highest willingness as MPR */ for (i=WILL_HIGH; i>WILL_NEVER; i--) { if (debug_level > 3) { printf ("...looking at willingness %d in this round\n", i); fprintf (y_file,"...looking at willingness %d in this round\n", i); } should_try_next=0; while(two_hop_covered_count<two_hop_count && (!should_try_next)) { /* qos OLSR */ if (use_qos) mprs = olsr_find_maximum_covered_with_qos(i); //i is the willingness that we should look in this round else mprs = olsr_find_maximum_covered(i); //i is the willingness that we should look in this round if (mprs!=NULL) { if (debug_level > 3) { printf ("MPR:%s\n", convert_address_to_string(&mprs->neighbor_addr)); fprintf (y_file,"MPR:%s\n", convert_address_to_string(&mprs->neighbor_addr)); } olsr_chosen_mpr(mprs,&two_hop_covered_count); } else { should_try_next=1; } } } /*************** end of revision ***********/ /* increment the mpr sequence number */ neighbortable.neighbor_mpr_seq++;}/*-----------------------------------------------------------------------------*//************** added by Y.Ge ************//*** compute vtime ***/olsr_u8_tolsr_compute_vtime (int input_time){ olsr_u8_t vtime_value; int a, b; //printf ("/************** in olsr_compute_vtime *************/\n"); //printf (" the input time is: %d\n", input_time); b = (int)((log((double)input_time * SCALING_FACTOR))/(log((double)2))); //printf ("b = %d\n", b); a = (int)(16*((double)input_time/((double)pow(2,b)/SCALING_FACTOR)-1)); //printf ("a = %d\n", a); if (a==16) { a = 0; b += 1; } vtime_value = (olsr_u8_t) a*16 + b; //printf (" a = %d, b=%d\n", a,b); //printf (" vtime_value is: %d\n", vtime_value); //printf ("\n"); return vtime_value; } /************* end of revision **********//*-----------------------------------------------------------------------------*/floatolsr_compute_time_from_vtime (olsr_u8_t vtime_value){ int result_time; int a,b; a = (int)vtime_value/16; b = vtime_value - a*16; result_time = ((1+(double)a/16)*pow(2,b))/SCALING_FACTOR; return result_time;}/*-----------------------------------------------------------------------------*/intolsr_timed_out(struct timeval *timer){ return( timercmp(timer,&now,<));}/*-----------------------------------------------------------------------------*/voidolsr_init_timer(olsr_u32_t time_value,struct timeval *hold_timer){ olsr_u16_t time_value_sec=0; olsr_u16_t time_value_msec=0; time_value_sec=time_value/1000; time_value_msec=time_value-(time_value_sec*1000); hold_timer->tv_sec=time_value_sec; hold_timer->tv_usec=time_value_msec*1000; }/*-----------------------------------------------------------------------------*//************* added by Y.Ge ************/voidolsr_assign_timer(const struct timeval *given_timer, struct timeval *change_timer){ change_timer->tv_sec = given_timer->tv_sec; change_timer->tv_usec = given_timer->tv_usec;}/*-----------------------------------------------------------------------------*/voidtimerminus (struct timeval *change_timer){ change_timer->tv_sec = -1;}/*-----------------------------------------------------------------------------*/olsr_u8_tcompare_timer(const struct timeval *timer_a, const struct timeval *timer_b){ if (timer_a->tv_sec > timer_b->tv_sec) return 1; else { if (timer_a->tv_sec == timer_b->tv_sec) { if (timer_a->tv_usec > timer_b->tv_usec) return 1; } return 0; } return 0;}/************* end of revision **********//*-------------------------------------------------------------------------*/voidolsr_linking_this_2_entries(struct neighbor_entry *neighbor,struct neighbor_2_entry *two_hop_neighbor){ struct neighbor_list_entry *list_of_1_neighbors; struct neighbor_2_list_entry *list_of_2_neighbors; list_of_1_neighbors=(struct neighbor_list_entry *)malloc(sizeof(struct neighbor_list_entry)); list_of_2_neighbors=(struct neighbor_2_list_entry *)malloc(sizeof(struct neighbor_2_list_entry)); list_of_1_neighbors->neighbor=neighbor; list_of_1_neighbors->neighbor_next=two_hop_neighbor->neighbor_2_nblist; two_hop_neighbor->neighbor_2_nblist=list_of_1_neighbors; list_of_2_neighbors->neighbor_2=two_hop_neighbor; timeradd(&now,&hold_time_neighbor,&list_of_2_neighbors->neighbor_2_timer); list_of_2_neighbors->neighbor_2_next=neighbor->neighbor_2_list; neighbor->neighbor_2_list=list_of_2_neighbors; /*increment the pointer counter*/ two_hop_neighbor->neighbor_2_pointer++;}/*-------------------------------------------------------------------------*//***************** added by Y.Ge **************/voidolsr_linking_neighbor_main_neighbor(struct neighbor_entry *neighbor,struct main_addr_neigh_entry *main_address_neighbor){ struct iface_addr_list_entry *list_of_iface_neighbors; struct link_to_main_neighbor *main_neighbor_link; list_of_iface_neighbors=(struct iface_addr_list_entry *)malloc(sizeof(struct iface_addr_list_entry)); main_neighbor_link=(struct link_to_main_neighbor *)malloc(sizeof(struct link_to_main_neighbor)); list_of_iface_neighbors->neighbor_iface=neighbor; list_of_iface_neighbors->iface_addr_next=main_address_neighbor->neigh_iface_list; main_address_neighbor->neigh_iface_list=list_of_iface_neighbors; main_neighbor_link->main_neighbor=main_address_neighbor; neighbor->neighbor_main_info=main_neighbor_link; main_address_neighbor->interface_pointer++; }/*-------------------------------------------------------------------------*/intolsr_lookup_my_own_address (struct olsr_ip_addr *rcvd_interface_addr){ int i; for (i=0; i<num_of_interface; i++) { if (0==memcmp(rcvd_interface_addr,&addr_manet[i],sizeof(struct olsr_ip_addr))) return 1; } return 0;}/*************** end of revision **************//*-------------------------------------------------------------------------*//*handle the neighbor linked list in the HELLO message*/voidolsr_process_message_neighbors(struct neighbor_entry *neighbor,struct hello_message *message, int iface_index) //"iface_index" added by Y.Ge{ olsr_u8_t ok_insert=0;// boolean struct hello_neighbor *message_neighbors; struct neighbor_entry *in_neighbor; struct neighbor_2_list_entry *two_hop_neighbor_yet; struct neighbor_2_entry *two_hop_neighbor; float rcvd_vtime; //added by Y.Ge struct timeval hold_time_tmp; //added by Y.Ge struct iface_addr_entry *message_neighbor_interface_address; //added by Y.Ge struct main_addr_entry *message_neighbor_main_address; //added by Y.Ge struct olsr_ip_addr *rcvd_main_address; //added by Y.Ge struct main_addr_neigh_entry *in_main_addr_neighbor; //added by Y.Ge struct neighbor_2_list_entry *two_hop_list; //added by Y.Ge
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -