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

📄 aodv.pc

📁 glomosim中的AODV实现,可参考RFC文档
💻 PC
📖 第 1 页 / 共 5 页
字号:
    return (ANY_DEST);} /* RoutingAodvGetNextHop *//* * RoutingAodvGetBcastId * * Obtains the broadcast ID for the outgoing packet */int RoutingAodvGetBcastId(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    int bcast;    bcast = aodv->bcastId;    aodv->bcastId++;    return (bcast);} /* RoutingAodvGetBcastId *//* * RoutingAodvGetSeq * * Obtains the sequence number of the destination node  */int RoutingAodvGetSeq(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)        {            return(current->destSeq);        }    }    return (-1);} /* RoutingAodvGetSeq *//* * RoutingAodvGetMySeq * * Obtains the node's seq number */int RoutingAodvGetMySeq(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    return (aodv->seqNumber);} /* RoutingAodvGetMySeq *//* * RoutingAodvGetHopCount * * Obtains the hop count to the destination node */int RoutingAodvGetHopCount(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)        {            return(current->hopCount);        }    }    return (-1);} /* RoutingAodvGetHopCount *//* * RoutingAodvGetLastHopCount * * Obtains the last hop count known to the destination node */int RoutingAodvGetLastHopCount(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)        {            return(current->lastHopCount);        }    }    return (-1);} /* RoutingAodvGetLastHopCount *//* * RoutingAodvGetTtl * * Obtains the ttl value for the outgoing RREQ */int RoutingAodvGetTtl(NODE_ADDR destAddr, AODV_SENT *sent){    AODV_SENT_Node *current;    for (current = sent->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(current->ttl);        }    }    return (TTL_START);} /* RoutingAodvGetTtl *//* * RoutingAodvGetTimes * * Obtains the number of times the RREQ was sent in TTL = NET_DIAMETER */int RoutingAodvGetTimes(NODE_ADDR destAddr, AODV_SENT *sent){    AODV_SENT_Node *current;    for (current = sent->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(current->times);        }    }    return (0);} /* RoutingAodvGetTimes *//* * RoutingAodvGetLifetime * * Obtains the lifetime value of an entry in the route table */clocktype RoutingAodvGetLifetime(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)        {            return(current->lifetime);        }    }    return (0);} /* RoutingAodvGetLifetime *//* * RoutingAodvGetBufferedPacket * * Extract the packet that was buffered */Message *RoutingAodvGetBufferedPacket(NODE_ADDR destAddr, AODV_BUFFER *buffer){    AODV_BUFFER_Node *current;    for (current = buffer->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(current->msg);        }    }    assert(FALSE); abort(); return NULL;} /* RoutingAodvGetBufferedPacket *//* * RoutingAodvCheckRouteExist *  * Returns TRUE if any route to the destination is known */BOOL RoutingAodvCheckRouteExist(NODE_ADDR destAddr, AODV_RT *routeTable){    AODV_RT_Node *current;    if (routeTable->size == 0)    {        return (FALSE);    }    for (current = routeTable->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if ((current->destAddr == destAddr) &&             (current->hopCount != AODV_INFINITY) &&            (current->lifetime > simclock()) &&            (current->activated == TRUE))        {            return(TRUE);        }    }    return (FALSE);} /* RoutingAodvCheckRouteExist *//* * RoutingAodvCheckNbrExist * * Returns TRUE if the node is already a neighbor */BOOL RoutingAodvCheckNbrExist(NODE_ADDR destAddr, AODV_NT *nbrTable){    AODV_NT_Node *current;    if (nbrTable->size == 0)    {        return (FALSE);    }    for (current = nbrTable->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(TRUE);        }    }    return (FALSE);} /* RoutingAodvCheckNbrExist *//* * RoutingAodvLookupSeenTable * * Returns TRUE if the broadcast packet is processed before */BOOL RoutingAodvLookupSeenTable(NODE_ADDR srcAddr,                                 int bcastId,                                AODV_RST *seenTable){    AODV_RST_Node *current;    if (seenTable->size == 0)    {        return (FALSE);    }    for (current = seenTable->front;         current != NULL;         current = current->next)    {        if (current->srcAddr == srcAddr && current->bcastId == bcastId)        {            return (TRUE);        }    }    return (FALSE);} /* RoutingAodvLookupSeenTable *//* * RoutingAodvLookupBuffer * * Returns TRUE if any packet is buffered to the destination * */BOOL RoutingAodvLookupBuffer(NODE_ADDR destAddr, AODV_BUFFER *buffer){    AODV_BUFFER_Node *current;    if (buffer->size == 0)    {        return (FALSE);    }    for (current = buffer->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(TRUE);        }    }    return (FALSE);} /* RoutingAodvLookupBuffer *//* * RoutingAodvCheckSent * * Check if RREQ has been sent; return TRUE if sent */BOOL RoutingAodvCheckSent(NODE_ADDR destAddr, AODV_SENT *sent){    AODV_SENT_Node *current;    if (sent->size == 0)    {        return (FALSE);    }    for (current = sent->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            return(TRUE);        }    }    return (FALSE);} /* RoutingAodvCheckSent *//* * RoutingAodvHandleProtocolPacket * * Called when the packet is received from MAC */void RoutingAodvHandleProtocolPacket(    GlomoNode *node, Message *msg, NODE_ADDR srcAddr,     NODE_ADDR destAddr, int ttl){    AODV_PacketType *aodvHeader = (AODV_PacketType*)GLOMO_MsgReturnPacket(msg);    switch (*aodvHeader)     {        case AODV_RREQ:        {            RoutingAodvHandleRequest(node, msg, ttl);            break;        } /* RREQ */        case AODV_RREP:        {            RoutingAodvHandleReply(node, msg, srcAddr, destAddr);            break;        } /* RREP */        case AODV_RERR:        {            assert(destAddr == ANY_DEST);            RoutingAodvHandleRouteError(node, msg, srcAddr);            break;        } /* RERR */                default:           assert(FALSE); abort();            break;    } /* switch */} /* RoutingAodvHandleProtocolPacket *//* * RoutingAodvHandleProtocolEvent * * Handles all the protocol events */void RoutingAodvHandleProtocolEvent(GlomoNode *node, Message *msg){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    switch (msg->eventType) {        /* Remove an entry from the RREQ Seen Table */        case MSG_NETWORK_FlushTables: {            RoutingAodvDeleteSeenTable(&aodv->seenTable);            GLOMO_MsgFree(node, msg);            break;        }        /* Remove the route that has not been used for awhile */        case MSG_NETWORK_CheckRouteTimeout: {            NODE_ADDR *destAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            RoutingAodvDeleteRouteTable(*destAddr, &aodv->routeTable);            GLOMO_MsgFree(node, msg);            break;        }        /* Check if RREP is received after sending RREQ */        case MSG_NETWORK_CheckReplied: {            NODE_ADDR *destAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            /* Route has not been obtained */            if (!RoutingAodvCheckRouteExist(*destAddr, &aodv->routeTable))            {                if (RoutingAodvGetTimes(*destAddr, &aodv->sent) < RREQ_RETRIES)                {                    /* Retry with increased TTL */                    RoutingAodvRetryRREQ(node, *destAddr);                } /* if under the retry limit */                /* over the limit */                else                {                    while (RoutingAodvLookupBuffer(*destAddr, &aodv->buffer))                    {                        Message* messageToDelete =                             RoutingAodvGetBufferedPacket(                               *destAddr, &aodv->buffer);                        RoutingAodvDeleteBuffer(*destAddr, &aodv->buffer);                                                GLOMO_MsgFree(node, messageToDelete);                        aodv->stats.numPacketsDropped++;                    }                } /* else */            } /* if no route */            GLOMO_MsgFree(node, msg);            break;        }        default:            fprintf(stderr, "RoutingAodv: Unknown MSG type %d!\n",                    msg->eventType);            abort();    } /* switch */} /* RoutingAodvHandleProtocolEvent *//* * RoutingAodvRouterFunction * * Determine the routing action to take for a the given data packet * set the PacketWasRouted variable to TRUE if no further handling of  * this packet by IP is necessary  */void RoutingAodvRouterFunction(    GlomoNode *node,    Message *msg,    NODE_ADDR destAddr,    BOOL *packetWasRouted){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    IpHeaderType *ipHeader = (IpHeaderType *) msg->packet;

⌨️ 快捷键说明

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