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

📄 aodv.pc

📁 aodv program to simulate in glomosim simulator
💻 PC
📖 第 1 页 / 共 5 页
字号:
 */void RoutingAodvActivateRoute(NODE_ADDR destAddr, AODV_RT *routeTable){    AODV_RT_Node *current;    for (current = routeTable->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            current->valid = TRUE;            current->lifetime = simclock() + ACTIVE_ROUTE_TIMEOUT;            return;        }    }} /* RoutingAodvActivateRoute *//* * RoutingAodvGetPrecursors * *  */ void RoutingAodvGetPrecursors(GlomoNode *node, NODE_ADDR destAddr,AODV_PL* precursorList){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    AODV_PL_Node *plnode;    AODV_RT_Node *current;    current = aodv->routeTable.head;    while((current!=NULL)&&(current->destAddr!=destAddr))    {	current = current->next;        }    assert(current!=NULL);	    plnode = current->precursorList.head;    while(plnode!=NULL)    {      if(RoutingAodvCheckPrecursorList(plnode->precursor,precursorList->head) == FALSE)//does not contain - add it      {          AODV_PL_Node *newNode;          newNode = (AODV_PL_Node*)pc_malloc(sizeof(AODV_PL_Node));          newNode->precursor = plnode->precursor;          newNode->next = NULL;														  if(precursorList->head==NULL)	    {	      precursorList->head = newNode;	      precursorList->tail = newNode; 	  	    }	  else	    {	      precursorList->tail->next = newNode;	      precursorList->tail = newNode;	   	    }	  precursorList->size++;	             }	         plnode = plnode->next;      }}/* * RoutingAodvInactivateRoutesAndGetDestinations * * Inactivate routes that use the broken link. Also passes the destinations and corresponding destination sequence numbers that are inaccessible because of this broken link. *  */void RoutingAodvInactivateRoutesAndGetDestinations(    GlomoNode* node,    AODV_RT* routeTable,    NODE_ADDR nextHop,    AODV_AddressSequenceNumberPairType destinationPairs[],    int maxNumberDestinationPairs,    int* numberDestinations,    AODV_PL* precursorList){    AODV_RT_Node *current;    int numDests = 0;    for (current = routeTable->head;         current != NULL;         current = current->next)    {      if (current->nextHop == nextHop)        {//link break for next hop of an active route	            if(current->valid==TRUE)	    {	      current->valid = FALSE;	      	      if(current->destSeqValid)		{		  current->destSeq++;   		}	      	      current->lifetime = simclock() + RoutingAodvGetDeletePeriod();	      RoutingAodvSetTimer(node, MSG_AODV_DeleteRouteEntry,				  current->destAddr,RoutingAodvGetDeletePeriod());	    }	  if(current->repairable==TRUE)	    {	      current->repairable = FALSE;	    }	  if(current->beingRepaired==TRUE)	    {	      current->beingRepaired=FALSE;	    } 	  	  if (current->precursorList.size>0) 	    {//There are neighbors sending traffic to this unreachable destination	      AODV_PL_Node *plnode;	      destinationPairs[numDests].destinationAddress = 		current->destAddr;	      destinationPairs[numDests].destinationSequenceNumber = 		current->destSeq;	      //Add each precursor to precursorList. RERRs would be sent to each neighbor in this precursor list	      RoutingAodvGetPrecursors(node,current->destAddr,precursorList);		      numDests++;            }//if//           }//if//    }//for//    *numberDestinations = numDests;} /* RoutingAodvInactivateRoute *//* * RoutingAodvInactivateRoutesInLocalRepair * * Inactivates routes and marks them as repairable/ being repaired */ void RoutingAodvInactivateRoutesInLocalRepair(GlomoNode *node, NODE_ADDR nextHop, NODE_ADDR destAddr){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;   AODV_RT_Node *current;   /*Note: This function is called when :     1. A Mac Layer notification is received regarding the link break. In that case destAddr is the address of the IP destination of the packet that was not delivered     2. On basis of HELLO packets, it is determined that a link to a particular neighbor is lost.  In that case, destAddr is set to ANY_DEST by the calling function and we just mark the routes using this neighbor as next hop as repairable.  No route is "being repaired" in this case.    */     for(current = aodv->routeTable.head;current!=NULL;current=current->next)     {       if(current->nextHop==nextHop)//This route uses this nextHop as the next hop.	 {	   if(current->valid==FALSE)	     {	       continue;	     }	   current->valid = FALSE;	   current->lifetime = simclock() + RoutingAodvGetDeletePeriod();	   RoutingAodvSetTimer(node, MSG_AODV_DeleteRouteEntry,			       current->destAddr,RoutingAodvGetDeletePeriod());		       	   if(current->destAddr==destAddr) //the link layer notification was received for packet bound to this dest	     {	       //Here the sequence number is updated	       assert(current->beingRepaired==FALSE);	  	       current->beingRepaired = TRUE;	       current->repairable = FALSE;	       if(current->destSeqValid==TRUE)		 current->destSeq++;	     }	  	   else	     { //route is broken, but we may try to repair it later .. not now though ...	     	       if(current->destSeqValid==TRUE)		 {		   current->destSeq++;		  		 }	       if((current->hopCount<=MAX_REPAIR_TTL))		 {		   assert(current->repairable==FALSE);		   current->repairable = TRUE;    		 }     	       else		 {		   current->repairable = FALSE; //too far away - not repairable    		   		 }	      	     }//else	 }//if current->nextHop==nextHop	           }//for }void SendRouteErrorPacket(    GlomoNode* node,     const AODV_RERR_Packet* rerrPacket,AODV_PL *precursorList){   GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;   GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;   clocktype delay;    Message* newMsg = GLOMO_MsgAlloc(node, 0, 0, 0);    int packetSize = sizeof(AODV_RERR_Packet);    int I;    AODV_PL_Node *plnode;    assert(rerrPacket->pktType == (unsigned short)AODV_RERR);    assert(rerrPacket->destinationCount >= 1);    GLOMO_MsgPacketAlloc(node, newMsg, packetSize);    memcpy(GLOMO_MsgReturnPacket(newMsg), rerrPacket, packetSize);    assert(precursorList->size>=1);    if(precursorList->size>1)    {      delay = pc_erand(node->seed) * BROADCAST_JITTER;            NetworkIpSendRawGlomoMessageWithDelay(node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, 1, delay);    }    else    {        NetworkIpSendRawGlomoMessageToMacLayer(node, newMsg, precursorList->head->precursor, CONTROL, IPPROTO_AODV, 1,				             DEFAULT_INTERFACE, precursorList->head->precursor);     //Single precursor hence unicast to that neighbor    }    //Free the space occupied by each precursor node    plnode = precursorList->head;    while(plnode!=NULL)    {      precursorList->head = plnode->next;      pc_free(plnode);      plnode = precursorList->head;	    }}/* * RoutingAodvInit * * Initialization function for AODV protocol */void RoutingAodvInit(    GlomoNode *node,    GlomoRoutingAodv **aodvPtr,    const GlomoNodeInput *nodeInput){    GlomoRoutingAodv *aodv =         (GlomoRoutingAodv *)checked_pc_malloc (sizeof(GlomoRoutingAodv));    clocktype delay;    int plusMinus;    (*aodvPtr) = aodv;    if (aodv == NULL)    {        fprintf(stderr, "AODV: Cannot alloc memory for AODV struct!\n");        assert (FALSE);    }    RoutingAodvInitStats(node);    RoutingAodvInitRouteTable(&aodv->routeTable);    RoutingAodvInitNbrTable(&aodv->nbrTable);    RoutingAodvInitSeenTable(&aodv->seenTable);    RoutingAodvInitBuffer(&aodv->buffer);    RoutingAodvInitSent(&aodv->sent);    RoutingAodvInitSeq(node);    RoutingAodvInitBcastId(node);    NetworkIpSetPacketDropNotificationFunction(        node, &RoutingAodvPacketDropNotificationHandler);#ifdef HELLO_PACKETS    aodv->lastbcast = 0;    if(pc_erand(node->seed)<=0.5) plusMinus = 1;else plusMinus = -1; //whether the delay is before or after one sec    delay = pc_erand(node->seed) * BROADCAST_JITTER;    RoutingAodvSetTimer(node,MSG_AODV_HELLO_EVENT,ANY_DEST,HELLO_INTERVAL+plusMinus * delay);    aodv->lastpkt = 0;#endif    NetworkIpSetRouterFunction(node, &RoutingAodvRouterFunction);} /* RoutingAodvInit *//* * RoutingAodvFinalize  * * Called at the end of the simulation to collect the results */void RoutingAodvFinalize(GlomoNode *node){    GlomoNetworkIp *ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;    GlomoRoutingAodv *aodv = (GlomoRoutingAodv *)ipLayer->routingProtocol;    FILE *statOut;    float avgHopCnt;    char buf[GLOMO_MAX_STRING_LENGTH];    sprintf(buf, "Number of Route Requests Txed = %d",                  aodv->stats.numRequestSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Route Requests Originated as source of route (Not local repair) = %d", 	    aodv->stats.numRequestOrig);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Replies Txed = %d", 	    aodv->stats.numReplySent);    GLOMO_PrintStat(node, "RoutingAodv", buf);        sprintf(buf, "Number of Replies Sent as Destination = %d",                  aodv->stats.numReplySentAsDest);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Replies Sent as Intermediate Node = %d", 	    aodv->stats.numReplySentAsIn);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Gratuitous Replies Sent = %d", 	    aodv->stats.numGratuitousReplySent);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Reply Acks Sent = %d", 	    aodv->stats.numReplyAckSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);        sprintf(buf, "Number of Route Errors (RERR) Txed = %d",                  aodv->stats.numRerrSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);                                sprintf(buf, "Number of Route Errors (RERR) sent without N bit set = %d",aodv->stats.numRerrNoNSent);                             GLOMO_PrintStat(node,"RoutingAodv",buf);                                 sprintf(buf, "Number of Route Errors (RERR) sent with N bit set = %d",aodv->stats.numRerrNSent);                             GLOMO_PrintStat(node,"RoutingAodv",buf);    sprintf(buf, "Number of CTRL Packets Txed = %d",                  aodv->stats.numRequestSent + aodv->stats.numReplySent+ aodv->stats.numReplyAckSent + aodv->stats.numRerrSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Routes Selected = %d", aodv->stats.numRoutes);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Hop Counts = %d", aodv->stats.numHops);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Data Txed = %d",                  aodv->stats.numDataTxed);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Data Packets Originated = %d",                  aodv->stats.numDataSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Data Packets Received = %d",                  aodv->stats.numDataReceived);    GLOMO_PrintStat(node, "RoutingAodv", buf);    if(aodv->stats.numDataReceived!=0)      {	avgHopCnt  = (float)aodv->stats.numHops/(float)aodv->stats.numDataReceived;	sprintf(buf,"Average route length = %f",avgHopCnt);	GLOMO_PrintStat(node,"RoutingAodv",buf);      }#ifdef HELLO_PACKETS    sprintf(buf,"Number of Hello packets sent = %d",aodv->stats.numHelloSent);    GLOMO_PrintStat(node,"RoutingAodv",buf);#endif#ifdef LOCAL_REPAIR    sprintf(buf,"Number of attempts at local repair = %d",aodv->stats.numAttemptsLocalRepair);    GLOMO_PrintStat(node,"RoutingAodv",buf);      sprintf(buf,"Number of successful local repair = %d",aodv->stats.numSuccessfulLocalRepair);    GLOMO_PrintStat(node,"RoutingAodv",buf);  #endif    sprintf(buf, "Number of Packets Dropped or Left waiting for Route = %d",	    (aodv->stats.numPacketsDropped + aodv->buffer.size));    GLOMO_PrintStat(node, "RoutingAodv", buf);    sprintf(buf, "Number of Broken Links = %d", aodv->stats.numBrokenLinks);    GLOMO_PrintStat(node, "RoutingAodv", buf);      sprintf(buf, "Number of Destination Unreachable Messages sent to application = %d", aodv->stats.numDestUnrchSent);    GLOMO_PrintStat(node, "RoutingAodv", buf);      } /* RoutingAodvFinalize*//* * RoutingAodvHandleData * * Processing procedure when data is received */void RoutingAodvHandleData(GlomoNode *node, Message *msg, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    IpHeaderType *ipHeader = (IpHeaderType *)GLOMO_MsgReturnPacket(msg);    NODE_ADDR sourceAddress = ipHeader->ip_src;    NODE_ADDR lastHop;    assert(sourceAddress  != node->nodeAddr);//Update Lifetime of source and next hop towards the source        if(RoutingAodvCheckRouteExist(sourceAddress,&aodv->routeTable)==TRUE)      {  //getting a data packet from a source, whose entry you don't have in route table is very much possible thanks to local repair ....         // hence this check needs to be made		RoutingAodvUpdateLifetime(sourceAddress, &aodv->routeTable);	RoutingAodvSetTimer(node, MSG_NETWORK_CheckRouteTimeout, 			    sourceAddress, (clocktype)ACTIVE_ROUTE_TIMEOUT);      }        lastHop = RoutingAodvGetNextHop(sourceAddress,&aodv->routeTable);        if(RoutingAodvCheckRouteExist(lastHop,&aodv->routeTable)==TRUE)      {            RoutingAodvUpdateLifetime(lastHop,&aodv->routeTable);            RoutingAodvSetTimer(node,MSG_NETWORK_CheckRouteTimeout,		                lastHop,(clocktype)ACTIVE_ROUTE_TIMEOUT);      }    if(RoutingAodvCheckNbrExist(node,lastHop)) //this neighbor did HELLO in the past DELETE_PERIOD      {	RoutingAodvUpdateLastPacketTime(node, lastHop);      }        /* the node is the destination of the route */    if (destAddr == node->nodeAddr)    {        aodv->stats.numDataReceived++;        aodv->stats.numHops += (64-ipHeader->ip_ttl);    }     else if (destAddr != ANY_DEST)     {        // The node is an intermediate node of the route.        // Relay the packet to the next hop of the route                 if (RoutingAodvCheckRouteExist(destAddr, &aodv->routeTable)) 	  {	    RoutingAodvTransmitData(node, msg, destAddr);	  } 	else 	  {		    AODV_RERR_Packet newRerrPacket;	    AODV_PL precursorList;	    	    //No active route to destination#ifdef LOCAL_REPAIR	    if(RoutingAodvCheckBeingRepaired(destAddr,&aodv->routeTable))	      {//The route is being repaired so insert in buffer 		RoutingAodvInsertBuffer(msg, destAddr, &aodv->buffer); 		return;		      }	    if(RoutingAodvCheckRepairable(destAddr,&aodv->routeTable))

⌨️ 快捷键说明

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