3 /* saturate - link saturation demo of GRAS features */
5 /* Copyright (c) 2003 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
17 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
19 /* **********************************************************************
21 * **********************************************************************/
23 /* Global private data */
28 /* Function prototypes */
29 int sensor (int argc,char *argv[]);
31 int sensor (int argc,char *argv[]) {
33 sensor_data_t *g=gras_userdata_new(sensor_data_t);
35 if ((errcode=gras_socket_server(4000,&(g->sock)))) {
36 CRITICAL1("Sensor: Error %s encountered while opening the server socket",xbt_error_name(errcode));
40 if (grasbw_register_messages()) {
41 gras_socket_close(g->sock);
46 if ((errcode=gras_msg_handle(60.0)) && errcode != timeout_error) {
47 CRITICAL1("Sensor: Error '%s' while handling message",
48 xbt_error_name(errcode));
53 gras_socket_close(g->sock);
58 /* **********************************************************************
60 * **********************************************************************/
62 /* Global private data */
67 /* Function prototypes */
68 int maestro (int argc,char *argv[]);
69 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2);
71 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2) {
73 int bufSize=32 * 1024;
74 int expSize=64 * 1024;
75 int msgSize=64 * 1024;
76 int satSize=msgSize * 10;
77 double sec, bw, sec_sat,bw_sat;
79 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec,&bw))) {
80 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
84 fprintf(stderr,"MAESTRO: BW(%s,%s) => %f sec, achieving %f Mb/s\n",bw1,bw2,sec,bw);
86 if ((errcode=grasbw_saturate_start(sat1,4000,sat2,4000,satSize,60))) {
87 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
88 xbt_error_name(errcode));
92 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec_sat,&bw_sat))) {
93 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
97 fprintf(stderr,"MAESTRO: BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s\n",
98 bw1,bw2,sat1,sat2,sec_sat,bw_sat);
100 if ((errcode=grasbw_saturate_stop(sat1,4000,sat2,4000))) {
101 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
102 xbt_error_name(errcode));
106 if (bw_sat/bw < 0.7) {
107 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE !!!\n");
109 if (bw/bw_sat < 0.7) {
110 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE (and Im a cretin) !!!\n");
116 //#define MAXHOSTS 33
119 int maestro(int argc,char *argv[]) {
120 int bufSize=32 * 1024;
121 int expSize= 1024 * 1024;
123 int satSize=msgSize * 100;
124 double dummy,beginSim;
126 maestro_data_t *g=gras_userdata_new(maestro_data_t);
127 // const char *hosts[MAXHOSTS] = { "61", "62", "63", "69", "70", "77", "81", "83", "85", "87", "88", "95", "98", "107", "109", "111", "112", "121", "124", "125", "131", "145", "150", "156", "157", "162", "165", "168", "169", "170", "175", "177", "178" };
128 const char *hosts[MAXHOSTS] = { "A", "B", "C", "D" };
130 double bw[MAXHOSTS][MAXHOSTS];
131 double bw_sat[MAXHOSTS][MAXHOSTS];
135 if ((errcode=gras_socket_server(4000,&(g->sock)))) {
136 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
140 if (grasbw_register_messages()) {
141 gras_socket_close(g->sock);
146 beginSim=gras_os_time();
147 for (a=0; a<MAXHOSTS; a++) {
148 for (b=0; b<MAXHOSTS; b++) {
150 fprintf(stderr,"BW XP(%s %s)=",hosts[a],hosts[b]);
151 if ((errcode=grasbw_request(hosts[a],4000,hosts[b],4000,bufSize,expSize,msgSize,
152 &dummy,&(bw[a][b])))) {
153 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
156 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
159 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
160 time(NULL)-begin,gras_os_time()-beginSim);
162 for (a=0; a<MAXHOSTS; a++) {
163 for (b=0; b<MAXHOSTS; b++) {
166 if ((errcode=grasbw_saturate_start(hosts[a],4000,hosts[b],4000,satSize,360000000))) {
167 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
168 xbt_error_name(errcode));
174 beginSim=gras_os_time();
175 for (c=0 ;c<MAXHOSTS; c++) {
179 for (d=0 ;d<MAXHOSTS; d++) {
184 if ((errcode=grasbw_request(hosts[c],4000,hosts[d],4000,bufSize,expSize,msgSize,
185 &dummy,&(bw_sat[c][d])))) {
186 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",xbt_error_name(errcode));
189 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
191 hosts[c],hosts[d],hosts[a],hosts[b],
192 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
194 (bw_sat[c][d]/bw[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE !!!":
195 ((bw[c][d]/bw_sat[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE (and Im a cretin) !!!":
200 if ((errcode=grasbw_saturate_stop(hosts[a],4000,hosts[b],4000))) {
201 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
202 xbt_error_name(errcode));
205 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
206 time(NULL)-begin, gras_os_time()-beginSim);
214 /* start saturation */
215 fprintf(stderr,"MAESTRO: Start saturation with size %d\n",msgSize);
216 if ((errcode=grasbw_saturate_start(argv[5],atoi(argv[6]),argv[7],atoi(argv[8]),msgSize*10,60))) {
217 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
218 xbt_error_name(errcode));
221 fprintf(stderr,"MAESTRO: Saturation started\n");
224 /* test with saturation */
225 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
226 bufSize,expSize,msgSize,&sec,&bw))) {
227 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
231 fprintf(stderr,"MAESTRO: Experience3 (%d ko in msgs of %d ko with saturation) took %f sec, achieving %f Mb/s\n",
232 expSize/1024,msgSize/1024,
235 /* stop saturation */
236 if ((errcode=grasbw_saturate_stop(argv[5],atoi(argv[6]),argv[7],atoi(argv[8])))) {
237 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
238 xbt_error_name(errcode));
242 /* test without saturation */
243 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
244 bufSize,expSize,msgSize,&sec,&bw))) {
245 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
249 fprintf(stderr,"MAESTRO: Experience4 (%d ko in msgs of %d ko, without saturation) took %f sec, achieving %f Mb/s\n",
250 expSize/1024,msgSize/1024,
255 gras_socket_close(g->sock);