Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
autogenerated
[simgrid.git] / examples / amok / saturate / env.c
1 /* $Id$ */
2
3 /* saturate - link saturation demo of AMOK features                         */
4
5 /* Copyright (c) 2003-6 Martin Quinson. All rights reserved.                */
6
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. */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <signal.h>
13 #include <time.h>
14
15 #include "gras.h"
16 #include "amok/bandwidth.h"
17 #include "amok/hostmanagement.h"
18
19 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example");
20
21 static void env_hosttohost_bw(int argc, char*argv[]) {
22
23   /* where are the sensors */
24   xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
25   int nb_hosts;
26
27   /* results */
28   double sec, bw;
29
30   /* iterators */
31   int i;
32   xbt_host_t h1;
33
34   gras_socket_t peer; /* socket to sensor */
35
36   /* wait to ensure that all server sockets are there before starting the experiment */ 
37   gras_os_sleep(0.5);
38
39   /* Get the sensor location from argc/argv */
40   for (i=1; i<argc-1; i+=2){
41     xbt_host_t host=xbt_new(s_xbt_host_t,1);
42     host->name=strdup(argv[i]);
43     host->port=atoi(argv[i+1]);
44     INFO2("New sensor: %s:%d",host->name,host->port);
45     xbt_dynar_push(hosts,&host);
46   }
47   nb_hosts = xbt_dynar_length(hosts);
48
49   INFO0(">>> start Test1: ENV end to end mesurements");
50
51   xbt_dynar_foreach(hosts,i,h1) {
52         peer = gras_socket_client(h1->name,h1->port);
53         amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw);
54         INFO6("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
55         h1->name,h1->port,
56         exp_size,msg_size,
57         sec,((double)bw)/1024.0);
58   }
59
60   xbt_dynar_map(hosts,kill_buddy_dynar);
61   xbt_dynar_free(&hosts);
62
63 }
64 /********************************************************************************************/
65 static void env_Pairwisehost_bw(int argc, char*argv[]) {
66   xbt_ex_t e;
67
68   /* where are the sensors */
69   xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host);
70   int nb_hosts;
71
72   /* getting the name of maestro for the saturation and the concurrent bandwidth measurements  */
73   char* host_test=argv[0];
74
75   /* results */
76   double sec, bw;
77
78   /* iterators */
79   int i,j;
80   xbt_host_t h1,h2;
81
82   /* socket to sensor */
83   gras_socket_t peer;
84
85   /* wait to ensure that all server sockets are there before starting the experiment */ 
86   gras_os_sleep(0.5);
87
88   INFO1(">>>>>< le maestro est: %s ",argv[0]);
89   /* Get the sensor location from argc/argv */
90   for (i=1; i<argc-1; i+=2){
91     xbt_host_t host=xbt_new(s_xbt_host_t,1);
92     host->name=strdup(argv[i]);
93     host->port=atoi(argv[i+1]);
94     INFO2("New sensor: %s:%d",host->name,host->port);
95     xbt_dynar_push(hosts,&host);
96   }
97   nb_hosts = xbt_dynar_length(hosts);
98
99   INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements");
100  xbt_dynar_foreach(hosts,i,h1) {
101
102       TRY {
103         amok_bw_saturate_start(h1->name,h1->port,
104                                host_test,h1->port,//"Ginette"
105                                msg_size,120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
106       } CATCH(e) {
107         RETHROW0("Cannot ask hosts to saturate the link: %s");
108       }
109      // gras_os_sleep(1.0);
110
111         xbt_dynar_foreach(hosts,j,h2) {
112         if (i==j) continue;
113
114         peer = gras_socket_client(h2->name,h2->port);
115         amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw);
116         INFO6("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
117         h2->name,h1->name,
118         exp_size,msg_size,
119         sec,((double)bw)/1024.0);
120
121   }
122         amok_bw_saturate_stop(h1->name,h1->port,NULL,NULL);
123 }
124   xbt_dynar_map(hosts,kill_buddy_dynar);
125   xbt_dynar_free(&hosts);
126
127 }
128
129 int maestro(int argc,char *argv[]) {
130
131   gras_init(&argc,argv);
132   amok_bw_init();
133   amok_hm_init();
134
135   gras_socket_server(3333); /* only so that messages from the transport layer in gras identify us */
136
137   //env_Pairwisehost_bw(argc,argv);
138   //env_hosttohost_bw(argc,argv);
139
140   gras_exit();
141   return 0;
142
143 }