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.05, 0.05 },
00022
00023 { 0.3, 0.3 },
00024
00025 { 0.6, 0.4 },
00026
00027 { 0.0, 0.0 },
00028 };
00029
00030 pair_t bw_approved[] = {
00031 { 0.05, 0.05 },
00032 { 0.3, 0.3 },
00033 { 0.1+(0.6-0.1)/(0.6-0.1+0.4-0.1)*(0.75-0.1-0.1), 0.1+(0.4-0.1)/(0.6-0.1+0.4-0.1)*(0.75-0.1-0.1) },
00034 { 0.0, 0.0 },
00035 };
00036
00037 double tolerance = 0.0001;
00038
00039 #define P 10000
00040 #define build_params(req_bw, min_bw, flags) (& ((qres_params_t) { bw2Q(min_bw, P), bw2Q(req_bw, P), P, flags }) )
00041 #define build_constr(l, w, max_bw, max_min_bw, flags) (& ((qsup_constraints_t) { l, w, max_bw, max_min_bw, flags }))
00042
00043 int main(int argc, char *argv[]) {
00044 int err = 0;
00045 unsigned int n;
00046 qsup_server_t *srv0, *srv1;
00047
00048 qos_log_debug("Initing...");
00049 qsup_init();
00050
00051 qsup_add_level_rule(0, d2bw(0.75));
00052
00053 qsup_add_group_constraints(0, build_constr(0, 1, d2bw(0.75), d2bw(0.3), 0));
00054
00055
00056 qos_chk_exit(qsup_create_server(&srv0, 0, 0, build_params(0, d2bw(0.5), 0)) == QOS_E_UNAUTHORIZED);
00057
00058 qos_chk_ok_exit(qsup_create_server(&srv0, 0, 0, build_params(0, d2bw(0.1), 0)));
00059 qos_chk_ok_exit(qsup_create_server(&srv1, 1, 0, build_params(0, d2bw(0.1), 0)));
00060
00061 qsup_dump();
00062
00063 for (n = 0; n < sizeof(bw_requests) / sizeof(pair_t); n++) {
00064 qos_log_debug("n=%d", n);
00065 qsup_set_required_bw(srv0, d2bw(bw_requests[n][0]));
00066 qsup_set_required_bw(srv1, d2bw(bw_requests[n][1]));
00067 if (
00068 (fabs(bw2d(qsup_get_approved_bw(srv0)) - bw_approved[n][0]) > tolerance)
00069 || (fabs(bw2d(qsup_get_approved_bw(srv1)) - bw_approved[n][1]) > tolerance)
00070 ) {
00071 qos_log_err("Requests were %g, %g. Expecting %g, %g while got %g, %g.",
00072 bw_requests[n][0], bw_requests[n][1],
00073 bw_approved[n][0], bw_approved[n][1],
00074 bw2d(qsup_get_approved_bw(srv0)), bw2d(qsup_get_approved_bw(srv1)));
00075 err = -1;
00076 }
00077 }
00078
00079 qsup_dump();
00080
00081 qos_log_debug("Destroying servers (earliest to latest)");
00082 qos_chk_ok_exit(qsup_destroy_server(srv0));
00083 qos_chk_ok_exit(qsup_destroy_server(srv1));
00084
00085 qos_log_debug("Cleaning up supervisor");
00086 qsup_cleanup();
00087
00088 return err;
00089 }