3 /* saturate - link saturation demo of GRAS features */
4 /* Authors: Martin Quinson */
5 /* Copyright (C) 2003 the OURAGAN project. */
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. */
18 GRAS_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
20 /* **********************************************************************
22 * **********************************************************************/
24 /* Global private data */
29 /* Function prototypes */
30 int sensor (int argc,char *argv[]);
32 int sensor (int argc,char *argv[]) {
34 sensor_data_t *g=gras_userdata_new(sensor_data_t);
36 if ((errcode=gras_socket_server(4000,&(g->sock)))) {
37 CRITICAL1("Sensor: Error %s encountered while opening the server socket",gras_error_name(errcode));
41 if (grasbw_register_messages()) {
42 gras_socket_close(g->sock);
47 if ((errcode=gras_msg_handle(60.0)) && errcode != timeout_error) {
48 CRITICAL1("Sensor: Error '%s' while handling message",
49 gras_error_name(errcode));
54 gras_socket_close(g->sock);
59 /* **********************************************************************
61 * **********************************************************************/
63 /* Global private data */
68 /* Function prototypes */
69 int maestro (int argc,char *argv[]);
70 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2);
72 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2) {
74 int bufSize=32 * 1024;
75 int expSize=64 * 1024;
76 int msgSize=64 * 1024;
77 int satSize=msgSize * 10;
78 double sec, bw, sec_sat,bw_sat;
80 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec,&bw))) {
81 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
85 fprintf(stderr,"MAESTRO: BW(%s,%s) => %f sec, achieving %f Mb/s\n",bw1,bw2,sec,bw);
87 if ((errcode=grasbw_saturate_start(sat1,4000,sat2,4000,satSize,60))) {
88 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
89 gras_error_name(errcode));
93 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec_sat,&bw_sat))) {
94 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
98 fprintf(stderr,"MAESTRO: BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s\n",
99 bw1,bw2,sat1,sat2,sec_sat,bw_sat);
101 if ((errcode=grasbw_saturate_stop(sat1,4000,sat2,4000))) {
102 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
103 gras_error_name(errcode));
107 if (bw_sat/bw < 0.7) {
108 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE !!!\n");
110 if (bw/bw_sat < 0.7) {
111 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE (and Im a cretin) !!!\n");
117 //#define MAXHOSTS 33
120 int maestro(int argc,char *argv[]) {
121 int bufSize=32 * 1024;
122 int expSize= 1024 * 1024;
124 int satSize=msgSize * 100;
125 double dummy,beginSim;
126 gras_error_t errcode;
127 maestro_data_t *g=gras_userdata_new(maestro_data_t);
128 // 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" };
129 const char *hosts[MAXHOSTS] = { "A", "B", "C", "D" };
131 double bw[MAXHOSTS][MAXHOSTS];
132 double bw_sat[MAXHOSTS][MAXHOSTS];
136 if ((errcode=gras_socket_server(4000,&(g->sock)))) {
137 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
141 if (grasbw_register_messages()) {
142 gras_socket_close(g->sock);
147 beginSim=gras_os_time();
148 for (a=0; a<MAXHOSTS; a++) {
149 for (b=0; b<MAXHOSTS; b++) {
151 fprintf(stderr,"BW XP(%s %s)=",hosts[a],hosts[b]);
152 if ((errcode=grasbw_request(hosts[a],4000,hosts[b],4000,bufSize,expSize,msgSize,
153 &dummy,&(bw[a][b])))) {
154 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
157 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
160 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
161 time(NULL)-begin,gras_os_time()-beginSim);
163 for (a=0; a<MAXHOSTS; a++) {
164 for (b=0; b<MAXHOSTS; b++) {
167 if ((errcode=grasbw_saturate_start(hosts[a],4000,hosts[b],4000,satSize,360000000))) {
168 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
169 gras_error_name(errcode));
175 beginSim=gras_os_time();
176 for (c=0 ;c<MAXHOSTS; c++) {
180 for (d=0 ;d<MAXHOSTS; d++) {
185 if ((errcode=grasbw_request(hosts[c],4000,hosts[d],4000,bufSize,expSize,msgSize,
186 &dummy,&(bw_sat[c][d])))) {
187 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",gras_error_name(errcode));
190 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
192 hosts[c],hosts[d],hosts[a],hosts[b],
193 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
195 (bw_sat[c][d]/bw[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE !!!":
196 ((bw[c][d]/bw_sat[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE (and Im a cretin) !!!":
201 if ((errcode=grasbw_saturate_stop(hosts[a],4000,hosts[b],4000))) {
202 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
203 gras_error_name(errcode));
206 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
207 time(NULL)-begin, gras_os_time()-beginSim);
215 /* start saturation */
216 fprintf(stderr,"MAESTRO: Start saturation with size %d\n",msgSize);
217 if ((errcode=grasbw_saturate_start(argv[5],atoi(argv[6]),argv[7],atoi(argv[8]),msgSize*10,60))) {
218 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
219 gras_error_name(errcode));
222 fprintf(stderr,"MAESTRO: Saturation started\n");
225 /* test with saturation */
226 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
227 bufSize,expSize,msgSize,&sec,&bw))) {
228 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
232 fprintf(stderr,"MAESTRO: Experience3 (%d ko in msgs of %d ko with saturation) took %f sec, achieving %f Mb/s\n",
233 expSize/1024,msgSize/1024,
236 /* stop saturation */
237 if ((errcode=grasbw_saturate_stop(argv[5],atoi(argv[6]),argv[7],atoi(argv[8])))) {
238 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
239 gras_error_name(errcode));
243 /* test without saturation */
244 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
245 bufSize,expSize,msgSize,&sec,&bw))) {
246 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
250 fprintf(stderr,"MAESTRO: Experience4 (%d ko in msgs of %d ko, without saturation) took %f sec, achieving %f Mb/s\n",
251 expSize/1024,msgSize/1024,
256 gras_socket_close(g->sock);