1 /* saturate - link saturation demo of AMOK features */
3 /* Copyright (c) 2003-6 Martin Quinson. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
15 #include "amok/bandwidth.h"
16 #include "amok/peermanagement.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate, "Messages specific to this example");
20 /* **********************************************************************
22 * **********************************************************************/
24 /* Function prototypes */
25 int sensor(int argc, char *argv[]);
27 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 msg_size = 50 * 1024;
60 const int msg_amount = 2;
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)
68 double sec, bw, sec_sat, bw_sat;
70 gras_os_sleep(5.0); /* wait for the sensors to show up */
71 /* Test BW without saturation */
72 amok_bw_request(bw1, 4000, bw2, 4000,
73 buf_size, msg_size, msg_amount, min_duration, &sec, &bw);
74 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
75 bw1, bw2, sec, (bw / 1024.0 / 1024.0));
78 /* Test BW with saturation */
79 amok_bw_saturate_start(sat1, 4000, sat2, 4000, sat_size, 60);
80 gras_os_sleep(1.0); /* let it start */
82 amok_bw_request(bw1, 4000, bw2, 4000,
83 buf_size, msg_size, msg_amount, min_duration, &sec_sat,
85 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s", bw1, bw2, sat1, sat2,
86 sec, bw / 1024.0 / 1024.0);
88 amok_bw_saturate_stop(sat1, 4000, NULL, NULL);
90 if (bw_sat / bw < 0.7) {
91 INFO0("THERE IS SOME INTERFERENCE !!!");
93 if (bw / bw_sat < 0.7) {
94 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
99 static void kill_buddy(char *name, int port)
101 gras_socket_t sock = gras_socket_client(name, port);
102 gras_msg_send(sock, "kill", NULL);
103 gras_socket_close(sock);
106 static void kill_buddy_dynar(void *b)
108 xbt_peer_t buddy = *(xbt_peer_t *) b;
109 kill_buddy(buddy->name, buddy->port);
112 static void free_peer(void *d)
114 xbt_peer_t h = *(xbt_peer_t *) d;
119 static void simple_saturation(int argc, char *argv[])
123 /* where are the sensors */
130 peers = amok_pm_group_new("saturate");
132 gras_msg_handleall(5);
134 /* Stop all sensors but two of them */
135 while (xbt_dynar_length(peers) > 2) {
136 xbt_dynar_pop(peers, &h1);
137 amok_pm_kill_hp(h1->name, h1->port);
142 xbt_dynar_get_cpy(peers, 0, &h1);
143 xbt_dynar_get_cpy(peers, 1, &h2);
145 /* Start saturation */
146 INFO4("Start saturation between %s:%d and %s:%d",
147 h1->name, h1->port, h2->name, h2->port);
149 amok_bw_saturate_start(h1->name, h1->port, h2->name, h2->port, 0, /* Be a nice boy, compute msg_size yourself */
150 30 /* 5 sec timeout */ );
152 /* Stop it after a while */
153 INFO0("Have a rest");
156 INFO0("Stop the saturation");
157 amok_bw_saturate_stop(h1->name, h1->port, &duration, &bw);
160 INFO0("Ooops, stoping the saturation raised an exception");
163 INFO2("Saturation took %.2fsec, achieving %fb/s", duration, bw);
165 /* Game is over, friends */
166 amok_pm_group_shutdown("saturate");
169 /********************************************************************************************/
170 static void full_fledged_saturation(int argc, char *argv[])
173 double time1 = 5.0, bw1 = 5.0; // 0.5 for test
175 double begin_simulated;
178 /* where are the sensors */
187 unsigned int i, j, k, l;
188 xbt_peer_t h1, h2, h3, h4;
191 peers = amok_pm_group_new("saturate");
197 nb_peers = xbt_dynar_length(peers);
199 INFO0("Let's go for the bw_matrix");
201 /* Do the test without saturation */
203 begin_simulated = gras_os_time();
205 bw = amok_bw_matrix(peers, buf_size, msg_size, msg_amount, min_duration);
207 INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
208 (long int) (time(NULL) - begin), gras_os_time() - begin_simulated);
210 /* Do the test with saturation */
211 bw_sat = xbt_new(double, nb_peers * nb_peers);
212 xbt_dynar_foreach(peers, i, h1) {
213 xbt_dynar_foreach(peers, j, h2) {
218 amok_bw_saturate_start(h1->name, h1->port, h2->name, h2->port, 0, /* Be nice, compute msg_size yourself */
219 0 /* no timeout */ );
222 RETHROW0("Cannot ask peers to saturate the link: %s");
227 begin_simulated = gras_os_time();
228 xbt_dynar_foreach(peers, k, h3) {
229 if (i == k || j == k)
232 xbt_dynar_foreach(peers, l, h4) {
234 if (i == l || j == l || k == l)
237 VERB4("TEST %s %s // %s %s",
238 h1->name, h2->name, h3->name, h4->name);
239 amok_bw_request(h3->name, h3->port, h4->name, h4->port,
240 buf_size, msg_size, msg_amount, min_duration,
241 NULL, &(bw_sat[k * nb_peers + l]));
243 ratio = bw_sat[k * nb_peers + l] / bw[k * nb_peers + l];
244 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
245 h1->name, h2->name, h3->name, h4->name,
247 bw[k * nb_peers + l], bw_sat[k * nb_peers + l],
248 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!" : "");
251 amok_bw_saturate_stop(h1->name, h1->port, &time1, &bw1);
254 ("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
255 (long int) (time(NULL) - begin), gras_os_time() - begin_simulated);
256 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",
262 /* Game is over, friends */
263 amok_pm_group_shutdown("saturate");
267 int maestro(int argc, char *argv[])
270 gras_init(&argc, argv);
274 gras_socket_server(atoi(argv[1]));
276 simple_saturation(argc, argv);
277 //full_fledged_saturation(argc, argv);