📄 telnet_client.pc
字号:
/* * 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: telnet_client.pc,v 1.13 2001/02/15 03:17:26 mineo Exp $ * * This file contains initialization function, message processing * function, and finalize function used by telnet client. */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h> #include "api.h"#include "structmsg.h"#include "fileio.h"#include "message.h"#include "application.h"#include "app_util.h"#include "telnet_client.h"#include "tcp.h"#include "tcpapps.h"#define noDEBUG/* * NAME: AppLayerTelnetClient. * PURPOSE: Models the behaviour of TelnetClient Client on receiving the * message encapsulated in msg. * PARAMETERS: nodePtr - pointer to the node which received the message. * msg - message received by the layer * RETURN: none. */void AppLayerTelnetClient(GlomoNode *nodePtr, Message *msg){ char buf[GLOMO_MAX_STRING_LENGTH]; GlomoAppTelnetClient *clientPtr; ctoa(simclock(), buf); switch(msg->eventType) { case MSG_APP_FromTransOpenResult: { TransportToAppOpenResult *openResult; openResult = (TransportToAppOpenResult *) msg->info; #ifdef DEBUG printf("%s: node %u got OpenResult\n", buf, nodePtr->nodeAddr); #endif assert(openResult->type == TCP_CONN_ACTIVE_OPEN); if (openResult->connectionId < 0) { nodePtr->appData.numAppTcpFailure ++; } else { GlomoAppTelnetClient *clientPtr; clientPtr = AppTelnetClientUpdateTelnetClient(nodePtr, openResult); assert(clientPtr != NULL); AppTelnetClientScheduleNextPkt(nodePtr, clientPtr); } break; } case MSG_APP_FromTransDataSent: { TransportToAppDataSent *dataSent; dataSent = (TransportToAppDataSent *) msg->info; #ifdef DEBUG printf("%s: node %u sent data %ld\n", buf, nodePtr->nodeAddr, dataSent->length); #endif clientPtr = AppTelnetClientGetTelnetClient(nodePtr, dataSent->connectionId); assert(clientPtr != NULL); clientPtr->numBytesSent += dataSent->length; if (clientPtr->sessionIsClosed == FALSE) { AppTelnetClientScheduleNextPkt(nodePtr, clientPtr); } else { AppTcpCloseConnection(nodePtr, TRANSPORT_PROTOCOL_TCP, clientPtr->connectionId); } break; } case MSG_APP_FromTransDataReceived: { TransportToAppDataReceived *dataRecvd; dataRecvd = (TransportToAppDataReceived *) msg->info; #ifdef DEBUG printf("%s: node %u received data %ld\n", buf, nodePtr->nodeAddr, msg->packetSize); #endif clientPtr = AppTelnetClientGetTelnetClient(nodePtr, dataRecvd->connectionId); assert(clientPtr != NULL); clientPtr->numBytesRecvd += msg->packetSize; break; } case MSG_APP_TimerExpired: { AppTimer *timer; timer = (AppTimer *) msg->info; #ifdef DEBUG printf("%s: node %u got timer %d\n", buf, nodePtr->nodeAddr, timer->type); #endif clientPtr = AppTelnetClientGetTelnetClient(nodePtr, timer->connectionId); assert(clientPtr != NULL); switch (timer->type) { case APP_TIMER_SEND_PKT: if (clientPtr->sessionIsClosed == FALSE) { AppTcpSendData(nodePtr, TRANSPORT_PROTOCOL_TCP, clientPtr->connectionId, "d", 1); } break; case APP_TIMER_CLOSE_SESS: AppTcpSendData(nodePtr, TRANSPORT_PROTOCOL_TCP, clientPtr->connectionId, "c", 1); clientPtr->sessionIsClosed = TRUE; break; default: assert(FALSE); } break; } case MSG_APP_FromTransCloseResult: { TransportToAppCloseResult *closeResult; closeResult = (TransportToAppCloseResult *) msg->info; #ifdef DEBUG printf("%s: node %u got close result\n", buf, nodePtr->nodeAddr); #endif clientPtr = AppTelnetClientGetTelnetClient(nodePtr, closeResult->connectionId); assert(clientPtr != NULL); if (clientPtr->sessionIsClosed == FALSE) { clientPtr->sessionIsClosed = TRUE; clientPtr->sessionFinish = simclock(); } break; } default: ctoa(simclock(), buf); printf("Time %s: Node %u received message of unknown type" " %ld.\n", buf, nodePtr->nodeAddr, msg->eventType); assert(FALSE); } GLOMO_MsgFree(nodePtr, msg);}/* * NAME: AppTelnetClientInit. * PURPOSE: Initialize a TelnetClient session. * PARAMETERS: nodePtr - pointer to the node, * serverAddr - address of the server, * sessDuration - length of telnet session. * waitTime - time until the session starts. * RETURN: none. */voidAppTelnetClientInit(GlomoNode *nodePtr, NODE_ADDR serverAddr, clocktype sessDuration, clocktype waitTime){ GlomoAppTelnetClient *clientPtr; clientPtr = AppTelnetClientNewTelnetClient(nodePtr, serverAddr, sessDuration); if (clientPtr == NULL) { printf("TELNET Client: Node %ld cannot allocate " "new telnet client\n", nodePtr->nodeAddr); assert(FALSE); } AppTcpOpenConnectionWithPriority(nodePtr, TRANSPORT_PROTOCOL_TCP, APP_TELNET_CLIENT, serverAddr, (short)APP_TELNET_SERVER, clientPtr->uniqueId, waitTime, NON_REAL_TIME);}/* * NAME: AppTelnetClientFinalize. * PURPOSE: Collect statistics of a TelnetClient session. * PARAMETERS: nodePtr - pointer to the node. * clientPtr - pointer to the telnet client data structure. * RETURN: none. */voidAppTelnetClientFinalize(GlomoNode *nodePtr, GlomoAppTelnetClient *clientPtr){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -