📄 routing_table.c
字号:
new_rt_entry->rt_local_if = list_destination_n->destination->rt_entry_infos.rtu_local_if; destination_n_1=(struct destination_n *)malloc(sizeof(struct destination_n)); destination_n_1->destination = new_rt_entry; destination_n_1->next=list_destination_n_1; list_destination_n_1=destination_n_1; if (debug_level > 5) { printf ("after update old entries, the routing table is:\n"); qos_olsr_print_routing_table (routingtable); fprintf (y_file,"after update old entries, the routing table is:\n"); qos_olsr_print_trace_routing_table (routingtable); } } } } 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; } /* 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; /* qos OLSR */ new_route_entry->rt_busy = returned_destination->rt_busy; } list_of_my_interface_address=list_of_my_interface_address->next; } } } } //CRC add for HNA olsr_add_routing_table_with_hna(); if(debug_level > 4) { printf ("\n********************** after calculate routing table, the routing table is: ********************\n"); qos_olsr_print_routing_table(routingtable); fprintf (y_file,"\n********************** after calculate routing table, the routing table is: ********************\n"); qos_olsr_print_trace_routing_table(routingtable); } /*-----------------*/ olsr_update_kernel_routes(); olsr_release_routing_table(mirror_table);}/*------------------------------------------------------------------------*/voidolsr_print_trace_routing_table(struct rthash *table){ struct rt_entry *destination; struct rthash *routing_hash; olsr_u8_t index; char str[INET6_ADDRSTRLEN]; fprintf(y_file,"\n\nROUTING TABLE\n"); fprintf(y_file,"DESTINATION \tSOURCE \tNEXT HOP \tINTERFACE \tMETRIC\n"); for(index=0;index<HASHSIZE;index++) { routing_hash=&table[index]; for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw) { //printf("%s ",convert_address_to_string(&destination->rt_dst)); //printf("%s \n ",convert_address_to_string(&destination->rt_router)); fprintf(y_file,"%s ",inet_ntop(AF_INET6,&destination->rt_dst,str,sizeof(str))); fprintf(y_file,"\t%s ",inet_ntop(AF_INET6,&destination->rt_src,str,sizeof(str))); fprintf(y_file,"\t%s ",inet_ntop(AF_INET6,&destination->rt_router,str,sizeof(str))); fprintf(y_file,"\t%d ", destination->rt_local_if); fprintf(y_file,"\t%d\n",destination->rt_metric); } }}/*------------------------------------------------------------------------*/voidqos_olsr_print_routing_table(struct rthash *table){ struct rt_entry *destination; struct rthash *routing_hash; olsr_u8_t index; char str[INET6_ADDRSTRLEN]; printf("\n\nROUTING TABLE\n"); printf("DESTINATION \tSOURCE \tNEXT HOP \tINTERFACE \tMETRIC \tBUSYTIME\n"); for(index=0;index<HASHSIZE;index++) { routing_hash=&table[index]; for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw) { //printf("%s ",convert_address_to_string(&destination->rt_dst)); //printf("%s \n ",convert_address_to_string(&destination->rt_router)); printf("%s ",inet_ntop(AF_INET6,&destination->rt_dst,str,sizeof(str))); printf("\t%s ",inet_ntop(AF_INET6,&destination->rt_src,str,sizeof(str))); printf("\t%s ",inet_ntop(AF_INET6,&destination->rt_router,str,sizeof(str))); printf("\t%d ", destination->rt_local_if); printf("\t%d",destination->rt_metric); printf("\t%d\n", destination->rt_busy); } }}voidqos_olsr_print_trace_routing_table(struct rthash *table){ struct rt_entry *destination; struct rthash *routing_hash; olsr_u8_t index; char str[INET6_ADDRSTRLEN]; fprintf(y_file,"\n\nROUTING TABLE\n"); fprintf(y_file,"DESTINATION \tSOURCE \tNEXT HOP \tINTERFACE \tMETRIC \tBUSYTIME\n"); for(index=0;index<HASHSIZE;index++) { routing_hash=&table[index]; for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw) { //printf("%s ",convert_address_to_string(&destination->rt_dst)); //printf("%s \n ",convert_address_to_string(&destination->rt_router)); fprintf(y_file,"%s ",inet_ntop(AF_INET6,&destination->rt_dst,str,sizeof(str))); fprintf(y_file,"\t%s ",inet_ntop(AF_INET6,&destination->rt_src,str,sizeof(str))); fprintf(y_file,"\t%s ",inet_ntop(AF_INET6,&destination->rt_router,str,sizeof(str))); fprintf(y_file,"\t%d ", destination->rt_local_if); fprintf(y_file,"\t%d",destination->rt_metric); fprintf(y_file,"\t%d\n", destination->rt_busy); } }}/****************** end of revision ****************//*------------------------------------------------------------------------*/voidolsr_print_routing_table(struct rthash *table){ struct rt_entry *destination; struct rthash *routing_hash; olsr_u8_t index; char str[INET6_ADDRSTRLEN]; printf("\n\nROUTING TABLE\n"); printf("DESTINATION \tSOURCE \tNEXT HOP \tINTERFACE \tMETRIC\n"); for(index=0;index<HASHSIZE;index++) { routing_hash=&table[index]; for(destination=routing_hash->rt_forw;destination!=(struct rt_entry *)routing_hash;destination=destination->rt_forw) { //printf("%s ",convert_address_to_string(&destination->rt_dst)); //printf("%s \n ",convert_address_to_string(&destination->rt_router)); printf("%s ",inet_ntop(AF_INET6,&destination->rt_dst,str,sizeof(str))); printf("\t%s ",inet_ntop(AF_INET6,&destination->rt_src,str,sizeof(str))); printf("\t%s ",inet_ntop(AF_INET6,&destination->rt_router,str,sizeof(str))); printf("\t%d ", destination->rt_local_if); printf("\t%d\n",destination->rt_metric); } }}/*------------------------------------------------------------------------*///CRC add for HNA/*------------------------------------------------------------------------*/void olsr_copy_routing_table(struct rthash *table){ /*copy a routing table from previous the mirror table*/ olsr_u32_t index; struct rthash *table_hash; struct rt_entry *destination; struct rt_entry *start_entry=NULL, *new_entry=NULL; for(index=0;index<HASHSIZE;index++) { if(table[index].rt_forw==(struct rt_entry *)&table[index]) { routingtable[index].rt_forw=(struct rt_entry *)&routingtable[index]; routingtable[index].rt_back=(struct rt_entry *)&routingtable[index]; } else { table_hash=&table[index]; for(destination=table_hash->rt_forw;destination!=(struct rt_entry *)table_hash;destination=destination->rt_forw) { if(destination==table_hash->rt_forw) { start_entry=(struct rt_entry *)malloc(sizeof(struct rt_entry)); memcpy(start_entry,destination,sizeof(struct rt_entry)); new_entry=start_entry; } else { new_entry->rt_forw=(struct rt_entry *)malloc(sizeof(struct rt_entry)); memcpy(new_entry->rt_forw,destination,sizeof(struct rt_entry)); new_entry->rt_forw->rt_back=new_entry; new_entry=new_entry->rt_forw; } } routingtable[index].rt_forw=start_entry; routingtable[index].rt_forw->rt_back=(struct rt_entry *)&routingtable[index]; routingtable[index].rt_back=new_entry; routingtable[index].rt_back->rt_forw=(struct rt_entry *)&routingtable[index]; } }} void olsr_add_routing_table_with_hna(){ olsr_u32_t index; olsr_u16_t shortest_metric; struct hna_subnet_hash *subnet_hash_hna; struct hna_subnet_entry *subnet_entry; struct host_list *list_of_hosts; struct rt_entry *host_rt_entry; struct rt_entry *shortest_rt_entry; struct rt_entry *net_rt_entry; if(debug_level > 4) { printf("\n************ now adding routint table from HNA table\n"); olsr_print_hna_host_table(); olsr_print_hna_subnet_table(); fprintf(y_file,"\n************ now adding routint table from HNA table\n"); olsr_print_trace_hna_host_table(); olsr_print_trace_hna_subnet_table(); } for(index=0;index<HASHSIZE;index++) { subnet_hash_hna=&hnasubnettable[index]; for(subnet_entry=subnet_hash_hna->hna_subnet_forw;subnet_entry!=(struct hna_subnet_entry*)subnet_hash_hna;subnet_entry=subnet_entry->hna_subnet_forw) { shortest_metric=10000; shortest_rt_entry=NULL; for(list_of_hosts=subnet_entry->hna_list_of_host;list_of_hosts!=NULL;list_of_hosts=list_of_hosts->next) { if(NULL!=(host_rt_entry=olsr_lookup_routing_table(&(list_of_hosts->host->hna_host_addr)))) if(shortest_metric>host_rt_entry->rt_metric) { shortest_metric=host_rt_entry->rt_metric; //"+1" is added by Y.Ge shortest_rt_entry=host_rt_entry; } } if(NULL!=shortest_rt_entry) { /*add a new net entry into routing table*/ net_rt_entry=olsr_insert_routing_table(&(subnet_entry->hna_subnet_addr)); net_rt_entry->rt_dst_prefix=subnet_entry->hna_subnet_prefix; memcpy(&(net_rt_entry->rt_router),&(shortest_rt_entry->rt_router),sizeof(struct olsr_ip_addr)); net_rt_entry->rt_router_prefix=shortest_rt_entry->rt_router_prefix; net_rt_entry->rt_metric=shortest_rt_entry->rt_metric+1; //"+1" is added by Y.Ge net_rt_entry->rt_flags=0; net_rt_entry->rt_flags=(RTF_UP|RTF_GATEWAY); net_rt_entry->rt_local_if = shortest_rt_entry->rt_local_if; //added by Y.Ge memcpy(&(net_rt_entry->rt_src), &(shortest_rt_entry->rt_src), sizeof(struct olsr_ip_addr)); //added by Y.Ge } } }}voidolsr_modify_routing_table_from_hna(){ olsr_routing_mirror(); olsr_copy_routing_table(mirror_table); if(debug_level > 4) { printf("\n************ now modify routing table from HNA table\n"); olsr_print_hna_host_table(); olsr_print_hna_subnet_table(); fprintf(y_file,"\n************ now modify routing table from HNA table\n"); olsr_print_trace_hna_host_table(); olsr_print_trace_hna_subnet_table(); } olsr_add_routing_table_with_hna(); olsr_update_kernel_routes(); olsr_release_routing_table(mirror_table);}/*-------------------------------------------------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -