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

📄 glomo.pc

📁 simulator for ad hoc
💻 PC
📖 第 1 页 / 共 2 页
字号:
                toVal = MIN(toVal, nNode->splayTree.leastPtr->timeValue);            }        }        if (NumMobilityEventsOnNextClockTick > 0) {            toVal = MIN(toVal, (simclock() + 1));        }                assert(toVal >= simclock());        timeoutDelay = toVal - simclock();                        /*         * DISTRIBUTION         * The next two receive statements can be removed for the purpose         * of distribution as we can't receive any remote messages. The         * declaration of the message types can also be removed.         */        /*         * Receive a message from a remote partition.         */                IsATimeoutEvent = FALSE;        receive (RemoteMessage rMsg) {                    }                    or timeout in (timeoutDelay) {           IsATimeoutEvent = TRUE;        }/*receive*/                if (IsATimeoutEvent) {            clocktype CurrentTime = simclock();            BOOL foundOne = FALSE;            GlomoNode *node = NULL;            SplayNode *splayNodePtr = NULL;            Message *msg = NULL;                        assert(toVal == CurrentTime);            /*             * Check for any internal mobility events that need to be             * scheduled for this time period. The internal mobility event             * may cause the node to move to another partition. This will             * be taken care of by sending a "MovingNow" message to the             * remote partition. (see below)             */                        while (partitionData->mobilityInternal.minTime == CurrentTime) {                foundOne = TRUE;                node = partitionData->mobilityInternal.heapNodePtr[1];                GLOMO_Mobility(node);            }                                    /*             * Check to see if any normal messages are scheduled for this             * time.             */            if (partitionData->heapSplayTree.heapSize != 0) {                while (TRUE) {                    int msgLayer;                                        node = partitionData->heapSplayTree.heapNodePtr[1];                    if ((node->splayTree.leastPtr == NULL) ||                            (node->splayTree.leastPtr->timeValue != simclock()))                     {                        break;                    }                    foundOne = TRUE;                    splayNodePtr = GLOMO_SplayTreeExtractMin(node);                    assert(splayNodePtr != NULL);                    msg = splayNodePtr->msg;                    if (partitionData->splayNodeFreeListNum <                        SPLAYTREE_MAX_FREE_LIST)                    {                        SplayNodeListCell* cellPtr =                            (SplayNodeListCell*)splayNodePtr;                        cellPtr->next = partitionData->splayNodeFreeList;                        partitionData->splayNodeFreeList = cellPtr;                        (partitionData->splayNodeFreeListNum)++;                    } else {                        pc_free(splayNodePtr);                    }                    splayNodePtr = NULL;                                        msgLayer = msg->layerType;                    GLOMO_GetNodeData(node, msg);                                                        }            }            assert(foundOne == TRUE);        }    }    finalize {        /*         * Finalize all the layers.        */        if (partitionData->firstNode != NULL) {            GlomoNode *nextNode = partitionData->firstNode;            while (nextNode != NULL) {                GLOMO_RadioFinalize(nextNode);                GLOMO_MacFinalize(nextNode);                GLOMO_NetworkFinalize(nextNode);                GLOMO_TransportFinalize(nextNode);                GLOMO_AppFinalize(nextNode);                GLOMO_MobilityFinalize(nextNode);                nextNode = nextNode->nextNodeData;           }         }        fclose(partitionData->statFd);    }}staticvoid FindNearestPositions(GlomoAreaNearestInfo *partitionNearest,                          GlomoAreaInfo **area,                          int numPartitionsX, int numPartitionsY,                          int x, int y){    //    // Assume a grid for now..    //    int i, j;    GlomoAreaInfo *thisArea = &(area[x][y]);    for (j = 0; j < numPartitionsY; j++) {        for (i = 0; i < numPartitionsX; i++) {            double nearestX, nearestY;            GlomoAreaInfo *anotherArea = &(area[i][j]);            if (i == x && j == y) {                continue;            }            if (anotherArea->start_x < thisArea->start_x) {                nearestX = anotherArea->end_x;            }            else if (anotherArea->start_x > thisArea->start_x) {                nearestX = anotherArea->start_x;            }            else {                nearestX = -1.0;            }            if (anotherArea->start_y < thisArea->start_y) {                nearestY = anotherArea->end_y;            }            else if (anotherArea->start_y > thisArea->start_y) {                nearestY = anotherArea->start_y;            }            else {                nearestY = -1.0;            }            partitionNearest[i + j * numPartitionsX].nearestX = nearestX;            partitionNearest[i + j * numPartitionsX].nearestY = nearestY;            partitionNearest[i + j * numPartitionsX].partitionEname                = anotherArea->partitionEname;        }    }}/* * FUNCTION     GLOMO_GetNodeData * PURPOSE      The partition has just received a message. If this is a *              special message for broadcasting catch it in this function. *              Otherwise retrieve data for the node and call CallLayer *              to execute the correct layer. * * Parameters: *     node         the node receiving the message *     msg          the message which has just been received */static GlomoNode *GLOMO_GetNodeData(GlomoNode *node, Message *msg) {    assert(node != NULL);    switch(msg->eventType) {        case MSG_MAC_SlotFront:            /*              * Slot synchronization is taken for granted.  Therefore,             * this message doesn't use any resources.             */            assert(GLOMO_MsgGetLayer(msg) == GLOMO_MAC_LAYER);            GLOMO_MacLayer(node, msg);            break;        case MSG_SPECIAL_Broadcast:            assert(FALSE);            exit(1);            break;        default:            /*             * Otherwise this is a normal packet.             */            GLOMO_CallLayer(node, msg);            break;    }        return 0;  /* Fix This (Code wasn't returning a value) */}/* * FUNCTION     GLOMO_CallLayer * PURPOSE      Function used to call the appropriate layer to execute *              instructions for the message * * Parameters *     node:         node for which message is to be delivered *     msg:          message for which instructions are to be executed */void GLOMO_CallLayer(GlomoNode *node, Message *msg) {    /*     * As layers are added this function will have to be changed.     */    switch(GLOMO_MsgGetLayer(msg)) {        case GLOMO_RADIO_LAYER:            GLOMO_RadioLayer(node, msg);            break;        case GLOMO_MAC_LAYER:            GLOMO_MacLayer(node, msg);            break;        case GLOMO_NETWORK_LAYER:            GLOMO_NetworkLayer(node, msg);            break;        case GLOMO_TRANSPORT_LAYER:            GLOMO_TransportLayer(node, msg);            break;        case GLOMO_APP_LAYER:            GLOMO_AppLayer(node, msg);            break;        default:            fprintf(stderr, "GLOMO Error: Received message for"                    " unknown layer %ld.\n", msg->layerType);            assert(FALSE);    }}/* * FUNCTION      GLOMO_ConvertToClock * PURPOSE       Read the string in "buf" and provide the corresponding *               clocktype value for the string. Use the following conversions: *               NS - nano-seconds *               MS - milli-seconds *               S  - seconds (default if no specification) *               H  - hours *               D  - days */void GLOMO_ConvertToCoordinates(char *buf, GlomoCoordinates *coordinates) {    char localBuffer[GLOMO_MAX_STRING_LENGTH];    char *stringPtr;    strcpy(localBuffer, buf);    stringPtr = strtok(localBuffer, "(,) ");    coordinates->x = atof(stringPtr);    stringPtr = strtok(NULL, "(,) ");    coordinates->y = atof(stringPtr);    stringPtr = strtok(NULL, "(,) ");    //    // If the third parameter is omitted, set it to zero.    //    if (stringPtr != NULL) {        coordinates->z = atof(stringPtr);    }    else {        coordinates->z = 0.0;    }    return;}/* * FUNCTION      GLOMO_ConvertToClock * PURPOSE       Read the string in "buf" and provide the corresponding *               clocktype value for the string. Use the following conversions: *               NS - nano-seconds *               MS - milli-seconds *               S  - seconds (default if no specification) *               H  - hours *               D  - days */clocktype GLOMO_ConvertToClock(char *buf) {    char        *temp;    clocktype maxSimClock;    if ((temp = strstr(buf, "NS")) != NULL) {        temp[0] = 0;        assert(temp[2] == 0);        maxSimClock = (clocktype) (atof(buf) + 0.5);    }    else if ((temp = strstr(buf, "MS")) != NULL) {        temp[0] = 0;        assert(temp[2] == 0);        maxSimClock = (clocktype) ((atof(buf) * MILLI_SECOND) + 0.5);    }    else if ((temp = strstr(buf, "S")) != NULL) {        temp[0] = 0;        assert(temp[1] == 0);        maxSimClock = (clocktype) ((atof(buf) * SECOND) + 0.5);    }    else if ((temp = strstr(buf, "M")) != NULL) {        temp[0] = 0;        assert(temp[1] == 0);        maxSimClock = (clocktype) ((atof(buf) * MINUTE) + 0.5);    }    else if ((temp = strstr(buf, "H")) != NULL) {        temp[0] = 0;        assert(temp[1] == 0);        maxSimClock = (clocktype) ((atof(buf) * HOUR) + 0.5);    }    else if ((temp = strstr(buf, "D")) != NULL) {        temp[0] = 0;        assert(temp[1] == 0);        maxSimClock = (clocktype) ((atof(buf) * DAY) + 0.5);    }    else {        maxSimClock = (clocktype) ((atof(buf) * SECOND) + 0.5);    }    return maxSimClock;}/* * FUNCTION      GLOMO_PrintStat * PURPOSE       Print out the relevant stat in "buf", along with the *               node id and the layer type generating this stat. *                * Paramters: *     node         the node generating the stat *     layer        the layer generating the stat *     buf          string which has the statistic to be printed out */void GLOMO_PrintStat(GlomoNode *node, char *layer, char *buf) {    fprintf(node->partitionData->statFd, "Node: %6u, Layer: %15.15s, %s\n",            node->nodeAddr, layer, buf);}void GLOMO_PrintClockInSecond(clocktype clock, char stringInSecond[]) {    char TimeString[GLOMO_MAX_STRING_LENGTH];    char TimeStringTemp[GLOMO_MAX_STRING_LENGTH];    char TimeStringSecond[GLOMO_MAX_STRING_LENGTH];    char TimeStringNanoSecond[GLOMO_MAX_STRING_LENGTH];    int  LengthOfTimeString;    ctoa(clock, TimeString);    LengthOfTimeString = strlen(TimeString);    if (LengthOfTimeString <= 9) {        strcpy(TimeStringSecond, "0");        strncpy(TimeStringNanoSecond, "000000000", 9 - LengthOfTimeString);        strncpy(&TimeStringNanoSecond[9-LengthOfTimeString],            TimeString, LengthOfTimeString);        TimeStringNanoSecond[9] = 0;    //    strcpy(TimeStringTemp, "000000000");    //    strcpy(TimeStringSecond, "0");    //    sprintf(TimeStringNanoSecond, "%09s", TimeString);    }    else {        strncpy(TimeStringSecond, TimeString, LengthOfTimeString - 9);        TimeStringSecond[LengthOfTimeString - 9] = 0;        strncpy(TimeStringNanoSecond,                &TimeString[LengthOfTimeString - 9],                9);        TimeStringNanoSecond[9] = 0;    }    sprintf(stringInSecond, "%s.%s", TimeStringSecond, TimeStringNanoSecond);}void* checked_pc_malloc(size_t size) {   void* Ptr = pc_malloc(size);   if (Ptr == NULL) {      printf("pc_malloc: Ran out of Memory. Run in debugger to see "              "the location.\n");      assert(FALSE); abort();   }   return Ptr;}clocktype PrintSimTimeInterval;

⌨️ 快捷键说明

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