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"
17 #include "amok/peermanagement.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
21 /* **********************************************************************
23 * **********************************************************************/
25 /* Function prototypes */
26 int sensor (int argc,char *argv[]);
28 int sensor (int argc,char *argv[]) {
32 gras_init(&argc, argv);
36 mysock = gras_socket_server_range(3000,9999,0,0);
37 INFO1("Sensor starting (on port %d)",gras_os_myport());
38 gras_os_sleep(2); /* let the master get ready */
39 master = gras_socket_client_from_string(argv[1]);
41 amok_pm_group_join(master,"saturate");
42 amok_pm_mainloop(600);
44 gras_socket_close(mysock);
45 gras_socket_close(master);
50 /* **********************************************************************
52 * **********************************************************************/
54 /* Function prototypes */
55 int maestro (int argc,char *argv[]);
58 const int buf_size = 0;
59 const int exp_size = 100 * 1024;
60 const int msg_size = 50 * 1024;
61 const int sat_size = 1024 * 1024 * 10;
62 const double min_duration = 1;
64 static double XP(const char *bw1, const char *bw2,
65 const char *sat1, const char *sat2) {
67 double sec, bw, sec_sat,bw_sat;
69 gras_os_sleep(5.0); /* wait for the sensors to show up */
70 /* Test BW without saturation */
71 amok_bw_request(bw1,4000,bw2,4000,
72 buf_size,exp_size,msg_size,min_duration,&sec,&bw);
73 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
74 bw1, bw2, sec, (bw/1024.0/1024.0));
77 /* Test BW with saturation */
78 amok_bw_saturate_start(sat1,4000,sat2,4000, sat_size,60);
79 gras_os_sleep(1.0); /* let it start */
81 amok_bw_request(bw1,4000,bw2,4000,
82 buf_size,exp_size,msg_size,min_duration,&sec_sat,&bw_sat);
83 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
84 bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
86 amok_bw_saturate_stop(sat1,4000,NULL,NULL);
88 if (bw_sat/bw < 0.7) {
89 INFO0("THERE IS SOME INTERFERENCE !!!");
91 if (bw/bw_sat < 0.7) {
92 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
97 static void kill_buddy(char *name,int port){
98 gras_socket_t sock=gras_socket_client(name,port);
99 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
100 gras_socket_close(sock);
102 static void kill_buddy_dynar(void *b) {
103 xbt_peer_t buddy=*(xbt_peer_t*)b;
104 kill_buddy(buddy->name,buddy->port);
107 static void free_peer(void *d){
108 xbt_peer_t h=*(xbt_peer_t*)d;
113 static void simple_saturation(int argc, char*argv[]) {
116 /* where are the sensors */
123 peers=amok_pm_group_new("saturate");
125 gras_msg_handleall(5);
128 xbt_dynar_get_cpy(peers,0,&h1);
129 xbt_dynar_get_cpy(peers,1,&h2);
131 /* Start saturation */
132 amok_bw_saturate_start(h1->name,h1->port,
134 0, /* Be a nice boy, compute msg_size yourself */
135 30 /* 5 sec timeout */);
137 /* Stop it after a while */
140 amok_bw_saturate_stop(h1->name,h1->port, &duration,&bw);
144 INFO2("Saturation took %.2fsec, achieving %fb/s",duration,bw);
146 /* Game is over, friends */
147 amok_pm_group_shutdown ("saturate");
149 /********************************************************************************************/
150 static void full_fledged_saturation(int argc, char*argv[]) {
152 double time1=5.0,bw1=5.0; // 0.5 for test
154 double begin_simulated;
157 /* where are the sensors */
167 xbt_peer_t h1,h2,h3,h4;
170 peers=amok_pm_group_new("saturate");
176 nb_peers = xbt_dynar_length(peers);
178 INFO0("Let's go for the bw_matrix");
180 /* Do the test without saturation */
182 begin_simulated=gras_os_time();
184 bw=amok_bw_matrix(peers,buf_size,exp_size,msg_size,min_duration);
186 INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
187 time(NULL)-begin,gras_os_time()-begin_simulated);
189 /* Do the test with saturation */
190 bw_sat=xbt_new(double,nb_peers*nb_peers);
191 xbt_dynar_foreach(peers,i,h1) {
192 xbt_dynar_foreach(peers,j,h2) {
196 amok_bw_saturate_start(h1->name,h1->port,
198 0, /* Be nice, compute msg_size yourself */
201 RETHROW0("Cannot ask peers to saturate the link: %s");
206 begin_simulated=gras_os_time();
207 xbt_dynar_foreach(peers,k,h3) {
208 if (i==k || j==k) continue;
210 xbt_dynar_foreach(peers,l,h4) {
212 if (i==l || j==l || k==l) continue;
214 VERB4("TEST %s %s // %s %s",
215 h1->name,h2->name,h3->name,h4->name);
216 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
217 buf_size,exp_size,msg_size,min_duration,
218 NULL,&(bw_sat[k*nb_peers + l]));
220 ratio=bw_sat[k*nb_peers + l] / bw[k*nb_peers + l];
221 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
222 h1->name,h2->name,h3->name,h4->name,
224 bw[k*nb_peers + l] , bw_sat[k*nb_peers + l],
225 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
228 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);
230 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
231 time(NULL)-begin, gras_os_time()-begin_simulated);
232 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
237 /* Game is over, friends */
238 amok_pm_group_shutdown ("saturate");
242 int maestro(int argc,char *argv[]) {
244 gras_init(&argc,argv);
248 gras_socket_server(atoi(argv[1]));
250 simple_saturation(argc,argv);
251 //full_fledged_saturation(argc, argv);