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[]) {
44 gras_init(&argc,argv);
47 g=gras_userdata_new(sensor_data_t);
48 g->sock = gras_socket_server(atoi(argv[1]));
51 gras_msgtype_declare("kill",NULL);
52 gras_cb_register(gras_msgtype_by_name("kill"),&sensor_cb_kill);
55 gras_msg_handle(120.0);
58 gras_socket_close(g->sock);
64 /* **********************************************************************
66 * **********************************************************************/
68 /* Function prototypes */
69 int maestro (int argc,char *argv[]);
72 const int buf_size = 0;
73 const int exp_size = 64*1024*1024; // * 1024;
74 const int msg_size = 16*1024*1024;
75 const int sat_size = 10*1024*1024; //1024 * 10 *
77 /* Global private data */
80 } s_maestro_data_t,*maestro_data_t;
82 static double XP(const char *bw1, const char *bw2,
83 const char *sat1, const char *sat2) {
85 double sec, bw, sec_sat,bw_sat;
87 /* Test BW without saturation */
88 amok_bw_request(bw1,4000,bw2,4000,
89 buf_size,exp_size,msg_size,&sec,&bw);
90 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
91 bw1, bw2, sec, (bw/1024.0/1024.0));
94 /* Test BW with saturation */
95 amok_bw_saturate_start(sat1,4000,sat2,4000, sat_size,60);
96 gras_os_sleep(1.0); /* let it start */
98 amok_bw_request(bw1,4000,bw2,4000,
99 buf_size,exp_size,msg_size,&sec_sat,&bw_sat);
100 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
101 bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
103 amok_bw_saturate_stop(sat1,4000,NULL,NULL);
105 if (bw_sat/bw < 0.7) {
106 INFO0("THERE IS SOME INTERFERENCE !!!");
108 if (bw/bw_sat < 0.7) {
109 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
114 static void kill_buddy(char *name,int port){
115 gras_socket_t sock=gras_socket_client(name,port);
116 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
117 gras_socket_close(sock);
119 static void kill_buddy_dynar(void *b) {
120 xbt_host_t buddy=*(xbt_host_t*)b;
121 kill_buddy(buddy->name,buddy->port);
124 static void free_host(void *d){
125 xbt_host_t h=*(xbt_host_t*)d;
130 static void simple_saturation(int argc, char*argv[]) {
133 kill_buddy(argv[5],atoi(argv[6]));
134 kill_buddy(argv[7],atoi(argv[8]));
136 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
140 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
146 kill_buddy(argv[1],atoi(argv[2]));
147 kill_buddy(argv[3],atoi(argv[4]));
149 /********************************************************************************************/
150 void env_hosttohost_bw(int argc, char*argv[]) {
153 /* where are the sensors */
154 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
164 /* socket to sensor */
167 g=gras_userdata_new(s_maestro_data_t);
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,&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);
196 gras_socket_close(g->sock);
199 /********************************************************************************************/
200 void env_Pairwisehost_bw(int argc, char*argv[]) {
203 /* where are the sensors */
204 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
207 /* getting the name of maestro for the saturation and the concurrent bandwidth measurements */
208 char* host_test=argv[0];
217 /* socket to sensor */
220 g=gras_userdata_new(s_maestro_data_t);
222 /* wait to ensure that all server sockets are there before starting the experiment */
225 INFO1(">>>>>< le maestro est: %s ",argv[0]);
226 /* Get the sensor location from argc/argv */
227 for (i=1; i<argc-1; i+=2){
228 xbt_host_t host=xbt_new(s_xbt_host_t,1);
229 host->name=strdup(argv[i]);
230 host->port=atoi(argv[i+1]);
231 INFO2("New sensor: %s:%d",host->name,host->port);
232 xbt_dynar_push(hosts,&host);
234 nb_hosts = xbt_dynar_length(hosts);
236 INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements");
237 xbt_dynar_foreach(hosts,i,h1) {
240 amok_bw_saturate_start(h1->name,h1->port,
241 host_test,h1->port,//"Ginette"
242 msg_size,120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
244 RETHROW0("Cannot ask hosts to saturate the link: %s");
246 // gras_os_sleep(1.0);
248 xbt_dynar_foreach(hosts,j,h2) {
251 peer = gras_socket_client(h2->name,h2->port);
252 amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw);
253 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",
256 sec,((double)bw)/1024.0);
259 amok_bw_saturate_stop(h1->name,h1->port,NULL,NULL);
261 xbt_dynar_map(hosts,kill_buddy_dynar);
262 xbt_dynar_free(&hosts);
264 gras_socket_close(g->sock);
267 /********************************************************************************************/
268 static void full_fledged_saturation(int argc, char*argv[]) {
270 //unsigned int time1=5,bw1=5;
271 double time1=5.0,bw1=5.0; // 0.5 for test
273 double begin_simulated;
276 /* where are the sensors */
277 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
286 xbt_host_t h1,h2,h3,h4;
288 /* Get the sensor location from argc/argv */
289 for (i=1; i<argc-1; i+=2){
290 xbt_host_t host=xbt_new(s_xbt_host_t,1);
291 host->name=strdup(argv[i]);
292 host->port=atoi(argv[i+1]);
293 INFO2("New sensor: %s:%d",host->name,host->port);
294 xbt_dynar_push(hosts,&host);
296 nb_hosts = xbt_dynar_length(hosts);
298 /* Do the test without saturation */
300 begin_simulated=gras_os_time();
302 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size);
304 INFO2("Did all BW tests in %d sec (%.2f simulated sec)",
305 time(NULL)-begin,gras_os_time()-begin_simulated);
307 /* Do the test with saturation */
308 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
309 xbt_dynar_foreach(hosts,i,h1) {
310 xbt_dynar_foreach(hosts,j,h2) {
314 amok_bw_saturate_start(h1->name,h1->port,
318 RETHROW0("Cannot ask hosts to saturate the link: %s");
323 begin_simulated=gras_os_time();
324 xbt_dynar_foreach(hosts,k,h3) {
325 if (i==k || j==k) continue;
327 xbt_dynar_foreach(hosts,l,h4) {
329 if (i==l || j==l || k==l) continue;
331 INFO4("TEST %s %s // %s %s",
332 h1->name,h2->name,h3->name,h4->name);
333 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
334 buf_size,exp_size,msg_size,
335 NULL,&(bw_sat[k*nb_hosts + l]));
337 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
338 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
339 h1->name,h2->name,h3->name,h4->name,
341 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
342 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
345 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
347 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
348 time(NULL)-begin, gras_os_time()-begin_simulated);
349 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
354 xbt_dynar_map(hosts,kill_buddy_dynar);
355 xbt_dynar_free(&hosts);
359 int maestro(int argc,char *argv[]) {
361 gras_init(&argc,argv);
364 env_Pairwisehost_bw(argc,argv);
365 //env_hosttohost_bw(argc,argv);
367 // simple_saturation(argc,argv);
368 //full_fledged_saturation(argc, argv);