Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_socketbase_c.hxx

00001 /******************************************************************
00002  * CAVERNsoft
00003  * Copyright (C) 1994-2000 Electronic Visualization Laboratory,
00004  * all rights reserved
00005  * By Jason Leigh, Yong-joo Cho, Naveen Krishnaprasad, Chris Scharver,
00006  * Stuart Bailey, Atul Nayak, Shalini Venkataraman
00007  * University of Illinois at Chicago
00008  * 
00009  * This publication and its text and code may not be copied for commercial 
00010  * use without the express written permission of the University of Illinois
00011  * at Chicago.
00012  * The contributors disclaim any representation of warranty: use this
00013  * code at your own risk.
00014  * Direct questions, comments etc to cavern@evl.uic.edu
00015  ******************************************************************/
00016 
00017 #ifndef _CAVERNPLUS_SOCKETBASE_C
00018 #define _CAVERNPLUS_SOCKETBASE_C
00019 
00020 #ifdef CAVERN_USE_GLOBUS_THREADS
00021 #include "globus_common.h"
00022 #endif
00023 
00024 #ifdef CAVERN_USE_PTHREADS
00025 #include <pthread.h>
00026 #endif
00027 
00028 #include <stdio.h>
00029 #include <fcntl.h>
00030 #include <time.h>
00031 #include <string.h>
00032 #include <stdio.h>
00033 #include <math.h>
00034 //#include <fstream.h>
00035 
00036 #ifdef WIN32
00037 #include <windows.h>
00038 #include <winsock.h>
00039 #include <sys\timeb.h>
00040 #else
00041 #include <unistd.h>
00042 #include <sys/types.h>
00043 #include <sys/socket.h>
00044 #include <netinet/in.h>
00045 #include <sys/uio.h>
00046 #include <arpa/inet.h>
00047 #include <sys/errno.h>
00048 #include <signal.h>
00049 #include <netdb.h>
00050 #include <unistd.h>
00051 #include <sys/param.h>
00052 #include <sys/time.h>
00053 #endif
00054 
00055 //These are the number of packets for which all calculations are done -this is to be changed as desired
00056 
00057 #define LATENCY_BUF_SIZE 100
00058 #define BANDWIDTH_BUF_SIZE 100
00059 
00060 extern int errno;
00061 
00068 class CAVERNnet_socketbase_c {
00069 public:
00070 
00072 
00073 
00074         static const int OK/* = 1*/;
00076         static const int FAILED/* = 0*/;
00078 
00079         CAVERNnet_socketbase_c();
00080 
00082         static int hostnameToIP(char *hostname, char* hostIP);
00083 
00085         static void ipNumToString(unsigned int ip, char *ipstring);
00086 
00088         static double getTimeInSecs();
00089 
00091         static void getHostName(char *name, int len);
00092 
00094         static void expandHostName(char *src, char *newname, int len);
00095 
00097         unsigned int getTotalDataSent();
00098 
00100         unsigned int getTotalDataRead();
00101 
00103         double getInstantReceiveBandwidth();
00104 
00106         double getInstantSendBandwidth();
00107 
00109         double getAverageReceiveBandwidth();
00110 
00112         double getAverageSendBandwidth();
00113 
00115         void setInstantLatency(double lat);
00116 
00118         double getInstantLatency();
00119 
00121         double getAverageLatency();
00122 
00124         double getMaxLatency();
00125 
00127         double getMinLatency();
00128 
00130         void incrementDataSent(unsigned long size);
00131 
00133         void incrementDataRead(unsigned long size);
00134 
00136         double getInstantInterMesgDelay();
00137 
00139         double getMaxInterMesgDelay();
00140 
00142         double getMinInterMesgDelay();
00143 
00145         double getAverageInterMesgDelay();
00146 
00148     double getSTABandwidth();
00149 
00151     double getSTALatency();
00152 
00154     double getBurstiness();   
00155 
00157     double getJitter();
00158 
00160     unsigned long getPacketsRead();
00161 
00163     unsigned long getPacketsSent();
00164 
00165 protected:
00166         double instLat, latTotal, minLat, maxLat, avgLat;
00167         unsigned long latCount,sentCount, readCount;
00168         double instDelay, totalDelay, minDelay, maxDelay, avgDelay, prevLocalTime;
00169         double currentTime, previousSentTime, previousReadTime,initialSentTime, initialReadTime;
00170         unsigned long prevTotalDataRead, prevTotalDataSent, totalDataRead, totalDataSent;
00171         double instReadBandwidth, instSendBandwidth, avgReadBandwidth, avgSendBandwidth;
00172 
00173         //STA - Short Term Average -calculated for  a specified number of packets (calcualted over a number of packets defined by LATENCY_BUF_SIZE)
00174 
00175     //Jitter is the average of the deviations of the instantaneous latencies from the STALatency
00176 
00177     //Burstiness(for bandwidths) is calculated the same way as Jitter is calculated for latencies
00178 
00179     double STALatency, STABandwidth, jitter, burstiness;
00180 
00181     //The latencies and bandwidth are stored in a buffer of defined size and the short term sums -(STlatencySum and STBandwidthSum) are calculated
00182     double latencyBuffer[LATENCY_BUF_SIZE];
00183     double bandwidthBuffer[BANDWIDTH_BUF_SIZE];  
00184     double STlatencySum, STbandwidthSum;
00185 
00186     //to simplify Short Term Average calculations
00187     int tempLatCounter, tempBWCounter;
00188 
00190         void computeInstantSendBandwidth();
00191 
00193     void computeInstantReceiveBandwidth();
00194 
00196         void computeAverageReceiveBandwidth();
00197 
00199     void computeAverageSendBandwidth();
00200 
00202     void calculateJitter(double lat);
00203     
00205     void calculateBurstiness(double bw);
00206 
00207 
00208 };
00209 
00210 
00211 #endif

Generated at Mon Jul 2 14:24:42 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001