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

📄 aodv.pc

📁 glomosim中的AODV实现,可参考RFC文档
💻 PC
📖 第 1 页 / 共 5 页
字号:
        }    }    return (deleted);} /* RoutingAodvDeleteBuffer *//* * RoutingAodvDeleteSent * * Remove an entry from the sent table */void RoutingAodvDeleteSent(NODE_ADDR destAddr, AODV_SENT *sent){    AODV_SENT_Node *toFree;    AODV_SENT_Node *current;    if (sent->size == 0)    {        return;    }    else if (sent->head->destAddr == destAddr)    {        toFree = sent->head;        sent->head = toFree->next;        pc_free(toFree);        --(sent->size);    }    else    {        for (current = sent->head;             current->next != NULL && current->next->destAddr < destAddr;             current = current->next)        {        }        if (current->next != NULL && current->next->destAddr == destAddr)        {            toFree = current->next;            current->next = toFree->next;            pc_free(toFree);            --(sent->size);        }    }} /* RoutingAodvDeleteSent *//* * RoutingAodvUpdateLifetime * * Update the lifetime field of the destination entry in the route table */void RoutingAodvUpdateLifetime(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->lifetime = simclock() + ACTIVE_ROUTE_TO;            return;        }    }} /* RoutingAodvUpdateLifetime *//* * RoutingAodvIncreaseSeq * * Increase the sequence number */void RoutingAodvIncreaseSeq(GlomoNode *node){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingAodv* aodv = (GlomoRoutingAodv *) ipLayer->routingProtocol;    aodv->seqNumber++;} /* RoutingAodvIncreaseSeq *//* * RoutingAodvIncreaseTtl * * Increase the TTL value */void RoutingAodvIncreaseTtl(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)        {            current->ttl += TTL_INCREMENT;            if (current->ttl > TTL_THRESHOLD)            {                current->ttl = NET_DIAMETER;            }            return;        }    }} /* RoutingAodvIncreaseTtl *//* * RoutingAodvUpdateTtl * * Update the ttl value */void RoutingAodvUpdateTtl(NODE_ADDR destAddr, int ttl, AODV_SENT *sent){    AODV_SENT_Node *current;    for (current = sent->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            current->ttl = ttl;            return;        }    }} /* RoutingAodvUpdateTtl *//* * RoutingAodvIncreaseTimes * * Increase the number of times RREQ sent in TTL = NET_DIAMETER */void RoutingAodvIncreaseTimes(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)        {            current->times++;            return;        }    }} /* RoutingAodvIncreaseTimes *//* * RoutingAodvActivateRoute * * Activate a route in the route table */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->activated = TRUE;            current->lifetime = simclock() + ACTIVE_ROUTE_TO;            return;        }    }} /* RoutingAodvActivateRoute *//* * RoutingAodvInactivateRoutesAndGetDestinations * * Inactivate routes that use the broken link * Returns the destAddr and whether the node must relay the RREP */void RoutingAodvInactivateRoutesAndGetDestinations(    GlomoNode* node,    AODV_RT* routeTable,    NODE_ADDR nextHop,    AODV_AddressSequenceNumberPairType destinationPairs[],    int maxNumberDestinationPairs,    int* numberDestinations){    AODV_RT_Node *current;        int numDests = 0;        for (current = routeTable->head;         current != NULL;         current = current->next)    {        if ((current->nextHop == nextHop) && (current->activated == TRUE))        {            current->activated = FALSE;            current->hopCount = AODV_INFINITY;            current->lifetime = simclock() + BAD_LINK_LIFETIME;            current->destSeq++;            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, current->destAddr,                (clocktype)BAD_LINK_LIFETIME);            if (!current->source) {                destinationPairs[numDests].destinationAddress =                    current->destAddr;                destinationPairs[numDests].destinationSequenceNumber =                    current->destSeq;                numDests++;            }//if//        }//if//    }//for//        *numberDestinations = numDests;} /* RoutingAodvInactivateRoute *//* * RoutingAodvMarkRouteBroken * * Mark the route with destAddr broken; returns TRUE if relay is required */BOOL RoutingAodvMarkRouteBroken(GlomoNode *node,                                NODE_ADDR destAddr,                                 AODV_RT *routeTable){    AODV_RT_Node *current;    BOOL relay = FALSE;    for (current = routeTable->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr && current->activated == TRUE)        {            current->activated = FALSE;            current->hopCount = AODV_INFINITY;            current->lifetime = simclock() + BAD_LINK_LIFETIME;            current->destSeq++;            RoutingAodvSetTimer(                node, MSG_NETWORK_CheckRouteTimeout, current->destAddr,                (clocktype)BAD_LINK_LIFETIME);            if (current->source == FALSE)            {                relay = TRUE;            }            return (relay);        }    }    return (relay);} /* RoutingAodvMarkRouteBroken *//* * RoutingAodvUpdateSeq * * Update the sequence number of a certain destination */void RoutingAodvUpdateSeq(NODE_ADDR destAddr, int seq, AODV_RT *routeTable){    AODV_RT_Node *current;    for (current = routeTable->head;         current != NULL && current->destAddr <= destAddr;         current = current->next)    {        if (current->destAddr == destAddr)        {            current->destSeq = seq;            return;        }    }} /* RoutingAodvUpdateSeq */static //inline//                         void SendRouteErrorPacket(    GlomoNode* node,     const AODV_RERR_Packet* rerrPacket){    Message* newMsg = GLOMO_MsgAlloc(node, 0, 0, 0);    int packetSize = AODV_RERR_PacketSize(rerrPacket);        assert(rerrPacket->pktType == (unsigned short)AODV_RERR);    assert(rerrPacket->destinationCount >= 1);            GLOMO_MsgPacketAlloc(node, newMsg, packetSize);    memcpy(GLOMO_MsgReturnPacket(newMsg), rerrPacket, packetSize);    NetworkIpSendRawGlomoMessage(        node, newMsg, ANY_DEST, CONTROL, IPPROTO_AODV, 1);}/* * RoutingAodvInit * * Initialization function for AODV protocol */void RoutingAodvInit(    GlomoNode *node,    GlomoRoutingAodv **aodvPtr,    const GlomoNodeInput *nodeInput){    GlomoRoutingAodv *aodv =         (GlomoRoutingAodv *)checked_pc_malloc (sizeof(GlomoRoutingAodv));    (*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);    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 Replies Txed = %d",                  aodv->stats.numReplySent);    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) Re-sent = %d",                  aodv->stats.numRerrResent);    GLOMO_PrintStat(node, "RoutingAodv", buf);                                                              sprintf(buf, "Number of CTRL Packets Txed = %d",                  aodv->stats.numRequestSent + aodv->stats.numReplySent);    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);        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 Broken Link Retries = %d", aodv->stats.numBrokenLinkRetries);    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;     assert(sourceAddress  != node->nodeAddr);        /* the node is the destination of the route */    if (destAddr == node->nodeAddr)    {        aodv->stats.numDataReceived++;        RoutingAodvUpdateLifetime(sourceAddress, &aodv->routeTable);        RoutingAodvSetTimer(node, MSG_NETWORK_CheckRouteTimeout,                             sourceAddress, (clocktype)ACTIVE_ROUTE_TO);    }     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 {            // Broken Route.  Drop Packet, send RERR again to make them stop            // sending more.            AODV_RERR_Packet newRerrPacket;            newRerrPacket.pktType = AODV_RERR;            newRerrPacket.destinationCount = 1;            newRerrPacket.destinationPairArray[0].destinationAddress = destAddr;            newRerrPacket.destinationPairArray[0].destinationSequenceNumber              = RoutingAodvGetSeq(destAddr, &aodv->routeTable);                        SendRouteErrorPacket(node, &newRerrPacket);            aodv->stats.numRerrResent++;                        aodv->stats.numPacketsDropped++;            GLOMO_MsgFree(node,msg);                    }//if//    }//if//} /* RoutingAodvHandleData *//* * RoutingAodvHandleRequest

⌨️ 快捷键说明

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