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[]) {
44 gras_init(&argc,argv);
47 g=gras_userdata_new(sensor_data_t);
48 g->sock = gras_socket_server(4000);
50 gras_msgtype_declare("kill",NULL);
51 gras_cb_register(gras_msgtype_by_name("kill"),&sensor_cb_kill);
54 gras_msg_handle(120.0);
57 gras_socket_close(g->sock);
63 /* **********************************************************************
65 * **********************************************************************/
67 /* Function prototypes */
68 int maestro (int argc,char *argv[]);
71 const int buf_size = 0;
72 const int exp_size = 1024;// * 1024;
73 const int msg_size = 1024;
74 const int sat_size = 1024 * 1024 * 10 * 10;
76 static double XP(const char *bw1, const char *bw2,
77 const char *sat1, const char *sat2) {
79 double sec, bw, sec_sat,bw_sat;
81 /* Test BW without saturation */
82 amok_bw_request(bw1,4000,bw2,4000,
83 buf_size,exp_size,msg_size,&sec,&bw);
84 INFO4("BW(%s,%s) => %f sec, achieving %f Mb/s",
85 bw1, bw2, sec, (bw/1024.0/1024.0));
88 /* Test BW with saturation */
89 amok_bw_saturate_start(sat1,4000,sat2,4000, sat_size,60);
90 gras_os_sleep(1.0); /* let it start */
92 amok_bw_request(bw1,4000,bw2,4000,
93 buf_size,exp_size,msg_size,&sec_sat,&bw_sat);
94 INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s",
95 bw1,bw2,sat1,sat2,sec,bw/1024.0/1024.0);
97 amok_bw_saturate_stop(sat1,4000,NULL,NULL);
99 if (bw_sat/bw < 0.7) {
100 INFO0("THERE IS SOME INTERFERENCE !!!");
102 if (bw/bw_sat < 0.7) {
103 INFO0("THERE IS SOME INTERFERENCE (and I'm an idiot) !!!");
108 static void kill_buddy(char *name,int port){
109 gras_socket_t sock=gras_socket_client(name,port);
110 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
111 gras_socket_close(sock);
113 static void kill_buddy_dynar(void *b) {
114 xbt_host_t buddy=*(xbt_host_t*)b;
115 kill_buddy(buddy->name,buddy->port);
118 static void free_host(void *d){
119 xbt_host_t h=*(xbt_host_t*)d;
124 static void simple_saturation(int argc, char*argv[]) {
127 kill_buddy(argv[5],atoi(argv[6]));
128 kill_buddy(argv[7],atoi(argv[8]));
130 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
134 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
140 kill_buddy(argv[1],atoi(argv[2]));
141 kill_buddy(argv[3],atoi(argv[4]));
144 static void full_fledged_saturation(int argc, char*argv[]) {
148 double begin_simulated;
151 /* where are the sensors */
152 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
161 xbt_host_t h1,h2,h3,h4;
163 /* Get the sensor location from argc/argv */
164 for (i=1; i<argc-1; i+=2){
165 xbt_host_t host=xbt_new(s_xbt_host_t,1);
166 host->name=strdup(argv[i]);
167 host->port=atoi(argv[i+1]);
168 INFO2("New sensor: %s:%d",host->name,host->port);
169 xbt_dynar_push(hosts,&host);
171 nb_hosts = xbt_dynar_length(hosts);
173 /* Do the test without saturation */
175 begin_simulated=gras_os_time();
177 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size);
179 INFO2("Did all BW tests in %ld sec (%.2f simulated sec)",
180 time(NULL)-begin,gras_os_time()-begin_simulated);
182 /* Do the test with saturation */
183 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
184 xbt_dynar_foreach(hosts,i,h1) {
185 xbt_dynar_foreach(hosts,j,h2) {
189 amok_bw_saturate_start(h1->name,h1->port,
193 RETHROW0("Cannot ask hosts to saturate the link: %s");
198 begin_simulated=gras_os_time();
199 xbt_dynar_foreach(hosts,k,h3) {
200 if (i==k || j==k) continue;
202 xbt_dynar_foreach(hosts,l,h4) {
204 if (i==l || j==l || k==l) continue;
206 INFO4("TEST %s %s // %s %s",
207 h1->name,h2->name,h3->name,h4->name);
208 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
209 buf_size,exp_size,msg_size,
210 NULL,&(bw_sat[k*nb_hosts + l]));
212 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
213 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
214 h1->name,h2->name,h3->name,h4->name,
216 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
218 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
222 amok_bw_saturate_stop(h1->name,h1->port, NULL,NULL);
224 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
225 time(NULL)-begin, gras_os_time()-begin_simulated);
231 xbt_dynar_map(hosts,kill_buddy_dynar);
232 xbt_dynar_free(&hosts);
236 int maestro(int argc,char *argv[]) {
238 gras_init(&argc,argv);
242 // simple_saturation(argc,argv);
243 full_fledged_saturation(argc, argv);