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

📄 mpr_selector_table.c

📁 OLSR Implementation for XORP
💻 C
字号:
/* * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based  *    on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message  *    creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA  *    message usage. The default gateway functionality supported the mobility *	  by cooperating with Mobile IPv6 for a mobile node as well as supported  * 	  Internet access for MANET nodes.  * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* * This Copyright notice is in French. An English summary is given * but the referee text is the French one. * * Copyright (c) 2000, 2001 Adokoe.Plakoo@inria.fr, INRIA Rocquencourt, *                          Anis.Laouiti@inria.fr, INRIA Rocquencourt. * * Ce logiciel informatique est disponible aux conditions * usuelles dans la recherche, c'est-à-dire qu'il peut * être utilisé, copié, modifié, distribué à l'unique * condition que ce texte soit conservé afin que * l'origine de ce logiciel soit reconnue. * Le nom de l'Institut National de Recherche en Informatique * et en Automatique (INRIA), ou d'une personne morale * ou physique ayant participé à l'élaboration de ce logiciel ne peut * être utilisé sans son accord préalable explicite. *  * Ce logiciel est fourni tel quel sans aucune garantie, * support ou responsabilité d'aucune sorte. * Certaines parties de ce logiciel sont dérivées de sources developpees par * University of California, Berkeley et ses contributeurs couvertes  * par des copyrights. * This software is available with usual "research" terms * with the aim of retain credits of the software.  * Permission to use, copy, modify and distribute this software for any * purpose and without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, * and the name of INRIA, or any contributor not be used in advertising * or publicity pertaining to this material without the prior explicit * permission. The software is provided "as is" without any * warranties, support or liabilities of any kind. * This product includes software developed by the University of * California, Berkeley and its contributors protected by copyrights. *//* * Routing table management daemon. */char mpr_selector_table_rcsid[] =   "$Id: mpr_selector_table.c,v 1.2 2000/12/06 10:36:11 prima Exp $";#include "defs.h"struct mpr_selector_table         mprstable;/*------------------------------------------------------------------------*/voidolsr_delete_mpr_selector_table(struct mpr_selector_entry *mprs){	olsr_remque((struct olsr_qelem *)mprs);	free((void *)mprs);  }/*------------------------------------------------------------------------*/voidolsr_insert_mpr_selector_table(struct mpr_selector_entry *mprs){	olsr_u32_t  hash;	struct mpr_selector_hash  *mprs_hash;  	olsr_hashing(&mprs->mpr_selector_addr,&hash);	mprs->mprselector_hash=hash;	mprs_hash=&mprstable.mpr_selector_hash[hash & HASHMASK];	olsr_insque((struct olsr_qelem *)mprs, (struct olsr_qelem *)mprs_hash);  }/*------------------------------------------------------------------------*/struct mpr_selector_entry*olsr_lookup_mpr_selector_table(struct olsr_ip_addr *dst){	struct mpr_selector_entry *mprs;	struct mpr_selector_hash  *mprs_hash;	olsr_u32_t                hash;  	olsr_hashing(dst,&hash);	mprs_hash=&mprstable.mpr_selector_hash[hash & HASHMASK];  	for(mprs=mprs_hash->mpr_selector_forw;mprs!=(struct mpr_selector_entry *)mprs_hash;mprs=mprs->mpr_selector_forw)	{		if(mprs->mprselector_hash!=hash)			continue;		if (0==memcmp(&mprs->mpr_selector_addr,dst,sizeof(struct olsr_ip_addr)))			return(mprs);	}	return(NULL);}/*------------------------------------------------------------------------*/voidolsr_update_mpr_selector_table(struct hello_message *message){  /*    If the mpr set is changed, then we must increment the mssn  */	struct mpr_selector_entry  *mprs;    	//if(NULL==(mprs = olsr_lookup_mpr_selector_table(&message->source_addr))) //commented by Y.Ge	if(NULL==(mprs = olsr_lookup_mpr_selector_table(&message->originator_addr))) //added by Y.Ge	{		/*if the mpr entry doesn't exist*/		mprs=(struct mpr_selector_entry *)malloc(sizeof(struct mpr_selector_entry));		//memcpy(&mprs->mpr_selector_addr,&message->source_addr,sizeof(struct olsr_ip_addr)); //commented by Y.Ge		memcpy(&mprs->mpr_selector_addr,&message->originator_addr,sizeof(struct olsr_ip_addr)); //added by Y.Ge		olsr_insert_mpr_selector_table(mprs);		//mprs->mpr_selector_seq=message->mpr_seq_number; //commented by Y.Ge		mprs->mpr_selector_seq=message->packet_seq_number; //added by Y.Ge				/* qos OLSR */		if (use_qos)			mprs->mpr_selector_busy_time = default_busy_time; //added by Y.Ge					timeradd(&now,&hold_time_neighbor,&mprs->mpr_selector_timer);		/*increment the mssn number don't forget to increment this number on time out too*/		mprstable.mssn++;		/* Set the changes flag to UP ( This flag will be set to DOWN after sending a TC packet)*/		changes=UP;	}	else	{		/*if the mpr entry exists*/		//if(message->mpr_seq_number>=mprs->mpr_selector_seq) //commented by Y.Ge		if(wrap_around_compare(message->packet_seq_number,mprs->mpr_selector_seq)>0) //added by Y.Ge		{				//mprs->mpr_selector_seq=message->mpr_seq_number;	  //commented by Y.Ge			mprs->mpr_selector_seq=message->packet_seq_number;	  //commented by Y.Ge			timeradd(&now,&hold_time_neighbor,&mprs->mpr_selector_timer);		}	}}/*------------------------------------------------------------------------*//****************** added by Y.Ge **************//* qos OLSR */voidolsr_update_mpr_selector_busy_time (struct qos_hello_message *message){	struct mpr_selector_entry  *mprs;		if(NULL==(mprs = olsr_lookup_mpr_selector_table(&message->originator_addr))) //added by Y.Ge	{		if (debug_level > 3)		{			printf ("QoS Hello sender is not the MPR selector!\n");			fprintf (y_file,"QoS Hello sender is not the MPR selector!\n");		}	}	else	{		if (message->packet_seq_number < mprs->mpr_selector_seq)		{			printf ("XXXXXXXXX something wrong with the mpr selector sequence number! XXXXXXXXX\n");			printf ("qos hello seq: %d, mpr selector seq: %d\n",message->packet_seq_number,  mprs->mpr_selector_seq);			exit (1);		}				if (message->packet_seq_number > mprs->mpr_selector_seq)		{			printf ("XXXXXXXXX the neighbor is no longer a mpr selector! XXXXXXXXX\n");			printf ("qos hello seq: %d, mpr selector seq: %d\n",message->packet_seq_number,  mprs->mpr_selector_seq);						fprintf (y_file,"...... the neighbor is no longer a mpr selector! ......\n");			fprintf (y_file,"qos hello seq: %d, mpr selector seq: %d\n",message->packet_seq_number,  mprs->mpr_selector_seq);					}				if (mprs->mpr_selector_busy_time != message->rcvd_busy_time)		{			mprs->mpr_selector_busy_time = message->rcvd_busy_time;			}			}}/****************** end of revision ***********//*------------------------------------------------------------------------*/voidolsr_release_mpr_seletector_table(){	struct mpr_selector_entry *mprs;	struct mpr_selector_entry *mprs_tmp;	struct mpr_selector_hash  *mprs_hash;	olsr_u8_t                   index;	for(index=0;index<HASHSIZE;index++)	{		mprs_hash=&mprstable.mpr_selector_hash[index];		mprs=mprs_hash->mpr_selector_forw;		while(mprs!=(struct mpr_selector_entry *)mprs_hash)		{			mprs_tmp=mprs;			mprs=mprs->mpr_selector_forw;			olsr_delete_mpr_selector_table(mprs_tmp);		}	}}/*------------------------------------------------------------------------*/voidolsr_time_out_mpr_selector_table(){	struct mpr_selector_entry *mprs;	struct mpr_selector_entry *mprs_tmp;	struct mpr_selector_hash  *mprs_hash;	olsr_u8_t                 index;	int 	mpr_time_out = 0;  	for(index=0;index<HASHSIZE;index++)	{		mprs_hash=&mprstable.mpr_selector_hash[index];		mprs=mprs_hash->mpr_selector_forw;		while(mprs!=(struct mpr_selector_entry *)mprs_hash)			{			if(olsr_timed_out(&mprs->mpr_selector_timer))			{				mpr_time_out = 1;								if (debug_level > 1)				{					printf ("\n\n-----------------time(%d, %d), mpr selector timed out!--------------\n", now.tv_sec, now.tv_usec);					printf (" the mpr selector is:%s\n", convert_address_to_string(&mprs->mpr_selector_addr));					printf (" mpr selector timer is: %d     %d\n\n", mprs->mpr_selector_timer.tv_sec, mprs->mpr_selector_timer.tv_usec);									fprintf (y_file,"\n\n-----------------time(%d, %d), mpr selector timed out!--------------\n", now.tv_sec, now.tv_usec);					fprintf (y_file," the mpr selector is:%s\n", convert_address_to_string(&mprs->mpr_selector_addr));					fprintf (y_file," mpr selector timer is: %d     %d\n\n", mprs->mpr_selector_timer.tv_sec, mprs->mpr_selector_timer.tv_usec);				}				mprs_tmp=mprs;				mprs=mprs->mpr_selector_forw;				olsr_delete_mpr_selector_table(mprs_tmp);	      						/*increment the mssn number don't forget to increment this number */				mprstable.mssn++;				/* The changes flag is set to UP*/				changes=UP;			}			else				mprs=mprs->mpr_selector_forw;		}	}		if (mpr_time_out && debug_level > 1)	{		printf ("XXXXXXXXXX after time out mpr selector table, the mpr selector table is:XXXXXXXXXXXX\n");		olsr_print_mpr_selector_table();					fprintf (y_file,"XXXXXXXXXX after time out mpr selector table, the mpr selector table is:XXXXXXXXX\n");		olsr_print_trace_mpr_selector_table(); 	}}/*------------------------------------------------------------------------*/voidolsr_print_mpr_selector_table(){	struct mpr_selector_entry *mprs;	struct mpr_selector_hash  *mprs_hash;	olsr_u8_t                 index;	char str[46];	printf("\n\nMPR SELECTOR TABLE\n");  	for(index=0;index<HASHSIZE;index++)	{		mprs_hash=&mprstable.mpr_selector_hash[index];      		for(mprs=mprs_hash->mpr_selector_forw;mprs!=(struct mpr_selector_entry *)mprs_hash;mprs=mprs->mpr_selector_forw)		{	 	  			//printf("%s            \n",convert_address_to_string(&mprs->mpr_selector_addr));			/********** "IF" added by Y.Ge *******/			if (use_qos)				printf("%s     %d \n",inet_ntop(AF_INET6,&mprs->mpr_selector_addr,str,46), mprs->mpr_selector_busy_time);			else					printf("%s            \n",inet_ntop(AF_INET6,&mprs->mpr_selector_addr,str,46));			/*********** end of revision ********/	  		}	}}/*------------------------------------------------------------------------*//******************* added by Y.Ge **********************/voidolsr_print_trace_mpr_selector_table(){	struct mpr_selector_entry *mprs;	struct mpr_selector_hash  *mprs_hash;	olsr_u8_t                 index;	char str[46];	fprintf(y_file,"\n\nMPR SELECTOR TABLE\n");  	for(index=0;index<HASHSIZE;index++)	{		mprs_hash=&mprstable.mpr_selector_hash[index];      		for(mprs=mprs_hash->mpr_selector_forw;mprs!=(struct mpr_selector_entry *)mprs_hash;mprs=mprs->mpr_selector_forw)		{	 	  			//printf("%s            \n",convert_address_to_string(&mprs->mpr_selector_addr));			if (use_qos)				fprintf(y_file,"%s     %d \n",inet_ntop(AF_INET6,&mprs->mpr_selector_addr,str,46), mprs->mpr_selector_busy_time);				else				fprintf(y_file,"%s            \n",inet_ntop(AF_INET6,&mprs->mpr_selector_addr,str,46));	  		}	}}/*------------------------------------------------------------------------*//**************** end of revision ********************/

⌨️ 快捷键说明

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