Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "DNS.h"
00036 #include <iostream.h>
00037 #include <fstream.h>
00038 #include <string.h>
00039 #include "VConnection.h"
00040 #include "stdio.h"
00041 #include "libts.h"
00042 #define N_STATE_MACHINES 1000
00043 #define MEASUREMENT_INTERVAL 100
00044 class TestDnsStateMachine;
00045
00046
00047
00048
00049
00050
00051
00052 unsigned g_host_ip = 0;
00053 char *in_file_name = "test_dns.in";
00054 char *out_file_name = "test_dns.out";
00055 char *rate_file_name = "rates.out";
00056 char *rate_misc_file_name = "rates.misc.out";
00057 ofstream fout;
00058 ofstream fout_rate, fout_rate_misc;
00059 FILE *fin;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 class TestDnsStateMachine:public Continuation
00070 {
00071 public:
00072 TestDnsStateMachine(char *ahost, size_t size);
00073 ~TestDnsStateMachine()
00074 {
00075
00076 return;
00077 }
00078
00079 const char *currentStateName();
00080
00081 int processEvent(int event, void *data);
00082
00083 enum
00084 { START, DNS_LOOKUP };
00085
00086 int m_state;
00087 char host[100];
00088 };
00089
00090 TestDnsStateMachine::TestDnsStateMachine(char *ahost, size_t size)
00091 :
00092 Continuation(new_ProxyMutex())
00093 {
00094 ink_strlcpy(host, ahost, size);
00095 m_state = START;
00096 SET_HANDLER(processEvent);
00097 return;
00098 }
00099
00100
00101 inline const char *
00102 TestDnsStateMachine::currentStateName()
00103 {
00104 switch (m_state) {
00105 case START:
00106 return ("START");
00107 case DNS_LOOKUP:
00108 return ("DNS_LOOKUP");
00109 default:
00110 return ("unknown state");
00111 }
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 int
00124 TestDnsStateMachine::processEvent(int event, void *data)
00125 {
00126 int rvalue = VC_EVENT_DONE;
00127 void complete();
00128
00129
00130
00131 switch (m_state) {
00132 case START:
00133 {
00134
00135
00136
00137
00138
00139
00140
00141 m_state = DNS_LOOKUP;
00142 dnsProcessor.gethostbyname(this, host);
00143 break;
00144 }
00145 case DNS_LOOKUP:
00146 {
00147 ink_assert(event == DNS_EVENT_LOOKUP);
00148 if (!host)
00149 ink_assert(!"Error - host has no value\n");
00150 if (data) {
00151 HostEnt *ent = (HostEnt *) data;
00152 g_host_ip = ((struct in_addr *) ent->h_addr_list[0])->s_addr;
00153
00154
00155 fout << "<" << host << "> <" << g_host_ip << ">\n";
00156
00157
00158 } else {
00159 fout << "<" << host << "> <>\n";
00160 }
00161 fout.flush();
00162 rvalue = VC_EVENT_DONE;
00163 m_state = 99;
00164 complete();
00165 delete this;
00166 break;
00167 }
00168 default:
00169 {
00170 ink_assert(!"unexpected m_state");
00171 break;
00172 }
00173 }
00174 return (rvalue);
00175 }
00176
00177 int state_machines_created, state_machines_finished, measurement_interval;
00178 ink_hrtime start_time, last_measurement_time;
00179
00180 void
00181 complete()
00182 {
00183 float throughput, cumul_throughput;
00184 ink_hrtime now;
00185 state_machines_finished++;
00186 if (!(state_machines_finished % measurement_interval)) {
00187 now = ink_get_hrtime();
00188 cumul_throughput = state_machines_finished * 1.0 * HRTIME_SECOND / (now - start_time);
00189 throughput = measurement_interval * 1.0 * HRTIME_SECOND / (now - last_measurement_time);
00190 last_measurement_time = now;
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 fout_rate << (now - start_time) * 1.0 / HRTIME_SECOND << " " << state_machines_finished << " " << cumul_throughput
00201 << " " << throughput << "\n";
00202 fout_rate.flush();
00203 }
00204 if (state_machines_finished == state_machines_created) {
00205 now = ink_get_hrtime();
00206 fout_rate_misc << (now - start_time) * 1.0 / HRTIME_SECOND << "\n";
00207 fout_rate_misc.flush();
00208 fout.close();
00209 fout_rate.close();
00210 fout_rate_misc.close();
00211 cout << "Dns Testing Complete\n";
00212 exit(0);
00213 }
00214
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 void
00226 test()
00227 {
00228 char host[100];
00229 ink_hrtime now;
00230 int i;
00231 TestDnsStateMachine *test_dns_state_machine;
00232 printf("removing file '%s'\n", out_file_name);
00233 unlink(out_file_name);
00234 printf("removing file '%s'\n", rate_file_name);
00235 unlink(rate_file_name);
00236 printf("removing file '%s'\n", rate_misc_file_name);
00237 unlink(rate_misc_file_name);
00238 fin = fopen(in_file_name, "r");
00239 fout.open(out_file_name);
00240 fout_rate.open(rate_file_name);
00241 fout_rate_misc.open(rate_misc_file_name);
00242 i = 0;
00243 state_machines_created = N_STATE_MACHINES;
00244 state_machines_finished = 0;
00245 measurement_interval = MEASUREMENT_INTERVAL;
00246 start_time = ink_get_hrtime();
00247 last_measurement_time = ink_get_hrtime();
00248 while ((fscanf(fin, "%s", host) != EOF) && (i < state_machines_created)) {
00249 test_dns_state_machine = new TestDnsStateMachine(host, sizeof(host));
00250 test_dns_state_machine->handleEvent();
00251 i++;
00252 }
00253 now = ink_get_hrtime();
00254 cout << "Finished creating all Continuations at " <<
00255 (now - start_time) / HRTIME_SECOND << " sec and " << (now - start_time) % HRTIME_SECOND << "nanosec\n";
00256 fout_rate_misc << (now - start_time) * 1.0 / HRTIME_SECOND << "\n";
00257 fout_rate_misc.flush();
00258 }