📄 olsr.c
字号:
struct neighbor_2_list_entry *two_hop_list_tmp; //added by Y.Ge struct neighbor_2_entry *two_hop_entry; //added by Y.Ge struct topology_last_entry *t_last; //added by Y.Ge struct destination_list *topo_dest; //added by Y.Ge struct destination_list *topo_dest_tmp; //added by Y.Ge struct topology_destination_entry *dest_entry; //added by Y.Ge int count=0; rcvd_vtime = olsr_compute_time_from_vtime(message->v_time); //added by Y.Ge olsr_init_timer(rcvd_vtime*1000,&hold_time_tmp); //added by Y.Ge , rcvd v_time if (debug_level > 3) { printf ("\n\n-------------- in process message neighbors ----------------\n"); printf ("the HELLO sender's main status is: %d\n", neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status); fprintf (y_file,"\n\n-------------- in process message neighbors ----------------\n"); fprintf (y_file,"the HELLO sender's main status is: %d\n", neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status); } message_neighbors=message->neighbors; while(message_neighbors!=NULL) { if (debug_level > 3) { printf ("\n\n...now looking at message neighbbor %s\n", convert_address_to_string(&message_neighbors->address)); fprintf (y_file,"\n\n...now looking at message neighbbor %s\n", convert_address_to_string(&message_neighbors->address)); } /* the one hop neighbor is not the host*/ //CRC modify //if(0!=memcmp(&message_neighbors->address,&addr_ip,sizeof(struct olsr_ip_addr))) //commented by Y.Ge if (olsr_lookup_my_own_address (&message_neighbors->address)==0) //added by Y.Ge { if (debug_level > 3) { printf (" this message neighbor is not my self!\n"); fprintf (y_file," this message neighbor is not my self!\n"); } /******************* added by Y.Ge ********************/ /*find main address of the message neighbor from MID */ message_neighbor_interface_address = olsr_lookup_interface_address_table (&message_neighbors->address); if (message_neighbor_interface_address == NULL) { if (debug_level > 3) { printf (" -- the message neighbor is NOT an interface address\n"); fprintf (y_file," -- the message neighbor is NOT an interface address\n"); } rcvd_main_address = &(message_neighbors->address); } else { if (debug_level > 3) { printf (" the neighbor have main address\n"); fprintf (y_file," the neighbor have main address\n"); } message_neighbor_main_address = message_neighbor_interface_address->node_mainaddress->mainaddress; rcvd_main_address = &(message_neighbor_main_address->node_main_address); } if (debug_level > 3) { printf (" the main address of this neighbor is: %s\n", convert_address_to_string(rcvd_main_address)); fprintf (y_file," the main address of this neighbor is: %s\n", convert_address_to_string(rcvd_main_address)); } /******************* end of revision *****************/ /*the one hop neighbor is NBS_SYM or NBS_MPR status*/ //if((message_neighbors->status==NBS_SYM)||(message_neighbors->status==NBS_MPR))//commented by Y.Ge if(((message_neighbors->neigh_status==SYM_NEIGH)||(message_neighbors->neigh_status==MPR_NEIGH))&& neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status!=NOT_NEIGH)//added by Y.Ge { if (debug_level > 3) { printf ("-- the message neighbor has a sym_link!\n"); fprintf (y_file,"-- the message neighbor has a sym_link!\n"); } //if((two_hop_neighbor_yet=olsr_lookup_my_neighbors(neighbor,&message_neighbors->address))!=NULL) //commented by Y.Ge if((two_hop_neighbor_yet=olsr_lookup_my_neighbors(neighbor,rcvd_main_address))!=NULL) //added by Y.Ge (use main address) { if (debug_level > 3) { printf ("-- the message neighbor is my two hop neighbor\n"); fprintf (y_file,"-- the message neighbor is my two hop neighbor\n"); } /* Updating the holding time for this neighbor */ //timeradd(&now,&hold_time_neighbor,&two_hop_neighbor_yet->neighbor_2_timer); //commented by Y.Ge timeradd(&now, &hold_time_tmp, &two_hop_neighbor_yet->neighbor_2_timer); //added by Y.Ge /*-------------------*/ if(debug_level > 3) { printf("%s=============>Update second hop neighbor time\n",convert_address_to_string(&message_neighbors->address)); fprintf(y_file,"%s=============>Update second hop neighbor time\n",convert_address_to_string(&message_neighbors->address)); } /*-------------------*/ } else { /*-------------------*/ if(debug_level > 3) { printf ("-- the message neighbor is not my two hop neighbor!\n"); printf("%s=============>MAYBE A new second hop neighbor\n",convert_address_to_string(&message_neighbors->address)); fprintf (y_file,"-- the message neighbor is not my two hop neighbor!\n"); fprintf(y_file,"%s=============>MAYBE A new second hop neighbor\n",convert_address_to_string(&message_neighbors->address)); } /*-------------------*/ /* Looking if this node is already in the two hop neighbor table!!! */ /* Y.Ge: use the main address! */ //if((two_hop_neighbor=olsr_lookup_two_hop_neighbor_table(&message_neighbors->address))==NULL) //commented by Y.Ge if((two_hop_neighbor=olsr_lookup_two_hop_neighbor_table(rcvd_main_address))==NULL) //added by Y.Ge { if (debug_level > 3) { printf ("-- this message neighbor is NOT in the two hop neighbor table!\n"); fprintf (y_file,"-- this message neighbor is NOT in the two hop neighbor table!\n"); } /*this node is not in the two hop neighbor table*/ ok_insert=0; /* This node will be inserted in the two hop neighbor table even if it exist in the neighbor table with the status ASYM or LOST. In this way we can have connectivity with this neighbor */ /* Y.Ge: we should look at main address neighbor table AND also the neighbor(link)table */ /*if((in_neighbor=olsr_lookup_neighbor_table(&message_neighbors->address))!=NULL) { if((in_neighbor->neighbor_status==NBS_ASYM)||(in_neighbor->neighbor_status==NBS_LOST)||(in_neighbor->neighbor_status==NBS_PENDING)) //commented by Y.Ge ok_insert=1; }*/ //commented by Y.Ge /************************* added by Y.Ge *******************/ in_neighbor = olsr_lookup_neighbor_table(&message_neighbors->address, &addr_manet[iface_index]); if (in_neighbor==NULL) { if (debug_level > 3) { printf (" --- the sender is NOT in my neighbor table!\n"); fprintf (y_file," --- the sender is NOT in my neighbor table!\n"); } if ((in_main_addr_neighbor=olsr_lookup_main_addr_neigh_table(rcvd_main_address))!=NULL) { if (debug_level > 3) { printf (" it is in the main_address_neighbor table!\n"); printf ("_____ address: %s, status:%d\n", convert_address_to_string(&in_main_addr_neighbor->main_addr_neigh_addr), in_main_addr_neighbor->main_addr_neigh_status); fprintf (y_file," it is in the main_address_neighbor table!\n"); fprintf (y_file,"_____ address: %s, status:%d\n", convert_address_to_string(&in_main_addr_neighbor->main_addr_neigh_addr), in_main_addr_neighbor->main_addr_neigh_status); } if(in_main_addr_neighbor->main_addr_neigh_status == NOT_NEIGH) ok_insert = 1; } else ok_insert=1; } else { if (debug_level > 3) { printf (" --- the sender is in my neighbor table, its status is:%d!\n", in_neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status); fprintf (y_file," --- the sender is in my neighbor table, its status is:%d!\n", in_neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status); } if (in_neighbor->neighbor_main_info->main_neighbor->main_addr_neigh_status == NOT_NEIGH) ok_insert=1; } /************************* end of revision *****************/ if(ok_insert) { if (debug_level > 3) { printf("%s=============>IT IS A new second hop neighbor\n",convert_address_to_string(rcvd_main_address)); fprintf(y_file,"%s=============>IT IS A new second hop neighbor\n",convert_address_to_string(rcvd_main_address)); } changes_neighborhood=UP; changes_topology=UP; two_hop_neighbor=(struct neighbor_2_entry *)malloc(sizeof(struct neighbor_2_entry)); two_hop_neighbor->neighbor_2_nblist=NULL; two_hop_neighbor->neighbor_2_pointer=0; //memcpy(&two_hop_neighbor->neighbor_2_addr,&message_neighbors->address,sizeof(struct olsr_ip_addr)); //commented by Y.Ge memcpy(&two_hop_neighbor->neighbor_2_addr,rcvd_main_address,sizeof(struct olsr_ip_addr)); //added by Y.Ge, use main address olsr_insert_two_hop_neighbor_table(two_hop_neighbor); olsr_linking_this_2_entries(neighbor,two_hop_neighbor); } } else { if (debug_level > 3) { printf ("-- this message neighbor is in the two hop neighbor table!\n"); fprintf (y_file,"-- this message neighbor is in the two hop neighbor table!\n"); } /* linking to this two_hop_neighbor entry */ /*this node is already in the two hop neighbor table*/ olsr_linking_this_2_entries(neighbor,two_hop_neighbor); /******** added by Y.Ge ***********/ /* * the hello sender has one more 2-hop-neighbor, * reselect MPR! */ changes_neighborhood=UP; changes_topology=UP; /************** end of revision ********/ } } } /******************* added by Y.Ge ****************/ /* only the HELLO sender who is a SYM neighbor of me can have 2 hop neighbors */ /* delete this neighbor's two hop neighbor if the neighbor status in the message is NOT_NEIGH */ else { if (debug_level > 3) { printf (" ----- this message neighbor or its HELLO sender is not a SYM neighbor, check if it is in the two hop list!\n"); fprintf (y_file," ----- this message neighbor or its HELLO sender is not a SYM neighbor, check if it is in the two hop list!\n"); } two_hop_list = neighbor->neighbor_2_list; neighbor->neighbor_2_list = NULL; while (two_hop_list != NULL) { /* * check both message neighbor's interface address and main address * incase the MID has not been received */ if((0==memcmp(rcvd_main_address, &two_hop_list->neighbor_2->neighbor_2_addr, sizeof(struct olsr_ip_addr))) || (0 == memcmp(&message_neighbors->address, &two_hop_list->neighbor_2->neighbor_2_addr, sizeof(struct olsr_ip_addr)))) { /* node exist in two_hop_neighbor list, delete it */ if (debug_level > 3) { printf (" ----- it is in the two hop list from the HELLO sender! DELETE IT!!!\n"); } two_hop_entry=two_hop_list->neighbor_2; two_hop_entry->neighbor_2_pointer --; olsr_delete_neighbor_pointer(two_hop_entry, &neighbor->neighbor_addr); if (two_hop_entry->neighbor_2_pointer<1) { olsr_remque((struct olsr_qelem *)two_hop_entry); free ((void *) two_hop_entry); } two_hop_list_tmp = two_hop_list; two_hop_list = two_hop_list->neighbor_2_next; free (two_hop_list_tmp); changes_neighborhood=UP; changes_topology=UP; } else { two_hop_list_tmp = two_hop_list; two_hop_list = two_hop_list->neighbor_2_next; two_hop_list_tmp->neighbor_2_next = neighbor->neighbor_2_list; neighbor->neighbor_2_list = two_hop_list_tmp; } } } /******************** end of revision ***************/ } else { if (debug_level > 3) { printf(" this neighbor is myself!\n"); fprintf(y_file," this neighbor is myself!\n"); } } message_neighbors=message_neighbors->next; }}/*------------------------------------------------------------------------*/intolsr_process_changes(){ /*------------------*/ if(debug_level > 8) { if(changes_neighborhood) printf("CHANGES IN NEIGHBORHOOD\n"); if(changes_topology) printf("CHANGES IN TOPOLOGY\n"); } /*------------------*/ if(changes_neighborhood) { /* Calculate new mprs and routing table */ olsr_calculate_mpr(); olsr_calculate_routing_table(); changes_neighborhood=DOWN; changes_topology=DOWN; //CRC HNA add /*-------------------------*/ changes_net=DOWN; /*-------------------------*/ if (debug_level ==1 || debug_level ==2) { printf ("\n\n.........time (%02d:%02d:%02d.%06lu), changes in neighborhood! .........\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec); printf (" now, the routing table is\n"); olsr_print_routing_table(routingtable); fprintf (y_file,"\n\n\n\n.........time (%02d:%02d:%02d.%06lu), changes in neighborhood! .........\n", nowtm->tm_hour, nowtm->tm_min,nowtm->tm_sec,now.tv_usec); fprintf (y_file," now, the routing table is\n"); olsr_print_trace_routing_table(routingtable); } if (debug_level ==2) { printf ("\n the neighbor table is\n"); olsr_print_neighbor_table(); printf ("\n the two hop neighbor table is\n"); olsr_print_two_hop_neighbor_table(); printf ("\n the main address routing table is\n"); olsr_print_main_addr_neigh_table(); fprintf (y_file,"\n the neighbor table is\n"); olsr_print_trace_neighbor_table(); fprintf (y_file,"\n the two hop neighbor table is\n"); olsr_print_trace_two_hop_neighbor_table(); fprintf (y_file,"\n the main address routing table is\n"); olsr_print_trace_main_addr_neigh_table(); } return 0; } if(changes_topology) { /* calculate the routing table
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -