📄 routing_table.c
字号:
list_destination_n=list_destination_tmp; } } } /******************* added by Y.Ge ****************/ /*** add main address of the neighbor into routingg list ***/ for(index=0;index<HASHSIZE;index++) { main_addr_neighhash=&mainaddrneightable[index]; for(main_addr_neigh=main_addr_neighhash->mainaddrneigh_forw;main_addr_neigh!=(struct main_addr_neigh_entry *)main_addr_neighhash;main_addr_neigh=main_addr_neigh->main_addr_neigh_forw) { if ((main_addr_neigh->main_addr_neigh_status != NOT_NEIGH) && (main_addr_neigh->covered_in_routing != 1)) { main_addr_neigh->covered_in_routing = 1; neighbor_any = olsr_find_sym_neighbor(main_addr_neigh); //select a SYM neighbor that connect to the main address neigghbor if (neighbor_any == NULL) { printf ("XXXXXXXXX error in find neighbor_any!\n"); exit (1); } new_route_entry=olsr_insert_routing_table(&main_addr_neigh->main_addr_neigh_addr); memcpy(&new_route_entry->rt_src, &neighbor_any->my_iface_addr, sizeof (struct olsr_ip_addr)); memcpy(&new_route_entry->rt_router, &neighbor_any->neighbor_addr, sizeof (struct olsr_ip_addr)); new_route_entry->rt_willingness = main_addr_neigh->main_addr_neigh_willingness; new_route_entry->rt_local_if = neighbor_any->my_iface_index; //added by Y.Ge /*The next router is the neighbor itself*/ new_route_entry->rt_metric=2; /*fisrt hop. may be we should use another metric*/ list_destination_tmp=(struct destination_n *)malloc(sizeof(struct destination_n)); list_destination_tmp->destination=new_route_entry; list_destination_tmp->next=list_destination_n; list_destination_n=list_destination_tmp; } } } /*** add the 2-hop-neighbors into routingg list ***/ /* find the higest willingness neighbor as the route to the 2-hop-neighbor */ for(index=0;index<HASHSIZE;index++) { hash_2_neighbor=&neighbor2table[index]; for(neighbor_2=hash_2_neighbor->neighbor2_forw;neighbor_2!=(struct neighbor_2_entry *)hash_2_neighbor;neighbor_2=neighbor_2->neighbor_2_forw) { /* find the highest willingness neighbor that the 2-hop-neighbor is connected to */ next_hop_neighbor = olsr_find_highest_willingness_neighbor(neighbor_2); if (next_hop_neighbor != NULL) { new_route_entry=olsr_insert_routing_table(&neighbor_2->neighbor_2_addr); memcpy(&new_route_entry->rt_src, &next_hop_neighbor->my_iface_addr, sizeof (struct olsr_ip_addr)); memcpy(&new_route_entry->rt_router, &next_hop_neighbor->neighbor_addr, sizeof (struct olsr_ip_addr)); new_route_entry->rt_willingness = next_hop_neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_willingness; new_route_entry->rt_local_if = next_hop_neighbor->my_iface_index; //added by Y.Ge /*The next router is the neighbor itself*/ new_route_entry->rt_metric=2; /*fisrt hop. may be we should use another metric*/ list_destination_tmp=(struct destination_n *)malloc(sizeof(struct destination_n)); list_destination_tmp->destination=new_route_entry; list_destination_tmp->next=list_destination_n; list_destination_n=list_destination_tmp; } } } /******************* end of revision **************/ return(list_destination_n);}/*------------------------------------------------------------------------*/void olsr_calculate_routing_table(){ struct destination_n *list_destination_n=NULL; struct destination_n *list_destination_n_1=NULL; struct destination_n *destination_n_1=NULL; struct topology_last_entry *topo_last; struct destination_list *topo_dest; struct rt_entry *destination_entry; struct rt_entry *returned_destination=NULL, *new_route_entry=NULL; //added by Y.Ge struct main_addr_entry *main_address; //added by Y.Ge struct main_addr_hash *main_address_hash; //added by Y.Ge struct interface_addr_list *list_of_my_interface_address; //added by Y.Ge int index; //added by Y.Ge /* For Debugging Messages: */ char tmp_my_ip_string[INET6_ADDRSTRLEN]; char str[INET6_ADDRSTRLEN]; struct destination_n *tmp_list=NULL; olsr_routing_mirror(); /*--------------------------*/ if(debug_level > 6) { printf(">>>>Etat des tables apres copie dans la mirror\n"); printf("La table de routage maintenant\n"); olsr_print_routing_table(routingtable); printf("l'acienne table de routage est:\n"); olsr_print_routing_table(mirror_table); printf("**************************************\n"); } if (debug_level > 4) { printf ("\n\n+++++++++++++++++++ olsr calculate routing table! ++++++++++++++++++++\n"); printf ("\nbefore calculation, the routing table is:\n"); olsr_print_routing_table(mirror_table); fprintf (y_file,"\n\n+++++++++++++++++++ olsr calculate routing table! ++++++++++++++++++++\n"); fprintf (y_file,"\nbefore calculation, the routing table is:\n"); olsr_print_trace_routing_table(mirror_table); } /*--------------------------*/ /* Delete old entries from the table */ /* * Y.Ge: based on the OLSR RFC, in the current implementation, * olsr_fill_routing_table_with_neighbors() not only deals with the 1-hop-neighbor, * but the 2-hop-neighbor as well */ if(debug_level >4) { printf ("\n************* fill routinting table with neighbors\n"); printf("the neighbor tables are:\n"); olsr_print_neighbor_table(); olsr_print_main_addr_neigh_table(); olsr_print_two_hop_neighbor_table(); fprintf (y_file,"\n************* fill routinting table with neighbors\n"); fprintf(y_file,"the neighbor tables are:\n"); olsr_print_trace_neighbor_table(); olsr_print_trace_main_addr_neigh_table(); olsr_print_trace_two_hop_neighbor_table(); } list_destination_n_1=olsr_fill_routing_table_with_neighbors(); /*--------------------------*/ if (debug_level > 4) { printf ("\n........after fill routing table with neighbors, the routing table is:\n"); olsr_print_routing_table(routingtable); fprintf (y_file,"\n........after fill routing table with neighbors, the routing table is:\n"); olsr_print_trace_routing_table(routingtable); } /*--------------------------*/ list_destination_n=list_destination_n_1; if (debug_level > 6) { //printf("\n\nRouting-Links List: %02d:%02d:%02d.%06lu\n",nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec, now.tv_usec); //CRC v4->v6 add //memcpy(tmp_my_ip_string, convert_address_to_string(&addr_ip),46); //memcpy(tmp_my_ip_string, convert_address_to_string(&addr_manet),46);//commented by Y.Ge tmp_list = list_destination_n_1; while(tmp_list!=NULL) { //printf("%s -> %s\n", tmp_my_ip_string, convert_address_to_string(&tmp_list->destination->rt_dst)); //printf("%s -> %s\n", tmp_my_ip_string, inet_ntop(AF_INET6,&(tmp_list->destination->rt_dst),str,sizeof(str))); //commented by Y.Ge //printf ("%s -> %s\n", inet_ntop(AF_INET6,&(tmp_list->destination->rt_src),str,sizeof(str)), inet_ntop(AF_INET6,&(tmp_list->destination->rt_dst),str,sizeof(str))); //added by Y.Ge tmp_list = tmp_list->next; } } if (debug_level >4) { printf ("\n**************** now add routing table from topology table!\n"); printf ("topology table:\n"); olsr_print_topology_table(); fprintf (y_file,"\n**************** now add routing table from topology table!\n"); fprintf (y_file,"topology table:\n"); olsr_print_trace_topology_table(); } while(list_destination_n_1!=NULL) { list_destination_n_1=NULL; while(list_destination_n!=NULL) { /*----------------------*/ if (debug_level > 6) //printf("%s+++++++++++ last hop\n",convert_address_to_string(&list_destination_n->destination->rt_dst)); printf("%s+++++++++++ last hop\n", inet_ntop(AF_INET6,&list_destination_n->destination->rt_dst,str,sizeof(str))); /*----------------------*/ if(NULL!=(topo_last=olsr_lookup_last_topology_table(&list_destination_n->destination->rt_dst))) { topo_dest=topo_last->topology_list_of_destinations; while(topo_dest!=NULL) { /* topo_dest is not in the routing table */ if(NULL==(returned_destination = olsr_lookup_routing_table(&topo_dest->destination_node->topology_destination_dst))) { /* PRINT OUT: Last Hop to Final Destination */ /* The function convert_address_to_string has to be seperately */ if (debug_level > 6) { //printf("%s -> ", convert_address_to_string(&list_destination_n->destination->rt_dst)); //printf("%s\n",convert_address_to_string(&topo_dest->destination_node->topology_destination_dst) ); printf("%s -> ",inet_ntop(AF_INET6,&list_destination_n->destination->rt_dst,str,sizeof(str))); printf("%s\n",inet_ntop(AF_INET6,&topo_dest->destination_node->topology_destination_dst,str,sizeof(str))); } destination_n_1=(struct destination_n *)malloc(sizeof(struct destination_n)); destination_n_1->destination=olsr_insert_routing_table_from_topo(list_destination_n->destination,topo_dest->destination_node); destination_n_1->next=list_destination_n_1; list_destination_n_1=destination_n_1; } /********************* added by Y.Ge ***************/ /* * check if we can optimize current route * in terms of willingness, hop-count, etc */ else { if (returned_destination->rt_metric >= list_destination_n->destination->rt_metric + 1) { if (returned_destination->rt_metric > list_destination_n->destination->rt_metric + 1) { /* update the routing entry to reduce the number of hops */ returned_destination->rt_flags = (RTF_UP|RTF_HOST|RTF_GATEWAY); memcpy(&returned_destination->rt_router, &list_destination_n->destination->rt_router, sizeof (struct olsr_ip_addr)); memcpy(&returned_destination->rt_src, &list_destination_n->destination->rt_src,sizeof (struct olsr_ip_addr)); returned_destination->rt_metric = list_destination_n->destination->rt_metric + 1; returned_destination->rt_willingness = list_destination_n->destination->rt_willingness; returned_destination->rt_local_if = list_destination_n->destination->rt_local_if; destination_n_1=(struct destination_n *)malloc(sizeof(struct destination_n)); destination_n_1->destination = returned_destination; destination_n_1->next=list_destination_n_1; list_destination_n_1=destination_n_1; } else { /* Y.Ge : Do we need to do so??? */ if (returned_destination->rt_willingness < list_destination_n->destination->rt_willingness) { /* update the routing entry to increase the willingness */ returned_destination->rt_flags = (RTF_UP|RTF_HOST|RTF_GATEWAY); memcpy(&returned_destination->rt_router, &list_destination_n->destination->rt_router, sizeof (struct olsr_ip_addr)); memcpy(&returned_destination->rt_src, &list_destination_n->destination->rt_src,sizeof (struct olsr_ip_addr)); returned_destination->rt_metric = list_destination_n->destination->rt_metric + 1; returned_destination->rt_willingness = list_destination_n->destination->rt_willingness; returned_destination->rt_local_if = list_destination_n->destination->rt_local_if; destination_n_1=(struct destination_n *)malloc(sizeof(struct destination_n)); destination_n_1->destination = returned_destination; destination_n_1->next=list_destination_n_1; list_destination_n_1=destination_n_1; } } } } /******************** end of revision *************/ topo_dest=topo_dest->next; } } destination_n_1=list_destination_n; list_destination_n=list_destination_n->next; free(destination_n_1); } list_destination_n=list_destination_n_1; } if (debug_level > 6) { printf("End of Routing-Links List.\n"); fflush(stdout); } /*--------------------------*/ if (debug_level > 4) { printf ("\n..........after fill routing table with topology table, the routing table is:\n"); olsr_print_routing_table(routingtable); fprintf (y_file,"\n..........after fill routing table with topology table, the routing table is:\n"); olsr_print_trace_routing_table(routingtable); } /************************* added by Y.Ge ************************/ /* look at MID table */ if(debug_level > 4) { printf("\n************ now adding routint table from MID table\n"); olsr_print_main_address_table(); fprintf(y_file,"\n************ now adding routint table from MID table\n"); olsr_print_trace_main_address_table(); } /*--------------------------*/ for (index=0; index<HASHSIZE; index++) { main_address_hash = &nodemainaddresstable[index]; for (main_address=main_address_hash->mainaddress_forw; main_address!=(struct main_addr_entry *)main_address_hash;main_address=main_address->main_addr_forw) { if(NULL!=(returned_destination = olsr_lookup_routing_table(&main_address->node_main_address))) { list_of_my_interface_address = main_address->list_of_interfaceaddress; while (list_of_my_interface_address!=NULL) { //printf ("%s, ", convert_address_to_string(&list_of_my_interface_address->interface_addresses->node_interface_address)); if (NULL==olsr_lookup_routing_table(&list_of_my_interface_address->interface_addresses->node_interface_address)) { new_route_entry=olsr_insert_routing_table(&list_of_my_interface_address->interface_addresses->node_interface_address); memcpy(&new_route_entry->rt_src, &returned_destination->rt_src, sizeof (struct olsr_ip_addr)); //added by Y.Ge memcpy(&new_route_entry->rt_router,&returned_destination->rt_router,sizeof(struct olsr_ip_addr)); new_route_entry->rt_flags=(RTF_UP|RTF_HOST); new_route_entry->rt_willingness = returned_destination->rt_willingness; //added by Y.Ge new_route_entry->rt_local_if = returned_destination->rt_local_if; //added by Y.Ge /*The next router is the neighbor itself*/ /* attention! different from the RFC */ /* in RFC, it should be - new_route_entry->rt_metric=returned_destination->rt_metric */ /* That is NOT corrrect ! */ new_route_entry->rt_metric=returned_destination->rt_metric+1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -