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

📄 aodv_timeout.c

📁 支持IPv6的adov路由协议(本人修改后)
💻 C
字号:
/***************************************************************************** * * Copyright (C) 2001 Uppsala University and Ericsson AB. * Copyright (C) 2003 Simon Fraser University and NewMIC * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * Authors: Erik Nordstr鰉, <erik.nordstrom@it.uu.se> *        : Peter Lee       <peter.lee@shaw.ca> *           * *****************************************************************************/#ifdef NS_PORT#include "aodv-uu.h"#else#include <time.h>#include "defs.h"#include "aodv_timeout.h"#include "aodv_socket.h"#include "aodv_rreq.h"#include "aodv_rerr.h"#include "timer_queue.h"#include "debug.h"#include "params.h"#include "routing_table.h"#include "packet_queue.h"#include "k_route.h"#include "seek_list.h"#include "address_conf.h"#include "address_areq.h"//PL:#ifdef _IPV6#include "ipv6_utils.h"#include "l_icmp6.h"#else#include "icmp.h"#endif /* _IPV6 */#endif /* NS_PORT *//* These are timeout functions which are called when timers expire... */#ifndef NS_PORTextern int expanding_ring_search;void route_delete_timeout(void *arg);#endifvoid NS_CLASS route_discovery_timeout(void *arg){    struct timeval now;    seek_list_t *seek_entry,*seek_entry_old=NULL;    rt_table_t *rt_entry=NULL,*rt_default_entry=NULL/*,*rt_gw_entry=NULL*/;    int i;    seek_entry = (seek_list_t *) arg;    /* Sanity check... */    if (!seek_entry)	return;    gettimeofday(&now, NULL);    //PL:#ifdef _IPV6    DEBUG(LOG_DEBUG, 0, "route_discovery_timeout: %s",	  ip6_to_str(seek_entry->dest_addr));#else    DEBUG(LOG_DEBUG, 0, "route_discovery_timeout: %s",	  ip_to_str(seek_entry->dest_addr));#endif /* _IPV6 */    printf("seek_entry->reqs:%d\n",seek_entry->reqs);    if (seek_entry->reqs < RREQ_RETRIES) {	RREQ *rreq;	if ((gw_find_flag==GW_FIND_NO_NEED)&&expanding_ring_search) {	    if (seek_entry->ttl < TTL_THRESHOLD)		seek_entry->ttl += TTL_INCREMENT;	    else {		seek_entry->ttl = NET_DIAMETER;		seek_entry->reqs++;	    }	    /* Set a new timer for seeking this destination */	    timer_add_msec(&seek_entry->seek_timer,			   2 * seek_entry->ttl * NODE_TRAVERSAL_TIME);	} else {	    seek_entry->reqs++;	    timer_add_msec(&seek_entry->seek_timer, NET_TRAVERSAL_TIME);	}	//PL:#ifdef _IPV6	DEBUG(LOG_DEBUG, 0,	      "route_discovery_timeout: Seeking %s ttl=%d wait=%d",	      ip6_to_str(seek_entry->dest_addr),	      seek_entry->ttl, 2 * seek_entry->ttl * NODE_TRAVERSAL_TIME);#else	DEBUG(LOG_DEBUG, 0,	      "route_discovery_timeout: Seeking %s ttl=%d wait=%d",	      ip_to_str(seek_entry->dest_addr),	      seek_entry->ttl, 2 * seek_entry->ttl * NODE_TRAVERSAL_TIME);#endif /* _IPV6 */	/* A routing table entry waiting for a RREP should not be expunged	   before PATH_TRAVERSAL_TIME... (Draft 10 section 6.4) */	rt_entry = rt_table_find(seek_entry->dest_addr);	if (rt_entry &&	    timeval_diff(&rt_entry->rt_timer.timeout, &now) / 1000 <	    PATH_TRAVERSAL_TIME)	    rt_table_update_timeout(rt_entry, PATH_TRAVERSAL_TIME);	for (i = 0; i < MAX_NR_INTERFACES; i++) {	    if (!DEV_NR(i).enabled)		continue;	    rreq = rreq_create(seek_entry->flags, seek_entry->dest_addr,			       seek_entry->dest_seqno, DEV_NR(i).ipaddr);	    //PL:#ifdef _IPV6	    aodv_socket_send((AODV_msg *) rreq, ipv6_multicast_addr, RREQ_SIZE,			     seek_entry->ttl, &DEV_NR(i));#else	    aodv_socket_send((AODV_msg *) rreq, AODV_BROADCAST, RREQ_SIZE,			     seek_entry->ttl, &DEV_NR(i));#endif /* _IPV6 */	}    } else {        if(gw_find_flag==GW_FIND_NEED){		seek_entry->to_internet=1;		//packet_queue_set_i(seek_entry->dest_addr);		rt_default_entry=rt_table_find_active(ipv6_dest_default);		/*if(rt_default_entry)			rt_gw_entry=rt_table_find_active(rt_default_entry->next_hop);		if(rt_default_entry&&rt_gw_entry)			//send the packet to gateway		*/		if(rt_default_entry){			rt_table_insert(seek_entry->dest_addr,rt_default_entry->next_hop,0,0,				rt_default_entry->last_life,FWD_ROUTE,rt_default_entry->ifindex);			if(seek_list_remove(seek_entry->dest_addr))				packet_queue_send(seek_entry->dest_addr);		}else{			/*finding gateway*/			gw_find_flag=GW_FINDING;			seek_entry->flags |=RREQ_INTERNET;			seek_entry_old=seek_entry;			rreq_route_discovery(gateway_mcast_addr,seek_entry->flags,seek_entry->ipd);		}	}else{		if(gw_find_flag==GW_FIND_NO_NEED){			seek_entry_old=seek_entry;			packet_queue_drop(seek_entry->dest_addr);		}		if(gw_find_flag==GW_FINDING)			packet_queue_drop(seek_entry_old->dest_addr);		DEBUG(LOG_DEBUG, 0, "route_discovery_timeout: NO ROUTE FOUND!");		#ifndef NS_PORT		/* Send an ICMP Destination Host Unreachable to the application: */		//PL:		#ifdef _IPV6		if (seek_entry->ipd)	    		icmp6_send_host_unreachable(seek_entry_old->ipd->data,seek_entry_old->ipd->len);		#else		if (seek_entry->ipd)	    	icmp_send_host_unreachable(seek_entry->ipd->data,seek_entry->ipd->len);		#endif /* _IPV6 */		#endif /* NS_PORT */		seek_list_remove(seek_entry->dest_addr);		printf("no route to %s\n",ip6_to_str(seek_entry_old->dest_addr));	}    }}void NS_CLASS route_expire_timeout(void *arg){    rt_table_t *rt_entry;    struct timeval now;    gettimeofday(&now, NULL);    rt_entry = (rt_table_t *) arg;    if (!rt_entry) {	log(LOG_WARNING, 0,	    "route_expire_timer: arg was NULL, ignoring timeout!");	return;    }    //PL:#ifdef _IPV6#else    DEBUG(LOG_DEBUG, 0, "route_expire_timeout: Route %s DOWN, seqno=%d",	  ip_to_str(rt_entry->dest_addr), rt_entry->dest_seqno);#endif /* _IPV6 */    /* If hopcount = 1, this is a direct neighbor and a link break has       occured. Send a RERR with the incremented sequence number */    if (rt_entry->hcnt == 1) {	RERR *rerr = NULL;	rt_table_t *u_entry;	//PL:#ifdef _IPV6	struct in6_addr rerr_unicast_dest = in6addr_any;#else	u_int32_t rerr_unicast_dest = 0;#endif /* _IPV6 */	int i, unicast_rerr = 0;	/* Invalidate the entry of the route that broke or timed out... */	/* Hop count -> INFTY, dest_seqno++ */	rt_table_invalidate(rt_entry);	/* Create a route error msg */	if (rt_entry->precursors) {	    rerr = rerr_create(0, rt_entry->dest_addr, rt_entry->dest_seqno);	    //PL:#ifdef _IPV6	    DEBUG(LOG_DEBUG, 0,		  "route_expire_timeout: Added %s as unreachable, seqno=%lu",		  ip6_to_str(rt_entry->dest_addr), rt_entry->dest_seqno);#else	    DEBUG(LOG_DEBUG, 0,		  "route_expire_timeout: Added %s as unreachable, seqno=%lu",		  ip_to_str(rt_entry->dest_addr), rt_entry->dest_seqno);#endif /* _IPV6 */	    if (!rt_entry->precursors->next) {		unicast_rerr = 1;		//PL:#ifdef _IPV6		memcpy(&rerr_unicast_dest, &rt_entry->precursors->neighbor, 		       sizeof(struct in6_addr)); #else		rerr_unicast_dest = rt_entry->precursors->neighbor;#endif /* _IPV6 */	    }	}	/* Purge precursor list: */	precursor_list_destroy(rt_entry);	/* Check the routing table for entries which have the unreachable	   destination (dest) as next hop. These entries (destinations)	   cannot be reached either since dest is down. They should	   therefore also be included in the RERR. */	for (i = 0; i < RT_TABLESIZE; i++) {	  for (u_entry = routing_table[i]; u_entry; u_entry = u_entry->next)	    {	        //PL:#ifdef _IPV6	      if( (memcmp(&u_entry->next_hop, &rt_entry->dest_addr, 			  sizeof(struct in6_addr)) == 0) && 		  (memcmp(&u_entry->dest_addr, &rt_entry->dest_addr, 			  sizeof(struct in6_addr)) != 0)) {#else		if ((u_entry->next_hop == rt_entry->dest_addr) &&		    (u_entry->dest_addr != rt_entry->dest_addr)) {#endif /* _IPV6 */		    if (u_entry->hcnt != INFTY)			rt_table_invalidate(u_entry);		    if (u_entry->precursors) {			if (!rerr) {			    rerr = rerr_create(0, u_entry->dest_addr,					       u_entry->dest_seqno);			    //PL:#ifdef _IPV6			    if (!u_entry->precursors->next) {				unicast_rerr = 1;				memcpy(&rerr_unicast_dest, &u_entry->precursors->neighbor,				       sizeof(struct in6_addr));			    }			    DEBUG(LOG_DEBUG, 0,				  "route_expire_timeout: Added %s as unreachable, seqno=%lu",				  ip6_to_str(u_entry->dest_addr),				  u_entry->dest_seqno);#else			    if (!u_entry->precursors->next) {				unicast_rerr = 1;				rerr_unicast_dest =				    u_entry->precursors->neighbor;			    }			    DEBUG(LOG_DEBUG, 0,				  "route_expire_timeout: Added %s as unreachable, seqno=%lu",				  ip_to_str(u_entry->dest_addr),				  u_entry->dest_seqno);#endif /* _IPV6 */			} else {			    rerr_add_udest(rerr, u_entry->dest_addr,					   u_entry->dest_seqno);			    //PL:#ifdef _IPV6			    if (!(!u_entry->precursors->next &&				  (memcmp(&rerr_unicast_dest, &u_entry->precursors->neighbor, 					  sizeof(struct in6_addr)))))			      {				unicast_rerr = 0;			      }			    DEBUG(LOG_DEBUG, 0,				  "route_expire_timeout: Added %s as unreachable, seqno=%lu",				  ip6_to_str(u_entry->dest_addr),				  u_entry->dest_seqno);#else			    if (!(!u_entry->precursors->next &&				  rerr_unicast_dest ==				  u_entry->precursors->neighbor))				unicast_rerr = 0;			    DEBUG(LOG_DEBUG, 0,				  "route_expire_timeout: Added %s as unreachable, seqno=%lu",				  ip_to_str(u_entry->dest_addr),				  u_entry->dest_seqno);#endif /* _IPV6 */			}		    }		    precursor_list_destroy(u_entry);		}	    }	}	if (rt_entry->flags & LREPAIR) {	    rreq_local_repair(rt_entry);	} else if (rerr) {	    DEBUG(LOG_DEBUG, 0,		  "route_expire_timeout: RERR created, %d bytes.",		  RERR_CALC_SIZE(rerr));	    u_entry = rt_table_find(rerr_unicast_dest);	    if (u_entry && rerr->dest_count == 1 && unicast_rerr)		aodv_socket_send((AODV_msg *) rerr,				 rerr_unicast_dest,				 RERR_CALC_SIZE(rerr), 1,				 &DEV_IFINDEX(u_entry->ifindex));	    else if (rerr->dest_count > 0) {		/* FIXME: Should only transmit RERR on those interfaces		 * which have precursor nodes for the broken route */		for (i = 0; i < MAX_NR_INTERFACES; i++) {		    if (!DEV_NR(i).enabled)			continue;		    //PL:#ifdef _IPV6		    aodv_socket_send((AODV_msg *) rerr, ipv6_multicast_addr,				     RERR_CALC_SIZE(rerr), 1, &DEV_NR(i));#else		    aodv_socket_send((AODV_msg *) rerr, AODV_BROADCAST,				     RERR_CALC_SIZE(rerr), 1, &DEV_NR(i));#endif /* _IPV6 */		}	    }	}    } else {	rt_table_invalidate(rt_entry);	precursor_list_destroy(rt_entry);    }    return;}void NS_CLASS route_delete_timeout(void *arg){    rt_table_t *rt_entry;    rt_entry = (rt_table_t *) arg;    /* Sanity check: */    if (rt_entry == NULL)	return;    //PL:#ifdef _IPV6#else    DEBUG(LOG_DEBUG, 0, "route_delete_timeout: %s",	  ip_to_str(rt_entry->dest_addr));#endif /* _IPV6 */    /* The kernel route entry is already deleted, so we only delete the       internal AODV routing entry... */    rt_table_delete(rt_entry->dest_addr);}/* This is called when we stop receiveing hello messages from a   node. For now this is basically the same as a route timeout. */void NS_CLASS hello_timeout(void *arg){    rt_table_t *rt_entry;    struct timeval now;    rt_entry = (rt_table_t *) arg;    gettimeofday(&now, NULL);    //PL:#ifdef _IPV6    DEBUG(LOG_DEBUG, 0, "hello_timeout: LINK FAILURE %s last HELLO: %d",	  ip6_to_str(rt_entry->dest_addr),	  timeval_diff(&now, &rt_entry->last_hello_time) / 1000);#else    DEBUG(LOG_DEBUG, 0, "hello_timeout: LINK FAILURE %s last HELLO: %d",	  ip_to_str(rt_entry->dest_addr),	  timeval_diff(&now, &rt_entry->last_hello_time) / 1000);#endif /* _IPV6 */    if (rt_entry && rt_entry->hcnt != INFTY && !(rt_entry->flags & UNIDIR))	timer_timeout_now(&rt_entry->rt_timer);}void NS_CLASS rreq_record_timeout(void *arg){    struct rreq_record *rreq_pkt;    rreq_pkt = (struct rreq_record *) arg;    //PL:#ifdef _IPV6    DEBUG(LOG_DEBUG, 0, "rreq_record_timeout: %s rreq_id=%lu",	  ip6_to_str(rreq_pkt->orig_addr), rreq_pkt->rreq_id);#else    DEBUG(LOG_DEBUG, 0, "rreq_record_timeout: %s rreq_id=%lu",	  ip_to_str(rreq_pkt->orig_addr), rreq_pkt->rreq_id);#endif /* _IPV6 */    /* Remove buffered information for this rreq */    rreq_record_remove(rreq_pkt->orig_addr, rreq_pkt->rreq_id);}void NS_CLASS rreq_blacklist_timeout(void *arg){    struct blacklist *bl_entry;    bl_entry = (struct blacklist *) arg;    //PL:#ifdef _IPV6    DEBUG(LOG_DEBUG, 0, "rreq_blacklist_timeout: %s",	  ip6_to_str(bl_entry->dest_addr));#else    DEBUG(LOG_DEBUG, 0, "rreq_blacklist_timeout: %s",	  ip_to_str(bl_entry->dest_addr));#endif /* _IPV6 */    rreq_blacklist_remove(bl_entry->dest_addr);}void areq_record_timeout(void *arg){    struct areq_record *areq_pkt;    areq_pkt = (struct areq_record *) arg;    DEBUG(LOG_DEBUG, 0, "areq_record_timeout: %s rreq_seqno=%lu",	  ip6_to_str(areq_pkt->req_addr), areq_pkt->seqno);    /* Remove buffered information for this rreq */    areq_record_remove(areq_pkt->req_addr, areq_pkt->seqno);}void areq_blacklist_timeout(void *arg){    struct areq_blacklist *bl_entry;    bl_entry = (struct areq_blacklist *) arg;    DEBUG(LOG_DEBUG, 0, "areq_blacklist_timeout: %s,areq_id=%lu",	  ip6_to_str(bl_entry->req_addr),bl_entry->id);    areq_blacklist_remove(bl_entry->req_addr,bl_entry->id);}void NS_CLASS rrep_ack_timeout(void *arg){    rt_table_t *rt_entry;    /* We must be really sure here, that this entry really exists at       this point... (Though it should). */    rt_entry = (rt_table_t *) arg;    /* When a RREP transmission fails (i.e. lack of RREP-ACK), add to       blacklist set... */    rreq_blacklist_insert(rt_entry->dest_addr);    //PL:#ifdef _IPV6     DEBUG(LOG_DEBUG, 0, "rrep_ack_timeout: %s", ip6_to_str(rt_entry->dest_addr));#else    DEBUG(LOG_DEBUG, 0, "rrep_ack_timeout: %s", ip_to_str(rt_entry->dest_addr));#endif /* _IPV6 */}void NS_CLASS wait_on_reboot_timeout(void *arg){    *((int *) arg) = 0;    DEBUG(LOG_DEBUG, 0, "wait_on_reboot_timeout: Wait on reboot over!!");}void arep_wait_timeout(void *arg){	printf("arep wait timeout!\n");    if(--areq_info.retries){		areq_info.seqno++;		dup_addr_detect();	}else{		tentative_address_config();		timer_remove(&addrconf_timer);	}}void addrconf_begin_timeout(void *arg){	tentative_addrconf_begin();}void address_config_timeout(void *arg){	DEBUG(LOG_DEBUG,0,"No usable address,please wait a while and try again!");	printf("No usable address,please wait a while and try again!\n");	exit(-1);}

⌨️ 快捷键说明

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