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 /* **********************************************************************
20 * **********************************************************************/
22 /* Global private data */
27 /* Function prototypes */
28 int sensor (int argc,char *argv[]);
30 int sensor (int argc,char *argv[]) {
32 sensor_data_t *g=gras_userdata_new(sensor_data_t);
34 if ((errcode=gras_sock_server_open(4000,4000,&(g->sock)))) {
35 fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
39 if (grasbw_register_messages()) {
40 gras_sock_close(g->sock);
45 if ((errcode=gras_msg_handle(60.0)) && errcode != timeout_error) {
46 fprintf(stderr,"Sensor: Error '%s' while handling message\n",
47 gras_error_name(errcode));
52 return gras_sock_close(g->sock);
55 /* **********************************************************************
57 * **********************************************************************/
59 /* Global private data */
64 /* Function prototypes */
65 int maestro (int argc,char *argv[]);
66 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2);
68 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2) {
70 int bufSize=32 * 1024;
71 int expSize=64 * 1024;
72 int msgSize=64 * 1024;
73 int satSize=msgSize * 10;
74 double sec, bw, sec_sat,bw_sat;
76 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec,&bw))) {
77 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
81 fprintf(stderr,"MAESTRO: BW(%s,%s) => %f sec, achieving %f Mb/s\n",bw1,bw2,sec,bw);
83 if ((errcode=grasbw_saturate_start(sat1,4000,sat2,4000,satSize,60))) {
84 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
85 gras_error_name(errcode));
89 if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec_sat,&bw_sat))) {
90 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
94 fprintf(stderr,"MAESTRO: BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s\n",
95 bw1,bw2,sat1,sat2,sec_sat,bw_sat);
97 if ((errcode=grasbw_saturate_stop(sat1,4000,sat2,4000))) {
98 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
99 gras_error_name(errcode));
103 if (bw_sat/bw < 0.7) {
104 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE !!!\n");
106 if (bw/bw_sat < 0.7) {
107 fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE (and Im a cretin) !!!\n");
113 //#define MAXHOSTS 33
116 int maestro(int argc,char *argv[]) {
117 int bufSize=32 * 1024;
118 int expSize= 1024 * 1024;
120 int satSize=msgSize * 100;
121 double dummy,beginSim;
122 gras_error_t errcode;
123 maestro_data_t *g=gras_userdata_new(maestro_data_t);
124 // 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" };
125 const char *hosts[MAXHOSTS] = { "A", "B", "C", "D" };
127 double bw[MAXHOSTS][MAXHOSTS];
128 double bw_sat[MAXHOSTS][MAXHOSTS];
132 if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) {
133 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
137 if (grasbw_register_messages()) {
138 gras_sock_close(g->sock);
143 beginSim=gras_time();
144 for (a=0; a<MAXHOSTS; a++) {
145 for (b=0; b<MAXHOSTS; b++) {
147 fprintf(stderr,"BW XP(%s %s)=",hosts[a],hosts[b]);
148 if ((errcode=grasbw_request(hosts[a],4000,hosts[b],4000,bufSize,expSize,msgSize,
149 &dummy,&(bw[a][b])))) {
150 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
153 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
156 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
157 time(NULL)-begin,gras_time()-beginSim);
159 for (a=0; a<MAXHOSTS; a++) {
160 for (b=0; b<MAXHOSTS; b++) {
163 if ((errcode=grasbw_saturate_start(hosts[a],4000,hosts[b],4000,satSize,360000000))) {
164 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
165 gras_error_name(errcode));
171 beginSim=gras_time();
172 for (c=0 ;c<MAXHOSTS; c++) {
176 for (d=0 ;d<MAXHOSTS; d++) {
181 if ((errcode=grasbw_request(hosts[c],4000,hosts[d],4000,bufSize,expSize,msgSize,
182 &dummy,&(bw_sat[c][d])))) {
183 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",gras_error_name(errcode));
186 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
188 hosts[c],hosts[d],hosts[a],hosts[b],
189 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
191 (bw_sat[c][d]/bw[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE !!!":
192 ((bw[c][d]/bw_sat[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE (and Im a cretin) !!!":
197 if ((errcode=grasbw_saturate_stop(hosts[a],4000,hosts[b],4000))) {
198 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
199 gras_error_name(errcode));
202 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
203 time(NULL)-begin, gras_time()-beginSim);
211 /* start saturation */
212 fprintf(stderr,"MAESTRO: Start saturation with size %d\n",msgSize);
213 if ((errcode=grasbw_saturate_start(argv[5],atoi(argv[6]),argv[7],atoi(argv[8]),msgSize*10,60))) {
214 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
215 gras_error_name(errcode));
218 fprintf(stderr,"MAESTRO: Saturation started\n");
221 /* test with saturation */
222 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
223 bufSize,expSize,msgSize,&sec,&bw))) {
224 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
228 fprintf(stderr,"MAESTRO: Experience3 (%d ko in msgs of %d ko with saturation) took %f sec, achieving %f Mb/s\n",
229 expSize/1024,msgSize/1024,
232 /* stop saturation */
233 if ((errcode=grasbw_saturate_stop(argv[5],atoi(argv[6]),argv[7],atoi(argv[8])))) {
234 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
235 gras_error_name(errcode));
239 /* test without saturation */
240 if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
241 bufSize,expSize,msgSize,&sec,&bw))) {
242 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
246 fprintf(stderr,"MAESTRO: Experience4 (%d ko in msgs of %d ko, without saturation) took %f sec, achieving %f Mb/s\n",
247 expSize/1024,msgSize/1024,
252 return gras_sock_close(g->sock);