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

📄 aodv.pc

📁 glomosim中的AODV实现,可参考RFC文档
💻 PC
📖 第 1 页 / 共 5 页
字号:
 * * 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);    /* Process only if the packet is not a duplicate */    if (!RoutingAodvLookupSeenTable(                rreqPkt->srcAddr, rreqPkt->bcastId, &aodv->seenTable))    {        RoutingAodvInsertSeenTable(                node, rreqPkt->srcAddr, rreqPkt->bcastId, &aodv->seenTable);        /* Update the neighbor table if the upstream is new */        if (!RoutingAodvCheckNbrExist(rreqPkt->lastAddr, &aodv->nbrTable))        {            RoutingAodvInsertNbrTable(rreqPkt->lastAddr, &aodv->nbrTable);            RoutingAodvIncreaseSeq(node);        }        /* The node is the destination of the route */        if (node->nodeAddr == rreqPkt->destAddr)        {            RoutingAodvReplaceInsertRouteTable(                rreqPkt->srcAddr, rreqPkt->srcSeq, rreqPkt->hopCount,                 rreqPkt->lastAddr, simclock() + ACTIVE_ROUTE_TO, TRUE, TRUE,                &aodv->routeTable);            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, rreqPkt->srcAddr,                 (clocktype)ACTIVE_ROUTE_TO);            /* Send a Route Reply */            RoutingAodvInitiateRREP(node, msg);        } /* if dest */        else        {            /* No route to destination is known */            if (!RoutingAodvCheckRouteExist(rreqPkt->destAddr,                                             &aodv->routeTable))            {                RoutingAodvReplaceInsertRouteTable(                    rreqPkt->srcAddr, rreqPkt->srcSeq, rreqPkt->hopCount,                     rreqPkt->lastAddr, simclock() + REV_ROUTE_LIFE, FALSE,                    FALSE, &aodv->routeTable);                RoutingAodvSetTimer(                    node, MSG_NETWORK_CheckRouteTimeout, rreqPkt->srcAddr,                    (clocktype)REV_ROUTE_LIFE);                if (ttl > 0)                {                    /* Relay the packet only if TTL is not zero */                    RoutingAodvRelayRREQ(node, msg, ttl);                } /* if ttl > 0 */                else                {                    GLOMO_MsgFree(node, msg);                }            } /* if no route */            /* Knows a route to the destination */            else            {                /* However, the known route is not a fresh one */                if (RoutingAodvGetSeq(rreqPkt->destAddr, &aodv->routeTable) <                    rreqPkt->destSeq)                {                    RoutingAodvReplaceInsertRouteTable(                        rreqPkt->srcAddr, rreqPkt->srcSeq, rreqPkt->hopCount,                        rreqPkt->lastAddr, simclock() + REV_ROUTE_LIFE,                        FALSE, FALSE,                        &aodv->routeTable);                    RoutingAodvSetTimer(                        node, MSG_NETWORK_CheckRouteTimeout, rreqPkt->srcAddr,                        (clocktype)REV_ROUTE_LIFE);                    if (ttl > 0)                    {                        /* Relay the packet only if TTL is not zero */                        RoutingAodvRelayRREQ(node, msg, ttl);                    } /* if ttl > 0 */                    else                    {                        GLOMO_MsgFree(node, msg);                    }                } /* if seq no is not fresh */                /* has a fresh route to the destination */                else                {                    RoutingAodvReplaceInsertRouteTable(                        rreqPkt->srcAddr, rreqPkt->srcSeq, rreqPkt->hopCount,                        rreqPkt->lastAddr, simclock() + ACTIVE_ROUTE_TO,                        TRUE, FALSE,                        &aodv->routeTable);                    RoutingAodvSetTimer(                        node, MSG_NETWORK_CheckRouteTimeout, rreqPkt->srcAddr,                        (clocktype)ACTIVE_ROUTE_TO);                    /* Send a Route Reply */                    RoutingAodvInitiateRREPbyIN(node, msg);                } /* else */            } /* else */        } /* else (not dest) */    } /* if new pkt */    else    {        GLOMO_MsgFree(node, msg);    }} /* 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 relay;    clocktype lifetime;    /* clocktype must be copied to access the field of that type */    memmove(&lifetime, &rrepPkt->lifetime, sizeof(clocktype));    /* Source of the route */        if (rrepPkt->srcAddr == node->nodeAddr)    {        /* The packet is the first reply received */        if (!RoutingAodvCheckRouteExist(rrepPkt->destAddr,                                         &aodv->routeTable))        {            RoutingAodvReplaceInsertRouteTable(                rrepPkt->destAddr, rrepPkt->destSeq, rrepPkt->hopCount,                srcAddr, simclock() + lifetime, TRUE,                TRUE, &aodv->routeTable);            aodv->stats.numRoutes++;            aodv->stats.numHops += rrepPkt->hopCount;            RoutingAodvDeleteSent(rrepPkt->destAddr, &aodv->sent);            /* Send any buffered packets to the destination */            while (RoutingAodvLookupBuffer(                       rrepPkt->destAddr, &aodv->buffer))            {                newMsg = RoutingAodvGetBufferedPacket(                                 rrepPkt->destAddr, &aodv->buffer);                 RoutingAodvTransmitData(node, newMsg, rrepPkt->destAddr);                aodv->stats.numDataSent++;                RoutingAodvDeleteBuffer(rrepPkt->destAddr, &aodv->buffer);            } /* while */            } /* if no route */        /* The packet contains a better route compared to the one already           known */        else if ((RoutingAodvGetSeq(rrepPkt->destAddr, &aodv->routeTable) <                  rrepPkt->destSeq) ||                 ((RoutingAodvGetSeq(rrepPkt->destAddr, &aodv->routeTable)                  == rrepPkt->destSeq) &&                  (RoutingAodvGetHopCount(rrepPkt->destAddr,                                           &aodv->routeTable) >                   rrepPkt->hopCount)))        {            RoutingAodvReplaceInsertRouteTable(                rrepPkt->destAddr, rrepPkt->destSeq, rrepPkt->hopCount,                srcAddr, simclock() + lifetime, TRUE,                 TRUE, &aodv->routeTable);            /* Send any buffered packet to the destination */            while (RoutingAodvLookupBuffer(                       rrepPkt->destAddr, &aodv->buffer))            {                newMsg = RoutingAodvGetBufferedPacket(                             rrepPkt->destAddr, &aodv->buffer);                RoutingAodvTransmitData(node, newMsg, rrepPkt->destAddr);                aodv->stats.numDataSent++;                RoutingAodvDeleteBuffer(rrepPkt->destAddr, &aodv->buffer);            } /* while */        } /* else if */        GLOMO_MsgFree(node, msg);    } /* if source */    /* Intermediate node of the route */    else    {        /* the packet is the first reply received */        if (!RoutingAodvCheckRouteExist(                 rrepPkt->destAddr, &aodv->routeTable))        {            RoutingAodvReplaceInsertRouteTable(                rrepPkt->destAddr, rrepPkt->destSeq, rrepPkt->hopCount,                srcAddr, simclock() + lifetime, TRUE, FALSE,                &aodv->routeTable);            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, rrepPkt->destAddr,                (clocktype)lifetime);            RoutingAodvActivateRoute(rrepPkt->srcAddr, &aodv->routeTable);            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, rrepPkt->srcAddr,                (clocktype)ACTIVE_ROUTE_TO);            /* Forward the packet to the upstream of the route */            RoutingAodvRelayRREP(node, msg, destAddr);        } /* if new route */        /* the packet carries a better route compared to the one already           known */        else if ((RoutingAodvGetSeq(rrepPkt->destAddr, &aodv->routeTable) <                                           rrepPkt->destSeq) ||                  ((RoutingAodvGetSeq(rrepPkt->destAddr, &aodv->routeTable)                    == rrepPkt->destSeq) &&                   (RoutingAodvGetHopCount(rrepPkt->destAddr,                                            &aodv->routeTable) >                      rrepPkt->hopCount)))        {            RoutingAodvReplaceInsertRouteTable(                rrepPkt->destAddr, rrepPkt->destSeq, rrepPkt->hopCount,                srcAddr, simclock() + lifetime, TRUE,                FALSE, &aodv->routeTable);            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, rrepPkt->destAddr,                (clocktype)lifetime);            RoutingAodvActivateRoute(rrepPkt->srcAddr, &aodv->routeTable);            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, rrepPkt->srcAddr,                (clocktype)ACTIVE_ROUTE_TO);            /* Forward the packet to the upstream of the route */            RoutingAodvRelayRREP(node, msg, destAddr);        } /* else if newer route or shorter route */         else        {            GLOMO_MsgFree(node, msg);        }//if//    }//if// } /* RoutingAodvHandleReply *///// 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;        newRerrPacket.pktType = (unsigned short)AODV_RERR;    newRerrPacket.destinationCount = 0;        for(I = 0; I < rerrPkt->destinationCount; I++) {        // Mark the route inactive in the route table; Must not remove it        // right away since the last hop count known is needed for future use         // Remove destination from packet if it doesn't need to be forwarded        // further.                NODE_ADDR destination =             rerrPkt->destinationPairArray[I].destinationAddress;         int sequenceNum =             rerrPkt->destinationPairArray[I].destinationSequenceNumber;                 BOOL mustRelay =            RoutingAodvMarkRouteBroken(               node,                destination,                &aodv->routeTable);                RoutingAodvUpdateSeq(destination,                             sequenceNum,                              &aodv->routeTable);                NetworkIpDeleteOutboundPacketsToANode(            node, srcAddr, destination, FALSE);                                      if (mustRelay) {           newRerrPacket.destinationPairArray[newRerrPacket.destinationCount] =              rerrPkt->destinationPairArray[I];              newRerrPacket.destinationCount++;           }//if//                                 }//while//        if (newRerrPacket.destinationCount > 0) {        SendRouteErrorPacket(node, &newRerrPacket);        aodv->stats.numRerrSent++;    }//if//        GLOMO_MsgFree(node, msg);}//RoutingAodvHandleRouteError///* * RoutingAodvInitRouteTable * * Initialize the route table */void RoutingAodvInitRouteTable(AODV_RT *routeTable){    routeTable->head = NULL;    routeTable->size = 0;} /* RoutingAodvInitRouteTable *//* * RoutingAodvInitNbrTable * * Initialize the neighbor table */void RoutingAodvInitNbrTable(AODV_NT *nbrTable){    nbrTable->head = NULL;    nbrTable->size = 0;} /* RoutingAodvInitNbrTable *//* * RoutingAodvInitSeenTable * * Initialize the seen table */void RoutingAodvInitSeenTable(AODV_RST *seenTable){    seenTable->front = NULL;    seenTable->rear = NULL;    seenTable->size = 0;} /* RoutingAodvInitSeenTable *//* * RoutingAodvInitBuffer * * Initialize the buffer */void RoutingAodvInitBuffer(AODV_BUFFER *buffer){    buffer->head = NULL;    buffer->size = 0;} /* RoutingAodvInitBuffer *//* * RoutingAodvInitSent * * Initialize the sent table */void RoutingAodvInitSent(AODV_SENT *sent){    sent->head = NULL;    sent->size = 0;} /* RoutingAodvInitBuffer *//* * RoutingAodvInitStats * * Initialize all the stat variables */void RoutingAodvInitStats(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    aodv->stats.numRequestSent = 0;    aodv->stats.numReplySent = 0;    aodv->stats.numRerrSent = 0;    aodv->stats.numRerrResent = 0;    aodv->stats.numDataSent = 0;    aodv->stats.numDataTxed = 0;    aodv->stats.numDataReceived = 0;    aodv->stats.numRoutes = 0;    aodv->stats.numHops = 0;    aodv->stats.numPacketsDropped = 0;    aodv->stats.numBrokenLinks = 0;    aodv->stats.numBrokenLinkRetries = 0;} /* RoutingAodvInitStats *//* * RoutingAodvInitSeq * * Initialize the sequence number */void RoutingAodvInitSeq(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    aodv->seqNumber = 0;} /* RoutingAodvInitSeq *//* * RoutingAodvInitBcastId * * Initialize the broadcast id */void RoutingAodvInitBcastId(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    aodv->bcastId = 0;} /* RoutingAodvInitBcastId *//* * RoutingAodvGetNextHop * * Looks up the routing table to obtain next hop to the destinaton */NODE_ADDR RoutingAodvGetNextHop(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->activated == TRUE)        {            return(current->nextHop);        }    }

⌨️ 快捷键说明

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