3 /* A few tests for the maxmin library */
5 /* Copyright (c) 2004 Arnaud Legrand. 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. */
14 #include "xbt/sysdep.h"
15 #include "surf/maxmin.h"
16 #include "surf/maxmin_private.h"
19 #include "xbt/module.h"
22 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
24 #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var));
28 /* ==l1== L2 ==L3== */
39 void test1(method_t method);
40 void test1(method_t method)
42 lmm_system_t Sys = NULL ;
43 lmm_constraint_t L1 = NULL;
44 lmm_constraint_t L2 = NULL;
45 lmm_constraint_t L3 = NULL;
47 lmm_variable_t R_1_2_3 = NULL;
48 lmm_variable_t R_1 = NULL;
49 lmm_variable_t R_2 = NULL;
50 lmm_variable_t R_3 = NULL;
52 if(method==LAGRANGE_VEGAS){
53 //set default functions for TCP Vegas
54 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
55 }else if(method==LAGRANGE_RENO){
56 //set default functions for TCP Reno
57 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
61 Sys = lmm_system_new();
62 L1 = lmm_constraint_new(Sys, (void *) "L1", 1.0);
63 L2 = lmm_constraint_new(Sys, (void *) "L2", 10.0);
64 L3 = lmm_constraint_new(Sys, (void *) "L3", 1.0);
66 R_1_2_3 = lmm_variable_new(Sys, (void *) "R 1->2->3", 1.0 , -1.0 , 3);
67 R_1 = lmm_variable_new(Sys, (void *) "R 1", 1.0 , -1.0 , 1);
68 R_2 = lmm_variable_new(Sys, (void *) "R 2", 1.0 , -1.0 , 1);
69 R_3 = lmm_variable_new(Sys, (void *) "R 3", 1.0 , -1.0 , 1);
71 lmm_expand(Sys, L1, R_1_2_3, 1.0);
72 lmm_expand(Sys, L2, R_1_2_3, 1.0);
73 lmm_expand(Sys, L3, R_1_2_3, 1.0);
75 lmm_expand(Sys, L1, R_1, 1.0);
77 lmm_expand(Sys, L2, R_2, 1.0);
79 lmm_expand(Sys, L3, R_3, 1.0);
89 Added the generic method to model fairness depending on the
90 transport protocol specific constraints and behavior. Protocols
91 TCP Reno and Vegas already implemented. Seems to work
92 with the testbed in src/testsuite/surf/simeng_usage. Still
93 need to be tested using a msg application.
101 }else if(method==SDP){
104 }else if(method==LAGRANGE_VEGAS){
105 //set default functions for TCP Vegas
107 }else if(method==LAGRANGE_RENO){
108 //set default functions for TCP Reno
111 xbt_assert0(0,"Invalid method");
119 lmm_system_free(Sys);
122 void test2(method_t method);
123 void test2(method_t method)
125 lmm_system_t Sys = NULL ;
126 lmm_constraint_t CPU1 = NULL;
127 lmm_constraint_t CPU2 = NULL;
129 lmm_variable_t T1 = NULL;
130 lmm_variable_t T2 = NULL;
133 if(method==LAGRANGE_VEGAS){
134 //set default functions for TCP Vegas
135 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
136 }else if(method==LAGRANGE_RENO){
137 //set default functions for TCP Reno
138 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
141 Sys = lmm_system_new();
142 CPU1 = lmm_constraint_new(Sys, (void *) "CPU1", 200.0);
143 CPU2 = lmm_constraint_new(Sys, (void *) "CPU2", 100.0);
145 T1 = lmm_variable_new(Sys, (void *) "T1", 1.0 , -1.0 , 1);
146 T2 = lmm_variable_new(Sys, (void *) "T2", 1.0 , -1.0 , 1);
148 lmm_expand(Sys, CPU1, T1, 1.0);
149 lmm_expand(Sys, CPU2, T2, 1.0);
160 }else if(method==SDP){
163 }else if(method==LAGRANGE_VEGAS){
164 //set default functions for TCP Vegas
166 }else if(method==LAGRANGE_RENO){
167 //set default functions for TCP Reno
170 xbt_assert0(0,"Invalid method");
178 lmm_system_free(Sys);
181 void test3(method_t method);
182 void test3(method_t method)
184 int flows=11; //flows and conexions are synonnims ?
185 int links=10; //topology info
187 //just to be carefull
193 lmm_system_t Sys = NULL ;
194 lmm_constraint_t *tmp_cnst = NULL;
195 lmm_variable_t *tmp_var = NULL;
199 /*array to add the the constraints of fictiv variables */
200 double B[15] = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
204 A = (double **)calloc(links+5, sizeof(double));
206 for(i=0 ; i< links+5; i++){
207 A[i] = (double *)calloc(flows+5, sizeof(double));
209 for(j=0 ; j< flows+5; j++){
212 if(i >= links || j >= flows){
218 /*matrix that store the constraints/topollogy*/
220 {{0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
221 {0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
222 {0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
223 {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
224 {1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
225 {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
226 {1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0},
227 {0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0},
228 {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
229 {0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0},
231 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
232 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
233 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
234 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
235 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
288 if(method==LAGRANGE_VEGAS){
289 //set default functions for TCP Vegas
290 lmm_set_default_protocol_functions(func_vegas_f, func_vegas_fp, func_vegas_fpi, func_vegas_fpip);
291 }else if(method==LAGRANGE_RENO){
292 //set default functions for TCP Reno
293 lmm_set_default_protocol_functions(func_reno_f, func_reno_fp, func_reno_fpi, func_reno_fpip);
296 Sys = lmm_system_new();
300 tmp_name = (char **) calloc(31, sizeof(char *));
302 tmp_name[i] = (char *) calloc(10, sizeof(char));
306 * Creates the constraints
308 tmp_cnst = calloc(15, sizeof(lmm_constraint_t));
310 sprintf(tmp_name[i], "C_%03d", i);
311 tmp_cnst[i] = lmm_constraint_new(Sys, (void *) tmp_name[i], B[i]);
316 * Creates the variables
318 tmp_var = calloc(16, sizeof(lmm_variable_t));
320 sprintf(tmp_name[i+j], "X_%03d", j);
321 tmp_var[j] = lmm_variable_new(Sys, (void *) tmp_name[i+j], 1.0, -1.0 , 15);
325 * Link constraints and variables
330 lmm_expand(Sys, tmp_cnst[i], tmp_var[j], 1.0);
340 PRINT_VAR(tmp_var[j]);
346 }else if(method==SDP){
349 }else if(method==LAGRANGE_VEGAS){
350 //set default functions for TCP Vegas
352 }else if(method==LAGRANGE_RENO){
353 //set default functions for TCP Reno
356 xbt_assert0(0,"Invalid method");
360 PRINT_VAR(tmp_var[j]);
366 lmm_system_free(Sys);
373 int main(int argc, char **argv)
375 xbt_init(&argc,argv);
377 DEBUG0("***** Test 1 (Max-Min) ***** \n");
380 DEBUG0("***** Test 1 (SDP) ***** \n");
383 DEBUG0("***** Test 1 (Lagrange - Vegas) ***** \n");
384 test1(LAGRANGE_VEGAS);
385 DEBUG0("***** Test 1 (Lagrange - Reno) ***** \n");
386 test1(LAGRANGE_RENO);
390 DEBUG0("***** Test 2 (Max-Min) ***** \n");
393 DEBUG0("***** Test 2 (SDP) ***** \n");
396 DEBUG0("***** Test 2 (Lagrange - Vegas) ***** \n");
397 test2(LAGRANGE_VEGAS);
398 DEBUG0("***** Test 2 (Lagrange - Reno) ***** \n");
399 test2(LAGRANGE_RENO);
402 DEBUG0("***** Test 3 (Max-Min) ***** \n");
405 DEBUG0("***** Test 3 (SDP) ***** \n");
408 DEBUG0("***** Test 3 (Lagrange - Vegas) ***** \n");
409 test3(LAGRANGE_VEGAS);
410 DEBUG0("***** Test 3 (Lagrange - Reno) ***** \n");
411 test3(LAGRANGE_RENO);