00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
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;
00076 static const int FAILED;
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
00174
00175
00176
00177
00178
00179 double STALatency, STABandwidth, jitter, burstiness;
00180
00181
00182 double latencyBuffer[LATENCY_BUF_SIZE];
00183 double bandwidthBuffer[BANDWIDTH_BUF_SIZE];
00184 double STlatencySum, STbandwidthSum;
00185
00186
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