📄 top_statique.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. *//* * $Id: top_statique.c,v 1.2 2000/12/06 10:36:12 prima Exp $ */#include "defs.h"struct address_neighbor *neighbors_network_address=NULL;struct timeval hold_time_neighbor_fixed;/*-----------------------------------------------------------------------------*/struct address_neighbor *already_exist_in_neighborhood(struct olsr_ip_addr address){ struct address_neighbor *address_network; address_network=neighbors_network_address; while(address_network!=NULL) { // if (address_network->address.s_addr==send_address->sin_addr.s_addr) /*v4->v6 del if (address_network->address.s_addr==address)*/ //v4->v6 add if(0== memcmp(&(address_network->address.s6_addr),&address,sizeof(struct olsr_ip_addr))) return (address_network); address_network=address_network->next; } return(NULL);}/*-----------------------------------------------------------------------------*/voiddel_from_static_neighborhood(struct olsr_ip_addr address){ struct address_neighbor *address_network; struct address_neighbor *address_network_tmp; address_network=neighbors_network_address; neighbors_network_address=NULL; while(address_network!=NULL) { /* v4->v6 del if((address_network->address.s_addr==address))*/ //v4->v6 if(0==memcmp(&(address_network->address.s6_addr),&address,sizeof(struct olsr_ip_addr))) { address_network_tmp=address_network; address_network=address_network->next; free(address_network_tmp); } else { address_network_tmp=address_network; address_network=address_network->next; address_network_tmp->next=neighbors_network_address; neighbors_network_address=address_network_tmp; } }}/*-----------------------------------------------------------------------------*/voidadd_to_static_neighborhood(struct olsr_ip_addr address){ struct address_neighbor *address_network; if(!already_exist_in_neighborhood(address)) { address_network=(struct address_neighbor *)malloc(sizeof(struct address_neighbor)); address_network->next=neighbors_network_address; neighbors_network_address=address_network; /*v4->v6 del address_network->address.s_addr=address;*/ //v4->v6 add memcpy(&(address_network->address.s6_addr),&address,sizeof(struct olsr_ip_addr)); } else { printf("Node already exist in the static neighborhood!!!\n"); }}/*-----------------------------------------------------------------------------*/voidupdate_static_neighborhood(struct hello_message *message){ struct hello_neighbor *message_neighbors; struct hello_neighbor *message_neighbors_tmp; message_neighbors=message->neighbors; while(message_neighbors!=NULL) { //switch(message_neighbors->status) //commented by Y.Ge switch(message_neighbors->neigh_status) //added by Y.Ge { case ADD_NEIGHBOR: add_to_static_neighborhood(message_neighbors->address); break; case DEL_NEIGHBOR: del_from_static_neighborhood(message_neighbors->address); break; default:; } message_neighbors=message_neighbors->next; } /*Verifier avec Epiphane si la variable passe en valeur ou bien par reference*/ olsr_destroy_hello_message(message);}/*-----------------------------------------------------------------------------*/voidload_topology_filter(){ char address_presentation[100]; struct address_neighbor *address_network; int size; FILE *f_id; olsr_init_timer(500000,&hold_time_neighbor_fixed); if(debug_level > 5) printf("le fixed time out %d %d \n",hold_time_neighbor_fixed.tv_sec,hold_time_neighbor_fixed.tv_usec); gettimeofday(&now,NULL); if ((f_id=fopen("topology.net","r"))==NULL) { printf("ERREUR fichier de topologie non existant\n"); // exit(0); } else while(fgets(address_presentation,sizeof(address_presentation),f_id)!=NULL) { if(strncmp(address_presentation,"#",1)==0) {} else { if(strncmp(address_presentation,"default",7)==0) { fgets(address_presentation,sizeof(address_presentation),f_id); size=strlen(address_presentation); address_presentation[size-1]='\0'; /*v4->v6 del default_gateway=inet_addr(address_presentation);*/ //v4->v6 add inet_pton(AF_INET6,address_presentation,&default_gateway); continue; } if(strncmp(address_presentation,"s",1)==0) { fgets(address_presentation,sizeof(address_presentation),f_id); size=strlen(address_presentation); address_presentation[size-1]='\0';// fscanf(f_id,"%s\n",address_presentation); //address_network=new(struct address_neighbor); address_network=(struct address_neighbor *)malloc(sizeof(struct address_neighbor)); address_network->next=neighbors_network_address; neighbors_network_address=address_network; /*v4->v6 del address_network->address.s_addr=inet_addr(address_presentation);*/ //v4->v6 add inet_pton(AF_INET6,address_presentation,&(address_network->address)); } else if(strncmp(address_presentation,"f",1)==0) { fgets(address_presentation,sizeof(address_presentation),f_id); size=strlen(address_presentation); address_presentation[size-1]='\0';// fscanf(f_id,"%s\n",address_presentation); add_fictif_neighbors(address_presentation); } } } fclose(f_id); }/*-----------------------------------------------------------------------------*/intis_neighbor(struct sockaddr_in6 *recv_node,struct sockaddr_in6 *send_node){ struct olsr_ip_addr *recv_address; struct olsr_ip_addr *send_address; struct address_neighbor * address_network; /*v4->v6 del recv_address= &recv_node->sin_addr.s_addr; send_address=&send_node->sin_addr.s_addr;*/ printf ("----- in is_neigbor -----\n"); //v4->v6 add memcpy(recv_address,&(recv_node->sin6_addr),sizeof(struct olsr_ip_addr)); memcpy(send_address,&(send_node->sin6_addr),sizeof(struct olsr_ip_addr)); address_network=neighbors_network_address; printf ("----- before print -----\n"); print_topology(); printf ("----- after print -----\n"); address_network=neighbors_network_address; while(address_network!=NULL) { //if (address_network->address.s_addr==send_address->sin_addr.s_addr) /*v4->v6 del if (address_network->address.s_addr==*send_address) */ //v4->v6 add if(0==memcmp(&(address_network->address),send_address,sizeof(struct olsr_ip_addr))) return 1; address_network=address_network->next; } return 0;}/*-----------------------------------------------------------------------------*/voidprint_topology(){ char str[INET6_ADDRSTRLEN]; struct address_neighbor * address_network; address_network=neighbors_network_address; printf ("----- in print topology -----\n"); while(address_network!=NULL) { /* v4->v6 del printf("voisin:%s\n",inet_ntoa(address_network->address));*/ printf("voisin:%s\n",inet_ntop(AF_INET6,&address_network->address, str, sizeof(str))); address_network=address_network->next; }}/*-----------------------------------------------------------------------------*/voidadd_fictif_neighbors(char *address_presentation){ //struct sockaddr_in file_address; struct olsr_ip_addr file_address; struct neighbor_entry *neighbor; struct neighbor_2_entry *two_hop_neighbor; struct sockaddr_in6 *address; struct mpr_selector_entry *mprs; if(debug_level > 5) printf(" address presentation %s \n",address_presentation);// memset(&file_address, 0, sizeof (file_address));// file_address.sin_family = AF_INET;// file_address.sin_port = 0;// (file_address.sin_addr).s_addr = inet_addr(address_presentation); /*v4->v6 del file_address = inet_addr(address_presentation);*/ //v4->v6 add inet_pton(AF_INET6,address_presentation,&file_address); //neighbor=new(struct neighbor_entry); neighbor=(struct neighbor_entry *)malloc(sizeof(struct neighbor_entry)); // memcpy(&neighbor->neighbor_addr,(struct sockaddr *)&file_address,sizeof(struct sockaddr)); memcpy(&neighbor->neighbor_addr,&file_address,sizeof(struct olsr_ip_addr)); // address=(struct sockaddr_in *)&neighbor->neighbor_addr; //printf("%d \n",address->sin_addr.s_addr); //printf("%s \n",inet_ntoa(address->sin_addr)); if(debug_level > 5) printf("%s \n",convert_address_to_string(&neighbor->neighbor_addr)); //olsr_update_hold_time(NEIGHB_HOLD_TIME,&neighbor->neighbor_timer); timeradd(&now,&hold_time_neighbor_fixed,&neighbor->neighbor_timer); if(debug_level > 5) { printf(" now %d %d \n",now.tv_sec,now.tv_usec); printf("le time ourtinsere %d %d \n",neighbor->neighbor_timer.tv_sec,neighbor->neighbor_timer.tv_usec); } neighbor->neighbor_ifp=NULL; neighbor->neighbor_2_list=NULL; neighbor->neighbor_2_nocov=0; olsr_insert_neighbor_table(neighbor); //neighbor->neighbor_status=NBS_SYM; //commented by Y.Ge neighbor->neighbor_status=SYM_LINK; //added by Y.Ge /* remove this neighbor from the two hop table if exist */ if((two_hop_neighbor=olsr_lookup_two_hop_neighbor_table(&neighbor->neighbor_addr))!=NULL) olsr_delete_two_hop_neighbor_table(two_hop_neighbor); /****Modifying the mpr selector table ***/ //mprs=new(struct mpr_selector_entry); mprs=(struct mpr_selector_entry *)malloc(sizeof(struct mpr_selector_entry)); //memcpy(&mprs->mpr_selector_addr,&message->source_addr,sizeof(struct sockaddr)); memcpy(&mprs->mpr_selector_addr,&file_address,sizeof(struct olsr_ip_addr)); olsr_insert_mpr_selector_table(mprs); //mprs->mpr_selector_seq=message->mpr_seq_number; mprs->mpr_selector_seq=1; // olsr_update_hold_time(NEIGHB_HOLD_TIME,&mprs->mpr_selector_timer); timeradd(&now,&hold_time_neighbor_fixed,&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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -