3 /* Copyright (c) 2005, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
17 #include <tbx_graph.h> /* alvin's graph toolbox (+ reconstruction algorithm) */
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_sock_server_open(4000,4000,&(g->sock)))) {
36 fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
40 if (grasbw_register_messages()) {
41 gras_sock_close(g->sock);
46 if ((errcode=gras_msg_handle(3600.0)) && errcode != timeout_error) {
47 fprintf(stderr,"Sensor: Error '%s' while handling message\n",
48 xbt_error_name(errcode));
53 return gras_sock_close(g->sock);
56 /* **********************************************************************
58 * **********************************************************************/
60 /* Global private data */
65 /* Function prototypes */
66 int maestro (int argc,char *argv[]);
70 #define INTERF(graph,table,a,u,b,v) INTERFERENCE(table,\
71 TBX_Graph_nodeSearch(graph,a),\
72 TBX_Graph_nodeSearch(graph,u),\
73 TBX_Graph_nodeSearch(graph,b),\
74 TBX_Graph_nodeSearch(graph,v))
76 int maestro(int argc,char *argv[]) {
77 int bufSize=32 * 1024;
78 int expSize= 1024 * 1024;
80 int satSize=msgSize * 100;
81 double dummy,beginSim;
83 maestro_data_t *g=gras_userdata_new(maestro_data_t);
85 double bw[MAXHOSTS][MAXHOSTS];
86 double bw_sat[MAXHOSTS][MAXHOSTS];
90 TBX_Graph_t graph = TBX_Graph_newGraph("Essai",0,NULL); /* a dummy graph containing all hosts */
91 TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO();
92 TBX_InterfTable_t interf = NULL; /* the measured interferences */
93 TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */
97 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);
101 if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) {
102 fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
106 if (grasbw_register_messages()) {
107 gras_sock_close(g->sock);
111 for (a=1; a<argc; a++) {
112 TBX_FIFO_insert(host_fifo,TBX_Graph_newNode(graph,argv[a], NULL));
114 TBX_Graph_fixNodeNumbering(graph);
115 interf=TBX_Graph_newInterfTable(host_fifo);
116 TBX_Graph_graphInterfTableInit(graph,interf);
118 /* measure the bandwidths */
120 beginSim=gras_time();
121 for (a=1; a<argc; a++) {
122 for (b=1; b<argc; b++) {
126 fprintf(stderr,"BW XP(%s %s)=",argv[a],argv[b]);
127 while ((errcode=grasbw_request(argv[a],4000,argv[b],4000,bufSize,expSize,msgSize,
128 &dummy,&(bw[a][b]))) && (errcode == timeout_error)) {
131 fprintf(stderr,"MAESTRO: 10 Timeouts; giving up\n");
136 fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
139 fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
142 fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
143 time(NULL)-begin,gras_time()-beginSim);
145 /* saturation tests */
146 for (a=1; a<argc; a++) {
147 for (b=1; b<argc; b++) {
148 for (c=1 ;c<argc; c++) {
149 INTERF(graph,interf,argv[a],argv[c],argv[b],argv[c])= 1;
154 for (a=1; a<argc; a++) {
155 for (b=1; b<argc; b++) {
158 if ((errcode=grasbw_saturate_start(argv[a],4000,argv[b],4000,satSize,360000000))) {
159 fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
160 xbt_error_name(errcode));
166 beginSim=gras_time();
167 for (c=1 ;c<argc; c++) {
168 if (a==c || b==c) continue;
170 for (d=1 ;d<argc; d++) {
171 if (a==d || b==d || c==d) continue;
173 if ((errcode=grasbw_request(argv[c],4000,argv[d],4000,bufSize,expSize,msgSize,
174 &dummy,&(bw_sat[c][d])))) {
175 fprintf(stderr,"MAESTRO: Error %s encountered in test\n",xbt_error_name(errcode));
178 fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
180 argv[c],argv[d],argv[a],argv[b],
181 bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
183 (bw_sat[c][d]/bw[c][d] < 0.75) ? " THERE IS SOME INTERFERENCE !!!":"");
184 INTERF(graph,interf,argv[c],argv[d],argv[a],argv[b])=
185 (bw_sat[c][d]/bw[c][d] < 0.75) ? 1 : 0;
189 if ((errcode=grasbw_saturate_stop(argv[a],4000,argv[b],4000))) {
190 fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
191 xbt_error_name(errcode));
194 fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
195 time(NULL)-begin, gras_time()-beginSim);
199 /* reconstruct the graph */
200 TBX_Graph_interferenceTableDump(interf);
201 TBX_Graph_interferenceTableSave(interf,"interference.dat");
203 fprintf(stderr, "MAESTRO: Reconstruct the graph... ");
204 builded_graph = TBX_Graph_exploreInterference(interf);
205 TBX_Graph_exportToGraphViz(builded_graph, "toto.dot");
206 fprintf(stderr, "done (took %d sec)",(int)time(NULL));
209 TBX_Graph_freeGraph(graph,NULL,NULL,NULL);
210 TBX_Graph_freeGraph(builded_graph,NULL,NULL,NULL);
211 TBX_Graph_freeInterfTable(interf);
214 exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */
215 return gras_sock_close(g->sock);