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/hostmanagement.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(0.5); /* 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_host_t buddy=*(xbt_host_t*)b;
104 kill_buddy(buddy->name,buddy->port);
107 static void free_host(void *d){
108 xbt_host_t h=*(xbt_host_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_host_t h1,h2,h3,h4;
154 hosts=amok_hm_group_new("saturate");
155 INFO0("Wait for peers for 5 sec");
156 gras_msg_handleall(5); /* friends, we're ready. Come and play */
157 nb_hosts = xbt_dynar_length(hosts);
159 INFO0("Let's go for the bw_matrix");
161 /* Do the test without saturation */
163 begin_simulated=gras_os_time();
165 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size,min_duration);
167 INFO2("Did all BW tests in %ld sec (%.2f simulated(?) sec)",
168 time(NULL)-begin,gras_os_time()-begin_simulated);
170 /* Do the test with saturation */
171 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
172 xbt_dynar_foreach(hosts,i,h1) {
173 xbt_dynar_foreach(hosts,j,h2) {
177 amok_bw_saturate_start(h1->name,h1->port,
179 sat_size, 0/* no timeout */);
181 RETHROW0("Cannot ask hosts to saturate the link: %s");
186 begin_simulated=gras_os_time();
187 xbt_dynar_foreach(hosts,k,h3) {
188 if (i==k || j==k) continue;
190 xbt_dynar_foreach(hosts,l,h4) {
192 if (i==l || j==l || k==l) continue;
194 VERB4("TEST %s %s // %s %s",
195 h1->name,h2->name,h3->name,h4->name);
196 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
197 buf_size,exp_size,msg_size,min_duration,
198 NULL,&(bw_sat[k*nb_hosts + l]));
200 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
201 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
202 h1->name,h2->name,h3->name,h4->name,
204 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
205 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
208 amok_bw_saturate_stop(h1->name,h1->port,&time1,&bw1);// NULL,NULL);
210 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
211 time(NULL)-begin, gras_os_time()-begin_simulated);
212 INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)",time1,bw1);
217 /* Game is over, friends */
218 amok_hm_group_shutdown ("saturate");
222 int maestro(int argc,char *argv[]) {
224 gras_init(&argc,argv);
228 gras_socket_server(atoi(argv[1]));
230 // simple_saturation(argc,argv);
231 full_fledged_saturation(argc, argv);