1 | /****************************************************************************** |
---|
2 | * QUANTA - A toolkit for High Performance Data Sharing |
---|
3 | * Copyright (C) 2003 Electronic Visualization Laboratory, |
---|
4 | * University of Illinois at Chicago |
---|
5 | * |
---|
6 | * All rights reserved. |
---|
7 | * |
---|
8 | * Redistribution and use in source and binary forms, with or without |
---|
9 | * modification, are permitted provided that the following conditions are met: |
---|
10 | * |
---|
11 | * * Redistributions of source code must retain the above copyright |
---|
12 | * notice, this list of conditions and the following disclaimer. |
---|
13 | * * Redistributions in binary form must reproduce the above |
---|
14 | * copyright notice, this list of conditions and the following disclaimer |
---|
15 | * in the documentation and/or other materials provided with the distribution. |
---|
16 | * * Neither the name of the University of Illinois at Chicago nor |
---|
17 | * the names of its contributors may be used to endorse or promote |
---|
18 | * products derived from this software without specific prior written permission. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
31 | * |
---|
32 | * Direct questions, comments etc about Quanta to cavern@evl.uic.edu |
---|
33 | *****************************************************************************/ |
---|
34 | |
---|
35 | #ifndef _QUANTAPLUS_SOCKETBASE_C |
---|
36 | #define _QUANTAPLUS_SOCKETBASE_C |
---|
37 | |
---|
38 | #ifndef _WIN32_WCE |
---|
39 | #include <fcntl.h> |
---|
40 | #endif |
---|
41 | |
---|
42 | #ifdef WIN32 |
---|
43 | #ifndef __HAVE_WINSOCK2_H |
---|
44 | #include <winsock2.h> |
---|
45 | #define __HAVE_WINSOCK2_H |
---|
46 | #endif /* __HAVE_WINSOCK2_H */ |
---|
47 | #else |
---|
48 | #ifndef __HAVE_ARPA_INET_H |
---|
49 | #include <arpa/inet.h> |
---|
50 | #define __HAVE_ARPA_INET_H |
---|
51 | #endif |
---|
52 | #ifndef __HAVE_NETINET_IN_H |
---|
53 | #include <netinet/in.h> |
---|
54 | #define __HAVE_ARPA_INET_H |
---|
55 | #endif |
---|
56 | #endif /* WIN32 */ |
---|
57 | |
---|
58 | #include "QUANTAglobals.hxx" |
---|
59 | |
---|
60 | //These are the number of packets for which all calculations are done - |
---|
61 | //this is to be changed as desired |
---|
62 | |
---|
63 | #define LATENCY_BUF_SIZE 100 |
---|
64 | #define BANDWIDTH_BUF_SIZE 100 |
---|
65 | |
---|
66 | /** A base level socket class subclassed by QUANTAnet_tcp_c, QUANTAnet_udp_c, QUANTAnet_mcast_c, QUANTAnet_parallelTcp_c, and QUANTAnet_perfMonitor_c. The class itself does no networking. It provides some common member functions that are useful for network coding. In general one does not create an instance of this type. |
---|
67 | |
---|
68 | This class also offers information about the bandwidth, latency, Inter-Message_delay, Jitter and Burstiness values associated with the individual socket connections. Latency and Jitter calculations are offered only if the individual subclasses have implemented and enabled it. Otherwise values will be zero. |
---|
69 | These calculations are used by the QUANTAnet_perfMonitor_c class |
---|
70 | */ |
---|
71 | |
---|
72 | class QUANTAnet_socketbase_c { |
---|
73 | public: |
---|
74 | |
---|
75 | ///Socketbase class return values |
---|
76 | //@{ |
---|
77 | /// Operation went ok |
---|
78 | static const int OK/* = 1*/; |
---|
79 | /// Operation failed |
---|
80 | static const int FAILED/* = 0*/; |
---|
81 | /// Operation timed out |
---|
82 | static const int TIMED_OUT/* = 2 */; |
---|
83 | //@} |
---|
84 | |
---|
85 | QUANTAnet_socketbase_c(); |
---|
86 | virtual ~QUANTAnet_socketbase_c() {} |
---|
87 | |
---|
88 | /// Convert a hostname to an ip address of xxx.xxx.xxx.xxx |
---|
89 | static int hostnameToIP(const char* hostname, char* hostIP); |
---|
90 | |
---|
91 | /// Convert ip address to a string of xxx.xxx.xxx.xxx |
---|
92 | static void ipNumToString(unsigned int ip, char* ipstring); |
---|
93 | |
---|
94 | /// Get time in secs with microsecond accuracy |
---|
95 | static double getTimeInSecs(); |
---|
96 | |
---|
97 | /// Get the full host name of a local client |
---|
98 | static void getHostName(char* name, int len); |
---|
99 | |
---|
100 | /// If hostname is not fully expanded (ie does not include its domain) then expand it. |
---|
101 | static void expandHostName(const char* src, char* newname, int len); |
---|
102 | |
---|
103 | /// Get the host IP address as a long integer. |
---|
104 | static long getSelfIP(); |
---|
105 | |
---|
106 | /// Get the host IP address as a character string. |
---|
107 | static void getSelfIP(char*); |
---|
108 | |
---|
109 | /// Get the total data sent by a connection. |
---|
110 | unsigned int getTotalDataSent(); |
---|
111 | |
---|
112 | /// Get total data received by a connection. |
---|
113 | unsigned int getTotalDataRead(); |
---|
114 | |
---|
115 | /// Get total instantaneous incoming bandwidth by a connection. |
---|
116 | double getInstantReceiveBandwidth(); |
---|
117 | |
---|
118 | /// Get total instantaneous outgoing bandwidth by a connection. |
---|
119 | double getInstantSendBandwidth(); |
---|
120 | |
---|
121 | /// Get average incoming bandwidth by a connection. |
---|
122 | double getAverageReceiveBandwidth(); |
---|
123 | |
---|
124 | /// Get average outgoing bandwidth by a connection. |
---|
125 | double getAverageSendBandwidth(); |
---|
126 | |
---|
127 | ///Set the instantaneous latency and also calculate the STALatency and Jitter values automatically |
---|
128 | void setInstantLatency(double lat); |
---|
129 | |
---|
130 | /// Retrieve most recent incoming packet's latency. |
---|
131 | double getInstantLatency(); |
---|
132 | |
---|
133 | /// Retrieve average incoming latency. |
---|
134 | double getAverageLatency(); |
---|
135 | |
---|
136 | /// Retrieve max latency so far. |
---|
137 | double getMaxLatency(); |
---|
138 | |
---|
139 | /// Retrieve min latency so far. |
---|
140 | double getMinLatency(); |
---|
141 | |
---|
142 | /// Record amount of data sent. |
---|
143 | void incrementDataSent(unsigned long size); |
---|
144 | |
---|
145 | /// Record amount of data read - and also compute instantaneous, average bandwidths along with the inter message delay values |
---|
146 | void incrementDataRead(unsigned long size); |
---|
147 | |
---|
148 | /// Get instantaneous inter-message delay (jitter) |
---|
149 | double getInstantInterMesgDelay(); |
---|
150 | |
---|
151 | /// Get max inter-message delay (jitter) |
---|
152 | double getMaxInterMesgDelay(); |
---|
153 | |
---|
154 | /// Get min inter-message delay (jitter) |
---|
155 | double getMinInterMesgDelay(); |
---|
156 | |
---|
157 | /// Get average inter-message delay (jitter) |
---|
158 | double getAverageInterMesgDelay(); |
---|
159 | |
---|
160 | ///Get the Short Term Average Bandwidth -over a fixed number of packets (defined by BANDWIDTH_BUF_SIZE) |
---|
161 | double getSTABandwidth(); |
---|
162 | |
---|
163 | ///Get the Short Term Average Latency -over a number of packets (defined by LATENCY_BUF_SIZE) |
---|
164 | double getSTALatency(); |
---|
165 | |
---|
166 | ///get the burstinesss |
---|
167 | double getBurstiness(); |
---|
168 | |
---|
169 | ///Get the Jitter |
---|
170 | double getJitter(); |
---|
171 | |
---|
172 | ///Return the total number of packets read |
---|
173 | unsigned long getPacketsRead(); |
---|
174 | |
---|
175 | ///Return the total number of packets sent |
---|
176 | unsigned long getPacketsSent(); |
---|
177 | |
---|
178 | ///Returns the socket id |
---|
179 | virtual int getSocketId(); |
---|
180 | |
---|
181 | ///Returns the status of the sockets being polled |
---|
182 | static int selectSock(void *ptr, int *status, int numSocks, |
---|
183 | struct timeval *timeout); |
---|
184 | |
---|
185 | |
---|
186 | protected: |
---|
187 | double instLat, latTotal, minLat, maxLat, avgLat; |
---|
188 | unsigned long latCount,sentCount, readCount; |
---|
189 | double instDelay, totalDelay, minDelay, maxDelay, avgDelay, prevLocalTime; |
---|
190 | double currentTime, previousSentTime, previousReadTime,initialSentTime, initialReadTime; |
---|
191 | unsigned long prevTotalDataRead, prevTotalDataSent, totalDataRead, totalDataSent; |
---|
192 | double instReadBandwidth, instSendBandwidth, avgReadBandwidth, avgSendBandwidth; |
---|
193 | |
---|
194 | //STA - Short Term Average -calculated for a specified number of packets (calcualted over a number of packets defined by LATENCY_BUF_SIZE) |
---|
195 | |
---|
196 | //Jitter is the average of the deviations of the instantaneous latencies from the STALatency |
---|
197 | |
---|
198 | //Burstiness(for bandwidths) is calculated the same way as Jitter is calculated for latencies |
---|
199 | |
---|
200 | double STALatency, STABandwidth, jitter, burstiness; |
---|
201 | |
---|
202 | //The latencies and bandwidth are stored in a buffer of defined size and the short term sums -(STlatencySum and STBandwidthSum) are calculated |
---|
203 | double latencyBuffer[LATENCY_BUF_SIZE]; |
---|
204 | double bandwidthBuffer[BANDWIDTH_BUF_SIZE]; |
---|
205 | double STlatencySum, STbandwidthSum; |
---|
206 | |
---|
207 | //to simplify Short Term Average calculations |
---|
208 | int tempLatCounter, tempBWCounter; |
---|
209 | |
---|
210 | ///Calculate the instantaneous outgoing bandwidth |
---|
211 | void computeInstantSendBandwidth(); |
---|
212 | |
---|
213 | ///Calculate the instantaneous incoming bandwidth |
---|
214 | void computeInstantReceiveBandwidth(); |
---|
215 | |
---|
216 | ///Calculate the average incoming bandwidth |
---|
217 | void computeAverageReceiveBandwidth(); |
---|
218 | |
---|
219 | ///Calculate the average outgoing bandwidth |
---|
220 | void computeAverageSendBandwidth(); |
---|
221 | |
---|
222 | ///Calculate the jitter over a specified number of packets |
---|
223 | void calculateJitter(double lat); |
---|
224 | |
---|
225 | ///Calculate the burstiness over a specified number of packets |
---|
226 | void calculateBurstiness(double bw); |
---|
227 | |
---|
228 | |
---|
229 | }; |
---|
230 | |
---|
231 | |
---|
232 | #endif |
---|