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. */
18 #include <tbx_graph.h> /* alvin's graph toolbox (+ reconstruction algorithm) */
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_sock_server_open(4000,4000,&(g->sock)))) {
37 fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
41 if (grasbw_register_messages()) {
42 gras_sock_close(g->sock);
47 if ((errcode=gras_msg_handle(3600.0)) && errcode != timeout_error) {
48 fprintf(stderr,"Sensor: Error '%s' while handling message\n",
49 xbt_error_name(errcode));
54 return gras_sock_close(g->sock);
57 /* **********************************************************************
59 * **********************************************************************/
61 /* Global private data */
66 /* Function prototypes */
67 int maestro (int argc,char *argv[]);
71 #define INTERF(graph,table,a,u,b,v) INTERFERENCE(table,\
72 TBX_Graph_nodeSearch(graph,a),\
73 TBX_Graph_nodeSearch(graph,u),\
74 TBX_Graph_nodeSearch(graph,b),\
75 TBX_Graph_nodeSearch(graph,v))
77 int maestro(int argc,char *argv[]) {
78 int bufSize=32 * 1024;
79 int expSize= 1024 * 1024;
81 int satSize=msgSize * 100;
82 double dummy,beginSim;
84 maestro_data_t *g=gras_userdata_new(maestro_data_t);
86 double bw[MAXHOSTS][MAXHOSTS];
87 double bw_sat[MAXHOSTS][MAXHOSTS];
91 TBX_Graph_t graph = TBX_Graph_newGraph("Essai",0,NULL); /* a dummy graph containing all hosts */
92 TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO();
93 TBX_InterfTable_t interf = NULL; /* the measured interferences */
94 TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */
98 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);
102 if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) {
103 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
107 if (grasbw_register_messages()) {
108 gras_sock_close(g->sock);
112 for (a=1; a<argc; a++) {
113 TBX_FIFO_insert(host_fifo,TBX_Graph_newNode(graph,argv[a], NULL));
115 TBX_Graph_fixNodeNumbering(graph);
116 interf=TBX_Graph_newInterfTable(host_fifo);
117 TBX_Graph_graphInterfTableInit(graph,interf);
119 /* measure the bandwidths */
121 beginSim=gras_time();
122 for (a=1; a<argc; a++) {
123 for (b=1; b<argc; b++) {
127 fprintf(stderr,"BW XP(%s %s)=",argv[a],argv[b]);
128 while ((errcode=grasbw_request(argv[a],4000,argv[b],4000,bufSize,expSize,msgSize,
129 &dummy,&(bw[a][b]))) && (errcode == timeout_error)) {
132 fprintf(stderr,"MAESTRO: 10 Timeouts; giving up\n");
137 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
140 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
143 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
144 time(NULL)-begin,gras_time()-beginSim);
146 /* saturation tests */
147 for (a=1; a<argc; a++) {
148 for (b=1; b<argc; b++) {
149 for (c=1 ;c<argc; c++) {
150 INTERF(graph,interf,argv[a],argv[c],argv[b],argv[c])= 1;
155 for (a=1; a<argc; a++) {
156 for (b=1; b<argc; b++) {
159 if ((errcode=grasbw_saturate_start(argv[a],4000,argv[b],4000,satSize,360000000))) {
160 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
161 xbt_error_name(errcode));
167 beginSim=gras_time();
168 for (c=1 ;c<argc; c++) {
169 if (a==c || b==c) continue;
171 for (d=1 ;d<argc; d++) {
172 if (a==d || b==d || c==d) continue;
174 if ((errcode=grasbw_request(argv[c],4000,argv[d],4000,bufSize,expSize,msgSize,
175 &dummy,&(bw_sat[c][d])))) {
176 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",xbt_error_name(errcode));
179 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
181 argv[c],argv[d],argv[a],argv[b],
182 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
184 (bw_sat[c][d]/bw[c][d] < 0.75) ? " THERE IS SOME INTERFERENCE !!!":"");
185 INTERF(graph,interf,argv[c],argv[d],argv[a],argv[b])=
186 (bw_sat[c][d]/bw[c][d] < 0.75) ? 1 : 0;
190 if ((errcode=grasbw_saturate_stop(argv[a],4000,argv[b],4000))) {
191 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
192 xbt_error_name(errcode));
195 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
196 time(NULL)-begin, gras_time()-beginSim);
200 /* reconstruct the graph */
201 TBX_Graph_interferenceTableDump(interf);
202 TBX_Graph_interferenceTableSave(interf,"interference.dat");
204 fprintf(stderr, "MAESTRO: Reconstruct the graph... ");
205 builded_graph = TBX_Graph_exploreInterference(interf);
206 TBX_Graph_exportToGraphViz(builded_graph, "toto.dot");
207 fprintf(stderr, "done (took %d sec)",(int)time(NULL));
210 TBX_Graph_freeGraph(graph,NULL,NULL,NULL);
211 TBX_Graph_freeGraph(builded_graph,NULL,NULL,NULL);
212 TBX_Graph_freeInterfTable(interf);
215 exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */
216 return gras_sock_close(g->sock);