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(60.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,char *port){
109 gras_socket_t sock=gras_socket_client(name,atoi(port));
110 gras_msg_send(sock,gras_msgtype_by_name("kill"),NULL);
111 gras_socket_close(sock);
114 static void free_host(void *d){
115 xbt_host_t h=*(xbt_host_t*)d;
120 static void simple_saturation(int argc, char*argv[]) {
123 kill_buddy(argv[5],argv[6]);
124 kill_buddy(argv[7],argv[8]);
126 amok_bw_saturate_start(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
130 amok_bw_saturate_stop(argv[1],atoi(argv[2]),NULL,NULL);
136 kill_buddy(argv[1],argv[2]);
137 kill_buddy(argv[3],argv[4]);
140 static void full_fledged_saturation(int argc, char*argv[]) {
144 double begin_simulated;
147 /* where are the sensors */
148 xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
157 xbt_host_t h1,h2,h3,h4;
159 /* Get the sensor location from argc/argv */
160 for (i=1; i<argc-1; i+=2){
161 xbt_host_t host=xbt_new(s_xbt_host_t,1);
162 host->name=strdup(argv[i]);
163 host->port=atoi(argv[i+1]);
164 INFO2("New sensor: %s:%d",host->name,host->port);
165 xbt_dynar_push(hosts,&host);
167 nb_hosts = xbt_dynar_length(hosts);
169 /* Do the test without saturation */
171 begin_simulated=gras_os_time();
173 bw=amok_bw_matrix(hosts,buf_size,exp_size,msg_size);
175 INFO2("Did all BW tests in %ld sec (%.2f simulated sec)",
176 time(NULL)-begin,gras_os_time()-begin_simulated);
178 /* Do the test with saturation */
179 bw_sat=xbt_new(double,nb_hosts*nb_hosts);
180 xbt_dynar_foreach(hosts,i,h1) {
181 xbt_dynar_foreach(hosts,j,h2) {
185 amok_bw_saturate_start(h1->name,h1->port,
189 RETHROW0("Cannot ask hosts to saturate the link: %s");
194 begin_simulated=gras_os_time();
195 xbt_dynar_foreach(hosts,k,h3) {
196 if (i==k || j==k) continue;
198 xbt_dynar_foreach(hosts,l,h4) {
200 if (i==l || j==l || k==l) continue;
202 INFO4("TEST %s %s // %s %s",
203 h1->name,h2->name,h3->name,h4->name);
204 amok_bw_request(h3->name,h3->port, h4->name,h4->port,
205 buf_size,exp_size,msg_size,
206 NULL,&(bw_sat[k*nb_hosts + l]));
208 ratio=bw_sat[k*nb_hosts + l] / bw[k*nb_hosts + l];
209 INFO8("SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s",
210 h1->name,h2->name,h3->name,h4->name,
212 bw[k*nb_hosts + l] , bw_sat[k*nb_hosts + l],
214 ratio < 0.7 ? " THERE IS SOME INTERFERENCE !!!": "");
218 amok_bw_saturate_stop(h1->name,h1->port, NULL,NULL);
220 INFO2("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)",
221 time(NULL)-begin, gras_os_time()-begin_simulated);
224 xbt_dynar_free(&hosts);
227 int maestro(int argc,char *argv[]) {
229 gras_init(&argc,argv);
233 // simple_saturation(argc,argv);
234 full_fledged_saturation(argc, argv);