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[])
34 sensor_data_t *g = gras_userdata_new(sensor_data_t);
36 if ((errcode = gras_sock_server_open(4000, 4000, &(g->sock)))) {
38 "Sensor: Error %s encountered while opening the server socket\n",
39 xbt_error_name(errcode));
43 if (grasbw_register_messages()) {
44 gras_sock_close(g->sock);
49 if ((errcode = gras_msg_handle(3600.0)) && errcode != timeout_error) {
50 fprintf(stderr, "Sensor: Error '%s' while handling message\n",
51 xbt_error_name(errcode));
56 return gras_sock_close(g->sock);
59 /* **********************************************************************
61 * **********************************************************************/
63 /* Global private data */
68 /* Function prototypes */
69 int maestro(int argc, char *argv[]);
73 #define INTERF(graph,table,a,u,b,v) INTERFERENCE(table,\
74 TBX_Graph_nodeSearch(graph,a),\
75 TBX_Graph_nodeSearch(graph,u),\
76 TBX_Graph_nodeSearch(graph,b),\
77 TBX_Graph_nodeSearch(graph,v))
79 int maestro(int argc, char *argv[])
81 int bufSize = 32 * 1024;
82 int expSize = 1024 * 1024;
83 int msgSize = expSize;
84 int satSize = msgSize * 100;
85 double dummy, beginSim;
87 maestro_data_t *g = gras_userdata_new(maestro_data_t);
89 double bw[MAXHOSTS][MAXHOSTS];
90 double bw_sat[MAXHOSTS][MAXHOSTS];
92 int a, b, c, d, begin;
94 TBX_Graph_t graph = TBX_Graph_newGraph("Essai", 0, NULL); /* a dummy graph containing all hosts */
95 TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO();
96 TBX_InterfTable_t interf = NULL; /* the measured interferences */
97 TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */
100 if (argc > MAXHOSTS) {
102 "You gave more than %d sensors for this experiment. Increase the MAX HOSTS constant in alnem code to be bigger than this number.\n",
107 if ((errcode = gras_sock_server_open(4000, 5000, &(g->sock)))) {
109 "MAESTRO: Error %s encountered while opening the server socket\n",
110 xbt_error_name(errcode));
114 if (grasbw_register_messages()) {
115 gras_sock_close(g->sock);
119 for (a = 1; a < argc; a++) {
120 TBX_FIFO_insert(host_fifo, TBX_Graph_newNode(graph, argv[a], NULL));
122 TBX_Graph_fixNodeNumbering(graph);
123 interf = TBX_Graph_newInterfTable(host_fifo);
124 TBX_Graph_graphInterfTableInit(graph, interf);
126 /* measure the bandwidths */
128 beginSim = gras_time();
129 for (a = 1; a < argc; a++) {
130 for (b = 1; b < argc; b++) {
135 fprintf(stderr, "BW XP(%s %s)=", argv[a], argv[b]);
137 grasbw_request(argv[a], 4000, argv[b], 4000, bufSize,
138 expSize, msgSize, &dummy, &(bw[a][b])))
139 && (errcode == timeout_error)) {
142 fprintf(stderr, "MAESTRO: 10 Timeouts; giving up\n");
148 "MAESTRO: Error %s encountered while doing the test\n",
149 xbt_error_name(errcode));
152 fprintf(stderr, "%f Mb/s in %f sec\n", bw[a][b], dummy);
155 fprintf(stderr, "Did all BW tests in %ld sec (%.2f simulated sec)\n",
156 time(NULL) - begin, gras_time() - beginSim);
158 /* saturation tests */
159 for (a = 1; a < argc; a++) {
160 for (b = 1; b < argc; b++) {
161 for (c = 1; c < argc; c++) {
162 INTERF(graph, interf, argv[a], argv[c], argv[b], argv[c]) = 1;
167 for (a = 1; a < argc; a++) {
168 for (b = 1; b < argc; b++) {
173 grasbw_saturate_start(argv[a], 4000, argv[b], 4000, satSize,
176 "MAESTRO: Error %s encountered while starting saturation\n",
177 xbt_error_name(errcode));
183 beginSim = gras_time();
184 for (c = 1; c < argc; c++) {
185 if (a == c || b == c)
188 for (d = 1; d < argc; d++) {
189 if (a == d || b == d || c == d)
193 grasbw_request(argv[c], 4000, argv[d], 4000, bufSize,
194 expSize, msgSize, &dummy,
196 fprintf(stderr, "MAESTRO: Error %s encountered in test\n",
197 xbt_error_name(errcode));
201 "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
202 gras_time(), argv[c], argv[d], argv[a], argv[b],
203 bw_sat[c][d] / bw[c][d], bw[c][d], bw_sat[c][d],
204 (bw_sat[c][d] / bw[c][d] <
205 0.75) ? " THERE IS SOME INTERFERENCE !!!" : "");
206 INTERF(graph, interf, argv[c], argv[d], argv[a], argv[b]) =
207 (bw_sat[c][d] / bw[c][d] < 0.75) ? 1 : 0;
211 if ((errcode = grasbw_saturate_stop(argv[a], 4000, argv[b], 4000))) {
213 "MAESTRO: Error %s encountered while stopping saturation\n",
214 xbt_error_name(errcode));
218 "Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
219 time(NULL) - begin, gras_time() - beginSim);
223 /* reconstruct the graph */
224 TBX_Graph_interferenceTableDump(interf);
225 TBX_Graph_interferenceTableSave(interf, "interference.dat");
227 fprintf(stderr, "MAESTRO: Reconstruct the graph... ");
228 builded_graph = TBX_Graph_exploreInterference(interf);
229 TBX_Graph_exportToGraphViz(builded_graph, "toto.dot");
230 fprintf(stderr, "done (took %d sec)", (int) time(NULL));
233 TBX_Graph_freeGraph(graph, NULL, NULL, NULL);
234 TBX_Graph_freeGraph(builded_graph, NULL, NULL, NULL);
235 TBX_Graph_freeInterfTable(interf);
238 exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */
239 return gras_sock_close(g->sock);