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

📄 odmrp.pc

📁 simulator for ad hoc
💻 PC
📖 第 1 页 / 共 5 页
字号:
/* * GloMoSim is COPYRIGHTED software.  Release 2.02 of GloMoSim is available  * at no cost to educational users only. * * Commercial use of this software requires a separate license.  No cost, * evaluation licenses are available for such purposes; please contact * info@scalable-networks.com * * By obtaining copies of this and any other files that comprise GloMoSim2.02, * you, the Licensee, agree to abide by the following conditions and * understandings with respect to the copyrighted software: * * 1.Permission to use, copy, and modify this software and its documentation *   for education and non-commercial research purposes only is hereby granted *   to Licensee, provided that the copyright notice, the original author's *   names and unit identification, and this permission notice appear on all *   such copies, and that no charge be made for such copies. Any entity *   desiring permission to use this software for any commercial or *   non-educational research purposes should contact:  * *   Professor Rajive Bagrodia  *   University of California, Los Angeles  *   Department of Computer Science  *   Box 951596  *   3532 Boelter Hall  *   Los Angeles, CA 90095-1596  *   rajive@cs.ucla.edu * * 2.NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY *   PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * * 3.Neither the software developers, the Parallel Computing Lab, UCLA, or any *   affiliate of the UC system shall be liable for any damages suffered by *   Licensee from the use of this software. */// Use the latest version of Parsec if this line causes a compiler error./* * Name: odmrp.pc * Purpose: To simulate On-Demand Multicast Routing Protocol (ODMRP)  *//*  * Notes: The implementation followed the latest specification in the Internet *        Draft (draft-ietf-manet-odmrp-02.txt).  * *        The mobility prediction using GPS is not included in this  *        implementation. *        *        We assumed that nodes sending multicast data packets are also *        multicast members (i.e., non-members cannot be multicast sources * *        In statistic collection, Join Query packets that piggybacked data *        are counted as control packets as well as data packets */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include "api.h"#include "structmsg.h"#include "fileio.h"#include "main.h"#include "message.h"#include "network.h"#include "ip.h"#include "nwip.h"#include "nwcommon.h"#include "application.h"#include "transport.h"#include "java_gui.h"#include "mac.h"#include "odmrp.h"#define noDEBUG//long McastReturnMemberCount(GlomoNode *node, NODE_ADDR groupAddr, clocktype theTime);/* * FUNCTION     RoutingOdmrpInit * PURPOSE      Initialization function for ODMRP protocol of NETWORK layer * * Parameters: *     node:       Node being initialized *     odmrpPtr:   Reference to ODMRP data structure. *     nodeInput:  Reference to input file. */void RoutingOdmrpInit(GlomoNode *node,                      GlomoRoutingOdmrp **odmrpPtr,                      const GlomoNodeInput *nodeInput){    GlomoNodeInput memberInput;    BOOL retVal;    int i;    char joinTimeStr[GLOMO_MAX_STRING_LENGTH];    char leaveTimeStr[GLOMO_MAX_STRING_LENGTH];    clocktype joinTime, leaveTime;    NODE_ADDR srcAddr, mcastAddr;    GlomoRoutingOdmrp *odmrp =        (GlomoRoutingOdmrp *)checked_pc_malloc (sizeof(GlomoRoutingOdmrp));    (*odmrpPtr) = odmrp;    if (odmrp == NULL)    {        fprintf(stderr, "ODMRP: Cannot alloc memory for ODMRP struct!\n");        assert (FALSE);    }    NetworkIpSetRouterFunction(node, &RoutingOdmrpRouterFunction);    RoutingOdmrpInitStats(node);    RoutingOdmrpInitMembership(&odmrp->memberFlag);    RoutingOdmrpInitFgFlag(&odmrp->fgFlag);    RoutingOdmrpInitMemberTable(&odmrp->memberTable);    RoutingOdmrpInitTempTable(&odmrp->tempTable);    RoutingOdmrpInitRouteTable(&odmrp->routeTable);    RoutingOdmrpInitMessageCache(&odmrp->messageCache);    RoutingOdmrpInitSeqTable(node);    RoutingOdmrpInitSent(&odmrp->sentTable);    RoutingOdmrpInitAckTable(&odmrp->ackTable);    RoutingOdmrpInitResponseTable(&odmrp->responseTable);    retVal = GLOMO_ReadCachedFile(nodeInput, "MCAST-CONFIG-FILE", &memberInput);    if (retVal == FALSE)     {        fprintf(stderr, "ODMRP: Needs MCAST-CONFIG-FILE.\n");        assert(FALSE);    }    /* Processing node membership. */    for (i = 0; i < memberInput.numLines; i++)     {        retVal = sscanf(memberInput.inputStrings[i],                        "%ld %ld %s %s",                        &srcAddr, &mcastAddr,                        joinTimeStr, leaveTimeStr);                                if (retVal != 4)         {            fprintf(stderr, "Application: Wrong configuration format!\n");            assert(0); abort();        }        joinTime = GLOMO_ConvertToClock(joinTimeStr);        leaveTime = GLOMO_ConvertToClock(leaveTimeStr);        if (node->nodeAddr == srcAddr)        {            RoutingOdmrpSetTimer(                            node, MSG_NETWORK_JoinGroup, mcastAddr, joinTime);            RoutingOdmrpSetTimer(                            node, MSG_NETWORK_LeaveGroup, mcastAddr, leaveTime);        }    }} /* RoutingOdmrpInit *//* * FUNCTION     RoutingOdmrpHandelProtocolEvent * PURPOSE      Handles ODMRP specific events only. * * Parameters:  *     node: Node that is handling the ODMRP event. *     msg:  Event that needs to be handled. */void RoutingOdmrpHandleProtocolEvent(GlomoNode *node, Message *msg){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingOdmrp* odmrp= (GlomoRoutingOdmrp *) ipLayer->routingProtocol;    char clockStr[GLOMO_MAX_STRING_LENGTH];    switch (msg->eventType)    {        case MSG_NETWORK_CheckAcked:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            clocktype jitterTime;            if (RoutingOdmrpCheckAckTable(*mcastAddr, &odmrp->ackTable))            {#ifdef DEBUG  printf("Node %ld not acked. Retx!\n", node->nodeAddr);#endif                RoutingOdmrpRetxReply(node, *mcastAddr, &odmrp->ackTable);            }             GLOMO_MsgFree(node, msg);            break;        }         /* Check expiration timers. */        case MSG_NETWORK_CheckTimeoutAlarm:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            /* If I'm source for the group. */            if (RoutingOdmrpLookupSentTable(*mcastAddr, &odmrp->sentTable))            {                if (RoutingOdmrpCheckMinExpTime(                                     *mcastAddr, &odmrp->sentTable) &&                    RoutingOdmrpCheckCongestionTime(                                     *mcastAddr, &odmrp->memberTable) &&                    !RoutingOdmrpCheckSendQuery(*mcastAddr, &odmrp->sentTable))                {#ifdef DEBUG printf("HERE\n");#endif                    RoutingOdmrpSetSendQuery(*mcastAddr, &odmrp->sentTable);                }                RoutingOdmrpSetTimer(                             node, MSG_NETWORK_CheckTimeoutAlarm,                              *mcastAddr, ODMRP_TIMER_INTERVAL);            }            GLOMO_MsgFree(node, msg);            break;        }              case MSG_NETWORK_FlushTables:        {            RoutingOdmrpDeleteMsgCache(&odmrp->messageCache);            GLOMO_MsgFree(node, msg);            break;        }        /* Join Multicast group. */        case MSG_NETWORK_JoinGroup:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            RoutingOdmrpJoinGroup(node, *mcastAddr);            GLOMO_MsgFree(node, msg);            break;        }        /* Leave Multicast group. */        case MSG_NETWORK_LeaveGroup:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            RoutingOdmrpLeaveGroup(node, *mcastAddr);            GLOMO_MsgFree(node, msg);            break;        }        case MSG_NETWORK_SendReply:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            RoutingOdmrpSendReply(                    node, *mcastAddr, &odmrp->memberTable, &odmrp->tempTable);            GLOMO_MsgFree(node, msg);            break;        } /* case - send reply */        /* Check if FG flag has been expired. */        case MSG_NETWORK_CheckFg:        {            NODE_ADDR *mcastAddr = (NODE_ADDR *)GLOMO_MsgReturnInfo(msg);            /* Check only if the node is a FG member. */            if (RoutingOdmrpLookupFgFlag(*mcastAddr, &odmrp->fgFlag))            {                /* If FG expired, reset the flag. */                if (RoutingOdmrpCheckFgExpired(*mcastAddr, &odmrp->fgFlag))                {                    RoutingOdmrpResetFgFlag(*mcastAddr, &odmrp->fgFlag);                }                else                {                    RoutingOdmrpSetTimer(                       node, MSG_NETWORK_CheckFg, *mcastAddr, ODMRP_FG_TIMEOUT);                }            } /* if fg */            GLOMO_MsgFree(node, msg);            break;        } /* case - check fg */        default:            printf("Time %s: Node %ld received message of unknown type %d.\n",                   clockStr, node->nodeAddr, msg->eventType);            assert(FALSE);    } }/* * FUNCTION     RoutingOdmrpHandelProtocolPacket * PURPOSE      Handles ODMRP packet that was received from the MAC layer *              with destination being some other node. * * Parameters:  *     node:       node that is handling the ODMRP packet. *     msg:        msg, that event that needs to be handled. *     srcAddr:    The address of the source that sent the packet. *     destAddr:   The multicast address that the packet belongs to. * * Note:           This function is called when packets are received *                 from MAC.  The IP header is already removed. */void RoutingOdmrpHandleProtocolPacket(          GlomoNode *node, Message *msg, NODE_ADDR srcAddr, NODE_ADDR destAddr){    ODMRP_PacketType *odmrpHeader = (ODMRP_PacketType *)                                     GLOMO_MsgReturnPacket(msg);    switch (*odmrpHeader)    {        case ODMRP_ACK:            RoutingOdmrpHandleAck(node, msg, srcAddr, destAddr);            break;        case ODMRP_JOIN_REPLY:            RoutingOdmrpHandleReply(node, msg, srcAddr, destAddr);            break;        default:            printf("ODMRP received packet of unknown type\n");            assert (FALSE);    }}/* * FUNCTION     RoutingOdmrpRouterFunction * PURPOSE      Handles ODMRP packet that was from the transport *              layer or from the MAC layer with this node as the *              destination. * * Parameters: *     node:       node that is handling the ODMRP event. *     msg:        msg, that event that needs to be handled. *     destAddr:   The multicast address that the packet belongs to. * * Note: Packet is from IP with IP header already created. *       ipHeader->ip_dst specifies the multicast destination. */void RoutingOdmrpRouterFunction(GlomoNode *node,                                Message *msg,                                NODE_ADDR destAddr,                                BOOL *packetWasRouted){    GlomoNetworkIp* ipLayer = (GlomoNetworkIp *) node->networkData.networkVar;    GlomoRoutingOdmrp* odmrp = (GlomoRoutingOdmrp *) ipLayer->routingProtocol;    IpHeaderType *ipHeader = (IpHeaderType *) msg->packet;    OdmrpIpOptionType option;    /*     * The case where packet came from MAC but belongs to this node.     */    if (ipHeader->ip_p == IPPROTO_ODMRP)     {        if (ipHeader->ip_dst >= IP_MIN_MULTICAST_ADDRESS)         {            NODE_ADDR sourceAddress;            NODE_ADDR destinationAddress;            unsigned char IpProtocol;            unsigned int ttl;            NetworkQueueingPriorityType priority;                    NetworkIpRemoveIpHeader(node, msg, &sourceAddress,                             &destinationAddress, &priority, &IpProtocol, &ttl);            RoutingOdmrpHandleProtocolPacket(                                node, msg, sourceAddress,destinationAddress);            *packetWasRouted = TRUE;            return;        }         else         {            *packetWasRouted = FALSE;            return;        }    }    *packetWasRouted = TRUE;    /* Packet from UDP */    if (FindAnIpOptionField(ipHeader, IPOPT_ODMRP) == NULL &&        ipHeader->ip_src == node->nodeAddr)    {#ifdef DEBUG    printf("Node %ld has data to send\n", node->nodeAddr);#endif          /*         * Check if the node is the member of the group.         * Send packet only if the nodes is member of the group          */        if (RoutingOdmrpLookupMembership(destAddr, &odmrp->memberFlag))        {            /*              * If group membership information is known,             * send data packet right away              */            if (RoutingOdmrpLookupSentTable(destAddr, &odmrp->sentTable) &&                !RoutingOdmrpCheckSendQuery(destAddr, &odmrp->sentTable))            {#ifdef DEBUG    printf("    Sending Data\n");#endif                RoutingOdmrpSendData(node, msg, destAddr);            } /* If group membership info. known */            /* If no group info is known, send Join Query */            else             {#ifdef DEBUG    printf("    Sending Join Query\n");#endif                RoutingOdmrpSendQuery(node, msg, destAddr);            } /* else - no group membership known */        } /* If Member of the group */    } /* if source */    else    {        RoutingOdmrpHandleData(node, msg);    }}/*  * FUNCTION     RoutingOdmrpFinalize * PURPOSE      Called at the end of simulation to collect the results of *              the simulation of ODMRP protocol of the NETWORK layer. * * Parameter: *     node:    node for which results are to be collected */void RoutingOdmrpFinalize(GlomoNode *node){    GlomoNetworkIp *ipLayer = (GlomoNetworkIp *)node->networkData.networkVar;    GlomoRoutingOdmrp *odmrp = (GlomoRoutingOdmrp *)ipLayer->routingProtocol;    FILE *statOut;    char buf[GLOMO_MAX_STRING_LENGTH];    sprintf(buf, "Number of Join Queries Txed = %d",                 odmrp->stats.numQueryTxed);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Join Replies Txed = %d",                 odmrp->stats.numReplySent);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Acks Txed = %d",                 odmrp->stats.numAckSent);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of CTRL Packets Txed = %d",                 odmrp->stats.numQueryTxed + odmrp->stats.numReplySent +                 odmrp->stats.numAckSent);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Data Txed = %d",                 odmrp->stats.numDataTxed);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Data Packets Originated = %d",                 odmrp->stats.numDataSent);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Data Packets Supposed to be Received = %d",                 odmrp->stats.numDataToReceive);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);    sprintf(buf, "Number of Data Packets Received = %d",                 odmrp->stats.numDataReceived);    GLOMO_PrintStat(node, "RoutingOdmrp", buf);} /* RoutingOdmrpFinalize */

⌨️ 快捷键说明

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