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