3 /* Copyright (c) 2003 Martin Quinson. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #include <tbx_graph.h> /* alvin's graph toolbox (+ reconstruction algorithm) */
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",xbt_error_name(errcode));
39 if (grasbw_register_messages()) {
40 gras_sock_close(g->sock);
45 if ((errcode=gras_msg_handle(3600.0)) && errcode != timeout_error) {
46 fprintf(stderr,"Sensor: Error '%s' while handling message\n",
47 xbt_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[]);
69 #define INTERF(graph,table,a,u,b,v) INTERFERENCE(table,\
70 TBX_Graph_nodeSearch(graph,a),\
71 TBX_Graph_nodeSearch(graph,u),\
72 TBX_Graph_nodeSearch(graph,b),\
73 TBX_Graph_nodeSearch(graph,v))
75 int maestro(int argc,char *argv[]) {
76 int bufSize=32 * 1024;
77 int expSize= 1024 * 1024;
79 int satSize=msgSize * 100;
80 double dummy,beginSim;
82 maestro_data_t *g=gras_userdata_new(maestro_data_t);
84 double bw[MAXHOSTS][MAXHOSTS];
85 double bw_sat[MAXHOSTS][MAXHOSTS];
89 TBX_Graph_t graph = TBX_Graph_newGraph("Essai",0,NULL); /* a dummy graph containing all hosts */
90 TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO();
91 TBX_InterfTable_t interf = NULL; /* the measured interferences */
92 TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */
96 fprintf(stderr,"You gave more than %d sensors for this experiment. Increase the MAX HOSTS constant in alnem code to be bigger than this number.\n",argc);
100 if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) {
101 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
105 if (grasbw_register_messages()) {
106 gras_sock_close(g->sock);
110 for (a=1; a<argc; a++) {
111 TBX_FIFO_insert(host_fifo,TBX_Graph_newNode(graph,argv[a], NULL));
113 TBX_Graph_fixNodeNumbering(graph);
114 interf=TBX_Graph_newInterfTable(host_fifo);
115 TBX_Graph_graphInterfTableInit(graph,interf);
117 /* measure the bandwidths */
119 beginSim=gras_time();
120 for (a=1; a<argc; a++) {
121 for (b=1; b<argc; b++) {
125 fprintf(stderr,"BW XP(%s %s)=",argv[a],argv[b]);
126 while ((errcode=grasbw_request(argv[a],4000,argv[b],4000,bufSize,expSize,msgSize,
127 &dummy,&(bw[a][b]))) && (errcode == timeout_error)) {
130 fprintf(stderr,"MAESTRO: 10 Timeouts; giving up\n");
135 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
138 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
141 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
142 time(NULL)-begin,gras_time()-beginSim);
144 /* saturation tests */
145 for (a=1; a<argc; a++) {
146 for (b=1; b<argc; b++) {
147 for (c=1 ;c<argc; c++) {
148 INTERF(graph,interf,argv[a],argv[c],argv[b],argv[c])= 1;
153 for (a=1; a<argc; a++) {
154 for (b=1; b<argc; b++) {
157 if ((errcode=grasbw_saturate_start(argv[a],4000,argv[b],4000,satSize,360000000))) {
158 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
159 xbt_error_name(errcode));
165 beginSim=gras_time();
166 for (c=1 ;c<argc; c++) {
167 if (a==c || b==c) continue;
169 for (d=1 ;d<argc; d++) {
170 if (a==d || b==d || c==d) continue;
172 if ((errcode=grasbw_request(argv[c],4000,argv[d],4000,bufSize,expSize,msgSize,
173 &dummy,&(bw_sat[c][d])))) {
174 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",xbt_error_name(errcode));
177 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
179 argv[c],argv[d],argv[a],argv[b],
180 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
182 (bw_sat[c][d]/bw[c][d] < 0.75) ? " THERE IS SOME INTERFERENCE !!!":"");
183 INTERF(graph,interf,argv[c],argv[d],argv[a],argv[b])=
184 (bw_sat[c][d]/bw[c][d] < 0.75) ? 1 : 0;
188 if ((errcode=grasbw_saturate_stop(argv[a],4000,argv[b],4000))) {
189 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
190 xbt_error_name(errcode));
193 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
194 time(NULL)-begin, gras_time()-beginSim);
198 /* reconstruct the graph */
199 TBX_Graph_interferenceTableDump(interf);
200 TBX_Graph_interferenceTableSave(interf,"interference.dat");
202 fprintf(stderr, "MAESTRO: Reconstruct the graph... ");
203 builded_graph = TBX_Graph_exploreInterference(interf);
204 TBX_Graph_exportToGraphViz(builded_graph, "toto.dot");
205 fprintf(stderr, "done (took %d sec)",(int)time(NULL));
208 TBX_Graph_freeGraph(graph,NULL,NULL,NULL);
209 TBX_Graph_freeGraph(builded_graph,NULL,NULL,NULL);
210 TBX_Graph_freeInterfTable(interf);
213 exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */
214 return gras_sock_close(g->sock);