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;
84 static double XP(const char *bw1, const char *bw2,
85 const char *sat1, const char *sat2) {
87 double sec, bw, sec_sat,bw_sat;
89 gras_os_sleep(5.0); /* wait for the sensors to show up */
90 /* Test BW without saturation */
91 amok_bw_request(bw1,4000,bw2,4000,
92 buf_size,exp_size,msg_size,&sec,&bw);
93 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
94 bw1, bw2, sec, (bw/1024.0/1024.0));
97 /* Test BW with saturation */
98 amok_bw_saturate_start(sat1,4000,sat2,4000, sat_size,60);
99 gras_os_sleep(1.0); /* let it start */
101 amok_bw_request(bw1,4000,bw2,4000,
102 buf_size,exp_size,msg_size,&sec_sat,&bw_sat);
103 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
104 bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
106 amok_bw_saturate_stop(sat1,4000,NULL,NULL);
108 if (bw_sat/bw < 0.7) {
109 INFO0("THERE IS SOME INTERFERENCE !!!");
111 if (bw/bw_sat < 0.7) {
112 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
117 static void kill_buddy(char *name,int port){
118 gras_socket_t sock=gras_socket_client(name,port);
119 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
120 gras_socket_close(sock);
122 static void kill_buddy_dynar(void *b) {
123 xbt_host_t buddy=*(xbt_host_t*)b;
124 kill_buddy(buddy->name,buddy->port);
127 static void free_host(void *d){
128 xbt_host_t h=*(xbt_host_t*)d;
133 static void simple_saturation(int argc, char*argv[]) {
136 kill_buddy(argv[5],atoi(argv[6]));
137 kill_buddy(argv[7],atoi(argv[8]));
139 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
143 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
149 kill_buddy(argv[1],atoi(argv[2]));
150 kill_buddy(argv[3],atoi(argv[4]));
152 /********************************************************************************************/
153 static void env_hosttohost_bw(int argc, char*argv[]) {
155 /* where are the sensors */
156 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
166 gras_socket_t peer; /* socket to sensor */
168 /* wait to ensure that all server sockets are there before starting the experiment */
171 /* Get the sensor location from argc/argv */
172 for (i=1; i<argc-1; i+=2){
173 xbt_host_t host=xbt_new(s_xbt_host_t,1);
174 host->name=strdup(argv[i]);
175 host->port=atoi(argv[i+1]);
176 INFO2("New sensor: %s:%d",host->name,host->port);
177 xbt_dynar_push(hosts,&host);
179 nb_hosts = xbt_dynar_length(hosts);
181 INFO0(">>> start Test1: ENV end to end mesurements");
183 xbt_dynar_foreach(hosts,i,h1) {
184 peer = gras_socket_client(h1->name,h1->port);
185 amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw);
186 INFO6("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
189 sec,((double)bw)/1024.0);
192 xbt_dynar_map(hosts,kill_buddy_dynar);
193 xbt_dynar_free(&hosts);
196 /********************************************************************************************/
197 static void env_Pairwisehost_bw(int argc, char*argv[]) {
200 /* where are the sensors */
201 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
204 /* getting the name of maestro for the saturation and the concurrent bandwidth measurements */
205 char* host_test=argv[0];
214 /* socket to sensor */
217 /* wait to ensure that all server sockets are there before starting the experiment */
220 INFO1(">>>>>< le maestro est: %s ",argv[0]);
221 /* Get the sensor location from argc/argv */
222 for (i=1; i<argc-1; i+=2){
223 xbt_host_t host=xbt_new(s_xbt_host_t,1);
224 host->name=strdup(argv[i]);
225 host->port=atoi(argv[i+1]);
226 INFO2("New sensor: %s:%d",host->name,host->port);
227 xbt_dynar_push(hosts,&host);
229 nb_hosts = xbt_dynar_length(hosts);
231 INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements");
232 xbt_dynar_foreach(hosts,i,h1) {
235 amok_bw_saturate_start(h1->name,h1->port,
236 host_test,h1->port,//"Ginette"
237 msg_size,120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
239 RETHROW0("Cannot ask hosts to saturate the link: %s");
241 // gras_os_sleep(1.0);
243 xbt_dynar_foreach(hosts,j,h2) {
246 peer = gras_socket_client(h2->name,h2->port);
247 amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw);
248 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",
251 sec,((double)bw)/1024.0);
254 amok_bw_saturate_stop(h1->name,h1->port,NULL,NULL);
256 xbt_dynar_map(hosts,kill_buddy_dynar);
257 xbt_dynar_free(&hosts);
260 /********************************************************************************************/
261 static void full_fledged_saturation(int argc, char*argv[]) {
263 //unsigned int time1=5,bw1=5;
264 double time1=5.0,bw1=5.0; // 0.5 for test
266 double begin_simulated;
269 /* where are the sensors */
270 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
279 xbt_host_t h1,h2,h3,h4;
281 /* Get the sensor location from argc/argv */
282 for (i=1; i<argc; i++){
283 xbt_host_t host=xbt_host_from_string(argv[i]);
284 INFO2("New sensor: %s:%d",host->name,host->port);
285 xbt_dynar_push(hosts,&host);
287 nb_hosts = xbt_dynar_length(hosts);
289 gras_os_sleep(2); /* wait for my pals to get ready */
290 INFO0("Let's go for the bw_matrix");
292 /* Do the test without saturation */
294 begin_simulated=gras_os_time();
296 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size);
298 INFO2("Did all BW tests in %ld sec (%.2f simulated sec)",
299 time(NULL)-begin,gras_os_time()-begin_simulated);
301 /* Do the test with saturation */
302 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
303 xbt_dynar_foreach(hosts,i,h1) {
304 xbt_dynar_foreach(hosts,j,h2) {
308 amok_bw_saturate_start(h1->name,h1->port,
310 sat_size, 0/* no timeout */);
312 RETHROW0("Cannot ask hosts to saturate the link: %s");
317 begin_simulated=gras_os_time();
318 xbt_dynar_foreach(hosts,k,h3) {
319 if (i==k || j==k) continue;
321 xbt_dynar_foreach(hosts,l,h4) {
323 if (i==l || j==l || k==l) continue;
325 VERB4("TEST %s %s // %s %s",
326 h1->name,h2->name,h3->name,h4->name);
327 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
328 buf_size,exp_size,msg_size,
329 NULL,&(bw_sat[k*nb_hosts + l]));
331 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
332 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
333 h1->name,h2->name,h3->name,h4->name,
335 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
336 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
339 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
341 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
342 time(NULL)-begin, gras_os_time()-begin_simulated);
343 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
348 xbt_dynar_map(hosts,kill_buddy_dynar);
349 xbt_dynar_free(&hosts);
353 int maestro(int argc,char *argv[]) {
355 gras_init(&argc,argv);
358 gras_socket_server(3333); /* only so that messages from the transport layer in gras identify us */
360 //env_Pairwisehost_bw(argc,argv);
361 //env_hosttohost_bw(argc,argv);
363 // simple_saturation(argc,argv);
364 full_fledged_saturation(argc, argv);