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

📄 gen_ftp_client.pc

📁 无线网络仿真工具Glomosim2.03
💻 PC
📖 第 1 页 / 共 2 页
字号:
        }    #endif    ctoa(clientPtr->sessionStart, startStr);    if (clientPtr->sessionIsClosed == FALSE)     {        clientPtr->sessionFinish = simclock();        ctoa(simclock(), clockStr);        sprintf(closeStr, "%s ns (not closed)", clockStr);    }    else     {        ctoa(clientPtr->sessionFinish, clockStr);        sprintf(closeStr, "%s ns (closed)", clockStr);    }    if (clientPtr->sessionFinish <= clientPtr->sessionStart)     {        throughput = 0;    }     else     {        throughput = (clientPtr->numBytesSent * 8.0 * SECOND) /                     (clientPtr->sessionFinish - clientPtr->sessionStart);    }    ctoa(throughput, throughputStr);    sprintf(buf, "from %ld to %ld (cid = %d), start = %s ns, end = %s, "            "bytes sent = %ld B, throughput = %s bps",            clientPtr->localAddr, clientPtr->remoteAddr,             clientPtr->connectionId, startStr, closeStr,            clientPtr->numBytesSent, throughputStr);               GLOMO_PrintStat(nodePtr, "AppGenFtpClient", buf);    #ifdef EXCEL        fprintf(excel, "%ld\t%ld\t%d\t%s\t%s\t%ld\t%s\n",                clientPtr->localAddr, clientPtr->remoteAddr,                clientPtr->connectionId, startStr, closeStr,                clientPtr->numBytesSent, throughputStr);        fflush(excel);        fclose(excel);    #endif}/* * NAME:        AppGenFtpClientFinalize. * PURPOSE:     Collect statistics of a ftp session. * PARAMETERS:  nodePtr - pointer to the node.  *              clientPtr - pointer to the ftp client data structure. * RETURN:      none. */voidAppGenFtpClientFinalize(GlomoNode *nodePtr, GlomoAppGenFtpClient *clientPtr){    if (nodePtr->appData.appStats == TRUE)    {        AppGenFtpClientPrintStats(nodePtr, clientPtr);    }}/* * NAME:        AppGenFtpClientGetGenFtpClient. * PURPOSE:     search for a ftp client data structure.  * PARAMETERS:  nodePtr - pointer to the node.  *              connId - connection ID of the ftp client.  * RETURN:      the pointer to the ftp client data structure, *              NULL if nothing found. */static GlomoAppGenFtpClient *AppGenFtpClientGetGenFtpClient(GlomoNode *nodePtr, int connId){    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppGenFtpClient *ftpClient;        for (; appList != NULL; appList = appList->appNext)     {        if (appList->appType == APP_GEN_FTP_CLIENT)        {            ftpClient = (GlomoAppGenFtpClient *) appList->appDetail;            if (ftpClient->connectionId == connId)            {                return ftpClient;            }        }    }    return NULL;}/* * NAME:        AppGenFtpClientUpdateGenFtpClient. * PURPOSE:     update existing ftp client data structure by including  *              connection id. * PARAMETERS:  nodePtr - pointer to the node. *              openResult - result of the open request. * RETRUN:      the pointer to the created ftp client data structure, *              NULL if no data structure allocated.  */static GlomoAppGenFtpClient *AppGenFtpClientUpdateGenFtpClient(GlomoNode *nodePtr,                                  TransportToAppOpenResult *openResult){    char clockStr[GLOMO_MAX_STRING_LENGTH];    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppGenFtpClient *tmpFtpClient = NULL;    GlomoAppGenFtpClient *ftpClient = NULL;       for (; appList != NULL; appList = appList->appNext)    {        if (appList->appType == APP_GEN_FTP_CLIENT)        {            tmpFtpClient = (GlomoAppGenFtpClient *) appList->appDetail;            #ifdef DEBUG                printf("GENERIC FTP Client: Node %ld comparing uniqueId "                       "%ld with %ld\n", nodePtr->nodeAddr,                        tmpFtpClient->uniqueId, openResult->uniqueId);            #endif            if (tmpFtpClient->uniqueId == openResult->uniqueId)            {                ftpClient = tmpFtpClient;                break;            }        }    }    if (ftpClient == NULL)    {        assert(FALSE);    }    /*     * fill in connection id, etc.     */    ftpClient->connectionId = openResult->connectionId;    ftpClient->localAddr = openResult->localAddr;    ftpClient->remoteAddr = openResult->remoteAddr;    ftpClient->sessionStart = simclock();    ftpClient->sessionFinish = simclock();    ftpClient->sessionIsClosed = FALSE;    #ifdef DEBUG        printf("GENERIC FTP Client: Node %ld updating ftp "               "client struture\n", nodePtr->nodeAddr);        printf("    connectionId = %d\n", ftpClient->connectionId);        printf("    localAddr = %d\n", ftpClient->localAddr);        printf("    remoteAddr = %d\n", ftpClient->remoteAddr);        printf("    itemsToSend = %d\n", ftpClient->itemsToSend);        printf("    itemSize = %d\n", ftpClient->itemSize);        ctoa(ftpClient->endTime, clockStr);        printf("    endTime = %s\n", clockStr);    #endif    return ftpClient;}/* * NAME:        AppGenFtpClientNewGenFtpClient. * PURPOSE:     create a new ftp client data structure, place it *              at the beginning of the application list.  * PARAMETERS:  nodePtr - pointer to the node. *              serverAddr - ftp server to this client. *              itemsToSend - number of ftp items to send in simulation. *              itemSize - size of each item. *              endTime - when simulation of ftp ends. * RETRUN:      the pointer to the created ftp client data structure, *              NULL if no data structure allocated.  */static GlomoAppGenFtpClient *AppGenFtpClientNewGenFtpClient(GlomoNode *nodePtr,                                NODE_ADDR serverAddr,                               long itemsToSend,                               long itemSize,                               clocktype endTime){    char clockStr[GLOMO_MAX_STRING_LENGTH];    AppInfo *newApp;    GlomoAppGenFtpClient *ftpClient;    newApp = (AppInfo *) pc_malloc(sizeof(AppInfo));    if (newApp == NULL)     {        assert(FALSE);    }    ftpClient = (GlomoAppGenFtpClient *)pc_malloc(sizeof(GlomoAppGenFtpClient));    if (ftpClient == NULL)     {        assert(FALSE);    }    /*     * fill in connection id, etc.     */    newApp->appType = APP_GEN_FTP_CLIENT;      ftpClient->connectionId = -1;    ftpClient->localAddr = nodePtr->nodeAddr;    ftpClient->remoteAddr = serverAddr;    ftpClient->itemsToSend = itemsToSend;    ftpClient->itemSize = itemSize;    ftpClient->endTime = endTime;    ftpClient->uniqueId = nodePtr->appData.uniqueId++;    ftpClient->numBytesSent = 0;    #ifdef DEBUG        printf("GENERIC FTP Client: Node %ld creating new ftp "               "client struture\n", nodePtr->nodeAddr);        printf("    uniqueId = %d\n", ftpClient->uniqueId);        printf("    connectionId = %d\n", ftpClient->connectionId);        printf("    localAddr = %d\n", ftpClient->localAddr);        printf("    remoteAddr = %d\n", ftpClient->remoteAddr);        printf("    itemsToSend = %d\n", ftpClient->itemsToSend);        printf("    itemSize = %d\n", ftpClient->itemSize);        ctoa(ftpClient->endTime, clockStr);        printf("    endTime = %s\n", clockStr);    #endif    newApp->appDetail = ftpClient;    newApp->appNext = nodePtr->appData.appPtr;     nodePtr->appData.appPtr = newApp;    return ftpClient;}/* * NAME:        AppGenFtpClientSendNextItem. * PURPOSE:     Send the next item. * PARAMETERS:  nodePtr - pointer to the node,  *              clientPtr - pointer to the ftp client data structure.  * RETRUN:      none.  */static voidAppGenFtpClientSendNextItem(GlomoNode *nodePtr, GlomoAppGenFtpClient *clientPtr){    #ifdef DEBUG        printf("GENERIC FTP Client: Node %ld has %ld items left to send\n",               nodePtr->nodeAddr, clientPtr->itemsToSend);    #endif    if (((clientPtr->itemsToSend > 1) && (simclock() < clientPtr->endTime)) ||       ((clientPtr->itemsToSend == 0) && (simclock() < clientPtr->endTime)) ||       ((clientPtr->itemsToSend > 1) && (clientPtr->endTime == 0)) ||       ((clientPtr->itemsToSend == 0) && (clientPtr->endTime == 0)))    {        AppGenFtpClientSendPacket(nodePtr, clientPtr, FALSE);    }     else    {        AppGenFtpClientSendPacket(nodePtr, clientPtr, TRUE);        #ifdef DEBUG            printf("GENERIC FTP Client: Node %ld closing connection %d\n",                   nodePtr->nodeAddr, clientPtr->connectionId);        #endif        clientPtr->sessionIsClosed = TRUE;        clientPtr->sessionFinish = simclock();    }    if (clientPtr->itemsToSend > 0)    {        clientPtr->itemsToSend--;    }}/* * NAME:        AppGenFtpClientSendPacket. * PURPOSE:     Send the remaining data. * PARAMETERS:  nodePtr - pointer to the node,  *              clientPtr - pointer to the ftp client data structure.  *              end - end of session. * RETRUN:      none.  */static voidAppGenFtpClientSendPacket(GlomoNode *nodePtr,                           GlomoAppGenFtpClient *clientPtr,                          BOOL end){    char payload[MAX_APP_DATA_UNIT];    memset(payload, 'd', MAX_APP_DATA_UNIT);    if (end == TRUE) {        payload[clientPtr->itemSize - 1] = 'c';    }    #ifdef DEBUG    {        char clockStr[GLOMO_MAX_STRING_LENGTH];        ctoa(simclock(), clockStr);        printf("GENERIC FTP Client: Node %ld sending pkt of size %d at %s\n",               nodePtr->nodeAddr, clientPtr->itemSize, clockStr);    }    #endif    AppTcpSendData(nodePtr, TRANSPORT_PROTOCOL_TCP,                   clientPtr->connectionId, payload, clientPtr->itemSize);}

⌨️ 快捷键说明

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