⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 olsr.c

📁 OLSR Implementation for XORP
💻 C
📖 第 1 页 / 共 5 页
字号:
		/******************* end of revision ***************/							  	}	else  //existing link	{      		/********************** added by Y.Ge ******************/		/*** debug ***/		if (debug_level >3)		{			printf ("\n+++ existing neighbor detected ! +++\n"); //added by Y.Ge			printf ("     link type is: %d\n", link_type); //added by Y.Ge			printf (" neighbor is: %s\n", convert_address_to_string (&neighbor->neighbor_addr));						fprintf (y_file,"\n+++ existing neighbor detected ! +++\n"); //added by Y.Ge			fprintf (y_file,"     link type is: %d\n", link_type); //added by Y.Ge			fprintf (y_file," neighbor is: %s\n", convert_address_to_string (&neighbor->neighbor_addr));		}				/* update hysteresis */		neighbor->neighbor_hysavg = hysteresis (neighbor->neighbor_hysavg, 1);		neighbor->h_time_value = rcvd_htime;				if (debug_level >3)		{			printf ("----- the hyst is: %f\n",neighbor->neighbor_hysavg); 			fprintf (y_file,"----- the hyst is: %f\n",neighbor->neighbor_hysavg);		} 				/*********** added by Y.Ge ***********/		/* qos OLSR */		if (use_qos)		{			neighbor->neighbor_hello_seq = message->packet_seq_number;		}		/********** end of revision *********/				/* update timer */		timeradd(&now, &next_hello_time, &neighbor->next_hello_timer);		timeradd(&now, &hold_time_tmp, &neighbor->neighbor_link_asym_timer);		timeradd(&now, &hold_time_tmp, &neighbor->neighbor_timer);				if (link_type != NOT_DETECTED && link_type != UNSPEC_LINK)		{			if (neighbor->neighbor_hysavg > HYST_THRESHOLD_HIGH)			{				neighbor->link_pending = 0;				timerminus(&neighbor->neighbor_link_lost_timer);							switch (neighbor->neighbor_status)				{					case LOST_LINK:						timerminus(&neighbor->neighbor_link_sym_timer); //expire the L_SYM_TIME						timeradd(&now, &hold_time_tmp, &neighbor->neighbor_timer);						neighbor->neighbor_status = ASYM_LINK;						break;					case SYM_LINK:					case ASYM_LINK:						if (neighbor->neighbor_status != SYM_LINK)						{							changes_neighborhood=UP;							changes_topology=UP;							changed = 1;												}						neighbor->neighbor_status = SYM_LINK;						timeradd(&now, &hold_time_tmp, &neighbor->neighbor_link_sym_timer);						olsr_assign_timer(&neighbor->neighbor_link_sym_timer, &neighbor->neighbor_timer);						timeradd(&neighbor->neighbor_timer, &hold_time_neighbor, &neighbor->neighbor_timer);						break;					default:						break;				}					}			else			{				/* HYST_THRESHOLD_LOW > L_link_qualitty */				if (neighbor->neighbor_hysavg < HYST_THRESHOLD_LOW)				{					neighbor->link_pending = 1;									if (neighbor->neighbor_status == SYM_LINK)					{						changes_neighborhood=UP;						changes_topology=UP;						changed = 1;					}					neighbor->neighbor_status = LOST_LINK;									timeradd(&now, &hold_time_tmp, &neighbor->neighbor_timer);					timeradd(&now, &hold_time_neighbor, &tmp_timeval);					if (compare_timer(&neighbor->neighbor_timer, &tmp_timeval) ==0)						olsr_assign_timer(&neighbor->neighbor_timer, &neighbor->neighbor_link_lost_timer); 					else						olsr_assign_timer(&tmp_timeval, &neighbor->neighbor_link_lost_timer); 					}							/* HYST_THRESHOLD_LOW <=L_link_qualitty<=HYST_THRESHOLD_HIGH */				else				{					timeradd(&now, &hold_time_tmp, &neighbor->neighbor_link_asym_timer); //update L_ASYM_time										if (link_type == LOST_LINK)					{						if (neighbor->neighbor_status == SYM_LINK)						{							changes_neighborhood=UP;							changes_topology=UP;							changed = 1;						}						neighbor->neighbor_status = LOST_LINK;						timerminus(&neighbor->neighbor_link_sym_timer); //expire the L_SYM_TIME						timeradd(&now, &hold_time_neighbor, &neighbor->neighbor_link_lost_timer);					}									else					{						if (link_type == SYM_LINK || link_type == ASYM_LINK)						{							if (olsr_timed_out(&neighbor->neighbor_link_lost_timer) && neighbor->link_pending ==0)							{								if (neighbor->neighbor_status != SYM_LINK)								{									changes_neighborhood=UP;									changes_topology=UP;									changed = 1;														}								neighbor->neighbor_status = SYM_LINK;								timeradd(&now, &hold_time_tmp, &neighbor->neighbor_link_sym_timer);								olsr_assign_timer(&neighbor->neighbor_link_sym_timer, &neighbor->neighbor_timer);								timeradd(&neighbor->neighbor_timer, &hold_time_neighbor, &neighbor->neighbor_timer);							}						}					} 								/* L_time = max (L_time, L_ASYM_time) */					if (compare_timer(&neighbor->neighbor_timer, &neighbor->neighbor_link_asym_timer) ==0)						olsr_assign_timer(&neighbor->neighbor_link_asym_timer, &neighbor->neighbor_timer); 				}			}							/* again, check the main_addr_neighbor table */			if (NULL == (main_addr_neighbor = olsr_lookup_main_addr_neigh_table(&message->originator_addr)))			{				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				printf ("XATTENTION: something wrong with the main_addr_neighbor_table!X\n");				printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");				olsr_destroy_hello_message(message);				exit  (1);			}			else			{				/* check if the main_addr_neighbor has a link to current neighbbor_iface */				if (NULL == (neighbor_iface_link = olsr_lookup_iface_neighbor(main_addr_neighbor, &neighbor->neighbor_addr)))				{					/* something must be wrong again, as the link should exist */					{						printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");						printf ("XATTENTION: something wrong with the main_addr_neighbor_link!X\n");						printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");						olsr_destroy_hello_message(message);						exit  (1);					}								}								/* check if the neighbor has changed its willingness */				if (main_addr_neighbor->main_addr_neigh_willingness != message->willingness)				{					if (debug_level > 3)					{						printf ("*********** the neighbor's willingness has been changed, recalculate MPRs!\n");						printf (" the original willingness is: %d, the new willingness is: %d\n",main_addr_neighbor->main_addr_neigh_willingness,message->willingness); 												fprintf (y_file, "*********** the neighbor's willingness has been changed, recalculate MPRs!\n");						fprintf (y_file, " the original willingness is: %d, the new willingness is: %d\n",main_addr_neighbor->main_addr_neigh_willingness,message->willingness); 					}										main_addr_neighbor->main_addr_neigh_willingness = message->willingness;										changes_neighborhood = UP;				}					/* the switch function is deleted completely */				/*************** end of revision *****************/			}		}						}		// Deleting this neighbor from the two hop list IF exist	//if((neighbor->neighbor_status==NBS_MPR)||(neighbor->neighbor_status==NBS_SYM)) //commented by Y.Ge	if(neighbor->neighbor_status==SYM_LINK) //added by Y.Ge	{		if (debug_level > 3)		{			printf (" ********** the neighor status is SYM_LINK, check if it is in the two hop neighbor table!\n");			fprintf (y_file," ********** the neighor status is SYM_LINK, check if it is in the two hop neighbor table!\n");		}				if((two_hop_neighbor=olsr_lookup_two_hop_neighbor_table(&neighbor->neighbor_addr))!=NULL)		{			if (debug_level > 3)			{				printf (" delete the hello sender from the 2-hop-neighbor table!\n");				fprintf (y_file," delete the hello sender from the 2-hop-neighbor table!\n");			}						olsr_delete_two_hop_neighbor_table(two_hop_neighbor);			// This flag is set to UP to recalculate the MPR set and the routing table			changes_neighborhood=UP;			changes_topology=UP;			changed = 1;		}						/***************** added by Y.Ge ****************/		/*		 * Y.Ge: should check both neighbor interface address and main address 		 * as at the time the HELLO is received, MID information may still not avaliable		 */		if((two_hop_neighbor=olsr_lookup_two_hop_neighbor_table(&message->originator_addr))!=NULL)		{			if (debug_level > 3)			{				printf (" delete the hello sender from the 2-hop-neighbor table!\n");				fprintf (y_file," delete the hello sender from the 2-hop-neighbor table!\n");			}						olsr_delete_two_hop_neighbor_table(two_hop_neighbor);			// This flag is set to UP to recalculate the MPR set and the routing table			changes_neighborhood=UP;			changes_topology=UP;			changed = 1;		}		/***************** end of revision *************/	}	processing: ;	// Processing the list of neighbors in the received message		if (changed)		olsr_update_main_addr_neigh_status(main_addr_neighbor); //added by Y.Ge, update the neighbor status based on the link status		/* 	 * Y.Ge : "IF" added by Y.Ge. 	 * don't link any two hop neighbors to a neighbor whose willingness is WILL_NEVER	 * this makes MPR selection and routing table calculation easier	 */ 	if (message->willingness != WILL_NEVER) 		olsr_process_message_neighbors(neighbor,message, iface_index);	olsr_destroy_hello_message(message);	/* olsr_process_changes(); */ //commented by Y.Ge, DO it after all the received messages are processed	if(debug_level > 2)	{		printf("\n\n*********** after process received hello, the tables are: \n");		olsr_print_neighbor_table();		olsr_print_main_addr_neigh_table(); 		olsr_print_two_hop_neighbor_table();		olsr_print_mpr_selector_table();				fprintf(y_file,"\n\n*********** after process received hello, the tables are: \n");		olsr_print_trace_neighbor_table();		olsr_print_trace_main_addr_neigh_table(); 		olsr_print_trace_two_hop_neighbor_table();		olsr_print_trace_mpr_selector_table();	}}/*------------------------------------------------------------------------*//*------ This function without hysteresis----*/intolsr_process_received_hello_no_hyst(struct hello_message *message, int iface_index) //"iface_index" added by Y.Ge{	olsr_u8_t                   	link=0;	olsr_u8_t               	link_type=0, neigh_type = 0;	struct neighbor_entry       	*neighbor;	struct neighbor_2_entry      	*two_hop_neighbor;	struct main_addr_neigh_entry	*main_addr_neighbor;  //added by Y.Ge	struct iface_addr_list_entry	*neighbor_iface_link; //added by Y.Ge	float                   	rcvd_vtime;  //added by Y.Ge  	olsr_u8_t               	change_hold_time = 0; //added by Y.Ge 	struct timeval 	        	hold_time_tmp; 		int                          	changed = 0;  //IF (changed), the main address neighbor status should be updated//added by L.Qin//	printf("             ******* received without hyst\n");		if(message==NULL)		return 1;    	//link=olsr_lookup_link_status(message); //commented by Y.Ge		if (debug_level > 4)	{		printf ("\n\nbefore process received HELLO, the tables are:\n");		olsr_print_neighbor_table();		olsr_print_main_addr_neigh_table(); 		olsr_print_two_hop_neighbor_table();		olsr_print_mpr_selector_table();		olsr_print_topology_table();		olsr_print_main_address_table();		olsr_print_interface_address_table();		olsr_print_routing_table(routingtable);				fprintf (y_file,"\n\nbefore process received HELLO, the tables are:\n");		olsr_print_trace_neighbor_table();		olsr_print_trace_main_addr_neigh_table(); 		olsr_print_trace_two_hop_neighbor_table();		olsr_print_trace_mpr_selector_table();		olsr_print_trace_topology_table();		olsr_print_trace_main_address_table();		olsr_print_trace_interface_address_table();		olsr_print_trace_routing_table(routingtable);	}	/********************** added by Y.Ge ********************/	/*	 * decompose link - link = neighbor type + link type 	 */	/********************** added by Y.Ge ******************/	link_type = olsr_lookup_link_status(message, iface_index);	neigh_type = olsr_lookup_neighbor_status(message, iface_index);	rcvd_vtime = olsr_compute_time_from_vtime(message->v_time);		/*printf (" the received v time is: %f\n", rcvd_vtime);	fprintf (y_file," the received v time is: %f\n", rcvd_vtime);*/	/* a message that announce link type == link_sym && neighbor type == not_neigh is invalid */	if (link_type == SYM_LINK && neigh_type == NOT_NEIGH)	{		printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");		printf ("XATTENTION: the link and neigghbor code in HELLO  does't match!X\n");		printf ("XXXXXXX   link type is: %d, neighbor type is: %d  XXXXXXXXXXXXXX\n", link_type, neigh_type);		printf ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");		olsr_destroy_hello_message(message);		exit  (1);	}	olsr_init_timer(rcvd_vtime*1000,&hold_time_tmp);  //the v_time value in HELLO	/******************** end of revision *******************/	//if(link==NBS_MPR) //commented by Y.Ge	if (neigh_type == MPR_NEIGH) //added by Y.Ge		olsr_update_mpr_selector_table(message);  	//if(NULL== (neighbor=olsr_lookup_neighbor_table(&message->source_addr))) //commented by Y.Ge	if(NULL== (neighbor=olsr_lookup_neighbor_table(&message->source_addr, &addr_manet[iface_index]))) //added by Y.Ge	{		//The neighbor entry doesn't exist in neighbtable				/**************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -