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_hm_group_join(master,"saturate");
42 amok_hm_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 kill_buddy(argv[5],atoi(argv[6]));
117 kill_buddy(argv[7],atoi(argv[8]));
119 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
123 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
129 kill_buddy(argv[1],atoi(argv[2]));
130 kill_buddy(argv[3],atoi(argv[4]));
132 /********************************************************************************************/
133 static void full_fledged_saturation(int argc, char*argv[]) {
135 //unsigned int time1=5,bw1=5;
136 double time1=5.0,bw1=5.0; // 0.5 for test
138 double begin_simulated;
141 /* where are the sensors */
151 xbt_peer_t h1,h2,h3,h4;
154 peers=amok_hm_group_new("saturate");
160 nb_peers = xbt_dynar_length(peers);
162 INFO0("Let's go for the bw_matrix");
164 /* Do the test without saturation */
166 begin_simulated=gras_os_time();
168 bw=amok_bw_matrix(peers,buf_size,exp_size,msg_size,min_duration);
170 INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
171 time(NULL)-begin,gras_os_time()-begin_simulated);
173 /* Do the test with saturation */
174 bw_sat=xbt_new(double,nb_peers*nb_peers);
175 xbt_dynar_foreach(peers,i,h1) {
176 xbt_dynar_foreach(peers,j,h2) {
180 amok_bw_saturate_start(h1->name,h1->port,
182 0, /* Be nice, compute msg_size yourself */
185 RETHROW0("Cannot ask peers to saturate the link: %s");
190 begin_simulated=gras_os_time();
191 xbt_dynar_foreach(peers,k,h3) {
192 if (i==k || j==k) continue;
194 xbt_dynar_foreach(peers,l,h4) {
196 if (i==l || j==l || k==l) continue;
198 VERB4("TEST %s %s // %s %s",
199 h1->name,h2->name,h3->name,h4->name);
200 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
201 buf_size,exp_size,msg_size,min_duration,
202 NULL,&(bw_sat[k*nb_peers + l]));
204 ratio=bw_sat[k*nb_peers + l] / bw[k*nb_peers + l];
205 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
206 h1->name,h2->name,h3->name,h4->name,
208 bw[k*nb_peers + l] , bw_sat[k*nb_peers + l],
209 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
212 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
214 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
215 time(NULL)-begin, gras_os_time()-begin_simulated);
216 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
221 /* Game is over, friends */
222 amok_hm_group_shutdown ("saturate");
226 int maestro(int argc,char *argv[]) {
228 gras_init(&argc,argv);
232 gras_socket_server(atoi(argv[1]));
234 // simple_saturation(argc,argv);
235 full_fledged_saturation(argc, argv);