📄 localrepair.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 <arpa/inet.h>#include <netinet/in.h>#include <sys/socket.h>#include <sys/types.h>#include "aodvConst.h"#include "aodvPktInfo.h"#include "callout.h"#include "const.h"#include "debug.h"#include "inet.h"#include "rerr.h"#include "routingTable.h"#include "rreq.h"#include "sendDatagram.h"struct LREntry { u_int32_t dest; struct LREntry *next;};static struct LREntry *firstLREntry = NULL;int inLRList(u_int32_t dest){ struct LREntry *entry = NULL; trace(TRACE_LOCAL_REPAIR,"inLRList"); for ( entry = firstLREntry ; entry != NULL ; entry = entry->next){ if(entry->dest == dest){ return TRUE; } } return FALSE;}static void addToLRList(u_int32_t dest){ struct LREntry *entry = NULL; struct LREntry *first = NULL; trace(TRACE_LOCAL_REPAIR,"addToList"); if(inLRList(dest) == FALSE) { entry = (struct LREntry *)malloc(sizeof(struct LREntry)); if(entry == NULL){ log(LOG_ERR,TRUE,"unable to allocate memory, LREntry"); } entry->dest=dest; first=firstLREntry; firstLREntry=entry; firstLREntry->next=first; }}void removeFromLRList(u_int32_t dest){ struct LREntry *toMe = NULL; struct LREntry *me = NULL; trace(TRACE_LOCAL_REPAIR,"removeFromLRList"); if(localRepair == TRUE){ for ( toMe = firstLREntry ; toMe != NULL ; toMe = toMe->next){ if(toMe->next->dest == dest){ me=toMe->next; toMe->next=me->next; free(me); return; } } }}static void issueRERR(u_int32_t broken){ trace(TRACE_LOCAL_REPAIR,"issueRERR"); //if in the list if(inLRList(broken) == TRUE){ //TODO what should N be? createAndSendRERR(broken,N); createAndSendRERR(broken,0); }}void repairLocally(u_int32_t broken) { struct RREQ *rreq = NULL; struct AodvPktInfo *info = NULL; int hopCount; trace(TRACE_LOCAL_REPAIR,"repairLocally"); if(inLRList(broken) == TRUE){ return; } hopCount = getHopCount(broken); if (hopCount == -1){ log(LOG_ERR,FALSE,"repairLocally: hopcount = -1"); return; } //create RREQ incrementDestSeqNum(broken); rreq = newRREQ(broken,DEFAULT_G); info = new_pktInfo(BROADCAST); //according to draft, good value of MIN_REPAIR_TTL //is lastHopCount //therfore using hopCount + LOCAL_ADD_TTL for initial TTL info->ttl = hopCount + LOCAL_ADD_TTL; //if(MIN_REPAIR_TTL > (hopCount / 2.0)) { //info->ttl = MIN_REPAIR_TTL + LOCAL_ADD_TTL; //} else { // info->ttl = (hopCount / 2.0) + LOCAL_ADD_TTL; //} addToLRList(broken); //create timer for RERR trace(TRACE_LOCAL_REPAIR|TRACE_TIMER,"repairLocally setting timer %u" ,2*info->ttl*NODE_TRAVERSAL_TIME); timer_setTimer(2*info->ttl*NODE_TRAVERSAL_TIME ,(cfunc_t)issueRERR ,(void *)broken); //send RREQ sendDatagram(info,rreq,sizeof(struct RREQ));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -