📄 aodv.pc
字号:
/* -*- Mode: C; -*- */ /* * GloMoSim is COPYRIGHTED software. Release 2.02 of GloMoSim is available * at no cost to educational users only. * * Commercial use of this software requires a separate license. No cost, * evaluation licenses are available for such purposes; please contact * info@scalable-networks.com * * By obtaining copies of this and any other files that comprise GloMoSim2.02, * you, the Licensee, agree to abide by the following conditions and * understandings with respect to the copyrighted software: * * 1.Permission to use, copy, and modify this software and its documentation * for education and non-commercial research purposes only is hereby granted * to Licensee, provided that the copyright notice, the original author's * names and unit identification, and this permission notice appear on all * such copies, and that no charge be made for such copies. Any entity * desiring permission to use this software for any commercial or * non-educational research purposes should contact: * * Professor Rajive Bagrodia * University of California, Los Angeles * Department of Computer Science * Box 951596 * 3532 Boelter Hall * Los Angeles, CA 90095-1596 * rajive@cs.ucla.edu * * 2.NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY * PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * * 3.Neither the software developers, the Parallel Computing Lab, UCLA, or any * affiliate of the UC system shall be liable for any damages suffered by * Licensee from the use of this software. */// Use the latest version of Parsec if this line causes a compiler error./* * Name: aodv.pc * * First Implemented for version 3 by SJ Lee (sjlee@cs.ucla.edu) * Updated for AODV IETF Draft version 13 by Vrishali Wagle * (vrishali@cs.ucsb.edu) */ /* * NOTE: - Reboots and subsequent actions after reboot are not implemented. * RREP-ACKS are implemented, however blacklist sets are not implemented.*/ #include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include "api.h"#include "structmsg.h"#include "fileio.h"#include "message.h"#include "network.h"#include "aodv.h"#include "ip.h"#include "nwip.h"#include "nwcommon.h"#include "application.h"#include "transport.h"#include "java_gui.h"#include "aodv.h" #define max(a,b) ((a > b) ? a : b)/* * RoutingAodvGetMyRouteTimeout * * The configured value for MY_ROUTE_TIMEOUT must be at least 2 * PATH_DISCOVERY_TIME * Individual nodes may wish to change their values of MY_ROUTE_TIMEOUT. in that case appropriate statements must be added to this function */clocktype RoutingAodvGetMyRouteTimeout(GlomoNode *node){ clocktype lifetime = MY_ROUTE_TIMEOUT;/*Calculate lifetime, as function of node if needed*/ // assert(lifetime >= 2 * PATH_DISCOVERY_TIME); return lifetime; } /* * RoutingAodvGetMinimalLifetime * * Given the hopCount, calculate the MinimalLifetime */ clocktype RoutingAodvGetMinimalLifetime(int hopCount){ return simclock() + 2 * NET_TRAVERSAL_TIME - 2 * hopCount * NODE_TRAVERSAL_TIME; } /* * RoutingAodvGetRingTraversalTime * * Given the TTL calculate the RING_TRAVERSAL_TIME */ clocktype RoutingAodvGetRingTraversalTime(int ttl){ return (clocktype)(2 * NODE_TRAVERSAL_TIME * (ttl + TIMEOUT_BUFFER));}/* * RoutingAodvGetDeletePeriod * * Returns the DeletePeriod */clocktype RoutingAodvGetDeletePeriod(){ return K * max(ACTIVE_ROUTE_TIMEOUT,HELLO_INTERVAL); }/* * RoutingAodvDisplayPrecursors * * Display the precursor list - may be used for debugging. */ void RoutingAodvDisplayPrecursors(AODV_PL_Node *head){ AODV_PL_Node *current; current = head; while(current!=NULL) { printf(" %d ",current->precursor); current= current->next; } }/* * RoutingAodvDisplayRouteTable * * Display the route table - may be used for debugging */ void RoutingAodvDisplayRouteTable(GlomoNode *node){ GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar; GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol; char clockdisplay[100]; AODV_RT_Node *current; char dsv,rv; AODV_PL_Node *precurr; GLOMO_PrintClockInSecond(simclock(),clockdisplay); printf("\nRoute table for Node %d with seq no %d at time %s is\n",node->nodeAddr,RoutingAodvGetMySeq(node),clockdisplay); current = aodv->routeTable.head; printf("Dest DestSeq RouteValid DestSeqValid HopCount NextHop Lifetime Precursors"); while(current!=NULL) { GLOMO_PrintClockInSecond(current->lifetime,clockdisplay); if(current->valid==TRUE)rv ='T'; else rv ='F'; if(current->destSeqValid==TRUE)dsv='T'; else dsv='F'; printf("\n%d\t%d\t%c\t%c\t%d\t%d\t%s ",current->destAddr,current->destSeq,rv,dsv,current->hopCount,current->nextHop,clockdisplay); RoutingAodvDisplayPrecursors(current->precursorList.head); current= current->next; }}/* * RoutingAodvReplaceInsertRouteTable * * Insert/Update an entry into the route table */void RoutingAodvReplaceInsertRouteTable( GlomoNode *node, NODE_ADDR destAddr, int destSeq, BOOL destSeqValid, BOOL valid, int hopCount, NODE_ADDR nextHop, clocktype lifetime){ GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar; GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol; AODV_RT *routeTable = &aodv->routeTable; AODV_RT_Node* theNode = NULL; AODV_RT_Node* current; AODV_RT_Node* previous; assert(node->nodeAddr!=destAddr); //no loops allowed if(destSeqValid==TRUE)//This entry is a proper route entry and not a neighbor entry { aodv->stats.numRoutes++; } //Find the insertion point. Entries are sorted in increaseing order of node addresses previous = NULL; current = routeTable->head; while ((current != NULL) && (current->destAddr < destAddr)) { previous = current; current = current->next; }//while// if((current==NULL)||(current->destAddr!=destAddr)) { //Corresponding entry does not exist. So add entry for this destination ++(routeTable->size); theNode = (AODV_RT_Node *)checked_pc_malloc(sizeof(AODV_RT_Node)); theNode->lifetime = lifetime; theNode->destAddr = destAddr; theNode->destSeq = destSeq; theNode->destSeqValid = destSeqValid; theNode->valid = valid; theNode->hopCount = hopCount; theNode->nextHop = nextHop; theNode->precursorList.head = NULL; theNode->precursorList.tail = NULL; theNode->precursorList.size = 0; theNode->beingRepaired=FALSE; theNode->repairable=FALSE; if (previous == NULL) { theNode->next = routeTable->head; routeTable->head = theNode; } else { theNode->next = previous->next; previous->next = theNode; } RoutingAodvSetTimer(node, MSG_NETWORK_CheckRouteTimeout, destAddr,lifetime-simclock()); } else { assert(current->destAddr==destAddr); if(((lifetime>current->lifetime)&&(current->valid==TRUE))||(current->valid==FALSE)) {//the entry was valid and new lifetime is greater than lifetime in entry or the entry was invalid - in which case the lifetime field may just be greater than current lifetime, but it is the DELETE_PERIOD current->lifetime = lifetime; RoutingAodvSetTimer(node, MSG_NETWORK_CheckRouteTimeout, destAddr,lifetime-simclock()); } current->destAddr = destAddr; if(destSeqValid==TRUE) { //update the destseq and destSeqValid fields only if new value is valid. else retain old values..... current->destSeq = destSeq; current->destSeqValid = destSeqValid; } else { //in this case update seq number ONLY if existing entry is invalid.......... if(current->valid==FALSE)// We had an entry, which was invalid .... possibly current->destSeqValid is true..... { current->destSeq = destSeq; current->destSeqValid = destSeqValid; } } assert(valid==TRUE); current->valid = TRUE; current->hopCount = hopCount; current->nextHop = nextHop; if(current->beingRepaired==TRUE) { current->beingRepaired=FALSE; } if(current->repairable==TRUE) { current->repairable = FALSE; } }}/* * RoutingAodvCheckPrecursorList * * Checks if a precursor node is present in the list */BOOL RoutingAodvCheckPrecursorList(NODE_ADDR precursor, AODV_PL_Node *head){ AODV_PL_Node *current; for(current=head;current!=NULL;current=current->next) { if(current->precursor==precursor) { return TRUE; } } return FALSE;}/* * RoutingAodvAddPrecursor * * Adds the precursor node to the precursor list for destination address destAddr */ void RoutingAodvAddPrecursor(NODE_ADDR precursor,NODE_ADDR destAddr, AODV_RT* routeTable){ AODV_RT_Node* current; AODV_PL_Node *newNode; //Find the insertion point. Entries are sorted in increaseing order of node addresses current = routeTable->head; while ((current != NULL) && (current->destAddr < destAddr)) { current = current->next; }//while// if(current==NULL||current->destAddr!=destAddr) { assert(FALSE); } newNode = (AODV_PL_Node*)pc_malloc(sizeof(AODV_PL_Node)); newNode->precursor = precursor; newNode->next=NULL; if(RoutingAodvCheckPrecursorList(precursor,current->precursorList.head)) { return; } if(current->precursorList.size==0) { current->precursorList.head = current->precursorList.tail = newNode; } else { current->precursorList.tail->next = newNode; current->precursorList.tail = newNode; } current->precursorList.size++; }/* * RoutingAodvInsertNbrTable * * Inserts new entry in neighbor table */void RoutingAodvInsertNbrTable(GlomoNode *node, NODE_ADDR nbrAddr){ GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar; GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol; AODV_NT *nbrTable = &aodv->nbrTable; AODV_NT_Node* current; AODV_NT_Node* previous; char clockdisplay[100]; AODV_NT_Node* newNode = (AODV_NT_Node *)checked_pc_malloc(sizeof(AODV_NT_Node)); newNode->nbrAddr = nbrAddr; newNode->lastHello = simclock(); newNode->lastPkt = simclock(); newNode->next = NULL; ++(nbrTable->size); // Find Insertion point. Insert after all address matches. previous = NULL; current = nbrTable->head; while ((current != NULL) && (current->nbrAddr <= nbrAddr)) { previous = current; current = current->next; }//while// if (previous == NULL) { newNode->next = nbrTable->head; nbrTable->head = newNode; } else { newNode->next = previous->next; previous->next = newNode; }//if// RoutingAodvSetTimer(node, MSG_AODV_CheckPacketsRecd, nbrAddr, (clocktype)(ALLOWED_HELLO_LOSS * HELLO_INTERVAL)); RoutingAodvSetTimer(node, MSG_AODV_CheckIfHelloed, nbrAddr, RoutingAodvGetDeletePeriod());} /* RoutingAodvInsertNbrTable *//* * RoutingAodvInsertSeenTable * * Insert an entry into the seen table */static voidRoutingAodvInsertSeenTable( GlomoNode *node, NODE_ADDR srcAddr, int bcastId, AODV_RST *seenTable){ if (seenTable->size == 0) { seenTable->rear = (AODV_RST_Node *) pc_malloc(sizeof(AODV_RST_Node)); assert(seenTable->rear != NULL); seenTable->front = seenTable->rear; } else { seenTable->rear->next = (AODV_RST_Node *) pc_malloc(sizeof(AODV_RST_Node)); assert(seenTable->rear->next != NULL); seenTable->rear = seenTable->rear->next; } seenTable->rear->srcAddr = srcAddr; seenTable->rear->bcastId = bcastId; seenTable->rear->next = NULL; ++(seenTable->size); RoutingAodvSetTimer( node, MSG_NETWORK_FlushTables, ANY_DEST, (clocktype)PATH_DISCOVERY_TIME);} /* RoutingAodvInsertSeenTable *//* * RoutingAodvInsertBuffer * * Insert a packet into the buffer if no route is available */static void RoutingAodvInsertBuffer(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -