manet_olsr_protocol_olsr_process.pr.c

来自「protocole sur opnet simulation」· C语言 代码 · 共 1,499 行 · 第 1/3 页

C
1,499
字号
					
					if (p_cour->MS_time < op_sim_time())
					
					{
					
					 	(noeud_infos[f_code].table_mpr_selector)->MSSN ++ ;
						
						if (noeud_infos[f_code].change_in_mpr_selector_table == 0 )
						
								noeud_infos[f_code].change_in_mpr_selector_table = 1 ;
						
						if(p_prec == NULL )
							
							{
							
								(noeud_infos[f_code].table_mpr_selector)->MPR_selector = ((noeud_infos[f_code].table_mpr_selector)->MPR_selector)->suiv ;
								
								free ( p_cour ) ;
								
								p_cour = (noeud_infos[f_code].table_mpr_selector)->MPR_selector ;
							
							 
							 }
						
						else 
							
							{
							   
								p_prec->suiv = p_cour->suiv ;
								
								free( p_cour );
								
								p_cour = p_prec->suiv ;
								
							  }
						
					   }
				
				   else
					   
					   {
					   
					   	  
					   		p_prec = p_cour ;
					   		p_cour = p_cour->suiv;
							
					   }
				   
			  }
		}
			


/*******************************************************************************************************/
/** fonction :  time_out_selector_table                                                              **/
/** objectif :  supprimer les entrees qui ont depasse leur time out                                   **/
/*******************************************************************************************************/

					
void time_out_neighbor_table (int f_code) 
	
   	{
	
			struct Neighbor_table *p_cour1,*p_prec1 ;
			
			struct Neighbor_2hop_table *p_cour2, * p_prec2, *p_suiv2 ;
			
			p_cour1 = noeud_infos[f_code].noeud_voisin ;
			
			p_prec1 = NULL ;
			
			while ( p_cour1 != NULL )
				
				{
				
					p_cour2 = p_cour1->N_2hop ;
						
					p_prec2 = NULL ;

				
					if (p_cour1->N_time < op_sim_time())
					
					{
					
						
						/****************** pour recalculer les MPR et la table du routage **************/
					
						if ( (noeud_infos[f_code].change_in_neigbor_table == 0 ) && ( (p_cour1->N_status == SYM_LINK) || (p_cour1->N_status ==MPR_LINK) ))
						
								noeud_infos[f_code].change_in_neigbor_table = 1 ;
						
												
						/********************************************************************************/

					
						if(p_prec1 == NULL )
							
							{
							
								noeud_infos[f_code].noeud_voisin = (noeud_infos[f_code].noeud_voisin)->suiv ;
								
								while ( p_cour2 != NULL )
									
									{
									 p_suiv2 = p_cour2->suiv ;
									 
									 free ( p_cour2);
									 
									 p_cour2 = p_suiv2 ;
									 }
										
								
								free ( p_cour1 ) ;
								
								p_cour1 = noeud_infos[f_code].noeud_voisin ;
							
							 
							 }
						
						else 
							
							{
							   
								p_prec1->suiv = p_cour1->suiv ;
								
								while ( p_cour2 != NULL )
									
								   {
									 p_suiv2 = p_cour2->suiv ;
									 
									 free ( p_cour2);
									 
									 p_cour2 = p_suiv2 ;
									 
									 
									}
								
								free( p_cour1 );
								
								p_cour1 = p_prec1->suiv ;
								
							  }
						
					   }
				
				   else
					   
					   {
					   
					   	  
					   		while ( p_cour2 != NULL )
								
								{
								
									if( p_cour2->N_2hop_time < op_sim_time ())
										
										{
										
											/**************************** pour recalculer les MPR et la table du routage *****************/
											
											if (noeud_infos[f_code].change_in_neigbor_table == 0 )
												
												         noeud_infos[f_code].change_in_neigbor_table = 1 ;
											
											
											/*********************************************************************************************/

										
											if(p_prec2 == NULL )
												
												{
												  p_cour1->N_2hop = (p_cour1->N_2hop)->suiv ;
												  
												  free ( p_cour2) ;
												  
												  p_cour2 = p_cour1->N_2hop ;
												  
												}
											else
												
												{
												  p_prec2->suiv = p_cour2->suiv ;
												  
												  free ( p_cour2 ) ;
												  
												  p_cour2 = p_prec2->suiv ;
												  
												}
										 }
									
									 else
										 
										 
										 {
										 	p_prec2 = p_cour2 ;
											
											p_cour2 = p_cour2->suiv ;
											
										 }
									 
								  }
											
											
													
												
												
					   
					   		p_prec1 = p_cour1 ;
					   		p_cour1 = p_cour1->suiv;
							
					   }
				   
			  }
			
		
	}


/*******************************************************************************************************/
/** fonction :  time_out_topology_table                                                             **/
/** objectif :  supprimer les entrees qui ont depasse leur time out                                   **/
/*******************************************************************************************************/
			


void time_out_topology_table  (int f_code)
	
	{
	
		
		struct topology_infos * p_cour,* p_prec ;
		
		/************** pour debuger il faire une fonction d'affichage avant et apres la suppression ***********/
		
		p_cour = noeud_infos[f_code].topology_table;
		
	   	p_prec = NULL ;

		
		
		while ( p_cour != NULL)
			
			{
			
				if (p_cour->T_time < op_sim_time())
					
					{
					
					
						if (noeud_infos[f_code].change_in_toplogy_table == 0 )
												
					         noeud_infos[f_code].change_in_toplogy_table = 1 ;

					
					 	if(p_prec == NULL )
							
							{
							
								noeud_infos[f_code].topology_table = (noeud_infos[f_code].topology_table)->suiv ;
								
								free ( p_cour ) ;
								
								p_cour = noeud_infos[f_code].topology_table ;
							
							 
							 }
						
						else 
							
							{
							   
								p_prec->suiv = p_cour->suiv ;
								
								free( p_cour );
								
								p_cour = p_prec->suiv ;
								
							  }
						
					   }
				
				   else
					   
					   {
					   
					   	  
					   		p_prec = p_cour ;
					   		p_cour = p_cour->suiv;
							
					   }
				   
			  }
		}
	
			
				
/*******************************************************************************************************/
/** fonction :  calculate_mpr                                                                         **/
/** objectif :  heuristique pour calculer la liste des mpr                                             **/
/*******************************************************************************************************/
		
void calculate_mpr(int f_code,int nb_max_mobiles)
	
	{
	
		int the_first_mpr;
		
	    struct Neighbor_table *p_cour ,*p_max;
		
		void positionner_degree_one_hop_neigbor (int n_code);
		
		void select_mpr_one_path(int n_code,int n_nb_max_mobiles) ;
		
		int existe_2hop_node_nocov (int n_code) ;
		
		int positionner_2hop_nocov ( struct Neighbor_table * n_cour,int n_code);
		
		the_first_mpr = 0;
			
			
		positionner_degree_one_hop_neigbor (f_code);
		
		
				
		select_mpr_one_path(f_code,nb_max_mobiles) ;
		
				
				
		while ( existe_2hop_node_nocov (f_code))
			
			{
			
				p_cour = noeud_infos[f_code].noeud_voisin ;
				
				while ( p_cour != NULL )
					
					{
						if ( p_cour->N_status == SYM_LINK )
							
								p_cour->nb_2hop_nocov = positionner_2hop_nocov ( p_cour,f_code) ;
						
						p_cour = p_cour->suiv ;
						
					 }
								
				p_cour = noeud_infos[f_code].noeud_voisin ;
				
				p_max = NULL ;
				
				while ( p_cour != NULL )
					
					{
						
						if ( p_max == NULL )
							
							{
							
								if ( p_cour->N_status == SYM_LINK )
									
									p_max = p_cour ;
							 }
						
						else
							
					
							{
								if ( (p_cour->N_status == SYM_LINK) && ( p_cour->nb_2hop_nocov >= p_max->nb_2hop_nocov))
							
									{
							
										if ( p_cour->nb_2hop_nocov > p_max->nb_2hop_nocov )
								  
											{
								  
											   		p_max->nb_2hop_nocov = 0 ;
									
													p_max = p_cour ;
									
											 }
										
										else
								  
											{
								  
												if ( p_cour->degree > p_max->degree )
										
													{
										
														p_max->nb_2hop_nocov = 0 ;
											
														p_max = p_cour ;
											
													}
												
												else
										
										 				p_cour->nb_2hop_nocov = 0 ;
									
											 }
										
										}
								}
						
						
						    p_cour = p_cour->suiv ;
							
					   }
				
				
					p_max->N_status = MPR_LINK	;
					
					if (the_first_mpr==0)
						
						{
						
						  noeud_infos[f_code].default_nexthop = p_max->N_addr;
						  
						  the_first_mpr = 1;
						}
						
					
					}
		
				
  }
						
										   
/*******************************************************************************************************/
/** fonction :  positionner_degree_one_hop_neigbor                                                    **/
/** objectif :  positionner dans chaque voisins le degree i.e le nombre des voisins 2hop              **/
/*******************************************************************************************************/


void positionner_degree_one_hop_neigbor (int n_code)
	
	{
		struct Neighbor_table *p_cour1 ;
		
		struct Neighbor_2hop_table *p_cour2 ;
		
		int existe ( int n_2hop , int p_code ) ;
		
		p_cour1 = noeud_infos[n_code].noeud_voisin ;
		
		while ( p_cour1 != NULL )
			
			{
				if ( (p_cour1->N_status == MPR_LINK ) || ( p_cour1->N_status == SYM_LINK ))
					
					{
					
						p_cour1->N_status = SYM_LINK ;
						
						p_cour1->degree = 0 ;
				
						p_cour2 = p_cour1->N_2hop ;
				
						while ( p_cour2 !=NULL )
					
							{
								if ( ( p_cour2->N_2hop_addr != n_code ) && ( ! existe ( p_cour2->N_2hop_addr , n_code )))
									
											p_cour1->degree ++ ;
								
								p_cour2 = p_cour2->suiv ;
								
							 }
						
						printf("\n le degree de %d = %d ",p_cour1->N_addr,p_cour1->degree);
					}
					
					
					p_cour1 = p_cour1->suiv ;
					
					
			   }
	 }


	
int existe ( int n_2hop , int p_code )  // est'il le noeud n_2hop comme un voisin directe de p_code
	
	{
		
		struct Neighbor_table *p_cour ;
		
		p_cour = noeud_infos[p_code].noeud_voisin ;
		
		while ( p_cour != NULL )
			
			{
			
				if ( p_cour->N_addr == n_2hop )
					
					return (1);
				else
					p_cour = p_cour->suiv ;
				
			 }
		

⌨️ 快捷键说明

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