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

📄 rreqresend.c

📁 ucsb大学开发的aodv路由协议代码。
💻 C
字号:
/* * Copyright (C) 2001, University of California, Santa Barbara *  * 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. *  * Other copyrights might apply to parts of this software and are so * noted when applicable. *//* * Parts of this program has been derived from PIM sparse-mode pimd. * The pimd program is covered by the license in the accompanying file * named "LICENSE.pimd". *   * The pimd program is COPYRIGHT 1998 by University of Southern California. * */#include <netinet/in.h>#include <sys/types.h>#include <stdlib.h>#include "aodvConst.h"#include "aodvSocket.h"#include "callout.h"#include "const.h"#include "debug.h"#include "inet.h"#include "packet_input.h"#include "routingTable.h"#include "rreq.h"#include "sendDatagram.h"struct REntry {  int tries;  struct RREQ *rreq;  struct AodvPktInfo *info;  struct REntry *next;};static struct REntry *firstREntry = NULL;static struct REntry *find(u_int32_t dest){  struct REntry *entry = NULL;  struct RREQ *rreq = NULL;  trace(TRACE_RREQ_RESEND,"RreqResend:find(%s)",inet_fmt_h(dest,s1));  for(entry = firstREntry	  ; entry != NULL	  ; entry = entry->next){    if(entry->rreq != NULL){      trace(TRACE_RREQ_RESEND,"RreqResend:found entry");      rreq=entry->rreq;      if ( (rreq->dest != NULL) && (ntohl(rreq->dest) == dest) ) {	trace(TRACE_RREQ_RESEND,"RreqResend:returning entry");	return entry;      }    } else {      trace(TRACE_RREQ_RESEND,"RreqResend:find HAVE NULL entry->rreq");    }  }  trace(TRACE_RREQ_RESEND,"RreqResend:returning NULL");  return NULL;}int rreqPending(u_int32_t dst){  if(find(dst) == NULL){    return FALSE;  }else{    return TRUE;  }}static void removeEntry(struct REntry *entry){  struct REntry *toMe = NULL;     trace(TRACE_RREQ_RESEND,"RreqResend:removeEntry");  //go through list and find who is pointing to entry  if(firstREntry != NULL && entry != NULL){    trace(TRACE_RREQ_RESEND,"RreqResend:removeEntry(%s)"	  ,inet_fmt_n(entry->rreq->dest,s1));    if(entry==firstREntry){      trace(TRACE_RREQ_RESEND,"RreqResend:entry==firstEntry");      firstREntry=firstREntry->next;      //free RREQ      free(entry->rreq);      //free AodvPktInfo      free(entry->info);      //free REntry      free(entry);      entry = NULL;      return;    }else{      for(toMe = firstREntry	    ; toMe != NULL	    ; toMe = entry->next) {	if (toMe->next == entry) {	  trace(TRACE_RREQ_RESEND,"RreqResend:entry!=firstEntry");	  toMe->next=entry->next;	  //free RREQ	  free(entry->rreq);	  //free AodvPktInfo	  free(entry->info);	  //free REntry	  free(entry);	  entry = NULL;	  return;	}      }      trace(TRACE_RREQ_RESEND,"RreqResend: remove(entry not found)");    }  }}void removeFromRreqResend(u_int32_t dest){  struct REntry *entry = NULL;  entry=find(dest);  removeEntry(entry);}//static void removeFromRreqResend(u_int32_t dest){  //set timer to remove route in one second  //otherwise another rreq might be generated  //needed because of possible delay of route update//  trace(TRACE_RREQ_RESEND|TRACE_TIMER,"removeFromRreqResend setTimer 1000");//  timer_setTimer(1000,(cfunc_t) removeFromRreqResend1,(void *) dest);//}static void resendRREQ(u_int32_t dest){  struct REntry *entry = NULL;  trace(TRACE_RREQ_RESEND, "resendRreq(dest=%s"      ,inet_fmt_h(dest,s1));  entry=find(dest);  if(entry != NULL){    if(entry->tries <= RREQ_RETRIES){      if(expandingRingSearch == TRUE) {	entry->info->ttl = entry->info->ttl + TTL_INCREMENT;	if(entry->info->ttl >= TTL_THRESHOLD){	  entry->info->ttl = NET_DIAMETER;	}      }      trace(TRACE_DEMO, "resending RREQ to dest=%s"	    ,inet_fmt_h(dest,s1));      trace(TRACE_RREQ_RESEND, "resendRreq: resending rreq");      entry->rreq->broadcastId = htonl(broadcastId++);      mySeqNum++;      entry->rreq->srcSeqNum = htonl(mySeqNum);      entry->rreq->destSeqNum = htonl(getDestinationSeqNum(ntohl(entry->rreq->dest)));      printRREQ(entry->rreq);      trace(TRACE_METRIC,"s r RREQ");      sendDatagram(entry->info,entry->rreq,sizeof(struct RREQ));      if(entry->info->ttl == NET_DIAMETER){	(entry->tries)++;      }      //set timer to resend      if(expandingRingSearch == FALSE){	trace(TRACE_RREQ_RESEND|TRACE_TIMER	      ,"resendRREQ setting timer %u",NET_TRAVERSAL_TIME);	timer_setTimer(NET_TRAVERSAL_TIME		       ,(cfunc_t)resendRREQ		       ,(void *)dest);      } else {	trace(TRACE_RREQ_RESEND|TRACE_TIMER	      ,"resendRREQ setting timer %u"	      ,2*entry->info->ttl*NODE_TRAVERSAL_TIME);	timer_setTimer(2*entry->info->ttl*NODE_TRAVERSAL_TIME		       ,(cfunc_t)resendRREQ		       ,(void *)dest);      }    } else {      packet_buff_drop(dest);      removeEntry(entry);    }  }}static void insert(struct REntry *entry){  struct REntry *first = NULL;  first=firstREntry;  firstREntry=entry;  firstREntry->next=first;}void insertRREQIntoResendList(struct AodvPktInfo *info, struct RREQ *rreq){  struct REntry *entry = NULL;  int newlyCreated = FALSE;    trace(TRACE_RREQ_RESEND, "insertRreqIntoResendList(info->src=%s"      ,inet_fmt_n(info->src,s1));  trace(TRACE_RREQ_RESEND, "insertRreqIntoResendList(rreq->dest=%s"      ,inet_fmt_n(rreq->dest,s1));  entry = find(ntohl(rreq->dest));    if(entry == NULL){    //create entry    entry = (struct REntry *)malloc(sizeof(struct REntry));    if(entry == NULL){      log(LOG_ERR,TRUE,"unable to allocate memory, REntry");    }      trace(TRACE_RREQ_RESEND,"insertRreqIntoResendList:ADDRESS:%u",entry);    entry->tries = 1;    entry->next = NULL;    newlyCreated=TRUE;  }    entry->info=info;  entry->rreq=rreq;  if(newlyCreated == TRUE){    insert(entry);  }  //set timer to resend  if(expandingRingSearch == FALSE){    trace(TRACE_RREQ_RESEND|TRACE_TIMER	  ,"insertRreqIntoResendList:timer:%u"	  ,NET_TRAVERSAL_TIME);    timer_setTimer(NET_TRAVERSAL_TIME		   ,(cfunc_t)resendRREQ		   ,(void *)ntohl(rreq->dest));  } else {    trace(TRACE_RREQ_RESEND|TRACE_TIMER	  ,"insertRreqIntoResendList:timer:%u"	  ,2*info->ttl*NODE_TRAVERSAL_TIME);    timer_setTimer(2*info->ttl*NODE_TRAVERSAL_TIME		   ,(cfunc_t)resendRREQ		   ,(void *)ntohl(rreq->dest));  }}

⌨️ 快捷键说明

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