00001 #include <linux/aquosa/qsup.h>
00002
00003 #include <linux/aquosa/qos_debug.h>
00004 #include <math.h>
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 typedef double pair_t[2];
00018
00019 pair_t bw_requests[] = {
00020
00021 { 0.1, 0.3 },
00022
00023 { 0.3, 0.3 },
00024
00025 { 0.2, 0.4 },
00026
00027 { 0.4, 0.4 },
00028
00029 { 0.3, 0.5 },
00030
00031 { 0.0, 0.0 },
00032 };
00033
00034 pair_t bw_approved[] = {
00035 { 0.1, 0.3 },
00036 { 0.3*0.5/(0.3+0.3), 0.3*0.5/(0.3+0.3) },
00037 { 0.2*0.5/(0.2+0.4), 0.4*0.5/(0.2+0.4) },
00038 { 0.4*0.5/(0.4+0.4), 0.4*0.5/(0.4+0.4) },
00039 { 0.3*0.5/(0.3+0.5), 0.5*0.5/(0.3+0.5) },
00040 { 0.0, 0.0 },
00041 };
00042
00043 #define P 10000
00044 #define build_params(req_bw, min_bw, flags) (& ((qres_params_t) { bw2Q(min_bw, P), bw2Q(req_bw, P), P, flags }) )
00045 #define build_constr(l, w, max_bw, max_min_bw, flags) (& ((qsup_constraints_t) { l, w, max_bw, max_min_bw, flags }))
00046
00047 double tolerance = 0.0001;
00048
00049 int main(int argc, char *argv[]) {
00050 int err = 0;
00051 unsigned int n;
00052 qsup_server_t *srv0, *srv1;
00053
00054 qos_log_debug("Initing...");
00055 qsup_init();
00056
00057 qsup_add_level_rule(0, d2bw(0.75));
00058
00059 qsup_add_user_constraints(0, build_constr(0, 1, d2bw(0.5), d2bw(0.0), 0));
00060
00061 qos_chk_ok_exit(qsup_create_server(&srv0, 0, 0, build_params(0, d2bw(0.0), 0)));
00062 qos_chk_ok_exit(qsup_create_server(&srv1, 0, 0, build_params(0, d2bw(0.0), 0)));
00063
00064 qsup_dump();
00065
00066 for (n = 0; n < sizeof(bw_requests) / sizeof(pair_t); n++) {
00067 qsup_set_required_bw(srv0, d2bw(bw_requests[n][0]));
00068 qsup_set_required_bw(srv1, d2bw(bw_requests[n][1]));
00069 if (
00070 (fabs(bw2d(qsup_get_approved_bw(srv0)) - bw_approved[n][0]) > tolerance)
00071 || (fabs(bw2d(qsup_get_approved_bw(srv1)) - bw_approved[n][1]) > tolerance)
00072 ) {
00073 qos_log_err("Requests were %g, %g. Expecting %g, %g while got %g, %g.",
00074 bw_requests[n][0], bw_requests[n][1],
00075 bw_approved[n][0], bw_approved[n][1],
00076 bw2d(qsup_get_approved_bw(srv0)), bw2d(qsup_get_approved_bw(srv1)));
00077 err = -1;
00078 }
00079 }
00080
00081 qsup_dump();
00082
00083 qos_log_debug("Destroying servers (latest to earliest)");
00084 qos_chk_ok_exit(qsup_destroy_server(srv1));
00085 qos_chk_ok_exit(qsup_destroy_server(srv0));
00086
00087 qos_log_debug("Cleaning up supervisor");
00088 qsup_cleanup();
00089
00090 return err;
00091 }