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

📄 aodv.pc

📁 glomosim中的AODV实现,可参考RFC文档
💻 PC
📖 第 1 页 / 共 5 页
字号:
    /* Control packets */    if (ipHeader->ip_p  == IPPROTO_AODV)    {        return;    }    if (destAddr == node->nodeAddr)    {        *packetWasRouted = FALSE;    }    else    {        *packetWasRouted = TRUE;    }    /* intermediate node or destination of the route */    if (ipHeader->ip_src != node->nodeAddr)     {        RoutingAodvHandleData(node, msg, destAddr);    }    /* source has a route to the destination */    else if (RoutingAodvCheckRouteExist(destAddr, &aodv->routeTable))    {        RoutingAodvTransmitData(node, msg, destAddr);        aodv->stats.numDataSent++;    }    /* There is no route to the destination and RREQ has not been sent */    else if (!RoutingAodvLookupBuffer(destAddr, &aodv->buffer))    {        RoutingAodvInsertBuffer(msg, destAddr, &aodv->buffer);         RoutingAodvInitiateRREQ(node, destAddr);    }    /* There is no route but RREQ has already been sent */    else    {        RoutingAodvInsertBuffer(msg, destAddr, &aodv->buffer);    }} /* RoutingAodvRouterFunction *//* * RoutingAodvMacLayerStatusHandler * * Reacts to the signal sent by the MAC protocol after link failure */void RoutingAodvPacketDropNotificationHandler(    GlomoNode *node, const Message* msg, const NODE_ADDR nextHopAddress){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    IpHeaderType* ipHeader;    NODE_ADDR destAddr;    int numberRouteDestinations;    ipHeader = (IpHeaderType *) GLOMO_MsgReturnPacket(msg);    if (ipHeader->ip_p  == IPPROTO_AODV)    {        return;    }//if//            destAddr = ipHeader->ip_dst;       if (nextHopAddress == ANY_DEST) {        aodv->stats.numBrokenLinkRetries++;        return;    }//if//       NetworkIpDeleteOutboundPacketsToANode(        node, nextHopAddress, ANY_DEST, FALSE);         aodv->stats.numBrokenLinks++;        RoutingAodvDeleteNbrTable(nextHopAddress, &aodv->nbrTable);    RoutingAodvIncreaseSeq(node);    do {        AODV_RERR_Packet newRerrPacket;        newRerrPacket.pktType = AODV_RERR;               RoutingAodvInactivateRoutesAndGetDestinations(            node,            &aodv->routeTable,            nextHopAddress,            newRerrPacket.destinationPairArray,            AODV_MAX_RERR_DESTINATIONS,            &numberRouteDestinations);                newRerrPacket.destinationCount = numberRouteDestinations;                if (newRerrPacket.destinationCount > 0) {            SendRouteErrorPacket(node, &newRerrPacket);            aodv->stats.numRerrSent++;        }//if//        } while (numberRouteDestinations == AODV_MAX_RERR_DESTINATIONS);}//RoutingAodvMaclayerStatusHandler///* * RoutingAodvSetTimer * * Set timers for protocol events */void RoutingAodvSetTimer(    GlomoNode *node, long eventType, NODE_ADDR destAddr, clocktype delay){    Message *newMsg;    NODE_ADDR *info;    newMsg = GLOMO_MsgAlloc(node,                            GLOMO_NETWORK_LAYER,                            ROUTING_PROTOCOL_AODV,                            eventType);    GLOMO_MsgInfoAlloc(node, newMsg, sizeof(NODE_ADDR));    info = (NODE_ADDR *) GLOMO_MsgReturnInfo(newMsg);    *info = destAddr;    GLOMO_MsgSend(node, newMsg, delay);} /* RoutingAodvSetTimer *//* * RoutingAodvInitiateRREQ * * Initiate a Route Request packet when no route to destination is known */void RoutingAodvInitiateRREQ(GlomoNode *node, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    Message *newMsg;    AODV_RREQ_Packet *rreqPkt;    char *pktPtr;    int pktSize = sizeof(AODV_RREQ_Packet);    int ttl;    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    rreqPkt = (AODV_RREQ_Packet *) pktPtr;    rreqPkt->pktType = AODV_RREQ;    rreqPkt->bcastId = RoutingAodvGetBcastId(node);     rreqPkt->destAddr = destAddr;    rreqPkt->destSeq = RoutingAodvGetSeq(destAddr, &aodv->routeTable);    rreqPkt->srcAddr = node->nodeAddr;    rreqPkt->srcSeq = RoutingAodvGetMySeq(node);    rreqPkt->lastAddr = node->nodeAddr;    rreqPkt->hopCount = 1;    if (RoutingAodvCheckSent(destAddr, &aodv->sent))    {        ttl = RoutingAodvGetTtl(destAddr, &aodv->sent);        RoutingAodvIncreaseTtl(destAddr, &aodv->sent);    }    else    {        ttl = RoutingAodvGetLastHopCount(destAddr, &aodv->routeTable);        if (ttl == -1)        {            ttl = TTL_START;        }        RoutingAodvInsertSent(destAddr, ttl, &aodv->sent);        RoutingAodvIncreaseTtl(destAddr, &aodv->sent);    }    NetworkIpSendRawGlomoMessage(          node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, ttl);    aodv->stats.numRequestSent++;    RoutingAodvInsertSeenTable(                node, node->nodeAddr, rreqPkt->bcastId, &aodv->seenTable);    RoutingAodvSetTimer(node, MSG_NETWORK_CheckReplied, destAddr,                        (clocktype)2 * ttl * NODE_TRAVERSAL_TIME);} /* RoutingAodvInitiateRREQ *//* * RoutingAodvRetryRREQ * * Send RREQ again after not receiving any RREP */void RoutingAodvRetryRREQ(GlomoNode *node, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    Message *newMsg;    AODV_RREQ_Packet *rreqPkt;    char *pktPtr;    int pktSize = sizeof(AODV_RREQ_Packet);    int ttl;    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    rreqPkt = (AODV_RREQ_Packet *) pktPtr;    rreqPkt->pktType = AODV_RREQ;    rreqPkt->bcastId = RoutingAodvGetBcastId(node);     rreqPkt->destAddr = destAddr;    rreqPkt->destSeq = RoutingAodvGetSeq(destAddr, &aodv->routeTable);    rreqPkt->srcAddr = node->nodeAddr;    rreqPkt->srcSeq = RoutingAodvGetMySeq(node);    rreqPkt->lastAddr = node->nodeAddr;    rreqPkt->hopCount = 1;    ttl = RoutingAodvGetTtl(destAddr, &aodv->sent);    NetworkIpSendRawGlomoMessage(          node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, ttl);    RoutingAodvIncreaseTtl(destAddr, &aodv->sent);    aodv->stats.numRequestSent++;    RoutingAodvInsertSeenTable(                node, node->nodeAddr, rreqPkt->bcastId, &aodv->seenTable);    if (ttl == NET_DIAMETER)    {        RoutingAodvIncreaseTimes(destAddr, &aodv->sent);    }    RoutingAodvSetTimer(node, MSG_NETWORK_CheckReplied, destAddr,                        (clocktype)2 * ttl * NODE_TRAVERSAL_TIME);} /* RoutingAodvRetryRREQ *//* * RoutingAodvTransmitData * * Forward the data packet to the next hop */void RoutingAodvTransmitData(GlomoNode *node, Message *msg, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    NODE_ADDR nextHop;    GLOMO_MsgSetLayer(msg, GLOMO_MAC_LAYER, 0);    GLOMO_MsgSetEvent(msg, MSG_MAC_FromNetwork);    nextHop = RoutingAodvGetNextHop(destAddr, &aodv->routeTable);        assert(nextHop != ANY_DEST);        NetworkIpSendPacketToMacLayer(node, msg, DEFAULT_INTERFACE, nextHop);    aodv->stats.numDataTxed++;        RoutingAodvUpdateLifetime(destAddr, &aodv->routeTable);    RoutingAodvSetTimer(node, MSG_NETWORK_CheckRouteTimeout,                             destAddr, (clocktype)ACTIVE_ROUTE_TO);} /* RoutingAodvTransmitData *//* * RoutingAodvRelayRREQ * * Forward (re-broadcast) the RREQ */void RoutingAodvRelayRREQ(GlomoNode *node, Message *msg, int ttl){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    Message *newMsg;    AODV_RREQ_Packet *oldRreq;    AODV_RREQ_Packet *newRreq;    char *pktPtr;    int pktSize = sizeof(AODV_RREQ_Packet);    clocktype delay;    oldRreq = (AODV_RREQ_Packet *) GLOMO_MsgReturnPacket(msg);    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    newRreq = (AODV_RREQ_Packet *) pktPtr;    newRreq->pktType = oldRreq->pktType;    newRreq->bcastId = oldRreq->bcastId;    newRreq->destAddr = oldRreq->destAddr;    newRreq->destSeq = oldRreq->destSeq;    newRreq->srcAddr = oldRreq->srcAddr;    newRreq->srcSeq = oldRreq->srcSeq;    newRreq->lastAddr = node->nodeAddr;    newRreq->hopCount = oldRreq->hopCount + 1;    delay = pc_erand(node->seed) * BROADCAST_JITTER;    NetworkIpSendRawGlomoMessageWithDelay(                   node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, ttl, delay);    aodv->stats.numRequestSent++;    GLOMO_MsgFree(node, msg);} /* RoutingAodvRelayRREQ *//* * RoutingAodvInitiateRREP * * Destination of the route sends RREP in reaction to RREQ */void RoutingAodvInitiateRREP(GlomoNode *node, Message *msg){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *)ipLayer->routingProtocol;    Message *newMsg;    AODV_RREQ_Packet *rreqPkt;    AODV_RREP_Packet *rrepPkt;    char *pktPtr;    int pktSize = sizeof(AODV_RREP_Packet);    int seq;    rreqPkt = (AODV_RREQ_Packet *) GLOMO_MsgReturnPacket(msg);    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    rrepPkt = (AODV_RREP_Packet *) pktPtr;    rrepPkt->pktType = AODV_RREP;    rrepPkt->srcAddr = rreqPkt->srcAddr;    rrepPkt->destAddr = node->nodeAddr;    seq = RoutingAodvGetMySeq(node);    if (seq >= rreqPkt->destSeq)    {        rrepPkt->destSeq = seq;    }    else    {        rrepPkt->destSeq = rreqPkt->destSeq;        RoutingAodvIncreaseSeq(node);    }    rrepPkt->hopCount = 1;    rrepPkt->lifetime = (clocktype)MY_ROUTE_TO;    NetworkIpSendRawGlomoMessageToMacLayer(        node, newMsg, rreqPkt->lastAddr, CONTROL, IPPROTO_AODV, 1,        DEFAULT_INTERFACE, rreqPkt->lastAddr);    aodv->stats.numReplySent++;    GLOMO_MsgFree(node, msg);} /* RoutingAodvInitiateRREP *//* * RoutingAodvInitiateRREPbyIN * * An intermediate node that knows the route to the destination sends the RREP */void RoutingAodvInitiateRREPbyIN(GlomoNode *node, Message *msg){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *)ipLayer->routingProtocol;    Message *newMsg;    AODV_RREQ_Packet *rreqPkt;    AODV_RREP_Packet *rrepPkt;    char *pktPtr;    int pktSize = sizeof(AODV_RREP_Packet);    int seq;    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    rrepPkt = (AODV_RREP_Packet *) pktPtr;    rreqPkt = (AODV_RREQ_Packet *) GLOMO_MsgReturnPacket(msg);    rrepPkt->pktType = AODV_RREP;    rrepPkt->srcAddr = rreqPkt->srcAddr;    rrepPkt->destAddr = rreqPkt->destAddr;    rrepPkt->destSeq = RoutingAodvGetSeq(rreqPkt->destAddr, &aodv->routeTable);    rrepPkt->lifetime = RoutingAodvGetLifetime(                            rreqPkt->destAddr, &aodv->routeTable) - simclock();    rrepPkt->hopCount =  RoutingAodvGetHopCount(                             rreqPkt->destAddr, &aodv->routeTable) + 1;    NetworkIpSendRawGlomoMessageToMacLayer(        node, newMsg, rreqPkt->lastAddr, CONTROL, IPPROTO_AODV, 1,        DEFAULT_INTERFACE, rreqPkt->lastAddr);    aodv->stats.numReplySent++;    GLOMO_MsgFree(node, msg);} /* RoutingAodvInitiateRREPbyIN *//* * RoutingAodvRelayRREP * * Forward the RREP packet */void RoutingAodvRelayRREP(GlomoNode *node, Message *msg, NODE_ADDR destAddr){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    Message *newMsg;    AODV_RREP_Packet *oldRrep;    AODV_RREP_Packet *newRrep;    char *pktPtr;    NODE_ADDR nextHop;    clocktype lifetime;    int pktSize = sizeof(AODV_RREP_Packet);    oldRrep = (AODV_RREP_Packet *) GLOMO_MsgReturnPacket(msg);    memmove(&lifetime, &oldRrep->lifetime, sizeof(clocktype));    newMsg = GLOMO_MsgAlloc(node, GLOMO_MAC_LAYER, 0, MSG_MAC_FromNetwork);    GLOMO_MsgPacketAlloc(node, newMsg, pktSize);    pktPtr = (char *) GLOMO_MsgReturnPacket(newMsg);    newRrep = (AODV_RREP_Packet *) pktPtr;    newRrep->pktType = oldRrep->pktType;    newRrep->srcAddr = oldRrep->srcAddr;    newRrep->destAddr = oldRrep->destAddr;    newRrep->destSeq = oldRrep->destSeq;    newRrep->hopCount = oldRrep->hopCount + 1;    newRrep->lifetime = lifetime;        if (destAddr == ANY_DEST)    {        NetworkIpSendRawGlomoMessage(            node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, 1);    }    else    {        nextHop = RoutingAodvGetNextHop(oldRrep->srcAddr, &aodv->routeTable);        if (nextHop != ANY_DEST)        {            NetworkIpSendRawGlomoMessageToMacLayer(                node, newMsg, nextHop, CONTROL, IPPROTO_AODV, 1,                DEFAULT_INTERFACE, nextHop);        }    }    aodv->stats.numReplySent++;    GLOMO_MsgFree(node, msg);} /* RoutingAodvRelayRREP */

⌨️ 快捷键说明

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