3 /* saturate - link saturation demo of AMOK features */
5 /* Copyright (c) 2003-6 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. */
16 #include "amok/bandwidth.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
20 /* **********************************************************************
22 * **********************************************************************/
24 /* Global private data */
30 /* Function prototypes */
31 int sensor (int argc,char *argv[]);
33 static int sensor_cb_kill(gras_msg_cb_ctx_t ctx,
36 sensor_data_t *g=gras_userdata_get();
41 int sensor (int argc,char *argv[]) {
45 gras_init(&argc,argv);
48 g=gras_userdata_new(sensor_data_t);
49 g->sock = gras_socket_server(atoi(argv[1]));
52 gras_msgtype_declare("kill",NULL);
53 gras_cb_register(gras_msgtype_by_name("kill"),&sensor_cb_kill);
57 gras_msg_handle(20.0);
59 if (e.category != timeout_error)
65 gras_socket_close(g->sock);
71 /* **********************************************************************
73 * **********************************************************************/
75 /* Function prototypes */
76 int maestro (int argc,char *argv[]);
79 const int buf_size = 0;
80 const int exp_size = 100 * 1024;
81 const int msg_size = 50 * 1024;
82 const int sat_size = 1024 * 1024 * 10;
83 const double min_duration = 1;
85 static double XP(const char *bw1, const char *bw2,
86 const char *sat1, const char *sat2) {
88 double sec, bw, sec_sat,bw_sat;
90 gras_os_sleep(5.0); /* wait for the sensors to show up */
91 /* Test BW without saturation */
92 amok_bw_request(bw1,4000,bw2,4000,
93 buf_size,exp_size,msg_size,min_duration,&sec,&bw);
94 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
95 bw1, bw2, sec, (bw/1024.0/1024.0));
98 /* Test BW with saturation */
99 amok_bw_saturate_start(sat1,4000,sat2,4000, sat_size,60);
100 gras_os_sleep(1.0); /* let it start */
102 amok_bw_request(bw1,4000,bw2,4000,
103 buf_size,exp_size,msg_size,min_duration,&sec_sat,&bw_sat);
104 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
105 bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
107 amok_bw_saturate_stop(sat1,4000,NULL,NULL);
109 if (bw_sat/bw < 0.7) {
110 INFO0("THERE IS SOME INTERFERENCE !!!");
112 if (bw/bw_sat < 0.7) {
113 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
118 static void kill_buddy(char *name,int port){
119 gras_socket_t sock=gras_socket_client(name,port);
120 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
121 gras_socket_close(sock);
123 static void kill_buddy_dynar(void *b) {
124 xbt_host_t buddy=*(xbt_host_t*)b;
125 kill_buddy(buddy->name,buddy->port);
128 static void free_host(void *d){
129 xbt_host_t h=*(xbt_host_t*)d;
134 static void simple_saturation(int argc, char*argv[]) {
137 kill_buddy(argv[5],atoi(argv[6]));
138 kill_buddy(argv[7],atoi(argv[8]));
140 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
144 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
150 kill_buddy(argv[1],atoi(argv[2]));
151 kill_buddy(argv[3],atoi(argv[4]));
153 /********************************************************************************************/
154 static void env_hosttohost_bw(int argc, char*argv[]) {
156 /* where are the sensors */
157 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
167 gras_socket_t peer; /* socket to sensor */
169 /* wait to ensure that all server sockets are there before starting the experiment */
172 /* Get the sensor location from argc/argv */
173 for (i=1; i<argc-1; i+=2){
174 xbt_host_t host=xbt_new(s_xbt_host_t,1);
175 host->name=strdup(argv[i]);
176 host->port=atoi(argv[i+1]);
177 INFO2("New sensor: %s:%d",host->name,host->port);
178 xbt_dynar_push(hosts,&host);
180 nb_hosts = xbt_dynar_length(hosts);
182 INFO0(">>> start Test1: ENV end to end mesurements");
184 xbt_dynar_foreach(hosts,i,h1) {
185 peer = gras_socket_client(h1->name,h1->port);
186 amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw);
187 INFO6("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
190 sec,((double)bw)/1024.0);
193 xbt_dynar_map(hosts,kill_buddy_dynar);
194 xbt_dynar_free(&hosts);
197 /********************************************************************************************/
198 static void env_Pairwisehost_bw(int argc, char*argv[]) {
201 /* where are the sensors */
202 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
205 /* getting the name of maestro for the saturation and the concurrent bandwidth measurements */
206 char* host_test=argv[0];
215 /* socket to sensor */
218 /* wait to ensure that all server sockets are there before starting the experiment */
221 INFO1(">>>>>< le maestro est: %s ",argv[0]);
222 /* Get the sensor location from argc/argv */
223 for (i=1; i<argc-1; i+=2){
224 xbt_host_t host=xbt_new(s_xbt_host_t,1);
225 host->name=strdup(argv[i]);
226 host->port=atoi(argv[i+1]);
227 INFO2("New sensor: %s:%d",host->name,host->port);
228 xbt_dynar_push(hosts,&host);
230 nb_hosts = xbt_dynar_length(hosts);
232 INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements");
233 xbt_dynar_foreach(hosts,i,h1) {
236 amok_bw_saturate_start(h1->name,h1->port,
237 host_test,h1->port,//"Ginette"
238 msg_size,120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
240 RETHROW0("Cannot ask hosts to saturate the link: %s");
242 // gras_os_sleep(1.0);
244 xbt_dynar_foreach(hosts,j,h2) {
247 peer = gras_socket_client(h2->name,h2->port);
248 amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw);
249 INFO6("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
252 sec,((double)bw)/1024.0);
255 amok_bw_saturate_stop(h1->name,h1->port,NULL,NULL);
257 xbt_dynar_map(hosts,kill_buddy_dynar);
258 xbt_dynar_free(&hosts);
261 /********************************************************************************************/
262 static void full_fledged_saturation(int argc, char*argv[]) {
264 //unsigned int time1=5,bw1=5;
265 double time1=5.0,bw1=5.0; // 0.5 for test
267 double begin_simulated;
270 /* where are the sensors */
271 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
280 xbt_host_t h1,h2,h3,h4;
282 /* Get the sensor location from argc/argv */
283 for (i=1; i<argc; i++){
284 xbt_host_t host=xbt_host_from_string(argv[i]);
285 INFO2("New sensor: %s:%d",host->name,host->port);
286 xbt_dynar_push(hosts,&host);
288 nb_hosts = xbt_dynar_length(hosts);
290 gras_os_sleep(2); /* wait for my pals to get ready */
291 INFO0("Let's go for the bw_matrix");
293 /* Do the test without saturation */
295 begin_simulated=gras_os_time();
297 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size,min_duration);
299 INFO2("Did all BW tests in %ld sec (%.2f simulated sec)",
300 time(NULL)-begin,gras_os_time()-begin_simulated);
302 /* Do the test with saturation */
303 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
304 xbt_dynar_foreach(hosts,i,h1) {
305 xbt_dynar_foreach(hosts,j,h2) {
309 amok_bw_saturate_start(h1->name,h1->port,
311 sat_size, 0/* no timeout */);
313 RETHROW0("Cannot ask hosts to saturate the link: %s");
318 begin_simulated=gras_os_time();
319 xbt_dynar_foreach(hosts,k,h3) {
320 if (i==k || j==k) continue;
322 xbt_dynar_foreach(hosts,l,h4) {
324 if (i==l || j==l || k==l) continue;
326 VERB4("TEST %s %s // %s %s",
327 h1->name,h2->name,h3->name,h4->name);
328 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
329 buf_size,exp_size,msg_size,min_duration,
330 NULL,&(bw_sat[k*nb_hosts + l]));
332 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
333 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
334 h1->name,h2->name,h3->name,h4->name,
336 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
337 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
340 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
342 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
343 time(NULL)-begin, gras_os_time()-begin_simulated);
344 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
349 xbt_dynar_map(hosts,kill_buddy_dynar);
350 xbt_dynar_free(&hosts);
354 int maestro(int argc,char *argv[]) {
356 gras_init(&argc,argv);
359 gras_socket_server(3333); /* only so that messages from the transport layer in gras identify us */
361 //env_Pairwisehost_bw(argc,argv);
362 //env_hosttohost_bw(argc,argv);
364 // simple_saturation(argc,argv);
365 full_fledged_saturation(argc, argv);