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

📄 aodv.pc

📁 aodv program to simulate in glomosim simulator
💻 PC
📖 第 1 页 / 共 5 页
字号:
	      {		//   NetworkIpDeleteOutboundPacketsToANode(node, sourceAddress, destAddr, FALSE);		//so that these do not cause packet drop notifications		if(RoutingAodvCheckSent(destAddr, &aodv->sent))		  { //RREQ for this node has already been sent 		    RoutingAodvInsertBuffer(msg,destAddr,&aodv->buffer);		    return;		  }					RoutingAodvInsertBuffer(msg,destAddr,&aodv->buffer);		RoutingAodvResetRepairableSetBeingRepairedAndIncSeq(destAddr,&aodv->routeTable);		RoutingAodvStartLocalRepair(node,sourceAddress,destAddr);					return;	   	      }#endif  	    // Broken Route.  Drop Packet, send RERR again to make them stop	    // sending more.	    precursorList.size = 0;	    precursorList.head=NULL;	    precursorList.tail=NULL;	    if(RoutingAodvCheckRouteEntryExist(destAddr,&aodv->routeTable))	      {		AODV_RT_Node *current;		current = aodv->routeTable.head;		while(current->destAddr!=destAddr)		  {		    current = current->next;    		  }	      		if(current->destSeqValid==TRUE)		  {		    current->destSeq++;    		  }		current->lifetime =  simclock() + RoutingAodvGetDeletePeriod();		RoutingAodvSetTimer(node, MSG_AODV_DeleteRouteEntry,				    current->destAddr,RoutingAodvGetDeletePeriod());		newRerrPacket.pktType = AODV_RERR;				newRerrPacket.N = FALSE;		newRerrPacket.destinationCount = 1;		newRerrPacket.destinationPairArray[0].destinationAddress = destAddr;		newRerrPacket.destinationPairArray[0].destinationSequenceNumber 		  = RoutingAodvGetSeq(destAddr, &aodv->routeTable);		//One unreachable destination. but it may have one or more precursors.		RoutingAodvGetPrecursors(node,destAddr,&precursorList);		if(precursorList.size>0)		  {		    SendRouteErrorPacket(node, &newRerrPacket,&precursorList);		    aodv->stats.numRerrNoNSent++;		    aodv->stats.numRerrSent++;		  		  }  		aodv->stats.numPacketsDropped++; 		GLOMO_MsgFree(node,msg);	      }	    else	      {		GLOMO_MsgFree(node,msg);	 	      }	  }//if//    }//if//    } /* RoutingAodvHandleData *//* * RoutingAodvHandleRequest * * Processing procedure when RREQ is received */void RoutingAodvHandleRequest(GlomoNode *node, Message *msg, int ttl){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    AODV_RREQ_Packet *rreqPkt = (AODV_RREQ_Packet *)GLOMO_MsgReturnPacket(msg);    Message *newMsg;    IpHeaderType *ipHeader;        /*When a node receives a RREQ it first creates or updates a route to the previous hop without a valid sequence number */        RoutingAodvReplaceInsertRouteTable(node, rreqPkt->lastAddr,-1,FALSE,TRUE,1,rreqPkt->lastAddr,simclock()+(clocktype)ACTIVE_ROUTE_TIMEOUT);    if(RoutingAodvLookupSeenTable(rreqPkt->origAddr,rreqPkt->bcastId,&aodv->seenTable))    {      /*Presence of (origAddr,bcastId) pair in the seenTable indicates that the RREQ  was seen before and was seen within the last PATH_DISCOVERY_TIME. Discard this RREQ since it was already processed*/        GLOMO_MsgFree(node,msg);       return;	    }        aodv->lastpkt = simclock();    rreqPkt->hopCount++;    /*To account for new hop through this intermediate node*/    RoutingAodvInsertSeenTable(node, rreqPkt->origAddr, rreqPkt->bcastId, &aodv->seenTable);    /*Saved for PATH_DISCOVERY_TIME to avoid processing the same RREQ again*/        /*This if-else block is for creating/updating reverse route to the originator*/    if(!RoutingAodvCheckRouteExist(rreqPkt->origAddr,&aodv->routeTable))      { //Route to originating node not present. So create an entry	//this block will also be executed, if a stale route exists with valid = false	clocktype lifetime = RoutingAodvGetMinimalLifetime(rreqPkt->hopCount);	RoutingAodvReplaceInsertRouteTable(node, rreqPkt->origAddr,rreqPkt->origSeq,TRUE,TRUE,rreqPkt->hopCount,rreqPkt->lastAddr,lifetime);      }    else      {// Valid route to originating node present. Update the entry if necessary.	//Lifetime should be maximum of (ExistingLifetime,MinimalLifetime)	clocktype lifetime = max(RoutingAodvGetLifetime(rreqPkt->origAddr,&aodv->routeTable),RoutingAodvGetMinimalLifetime(rreqPkt->hopCount)); 	int seq = RoutingAodvGetSeq(rreqPkt->origAddr,&aodv->routeTable);	/*the originator sequence number is compared and copied if GREATER than existing value*/	 	RoutingAodvReplaceInsertRouteTable(node, rreqPkt->origAddr,max(seq,rreqPkt->origSeq),TRUE,TRUE,rreqPkt->hopCount,rreqPkt->lastAddr,lifetime);      }     /* Node generates RREP if   * 1. it is either the destination  * 2. it has an active route to the destination with valid sequence number not less than that in RREQ packet and the D flag is not set - destination only flag*/        if(rreqPkt->destAddr==node->nodeAddr)    {	//RREP to be generated by the destination itself	RoutingAodvInitiateRREP(node,msg);    }    else    if((rreqPkt->destinationOnly==FALSE)&&(RoutingAodvCheckRouteExist(rreqPkt->destAddr,&aodv->routeTable))&&(RoutingAodvIfSeqValid(rreqPkt->destAddr,&aodv->routeTable))&&(RoutingAodvGetSeq(rreqPkt->destAddr,&aodv->routeTable)>=rreqPkt->destSeq))    {	//RREP is generated by this intermediate node that has an active route to destination	    	RoutingAodvInitiateRREPbyIN(node,msg);    }   else    /* The node has not generated RREP  */    if(ttl==0)    {      GLOMO_MsgFree(node,msg);    }    else     {        RoutingAodvRelayRREQ(node,msg,ttl);     }    /*It may be possible that this node has buffered packets for the originator or previous hop. check to see if there are packets in buffer */    while(RoutingAodvLookupBuffer(rreqPkt->lastAddr, &aodv->buffer))      {	newMsg = RoutingAodvGetBufferedPacket(rreqPkt->lastAddr, &aodv->buffer);	ipHeader = (IpHeaderType *) newMsg->packet;	if(ipHeader->ip_src==node->nodeAddr)	  aodv->stats.numDataSent++;// This check is made because the node could be buffering packets due to local repair. in that case, this counter (no of data packets sent as a source) should not be incremented..	RoutingAodvTransmitData(node, newMsg, rreqPkt->lastAddr);	RoutingAodvDeleteBuffer(rreqPkt->lastAddr, &aodv->buffer);               }    while(RoutingAodvLookupBuffer(rreqPkt->origAddr, &aodv->buffer))         {	   newMsg = RoutingAodvGetBufferedPacket(rreqPkt->origAddr, &aodv->buffer);	   ipHeader = (IpHeaderType *) newMsg->packet;	   if(ipHeader->ip_src==node->nodeAddr)	     aodv->stats.numDataSent++;// This check is made because the node could be buffering packets due to local repair. in that case, this counter (no of data packets sent as a source) should not be incremented..	   RoutingAodvTransmitData(node, newMsg, rreqPkt->origAddr);	   RoutingAodvDeleteBuffer(rreqPkt->origAddr, &aodv->buffer);                   }}/*RoutingAodvHandleRequest*//* * RoutingAodvHandleReply * * Processing procedure when RREP is received */void RoutingAodvHandleReply(GlomoNode *node, Message *msg, NODE_ADDR srcAddr, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    Message *newMsg;    AODV_RREP_Packet *rrepPkt = (AODV_RREP_Packet *)GLOMO_MsgReturnPacket(msg);    BOOL causedNewRoute = FALSE;    BOOL wasBeingRepaired = FALSE;    int oldHopCount = -1;    char clockdisplay[100];    IpHeaderType *ipHeader;    assert(destAddr==node->nodeAddr);      #ifdef LOCAL_REPAIR    wasBeingRepaired = RoutingAodvCheckBeingRepaired(rrepPkt->destAddr,&aodv->routeTable);    if(wasBeingRepaired)    {        oldHopCount = RoutingAodvGetHopCount(rrepPkt->destAddr,&aodv->routeTable);	        }   #endif      if(rrepPkt->ackReqd==TRUE)    {	 RoutingAodvInitiateRREPACK(node,msg,srcAddr);       }     RoutingAodvReplaceInsertRouteTable(node, srcAddr,-1,FALSE,TRUE,1,srcAddr,simclock() + rrepPkt->lifetime); //Entry for the neighbor from which the RREP was received         if(srcAddr==rrepPkt->destAddr && RoutingAodvIfSeqValid(srcAddr,&aodv->routeTable))        {// A valid seq number entry was already there but this entry was invalid when the RREQ was recd (Else a RREP would have been generated here itself as an intermediate node 	 causedNewRoute = TRUE;       }    rrepPkt->hopCount++;         if(!RoutingAodvCheckRouteEntryExist(rrepPkt->destAddr,&aodv->routeTable))    {//Forward route does not exist. so creating new entry       RoutingAodvReplaceInsertRouteTable(node, rrepPkt->destAddr,rrepPkt->destSeq,TRUE, TRUE,rrepPkt->hopCount,srcAddr,simclock()+rrepPkt->lifetime); 	               causedNewRoute = TRUE;    }    else      {//The entry does exist - it should be updated in one of the following four conditions	/* 1. the sequence number in the routing table entry is marked as invalid	 * 2. destination sequence number in RREP is greater than the node's copy of the destination sequence number and the known value is valid	 * 3. the sequence numbers are the same, but the route is inactive	 * 4. sequence numbers are the same and new hop count is smaller than the hop count in the route table entry	 * */	BOOL seqInvalid = FALSE, seqGreater=FALSE, routeInactive=FALSE, smallerHopCount=FALSE;	seqInvalid = !RoutingAodvIfSeqValid(rrepPkt->destAddr,&aodv->routeTable);	if(!seqInvalid)	{//Valid sequence number	  int seq = RoutingAodvGetSeq(rrepPkt->destAddr, &aodv->routeTable);	  if(seq < rrepPkt->destSeq)	    {	      seqGreater = TRUE;	      	    }	  if((seq==rrepPkt->destSeq)&&(RoutingAodvIfRouteInactive(rrepPkt->destAddr,&aodv->routeTable)))	    {	      routeInactive = TRUE;    	       	    }	  if((seq==rrepPkt->destSeq)&&(rrepPkt->hopCount<RoutingAodvGetHopCount(rrepPkt->destAddr,&aodv->routeTable)))	    {	      smallerHopCount = TRUE;    	    }	  	}		if(seqInvalid||seqGreater||routeInactive||smallerHopCount)	{	  	  RoutingAodvReplaceInsertRouteTable(node, rrepPkt->destAddr,rrepPkt->destSeq,TRUE,TRUE,rrepPkt->hopCount,srcAddr,simclock()+rrepPkt->lifetime);		  	  causedNewRoute = TRUE;	}    }//The entry does exist#ifdef LOCAL_REPAIR    if(causedNewRoute && wasBeingRepaired)    {//The being repaired flag was set to FALSE in ReplaceInsert     // The RREP has come back to the intermediate node that initiated the local repair       while(RoutingAodvLookupBuffer(rrepPkt->destAddr, &aodv->buffer))         {	   newMsg = RoutingAodvGetBufferedPacket(rrepPkt->destAddr, &aodv->buffer);	   RoutingAodvTransmitData(node, newMsg, rrepPkt->destAddr);	   RoutingAodvDeleteBuffer(rrepPkt->destAddr, &aodv->buffer);                   }        if(RoutingAodvGetHopCount(rrepPkt->destAddr,&aodv->routeTable)>oldHopCount)	 {//Checking if new hopcount is greater than old one. if yes a RERR with N flag set must be sent	   AODV_RERR_Packet newRerrPacket;	   AODV_PL precursorList;	  	   precursorList.size = 0;	   precursorList.head=NULL;	   precursorList.tail=NULL;	   newRerrPacket.pktType = AODV_RERR;	   newRerrPacket.N = TRUE;	   newRerrPacket.destinationCount = 1;	   newRerrPacket.destinationPairArray[0].destinationAddress = rrepPkt->destAddr;	   newRerrPacket.destinationPairArray[0].destinationSequenceNumber 	     = RoutingAodvGetSeq(destAddr, &aodv->routeTable);	   //One unreachable destination. but it may have one or more precursors.	   RoutingAodvGetPrecursors(node,rrepPkt->destAddr,&precursorList);	   if(precursorList.size>0)	     {	       SendRouteErrorPacket(node, &newRerrPacket,&precursorList);	       aodv->stats.numRerrNSent++;	     }	 }	           }#endif        if(causedNewRoute)      {      //The originator of the route or any other intermediate node contains buffered packets meant for detinstion get rid of them ...      //it may be possible that this node is not the originator of RREQ. i.e this is an intermediate node for this route. but it has just issued RREQ for the same dest from which it has not heard  ...      if(node->nodeAddr==rrepPkt->origAddr)	{	    RoutingAodvDeleteSent(rrepPkt->destAddr,&aodv->sent);	}              while (RoutingAodvLookupBuffer(rrepPkt->destAddr, &aodv->buffer))       {	 newMsg = RoutingAodvGetBufferedPacket(rrepPkt->destAddr, &aodv->buffer);	 ipHeader = (IpHeaderType *) newMsg->packet;	 if(ipHeader->ip_src==node->nodeAddr)	   aodv->stats.numDataSent++;// This check is made because the node could be buffering packets due to local repair. in that case, this counter (no of data packets sent as a source) should not be incremented..	 RoutingAodvTransmitData(node, newMsg, rrepPkt->destAddr);	 RoutingAodvDeleteBuffer(rrepPkt->destAddr, &aodv->buffer);	 													                  } /* while */     }    while (RoutingAodvLookupBuffer(srcAddr, &aodv->buffer))      { //Just in case there were buffered packets for the last hop from which the RREP rrived	newMsg = RoutingAodvGetBufferedPacket(srcAddr, &aodv->buffer);	ipHeader = (IpHeaderType *) newMsg->packet;	if(ipHeader->ip_src==node->nodeAddr)	  aodv->stats.numDataSent++;// This check is made because the node could be buffering packets due to local repair. in that case, this counter (no of data packets sent as a source) should not be incremented..	RoutingAodvTransmitData(node, newMsg, srcAddr);      	RoutingAodvDeleteBuffer(srcAddr, &aodv->buffer);           													                  }        if((node->nodeAddr!=rrepPkt->origAddr)&&(causedNewRoute))    {	RoutingAodvRelayRREP(node,msg,srcAddr);	    }    else    {	GLOMO_MsgFree(node,msg);    }}void RoutingAodvHandleReplyAck(GlomoNode *node, Message *msg){/*Black lists blah blah*/   AODV_RREP_ACK_Packet *rrepAckPkt = (AODV_RREP_ACK_Packet*)GLOMO_MsgReturnPacket(msg);   	   GLOMO_MsgFree(node,msg);	   }  /* *  RoutingAodvHandleHello * *  Processing procedure when HELLO packet is received ... */void RoutingAodvHandleHello(GlomoNode *node,Message *msg, NODE_ADDR nbrAddr){  GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;  GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;  AODV_RREP_Packet* helloPkt =  (AODV_RREP_Packet*)GLOMO_MsgReturnPacket(msg);  clocktype oldlifetime;  assert(nbrAddr==helloPkt->destAddr);  if(RoutingAodvCheckRouteExist(nbrAddr,&aodv->routeTable))    {//Valid route to this neighbor exists - update lifetime if necessary and sequence number ..      oldlifetime = RoutingAodvGetLifetime(nbrAddr,&aodv->routeTable);      if(oldlifetime < simclock() + ALLOWED_HELLO_LOSS * HELLO_INTERVAL)	{// The lifetime of the route should be increased if it is less than ALLOWED_HELLO_LOSS * LOSS_INTERVAL	  oldlifetime = simclock() + ALLOWED_HELLO_LOSS * HELLO_INTERVAL;	}      RoutingAodvReplaceInsertRouteTable(node,nbrAddr,helloPkt->destSeq,TRUE,TRUE,1,nbrAddr,oldlifetime);    } else    {      //Entry present, but it is invalid or entry not present altogether            RoutingAodvReplaceInsertRouteTable(node,nbrAddr,helloPkt->destSeq,TRUE,TRUE,1,nbrAddr,simclock() + ALLOWED_HELLO_LOSS * HELLO_INTERVAL);            }  if(RoutingAodvCheckNbrExist(node,nbrAddr))    {// this entry already existed in nbr table - i.e. this neighbor has helloed in the past DELETE_PERIOD      RoutingAodvUpdateLastHelloTime(node,nbrAddr);      RoutingAodvUpdateLastPacketTime(node,nbrAddr);    }  else    {      RoutingAodvInsertNbrTable(node,nbrAddr);    }    GLOMO_MsgFree(node,msg);} /* RoutingAodvHandleHello *//* * RoutingAodvHandleRouteError *  * Processing procedure when RERR is received */ void RoutingAodvHandleRouteError(    GlomoNode *node, Message *msg, NODE_ADDR srcAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    AODV_RERR_Packet* rerrPkt =        (AODV_RERR_Packet*)GLOMO_MsgReturnPacket(msg);    AODV_RERR_Packet newRerrPacket;    int I;    AODV_PL precursorList;    precursorList.size=0;    precursorList.head = NULL;    precursorList.tail = NULL;        newRerrPacket.pktType = AODV_RERR;    newRerrPacket.destinationCount = 0;    newRerrPacket.N = rerrPkt->N;        for(I = 0; I < rerrPkt->destinationCount; I++)     {      NODE_ADDR destAddr;      int seqNum;      destAddr = rerrPkt->destinationPairArray[I].destinationAddress;      //This is the destination to which srcAddr has lost a route See if you have it in your route table      seqNum = rerrPkt->destinationPairArray[I].destinationSequenceNumber;                        if(RoutingAodvCheckRouteExist(destAddr,&aodv->routeTable))	{//If yes, was I using srcAddr as a next hop towards destAddr ?	    if(RoutingAodvGetNextHop(destAddr,&aodv->routeTable)==srcAddr)	    {//Yes.. I was using this route	      AODV_RT_Node *current;	      	      //Check if the N bit is set. If yes, the only action to be taken is the retransmission of RERR if there are one or more precursors.. 	      if(rerrPkt->N==FALSE)		{//The route is lost ...				  current = aodv->routeTable.head;		  while(current->destAddr!=destAddr)		    {		      current=current->next;	 		    }		  if(seqNum!=-1)		    {		      current->destSeqValid = TRUE;		      current->destSeq = seqNum;		    }

⌨️ 快捷键说明

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