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

📄 duplicate_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 dupplicate_table_rcsid[] =   "$Id: duplicate_table.c,v 1.2 2000/12/06 10:36:11 prima Exp $";#include "defs.h"struct duplicatehash              duplicatetable[HASHSIZE];/*------------------------------------------------------------------------*/voidolsr_delete_duplicate_table(struct duplicate_entry *dup_entry){	struct rcving_interface	*rcvg_iface_list;	//added by Y.Ge	struct rcving_interface	*rcvg_iface_list_tmp;	//added by Y.Ge	/******************* added by Y.Ge ************/	/*free list of receiving interface address */	rcvg_iface_list = dup_entry->duplicate_rcvg_iface_list;	while (rcvg_iface_list !=NULL)	{		rcvg_iface_list_tmp = rcvg_iface_list;		rcvg_iface_list = rcvg_iface_list->next;		free(rcvg_iface_list_tmp); 	} 	/****************** end of revision **********/	olsr_remque((struct olsr_qelem *)dup_entry);	free((void *)dup_entry);}/*------------------------------------------------------------------------*//****************** commented by Y.Ge  ***************//*voidolsr_insert_duplicate_table(struct tc_message *message){	olsr_u32_t  hash;	struct duplicatehash *dup_hash;	struct duplicate_entry *dup_message;  	dup_message=(struct duplicate_entry *)malloc(sizeof(struct duplicate_entry));	dup_message->duplicate_seq=message->packet_seq_number;	memcpy(&dup_message->duplicate_addr,&message->originator,sizeof(struct olsr_ip_addr));  	timeradd(&now,&hold_time_duplicate_tc,&dup_message->duplicate_timer);	olsr_hashing(&dup_message->duplicate_addr,&hash);	dup_message->duplicate_hash=hash;	dup_hash=&duplicatetable[hash & HASHMASK];	olsr_insque((struct olsr_qelem *)dup_message, (struct olsr_qelem *)dup_hash);}*//***************** end of revision ****************//*------------------------------------------------------------------------*//***************** added by Y.Ge ****************/voidolsr_insert_duplicate_table (int type, struct olsr_ip_addr org_addr, int sequence, int rcvd_if_index, int should_forward){	olsr_u32_t  hash;	struct duplicatehash *dup_hash;	struct duplicate_entry *dup_message;	struct rcving_interface *rcvg_list;  	dup_message=(struct duplicate_entry *)malloc(sizeof(struct duplicate_entry));	dup_message->duplicate_rcvg_iface_list = (struct rcving_interface *)NULL;	dup_message->duplicate_type = type;	memcpy(&dup_message->duplicate_addr, &org_addr, sizeof (struct olsr_ip_addr));	dup_message->duplicate_seq = sequence;	timeradd(&now,&hold_time_duplicate,&dup_message->duplicate_timer);	dup_message->duplicate_retransmitted = should_forward;	rcvg_list = (struct rcving_interface *)malloc(sizeof(struct rcving_interface));	memcpy(&rcvg_list->rcvg_interface_address, &addr_manet[rcvd_if_index], sizeof (struct olsr_ip_addr));	rcvg_list->next = dup_message->duplicate_rcvg_iface_list;	dup_message->duplicate_rcvg_iface_list = rcvg_list;	olsr_hashing(&dup_message->duplicate_addr,&hash);	dup_message->duplicate_hash=hash;	dup_hash=&duplicatetable[hash & HASHMASK];	olsr_insque((struct olsr_qelem *)dup_message, (struct olsr_qelem *)dup_hash);	}/********************* end of revision *****************//*------------------------------------------------------------------------*//****************** commented by Y.Ge  ***************//*struct duplicate_entry*olsr_lookup_duplicate_table(struct tc_message *message){  struct duplicate_entry *dup_message;  struct duplicatehash   *dup_hash;  olsr_u32_t             hash;  olsr_hashing(&message->originator,&hash);    dup_hash=&duplicatetable[hash & HASHMASK];    for(dup_message=dup_hash->duplicate_forw;dup_message!=(struct duplicate_entry *)dup_hash;dup_message=dup_message->duplicate_forw)    {      if(dup_message->duplicate_hash!=hash)	continue;      if    ((0==memcmp(&dup_message->duplicate_addr,&message->originator,sizeof(struct olsr_ip_addr)))&&(dup_message->duplicate_seq==message->packet_seq_number))	{	  if(debug_level > 2)	    {	      printf("THIS TC MESSAGE IS IN THE DUPLICATE TABLE YET seq_nu of this message is %d  and in the TC Table is %d\n",message->packet_seq_number,dup_message->duplicate_seq);	    }	  return (dup_message);	}    }  return (NULL);}*//***************** end of revision ****************//*------------------------------------------------------------------------*//***************** added by Y.Ge ****************/struct duplicate_entry*olsr_lookup_duplicate_table(int type, struct olsr_ip_addr org_addr, int sequence, int rcvd_if_index){	struct duplicate_entry *dup_message;	struct duplicatehash   *dup_hash;	olsr_u32_t             hash;	olsr_hashing(&org_addr,&hash);	dup_hash=&duplicatetable[hash & HASHMASK];	for(dup_message=dup_hash->duplicate_forw;dup_message!=(struct duplicate_entry *)dup_hash;dup_message=dup_message->duplicate_forw)	{		if(dup_message->duplicate_hash!=hash)			continue;		if(0==memcmp(&dup_message->duplicate_addr,&org_addr,sizeof(struct olsr_ip_addr)))		{			if((dup_message->duplicate_type == type)&&(dup_message->duplicate_seq==sequence))			{				return (dup_message);			}		}	}	return (NULL);}/********************* end of revision *****************//*------------------------------------------------------------------------*/voidolsr_release_duplicate_table(){	olsr_u8_t              index;	struct duplicatehash   *dup_hash;	struct duplicate_entry *dup_message;	struct duplicate_entry *dup_message_tmp;	for(index=0;index<HASHSIZE;index++)	{		dup_hash=&duplicatetable[index];		dup_message=dup_hash->duplicate_forw;		while(dup_message!=(struct duplicate_entry *)dup_hash)		{			dup_message_tmp=dup_message;			dup_message=dup_message->duplicate_forw;			olsr_delete_duplicate_table(dup_message_tmp);		}	}}/*------------------------------------------------------------------------*/voidolsr_time_out_duplicate_table(){  olsr_u8_t              index;  struct duplicatehash   *dup_hash;  struct duplicate_entry *dup_message;  struct duplicate_entry *dup_message_tmp;    for(index=0;index<HASHSIZE;index++)    {      dup_hash=&duplicatetable[index];      dup_message=dup_hash->duplicate_forw;      while(dup_message!=(struct duplicate_entry *)dup_hash)	{	  if(olsr_timed_out(&dup_message->duplicate_timer))	    {	      dup_message_tmp=dup_message;	      dup_message=dup_message->duplicate_forw;	      olsr_delete_duplicate_table(dup_message_tmp);	    }	  else	    dup_message=dup_message->duplicate_forw;	    	}    }}/*------------------------------------------------------------------------*//* the function is re-written by Y.Ge *//*voidolsr_print_duplicate_table(){  olsr_u8_t              index;  struct duplicatehash   *dup_hash;  struct duplicate_entry *dup_message;  char str[46];    printf("DUPLICATE TABLE\n");  printf("   HASH           ADDRESS          DUPLICATE seq nu      \n");  printf("---------------------------------------------------------\n");    for(index=0;index<HASHSIZE;index++)    {      dup_hash=&duplicatetable[index];            for(dup_message=dup_hash->duplicate_forw;dup_message!=(struct duplicate_entry *)dup_hash;dup_message=dup_message->duplicate_forw)	{	  printf("%d              ",dup_message->duplicate_hash);	  	  //printf("%s            ",convert_address_to_string(&dup_message->duplicate_addr));	  printf("%s            ",inet_ntop(AF_INET6,&dup_message->duplicate_addr,str,46));	  printf("%d            \n",dup_message->duplicate_seq);	  	}    }  printf("######################################################################\n");}*//*------------------------------------------------------------------------*//************** added  by Y.Ge *************//*------------------------------------------------------------------------*/voidolsr_print_duplicate_table(){	olsr_u8_t              index;	struct duplicatehash   *dup_hash;	struct duplicate_entry *dup_message;	char str[46];	struct rcving_interface	*rcvg_iface_list;  	printf("DUPLICATE TABLE\n");	printf ("\tHASH\tMESSAGE TYPE\tORIGINATOR ADDRESS\tSEQUENCE\n");  	for(index=0;index<HASHSIZE;index++)	{		dup_hash=&duplicatetable[index];      		for(dup_message=dup_hash->duplicate_forw;dup_message!=(struct duplicate_entry *)dup_hash;dup_message=dup_message->duplicate_forw)		{			printf("\t%d",dup_message->duplicate_hash);			printf("\t%d",dup_message->duplicate_type);	  			printf("\t%s",convert_address_to_string(&dup_message->duplicate_addr));			//printf("\t%s",inet_ntop(AF_INET6,&dup_message->duplicate_addr,str,46));			printf("\t%d\n",dup_message->duplicate_seq);			printf ("--- my receiving interface address:");						rcvg_iface_list = dup_message->duplicate_rcvg_iface_list;			while (rcvg_iface_list !=NULL)			{				printf ("%s , ", convert_address_to_string(&rcvg_iface_list->rcvg_interface_address));				rcvg_iface_list = rcvg_iface_list->next;			}			printf ("\n");		}	  	}}/*------------------------------------------------------------------------*/voidolsr_print_trace_duplicate_table(){	olsr_u8_t              index;	struct duplicatehash   *dup_hash;	struct duplicate_entry *dup_message;	char str[46];	struct rcving_interface	*rcvg_iface_list;  	fprintf(y_file,"DUPLICATE TABLE\n");	fprintf (y_file,"\tHASH\tMESSAGE TYPE\tORIGINATOR ADDRESS\tSEQUENCE\n");  	for(index=0;index<HASHSIZE;index++)	{		dup_hash=&duplicatetable[index];      		for(dup_message=dup_hash->duplicate_forw;dup_message!=(struct duplicate_entry *)dup_hash;dup_message=dup_message->duplicate_forw)		{			fprintf(y_file,"\t%d",dup_message->duplicate_hash);			fprintf(y_file,"\t%d",dup_message->duplicate_type);	  			fprintf(y_file,"\t%s",convert_address_to_string(&dup_message->duplicate_addr));			//printf("\t%s",inet_ntop(AF_INET6,&dup_message->duplicate_addr,str,46));			fprintf(y_file,"\t%d\n",dup_message->duplicate_seq);			fprintf (y_file,"--- my receiving interface address:");						rcvg_iface_list = dup_message->duplicate_rcvg_iface_list;			while (rcvg_iface_list !=NULL)			{				fprintf (y_file,"%s , ", convert_address_to_string(&rcvg_iface_list->rcvg_interface_address));				rcvg_iface_list = rcvg_iface_list->next;			}			fprintf (y_file,"\n");		}	  	}}/*------------------------------------------------------------------------*/intolsr_lookup_interface_address_from_duplicate_entry(struct duplicate_entry *dup_entry, struct olsr_ip_addr *addr){	struct rcving_interface	*rcvg_iface_list;		rcvg_iface_list = dup_entry->duplicate_rcvg_iface_list;		while (rcvg_iface_list != NULL)	{		if (0==memcmp(&rcvg_iface_list->rcvg_interface_address, addr, sizeof (struct olsr_ip_addr)))		{			return 1;		}				rcvg_iface_list = rcvg_iface_list->next;	}		return 0;}/*------------------------------------------------------------------------*/voidolsr_insert_interface_address_into_duplicate_entry(struct duplicate_entry *dup_entry, struct olsr_ip_addr *addr){	struct rcving_interface	 *rcvg_list;			rcvg_list = (struct rcving_interface *)malloc(sizeof(struct rcving_interface));	memcpy(&rcvg_list->rcvg_interface_address, addr, sizeof (struct olsr_ip_addr));	rcvg_list->next = dup_entry->duplicate_rcvg_iface_list;	dup_entry->duplicate_rcvg_iface_list = rcvg_list;	}	    

⌨️ 快捷键说明

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