📄 ftp_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: ftp_client.pc,v 1.17 2001/02/15 03:17:26 mineo Exp $ * * This file contains initialization function, message processing * function, and finalize function used by ftp 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 "ftp_client.h"#include "ftp_server.h"#include "tcpapps.h"#include "tcp.h"/* * NAME: AppLayerFtpClient. * PURPOSE: Models the behaviour of Ftp 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 AppLayerFtpClient(GlomoNode *nodePtr, Message *msg){ char buf[GLOMO_MAX_STRING_LENGTH]; GlomoAppFtpClient *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) { #ifdef DEBUG printf("%s: node %u connection failed!\n", buf, nodePtr->nodeAddr); #endif nodePtr->appData.numAppTcpFailure ++; } else { GlomoAppFtpClient *clientPtr; clientPtr = AppFtpClientUpdateFtpClient(nodePtr, openResult); assert(clientPtr != NULL); AppFtpClientSendNextItem(nodePtr, clientPtr); } break; } case MSG_APP_FromTransDataSent: { TransportToAppDataSent *dataSent; dataSent = (TransportToAppDataSent *) msg->info; #ifdef DEBUG printf("%s: node %u sent data %d\n", buf, nodePtr->nodeAddr, dataSent->length); #endif clientPtr = AppFtpClientGetFtpClient(nodePtr, dataSent->connectionId); assert(clientPtr != NULL); clientPtr->numBytesSent += dataSent->length; if (clientPtr->itemSizeLeft > 0) { AppFtpClientSendNextPacket(nodePtr, clientPtr); } else if (clientPtr->itemsToSend == 0 && clientPtr->sessionIsClosed == TRUE) { 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 %d\n", buf, nodePtr->nodeAddr, msg->packetSize); #endif clientPtr = AppFtpClientGetFtpClient(nodePtr, dataRecvd->connectionId); assert(clientPtr != NULL); clientPtr->numBytesRecvd += msg->packetSize; assert(msg->packet[msg->packetSize - 1] == 'd'); if ((clientPtr->sessionIsClosed == FALSE) && (clientPtr->itemSizeLeft == 0)) { AppFtpClientSendNextItem(nodePtr, clientPtr); } 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 = AppFtpClientGetFtpClient(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" " %d.\n", buf, nodePtr->nodeAddr, msg->eventType); assert(FALSE); } GLOMO_MsgFree(nodePtr, msg);}/* * NAME: AppFtpClientInit. * PURPOSE: Initialize a Ftp session. * PARAMETERS: nodePtr - pointer to the node, * serverAddr - address of the server, * itemsToSend - number of items to send, * waitTime - time until the session starts. * RETURN: none. */voidAppFtpClientInit(GlomoNode *nodePtr, NODE_ADDR serverAddr, int itemsToSend, clocktype waitTime){ GlomoAppFtpClient *clientPtr; /* Check to make sure the number of ftp items is a correct value. */ if (itemsToSend < 0) { printf("FTP Client: Node %d items to send needs to be >= 0\n", nodePtr->nodeAddr); exit(0); } clientPtr = AppFtpClientNewFtpClient(nodePtr, serverAddr, itemsToSend); if (clientPtr == NULL) { printf("FTP Client: Node %d cannot allocate " "new ftp client\n", nodePtr->nodeAddr); assert(FALSE); } AppTcpOpenConnectionWithPriority(nodePtr, TRANSPORT_PROTOCOL_TCP, APP_FTP_CLIENT, serverAddr, (short)APP_FTP_SERVER, clientPtr->uniqueId, waitTime, NON_REAL_TIME);}/* * NAME: AppFtpClientPrintStats. * PURPOSE: Prints statistics of a Ftp session. * PARAMETERS: nodePtr - pointer to the node. * clientPtr - pointer to the ftp client data structure. * RETURN: none. */static voidAppFtpClientPrintStats(GlomoNode *nodePtr, GlomoAppFtpClient *clientPtr){ 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 %d to %d (cid = %d), start = %s, end = %s, " "bytes sent = %d B, bytes recv = %d B, throughput = %s bps", clientPtr->localAddr, clientPtr->remoteAddr, clientPtr->connectionId, startStr, closeStr, clientPtr->numBytesSent, clientPtr->numBytesRecvd, throughputStr); GLOMO_PrintStat(nodePtr, "AppFtpClient", buf);}/* * NAME: AppFtpClientFinalize. * PURPOSE: Collect statistics of a Ftp session. * PARAMETERS: nodePtr - pointer to the node. * clientPtr - pointer to the ftp client data structure. * RETURN: none. */voidAppFtpClientFinalize(GlomoNode *nodePtr, GlomoAppFtpClient *clientPtr){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -