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

📄 telnet_client.pc

📁 无线网络仿真工具Glomosim2.03
💻 PC
📖 第 1 页 / 共 2 页
字号:
    clocktype throughput;    char clockStr[GLOMO_MAX_STRING_LENGTH];    char startStr[GLOMO_MAX_STRING_LENGTH];    char closeStr[GLOMO_MAX_STRING_LENGTH];    char buf[GLOMO_MAX_STRING_LENGTH];    char throughputStr[GLOMO_MAX_STRING_LENGTH];    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, end = %s, "            "bytes sent = %ld B, bytes recv = %ld B, throughput = %s bps",            clientPtr->localAddr, clientPtr->remoteAddr,            clientPtr->connectionId, startStr, closeStr,            clientPtr->numBytesSent, clientPtr->numBytesRecvd,            throughputStr);    if (nodePtr->appData.appStats == TRUE)        GLOMO_PrintStat(nodePtr, "AppTelnetClient", buf);}/* * NAME:        AppTelnetClientGetTelnetClient. * PURPOSE:     search for a telnet client data structure.  * PARAMETERS:  nodePtr - pointer to the node,  *              connId - connection ID of the telnet client.  * RETURN:      the pointer to the telnet client data structure, *              NULL if nothing found. */static GlomoAppTelnetClient *AppTelnetClientGetTelnetClient(GlomoNode *nodePtr, int connId){    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppTelnetClient *telnetClient;        for (; appList != NULL; appList = appList->appNext)     {        if (appList->appType == APP_TELNET_CLIENT)         {            telnetClient = (GlomoAppTelnetClient *) appList->appDetail;            if (telnetClient->connectionId == connId)             {                return telnetClient;            }        }    }    return NULL;}/* * NAME:        AppTelnetClientUpdateTelnetClient. * PURPOSE:     create a new telnet client data structure, place it                at the beginning of the application list.  * PARAMETERS:  nodePtr - pointer to the node,  *              openResult - result of the open request.  * RETRUN:      the pointer to the created telnet client data structure, *              NULL if no data structure allocated.  */static GlomoAppTelnetClient *AppTelnetClientUpdateTelnetClient(GlomoNode *nodePtr,                                   TransportToAppOpenResult *openResult){    AppInfo *appList = nodePtr->appData.appPtr;    GlomoAppTelnetClient *telnetClient;    GlomoAppTelnetClient *tmpTelnetClient;    for (; appList != NULL; appList = appList->appNext)    {        if (appList->appType == APP_TELNET_CLIENT)        {            tmpTelnetClient = (GlomoAppTelnetClient *) appList->appDetail;            #ifdef DEBUG                printf("TELNET Client: Node %ld comparing uniqueId "                       "%ld with %ld\n", nodePtr->nodeAddr,                       tmpTelnetClient->uniqueId, openResult->uniqueId);            #endif            if (tmpTelnetClient->uniqueId == openResult->uniqueId)            {                telnetClient = tmpTelnetClient;                break;            }        }    }    if (telnetClient == NULL)    {        assert(FALSE);    }    /*     * fill in connection id, etc.     */    telnetClient->connectionId = openResult->connectionId;    telnetClient->localAddr = openResult->localAddr;    telnetClient->remoteAddr = openResult->remoteAddr;    telnetClient->sessionStart = simclock();    telnetClient->sessionFinish = simclock() + telnetClient->sessDuration;     telnetClient->sessionIsClosed = FALSE;    return telnetClient;}/* * NAME:        AppTelnetClientNewTelnetClient. * PURPOSE:     create a new telnet client data structure, place it                at the beginning of the application list.  * PARAMETERS:  nodePtr - pointer to the node,  *              serverAddr - server node of this telnet session. *              sessDuration - length of telnet session. * RETRUN:      the pointer to the created telnet client data structure, *              NULL if no data structure allocated.  */static GlomoAppTelnetClient *AppTelnetClientNewTelnetClient(GlomoNode *nodePtr,                                NODE_ADDR serverAddr,                               clocktype sessDuration){    AppInfo *newApp;    GlomoAppTelnetClient *telnetClient;    clocktype sessionTime;    newApp = (AppInfo *) pc_malloc(sizeof(AppInfo));    if (newApp == NULL)     {        assert(FALSE);    }    telnetClient = (GlomoAppTelnetClient *)                     pc_malloc(sizeof(GlomoAppTelnetClient));     if (telnetClient == NULL)     {        assert(FALSE);    }    /*     * fill in connection id, etc.     */    newApp->appType = APP_TELNET_CLIENT;      telnetClient->connectionId = -1;    telnetClient->uniqueId = nodePtr->appData.uniqueId++;    telnetClient->localAddr = nodePtr->nodeAddr;    telnetClient->remoteAddr = serverAddr;    if (sessDuration > 0)     {        telnetClient->sessDuration = sessDuration;    }    else     {        telnetClient->sessDuration = AppTelnetClientSessDuration(nodePtr);    }    telnetClient->numBytesSent = 0;    telnetClient->numBytesRecvd = 0;    newApp->appDetail = telnetClient;    newApp->appNext = nodePtr->appData.appPtr;     nodePtr->appData.appPtr = newApp;    return telnetClient;}/* * NAME:        AppTelnetClientScheduleNextPkt. * PURPOSE:     schedule the next packet the client will send.  If next packet *              won't arrive until the finish deadline, schedule a close. * PARAMETERS:  nodePtr - pointer to the node,  *              clientPtr - pointer to the telnet client data structure.  * RETRUN:      none.  */static voidAppTelnetClientScheduleNextPkt(GlomoNode *nodePtr,                                GlomoAppTelnetClient *clientPtr){    clocktype interval = AppTelnetClientPktInterval(nodePtr);    Message *timerMsg;    AppTimer *timer;    timerMsg = GLOMO_MsgAlloc(nodePtr, GLOMO_APP_LAYER,                               APP_TELNET_CLIENT, MSG_APP_TimerExpired);     GLOMO_MsgInfoAlloc(nodePtr, timerMsg, sizeof(AppTimer));    timer = (AppTimer *)timerMsg->info;    timer->connectionId = clientPtr->connectionId;    if ((simclock() + interval) < clientPtr->sessionFinish)     {        timer->type = APP_TIMER_SEND_PKT;    }     else     {        timer->type = APP_TIMER_CLOSE_SESS;        interval = clientPtr->sessionFinish - simclock();    }     GLOMO_MsgSend(nodePtr, timerMsg, interval);}/* * NAME:        AppTelnetClientSessDuration. * PURPOSE:     call tcplib function telnet_duration to get the duration *              of this session.  * PARAMETERS:  nodePtr - pointer to the node. * RETRUN:      session duration in clocktype.  */static clocktypeAppTelnetClientSessDuration(GlomoNode *nodePtr){    float duration;    duration = telnet_duration(nodePtr->seed);    #ifdef DEBUG        printf("TELNET duration = %f\n", duration);    #endif    return (((clocktype)(duration + 0.5)) * MILLI_SECOND);}/* * NAME:        AppTelnetClientPktInterval. * PURPOSE:     call tcplib function telnet_interarrival to get the  *              between the arrival of the next packet and the current one.  * PARAMETERS:  nodePtr - pointer to the node. * RETRUN:      interarrival time in clocktype.  */static clocktypeAppTelnetClientPktInterval(GlomoNode *nodePtr){    float interval;    interval = telnet_interarrival(nodePtr->seed);    #ifdef DEBUG        printf("TELNET interarrival = %f\n", interval);    #endif    return (((clocktype)(interval + 0.5)) * MILLI_SECOND); }

⌨️ 快捷键说明

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