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

📄 glomo.pc

📁 无线网络仿真工具Glomosim2.03
💻 PC
📖 第 1 页 / 共 2 页
字号:
/* * 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./* * $Id: glomo.pc,v 1.79 2001/04/14 03:35:12 jmartin Exp $ * * Definition of entity which represents a partition in the simulation. */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include <limits.h>#include "main.h"#include "api.h"#include "fileio.h"#include "message.h"#include "splaytree.h"#include "driver.h"#include "structmsg.h"#include "glomo.h"#include "queue.h"#include "mobility.h"#include "propagation.h"#include "../mac/802_11.h"#include "../mac/wiredlink.h"#ifdef _WIN32  #include <sys\timeb.h>  static double RealTimeSecs() {      struct _timeb timerec;      _ftime(&timerec);      return ((double)(timerec.time) + ((double)(timerec.millitm)/1000.0));  }#else  #include <sys/time.h>  static double RealTimeSecs() {      struct timeval  Tp;      int rc = gettimeofday(&Tp,0);  assert((rc==0));      return ((double)(Tp.tv_sec) + ((double)(Tp.tv_usec) / 1000000.0));  }#endifstaticvoid FindNearestPositions(GlomoAreaNearestInfo *areaNearest,                          GlomoAreaInfo       **area,                          int numPartitionsX, int numPartitionsY,                          int x, int y);static GlomoNode *GLOMO_GetNodeData(GlomoNode *node, Message *msg);/* * The definition for the partition entity. The following are the major * steps performed in this program. * 1] Receive information from driver entity. * 2] Find out nodes which belong to this partition and initialize them. * 3] Go into an infinite loop trying to receive messages. When message *    is received call the appropriate node and layer. * 4] When the simulation ends, go to the finalize code. This code will *    call the Finalize function for all the layers of all the nodes in *    this partition. We can thus collect any needed statistics. */entity GLOMOPartition(int partitionId, ename creator) {    int    i;    int    numNodes;               /* number of nodes in simulation */    int    numPartitions;    char    buf[10];    double  StartRealTime = RealTimeSecs();    clocktype NextSimtimePrintTime = 0;    int NumMobilityEventsOnNextClockTick = 0;    unsigned short seedVal;         /* seed value supplied by creator */    GlomoNodeInput  nodeInput;    GlomoPartition *partitionData;        /*     * Allocate space for partition information     */    partitionData =        (GlomoPartition *)checked_pc_malloc(sizeof(GlomoPartition));    memset(partitionData, 0, sizeof(GlomoPartition));    partitionData->partitionId = partitionId;                                              /* mobility events currently do not exist */    partitionData->mobilityInternal.minTime = CLOCKTYPE_MAX;    partitionData->mobilityOutgoing.minTime = CLOCKTYPE_MAX;    /* file where stats will be stored for this partition */    sprintf(buf, ".STAT.%d", partitionId);    partitionData->statFd = fopen(buf, "w");    assert(partitionData->statFd != NULL);    add_source(creator);    add_dest(creator);    receive (PartitionInfoMsg partitionMsg) {        int x = partitionMsg.indexX;        int y = partitionMsg.indexY;        GlomoAreaInfo **area = partitionMsg.area;        int i, j;        partitionData->indexX = x;        partitionData->indexY = y;        partitionData->area = area;        partitionData->areaNearest = NULL;                partitionData->terrainDimensions = partitionMsg.terrainDimensions;        partitionData->numPartitionsX = partitionMsg.numPartitionsX;        partitionData->numPartitionsY = partitionMsg.numPartitionsY;        numPartitions            = partitionData->numPartitionsX * partitionData->numPartitionsY;        for (j = 0; j < partitionData->numPartitionsY; j++) {            for (i = 0; i < partitionData->numPartitionsX; i++) {                if (((i != x) || (j != y)) &&                    (abs(i-x) <= partitionMsg.partitionConnectivityDistance) &&                    (abs(j-y) <= partitionMsg.partitionConnectivityDistance))                {                    add_source(area[i][j].partitionEname);                    add_dest(area[i][j].partitionEname);                }            }        }        seedVal = partitionMsg.seedVal;        numNodes = partitionMsg.numNodes;                partitionData->nodeData            = (GlomoNode **)checked_pc_malloc(sizeof(GlomoNode *) * numNodes);        memset(partitionData->nodeData, 0, sizeof(GlomoNode *) * numNodes);        nodeInput = partitionMsg.nodeInput;    }             /*     * Receive source set and destination set information.     * Also receive information about Nodes represented by     * this entity. Break out of the loop once we receive     * NodeInfoFinish message.     */    while (TRUE) {        receive (NeighborInfoMsg nMsg) {                    }        /*         * All the information about the neighbors has been received.         * Get information about the node data structure.         */        or receive (NodePositionMsg nodePosMsg) {            GlomoNode *nextNode = NULL;     /* temporary pointer to node */            GlomoNodePositionInfo *nodePos;            partitionData->nodePositions                = (GlomoNodePositionInfo *)nodePosMsg.nodePos;            nodePos = partitionData->nodePositions;            /*             * Information about the nodes has been set by the driver entity.             * Go through all nodes to figure out which nodes belong to             * this entity             */            for (i = 0; i < numNodes; i++) {                                {                    int j;                    partitionData->nodeData[i] =                                (GlomoNode *) pc_malloc(sizeof(GlomoNode));                    assert(partitionData->nodeData[i] != NULL);                    memset(partitionData->nodeData[i], 0, sizeof(GlomoNode));                    partitionData->nodeData[i]->id = i;                    partitionData->nodeData[i]->numNodes = numNodes;                    partitionData->nodeData[i]->nodeAddr = nodePos[i].nodeAddr;                    partitionData->nodeData[i]->numberInterfaces = 0;                    /*                     * Set the seed of the node                     */                    partitionData->nodeData[i]->seed[2] =                                (unsigned short) ((i + 1) % (USHRT_MAX + 1));                    partitionData->nodeData[i]->seed[0] =                                (unsigned short) ((i + 1) / (USHRT_MAX + 1));                    partitionData->nodeData[i]->seed[1] = seedVal;                                        partitionData->nodeData[i]->initialSeedValue[0] =                        partitionData->nodeData[i]->seed[0];                    partitionData->nodeData[i]->initialSeedValue[1] =                       partitionData->nodeData[i]->seed[1];                    partitionData->nodeData[i]->initialSeedValue[2] =                        partitionData->nodeData[i]->seed[2];                                       /*                     * Set the neighborData and nodeData variables                     * needed by the channel layer.                     */                    partitionData->nodeData[i]->position = nodePos[i].position;                    partitionData->nodeData[i]->partitionData = partitionData;                    GLOMO_HeapSplayInsert(&(partitionData->heapSplayTree),                                          partitionData->nodeData[i]);                                                            /*                     * If firstNode is currently NULL, make this Node                     * the firstNode.                     */                    if (partitionData->firstNode == NULL) {                        partitionData->firstNode = partitionData->nodeData[i];                        partitionData->firstNode->prevNodeData = NULL;                        partitionData->firstNode->nextNodeData = NULL;                    }                    else {                        /*                         * We encountered a node previously.                         * Update the prevNodeData and nextNodeData                         * fields.                         */                        assert(nextNode != NULL);                        partitionData->nodeData[i]->prevNodeData = nextNode;                        nextNode->nextNodeData = partitionData->nodeData[i];                        partitionData->nodeData[i]->nextNodeData = NULL;                    }                    /*                     * Make the current node we are considering                     * the next code.                     */                    nextNode = partitionData->nodeData[i];                }            }            /*             * Initialize all the layers for all the nodes             */            GLOMO_GlobalPropInit(&(partitionData->propData), &nodeInput);            nextNode = partitionData->firstNode;            while (nextNode != NULL) {                GLOMO_NetworkPreInit(nextNode, &nodeInput);                                     GLOMO_PropInit(nextNode, &partitionData->propData);                GLOMO_RadioInit(nextNode, &nodeInput);                GLOMO_MacInit(nextNode, &nodeInput);                GLOMO_NetworkInit(nextNode, &nodeInput);                GLOMO_TransportInit(nextNode, &nodeInput);                GLOMO_AppInit(nextNode, &nodeInput);                GLOMO_MobilityInit(nextNode, &nodeInput);                assert((nextNode->nextNodeData == NULL) ||                       (nextNode->nextNodeData->prevNodeData == nextNode));                assert((nextNode->prevNodeData == NULL) ||                        (nextNode->prevNodeData->nextNodeData == nextNode));                nextNode = nextNode->nextNodeData;            }                        break;        }    }        if (partitionData->firstNode != NULL) {        int    nodeCount = 0;        GlomoNode* nextNode = partitionData->firstNode;        while (nextNode != NULL) {            nodeCount++;            printf("Node %u (%.2lf, %.2lf, %.2lf).\n",                   nextNode->nodeAddr,                   nextNode->position.x,                   nextNode->position.y,                   nextNode->position.z);            nextNode = nextNode->nextNodeData;        }         printf("Partition %d (%hu %hu) has range (%.0lf, %.0lf) to "               "(%.0lf, %.0lf): %d nodes\n",               partitionId, self.node, self.pid,               partitionData->thisArea.start_x,               partitionData->thisArea.start_y,               partitionData->thisArea.end_x,               partitionData->thisArea.end_y,               nodeCount);        if (nodeCount == 0) {            printf("Partition has zero nodes!.\n");            printf("This indicates a problem with node positions.\n");            assert(FALSE);        }    }    /*     * Inform creator that we are ready.     * Wait to receive Start Simulation message from creator.     */    send Ready { } to creator;    receive (StartSim smsg);    del_source(creator);    del_dest(creator);    NumMobilityEventsOnNextClockTick = 0;        /*     * Upon receiving a message, retrieve information about the     * receiving node id. Call GLOMO_CallLayer which will call     * the appropriate layer.     */    while (TRUE) {        clocktype EarliestOutputTime;        clocktype timeoutDelay;        clocktype toVal;        BOOL IsATimeoutEvent;        /*         * Display the current simulation time.         */        if ((partitionId == 1) && (simclock() >= NextSimtimePrintTime)) {            int PercentageDone;            char TimeStringInSecond[GLOMO_MAX_STRING_LENGTH];            GLOMO_PrintClockInSecond(simclock(), TimeStringInSecond);            PercentageDone                = ((100 * (NextSimtimePrintTime/PrintSimTimeInterval)) /                   NUM_SIM_TIME_STATUS_PRINTS);                         printf("Current Sim Time[s] =%15s  "                   "Real Time[s] =%5d  "                   "Completed%3d%%\n",                    TimeStringInSecond,                   (int)(RealTimeSecs() - StartRealTime),                    PercentageDone);            fflush(stdout);            NextSimtimePrintTime = NextSimtimePrintTime + PrintSimTimeInterval;         }         /* Determine the earliest regular and mobility event */        /* This time will be used to set a timeout. */        toVal = MIN(partitionData->mobilityInternal.minTime,                    partitionData->mobilityOutgoing.minTime);               /* nNode represents the node with the earliest message */        if (partitionData->heapSplayTree.heapSize > 0) {            GlomoNode* nNode = partitionData->heapSplayTree.heapNodePtr[1];            if (nNode->splayTree.leastPtr != NULL) {

⌨️ 快捷键说明

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