]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
Tested every subtask for fwp_admctrl
authorTuka Martin <tukamart@fel.cvut.cz>
Tue, 26 Apr 2011 13:01:22 +0000 (15:01 +0200)
committerTuka Martin <tukamart@fel.cvut.cz>
Tue, 26 Apr 2011 13:01:22 +0000 (15:01 +0200)
Added interface.

src/fwp/fwp/mngr/fwp_admctrl.c
src/fwp/fwp/mngr/test/fwp_adm_test.c

index 2ad559ddea9e522241b5bd2b5f729d7ec7e34f01..6d62e6a228d76b82da67397bd3cbcbd2492b19fd 100644 (file)
@@ -246,7 +246,8 @@ int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
                        fres_contract_add_block(c->contract, FRES_BLOCK_FWP_SCHED, fwp_sched);
                }
 
-               utilization += /*(long long)*/duration_usec * 10000 / period_usec;
+               utilization += (long long)duration_usec * 10000 / period_usec;
+
        }
        
        if (utilization >= 10000 * 96/100 && !pr->bypass) {
index f632ef621d71ab315b93a411a257c13599397172..9a8be266c455d7e988a6b3e8ecd440d53f87b214 100644 (file)
@@ -1,13 +1,18 @@
-#include <fres_contract.h>
-#include <fres_blocks.h>
-#include <fres_contract_type.h>
+/*
+ *     @brief test of fwp_admctrl_utilization function
+ *
+ *     program fills scenario with 3 contracts and calls fwp_adm_ctrl_util function
+ *     results are compared with expected
+ *
+ */
+
 #include <fres_sa_scenario.h>
 #include <fwp_res.h>
 #include <fwp_vres.h>
-#include <string.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <wvtest.h>
+#include <frsh.h>
 
 typedef struct fwp_sta {
        long long client_mac_addr;
@@ -43,178 +48,256 @@ struct frm_fwp_priv priv = {
 //     .list_head = NULL,//head of linked list initialized in main function
 };
 
-int main(void)
+struct stream_params {
+       int id;
+       int budget1;
+       int period_ms1;
+       int budget2;
+       int period_ms2;
+       int budget3;
+       int period_ms3;
+       int async;
+       int number;
+       int count;
+       long long mac_address1;
+       long long mac_address2;
+       long long mac_address3;
+};
+
+int fwp_admctrl_utilization_test(struct stream_params *p)
 {
-       fwp_sta_t *new_to_add1,*new_to_add2,*new_to_add3;
+       frsh_contract_t contract1;
+       frsh_contract_t contract2;
+       frsh_contract_t contract3;
+       int ret;
+       frsh_rel_time_t period1;
+       frsh_rel_time_t period2;
+       frsh_rel_time_t period3;
+       frsh_rel_time_t budget1;
+       frsh_rel_time_t budget2;
+       frsh_rel_time_t budget3;
+       frsh_rel_time_t deadline1;
+       frsh_rel_time_t deadline2;
+       frsh_rel_time_t deadline3;
+       
        bool schedulable;
-       int num_of_contract1 = 1;
-       int *p_num_of_contract1 = &num_of_contract1;
-       int num_of_contract2 = 2;
-       int *p_num_of_contract2 = &num_of_contract2;
-       int num_of_contract3 = 3;
-       int *p_num_of_contract3 = &num_of_contract3;
 
+       fres_block_fwp_sched *fwp_sched;
+       fwp_sta_t new_to_add1, new_to_add2, new_to_add3;
+       
+       /* define scenario and its contracts */
+       struct fres_sa_scenario * scenario = fres_sa_scenario_new();
+       if(scenario == NULL) PERROR_AND_EXIT(-1, "fres_sa_scenario_new");
+
+       struct fres_sa_contract * c1 = fres_sa_contract_new();
+       if(c1 == NULL) PERROR_AND_EXIT(-1, "fres_sa_contract_new");
+
+       struct fres_sa_contract * c2 = fres_sa_contract_new();
+       if(c2 == NULL) PERROR_AND_EXIT(-1, "fres_sa_contract_new");
+
+       struct fres_sa_contract * c3 = fres_sa_contract_new();
+       if(c3 == NULL) PERROR_AND_EXIT(-1, "fres_sa_contract_new");
+
+       /* initialization of contracts */
+       ret = frsh_contract_init(&contract1);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+       ret = frsh_contract_init(&contract2);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+       ret = frsh_contract_init(&contract3);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+
+       /* set resource and label of contracts */
+       ret = frsh_contract_set_resource_and_label(
+               &contract1,
+               FRSH_RT_NETWORK, FRSH_NETPF_FWP,
+               NULL);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+       ret = frsh_contract_set_resource_and_label(
+               &contract2,
+               FRSH_RT_NETWORK, FRSH_NETPF_FWP,
+               NULL);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+       ret = frsh_contract_set_resource_and_label(
+               &contract3,
+               FRSH_RT_NETWORK, FRSH_NETPF_FWP,
+               NULL);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+       /* set basic parameters of contracts */
+       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, p->budget1, &budget1);
+       period1 = fosa_msec_to_rel_time(p->period_ms1);
+       ret = frsh_contract_set_basic_params(&contract1,
+                                            &budget1,
+                                            &period1,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, p->budget2, &budget2);
+       period2 = fosa_msec_to_rel_time(p->period_ms2);
+       ret = frsh_contract_set_basic_params(&contract2,
+                                            &budget2,
+                                            &period2,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+       frsh_network_bytes_to_budget(FRSH_NETPF_FWP, p->budget3, &budget3);
+       period3 = fosa_msec_to_rel_time(p->period_ms3);
+       ret = frsh_contract_set_basic_params(&contract3,
+                                            &budget3,
+                                            &period3,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+
+       /* FWP doesn't accept smaller deadlines than 30 ms. */
+       if ((frsh_rel_time_smaller(period1, frsh_msec_to_rel_time(30))) || (frsh_rel_time_smaller(period2, frsh_msec_to_rel_time(30))) || (frsh_rel_time_smaller(period3, frsh_msec_to_rel_time(30))))
+               deadline1 = deadline2 = deadline3 = frsh_msec_to_rel_time(30);
+       else
+       {       deadline1 = period1;
+               deadline2 = period2;
+               deadline3 = period3;
+       }
+       ret = frsh_contract_set_timing_reqs(&contract1, false, &deadline1);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
+       ret = frsh_contract_set_timing_reqs(&contract2, false, &deadline2);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
+       ret = frsh_contract_set_timing_reqs(&contract3, false, &deadline3);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
+               
+       /* set fwp parameters of contract */
        fres_block_fwp *fwp_block1 = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
+       if(!fwp_block1) PERROR_AND_EXIT(ret, "malloc for adding fwp_block");
        fres_block_fwp *fwp_block2 = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
+       if(!fwp_block2) PERROR_AND_EXIT(ret, "malloc for adding fwp_block");
        fres_block_fwp *fwp_block3 = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
-
-       struct fres_sa_scenario *scenario = (struct fres_sa_scenario*)malloc(sizeof(struct fres_sa_scenario));
-       scenario = fres_sa_scenario_new();
-       struct fres_sa_contract * contract1 = (struct fres_sa_contract*)malloc(sizeof(struct fres_sa_contract));
-       contract1 = fres_sa_contract_new();
-       struct fres_sa_contract *contract2 = (struct fres_sa_contract*)malloc(sizeof(struct fres_sa_contract));
-       contract2 = fres_sa_contract_new();
-       struct fres_sa_contract *contract3 = (struct fres_sa_contract*)malloc(sizeof(struct fres_sa_contract));
-       contract3 = fres_sa_contract_new();
-
-       struct fres_contract * c1 = (struct fres_contract*)malloc(sizeof(struct fres_contract));
-       c1 = fres_contract_new();
-       struct fres_contract *c2 = (struct fres_contract*)malloc(sizeof(struct fres_contract));
-       c2 = fres_contract_new();
-       struct fres_contract *c3 = (struct fres_contract*)malloc(sizeof(struct fres_contract));
-       c3 = fres_contract_new();
-
-       fres_block_label *label = (fres_block_label*)malloc(sizeof(fres_block_label));
-       fres_block_resource *resource = (fres_block_resource*)malloc(sizeof(fres_block_resource));
-       fres_block_basic *basic = (fres_block_basic*)malloc(sizeof(fres_block_basic));
-       fres_block_timing_reqs *timing_reqs = (fres_block_timing_reqs*)malloc(sizeof(fres_block_timing_reqs));
-
-       fres_block_label *label2 = (fres_block_label*)malloc(sizeof(fres_block_label));
-       fres_block_resource *resource2 = (fres_block_resource*)malloc(sizeof(fres_block_resource));
-       fres_block_basic *basic2 = (fres_block_basic*)malloc(sizeof(fres_block_basic));
-       fres_block_timing_reqs *timing_reqs2 = (fres_block_timing_reqs*)malloc(sizeof(fres_block_timing_reqs));
-
-       fres_block_label *label3 = (fres_block_label*)malloc(sizeof(fres_block_label));
-       fres_block_resource *resource3 = (fres_block_resource*)malloc(sizeof(fres_block_resource));
-       fres_block_basic *basic3 = (fres_block_basic*)malloc(sizeof(fres_block_basic));
-       fres_block_timing_reqs *timing_reqs3 = (fres_block_timing_reqs*)malloc(sizeof(fres_block_timing_reqs));
-
-       fres_block_fwp_sched *fwp_sched = (fres_block_fwp_sched*)malloc(sizeof(fres_block_fwp_sched));
-
-       fres_block_register_fwp();
-
-       /*Create contracts*/
-       strcpy(label->label, "Contract1");
-       fres_contract_add_label(c1, label);
-       resource->resource_type = FRSH_RT_NETWORK;
-       resource->resource_id = 1;
-       fres_contract_add_resource(c1, resource);
-
-       basic->budget = fosa_msec_to_rel_time(10);
-       basic->period = fosa_msec_to_rel_time(100);
-       basic->workload = FRSH_WT_SYNCHRONIZED;
-       basic->contract_type = FRSH_CT_REGULAR;
-       fres_contract_add_basic(c1, basic);
-
-       timing_reqs->d_equals_t = CORBA_FALSE;
-       timing_reqs->deadline = fosa_msec_to_rel_time(50);
-       fres_contract_add_timing_reqs(c1, timing_reqs);
-
-       strcpy(label2->label, "Contract2");
-       fres_contract_add_label(c2, label2);
-       resource2->resource_type = FRSH_RT_NETWORK;
-       resource2->resource_id = 12;
-       fres_contract_add_resource(c2, resource2);
-
-       basic2->budget = fosa_msec_to_rel_time(100);
-       basic2->period = fosa_msec_to_rel_time(1000);
-       basic2->workload = FRSH_WT_SYNCHRONIZED;
-       basic2->contract_type = FRSH_CT_REGULAR;
-       fres_contract_add_basic(c2, basic2);
-
-       timing_reqs2->d_equals_t = CORBA_FALSE;
-       timing_reqs2->deadline = fosa_msec_to_rel_time(1100);
-       fres_contract_add_timing_reqs(c2, timing_reqs2);
-
-       strcpy(label3->label, "Contract3");
-       fres_contract_add_label(c3, label3);
-       resource3->resource_type = FRSH_RT_NETWORK;
-       resource3->resource_id = 12;
-       fres_contract_add_resource(c3, resource3);
-
-       basic3->budget = fosa_msec_to_rel_time(100);
-       basic3->period = fosa_msec_to_rel_time(100);
-       basic3->workload = FRSH_WT_SYNCHRONIZED;
-       basic3->contract_type = FRSH_CT_REGULAR;
-       fres_contract_add_basic(c3, basic3);
-
-       timing_reqs3->d_equals_t = CORBA_FALSE;
-       timing_reqs3->deadline = fosa_msec_to_rel_time(100);
-       fres_contract_add_timing_reqs(c3, timing_reqs3);
-
-       /*Add mac address for each contract*/
-       fwp_block1->mac_address = 1;
-       fres_contract_add_block(c1, FRES_BLOCK_FWP, fwp_block1);
-       fwp_block2->mac_address = 2;
-       fres_contract_add_block(c2, FRES_BLOCK_FWP, fwp_block2);
-       fwp_block3->mac_address = 3;
-       fres_contract_add_block(c3, FRES_BLOCK_FWP, fwp_block3);
-
-       /*Add id for each contract*/
-       fres_contract_id_t *id1 = (fres_contract_id_t *)malloc(sizeof(fres_contract_id_t));;
-       *id1 = *p_num_of_contract1;
-       fres_contract_id_t *id2 = (fres_contract_id_t *)malloc(sizeof(fres_contract_id_t));;
-       *id2 = *p_num_of_contract2;
-       fres_contract_id_t *id3 = (fres_contract_id_t *)malloc(sizeof(fres_contract_id_t));;
-       *id3 = *p_num_of_contract3;
+       if(!fwp_block3) PERROR_AND_EXIT(ret, "malloc for adding fwp_block");
        
+       /*Add mac address for each contract*/
+       fwp_block1->mac_address = p->mac_address1;
+       ret = fres_contract_add_block(contract1, FRES_BLOCK_FWP, fwp_block1);
+       if (ret) PERROR_AND_EXIT(ret, "fres_contract_add_fwp_block");
+       fwp_block2->mac_address = p->mac_address2;
+       ret = fres_contract_add_block(contract2, FRES_BLOCK_FWP, fwp_block2);
+       if (ret) PERROR_AND_EXIT(ret, "fres_contract_add_fwp_block");
+       fwp_block3->mac_address = p->mac_address3;
+       ret = fres_contract_add_block(contract3, FRES_BLOCK_FWP, fwp_block3);
+       if (ret) PERROR_AND_EXIT(ret, "fres_contract_add_fwp_block");
+
+       /* set id of contracts */
+       int *id1 = (int*)malloc(sizeof(int));
+       if(!id1) PERROR_AND_EXIT(errno, "malloc");
+       int *id2 = (int*)malloc(sizeof(int));
+       if(!id2) PERROR_AND_EXIT(errno, "malloc");
+       int *id3 = (int*)malloc(sizeof(int));
+       if(!id3) PERROR_AND_EXIT(errno, "malloc");
+       *id1 = 1;
+       *id2 = 2;
+       *id3 = 3;
+
+       c1->contract = c1->new = contract1;
        c1->id = *id1;
+       c2->contract = c2->new = contract2;
        c2->id = *id2;
+       c3->contract = c3->new = contract3;
        c3->id = *id3;
 
-       contract1->contract = contract1->new = c1;
-       contract1->id = *id1;
-       contract2->contract = contract2->new = c2;
-       contract2->id = *id2;
-       contract3->contract = contract3->new = c3;
-       contract3->id = *id3;
-
-       fres_sa_scenario_add_contract(scenario, contract1);
-       fres_sa_scenario_add_contract(scenario, contract2);
-       fres_sa_scenario_add_contract(scenario, contract3);
-
-       /*Information about stations*/
-       sta_list_init_head(&priv.sta_list);
+       /* add contracts to scenario */
+       ret = fres_sa_scenario_add_contract(scenario, c1);
+       if(ret != 0) PERROR_AND_EXIT(ret, "fres_sa_scenario_add_contract");
+       ret = fres_sa_scenario_add_contract(scenario, c2);
+       if(ret != 0) PERROR_AND_EXIT(ret, "fres_sa_scenario_add_contract");
+       ret = fres_sa_scenario_add_contract(scenario, c3);
+       if(ret != 0) PERROR_AND_EXIT(ret, "fres_sa_scenario_add_contract");
+
+       /* create conditions of network (mac address and rate) */
+       new_to_add1.rate = 1;
+       new_to_add1.client_mac_addr = p->mac_address1;
+       sta_list_ins_tail(&priv.sta_list, &new_to_add1);
+       new_to_add2.rate = 64;
+       new_to_add2.client_mac_addr = p->mac_address2;
+       sta_list_ins_tail(&priv.sta_list, &new_to_add2);
+       new_to_add3.rate = 18;
+       new_to_add3.client_mac_addr = p->mac_address3;
+       sta_list_ins_tail(&priv.sta_list, &new_to_add3);
        
-       new_to_add1 = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
-       new_to_add2 = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
-       new_to_add3 = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
-       new_to_add1->rate = 1;
-       new_to_add1->client_mac_addr = 1;
-       sta_list_ins_tail(&priv.sta_list, new_to_add1);
-       new_to_add2->rate = 64;
-       new_to_add2->client_mac_addr = 2;
-       sta_list_ins_tail(&priv.sta_list, new_to_add2);
-       new_to_add3->rate = 16;
-       new_to_add3->client_mac_addr = 3;
-       sta_list_ins_tail(&priv.sta_list, new_to_add3);
-
-       /*Tested  function*/
-       fwp_admctrl_utilization(scenario, &priv, &schedulable);
-
-       /*Check results*/
-       contract1 = fres_sa_scenario_find_contract(scenario, id1);
-       contract2 = fres_sa_scenario_find_contract(scenario, id2);
-       contract3 = fres_sa_scenario_find_contract(scenario, id3);
-
-       fwp_sched = fres_contract_get_block(contract1->contract, FRES_BLOCK_FWP_SCHED);
+       /* tested function */
+       ret = fwp_admctrl_utilization(scenario, &priv, &schedulable);
+       if(ret != 0) PERROR_AND_EXIT(ret, "fwp_admctrl_utilization");
+
+       /* checked results */
+       c1 = fres_sa_scenario_find_contract(scenario, (fres_contract_id_t *)id1);
+       if(!c1) PERROR_AND_EXIT(ret, "fres_sa_scenario_find_contract");
+       fwp_sched = fres_contract_get_block(c1->contract, FRES_BLOCK_FWP_SCHED);
        if(fwp_sched != NULL) 
                WVPASSEQ(fwp_sched->ac_id, FWP_AC_VO);
        else goto not_schedulable;
-       
-       fwp_sched = fres_contract_get_block(contract2->contract, FRES_BLOCK_FWP_SCHED);
+
+       c2 = fres_sa_scenario_find_contract(scenario, (fres_contract_id_t *)id2);
+       if(!c2) PERROR_AND_EXIT(ret, "fres_sa_scenario_find_contract");
+       fwp_sched = fres_contract_get_block(c1->contract, FRES_BLOCK_FWP_SCHED);
        if(fwp_sched != NULL) 
-               WVPASSEQ(fwp_sched->ac_id, FWP_AC_BK);
+               WVPASSEQ(fwp_sched->ac_id, FWP_AC_VO);
        else goto not_schedulable;
-       
-       fwp_sched = fres_contract_get_block(contract3->contract, FRES_BLOCK_FWP_SCHED);
+
+       c3 = fres_sa_scenario_find_contract(scenario, (fres_contract_id_t *)id3);
+       if(!c3) PERROR_AND_EXIT(ret, "fres_sa_scenario_find_contract");
+       fwp_sched = fres_contract_get_block(c1->contract, FRES_BLOCK_FWP_SCHED);
        if(fwp_sched != NULL) 
-               WVPASSEQ(fwp_sched->ac_id, FWP_AC_VI);
+               WVPASSEQ(fwp_sched->ac_id, FWP_AC_VO);
        else goto not_schedulable;
 
        WVPASSEQ(schedulable, 1);
 
 not_schedulable:
+       return ret;
+}
+
+
+int main(int argc, char *argv[])
+{
+       int ret;
+       int i;
+       int num = 0;
+
+       struct stream_params sp = {
+               .budget1 = 1000,
+               .period_ms1 = 20,
+               .budget2 = 500,
+               .period_ms2 = 1000,
+               .budget3 = 50,
+               .period_ms3 = 50,
+               .async = false,
+               .number = 1,
+               .count = -1,
+               .mac_address1 = 1,
+               .mac_address2 = 2,
+               .mac_address3 = 3,
+       };
+
+       struct stream_params *p[100];
+
+       memset(p, 0, sizeof(p));
+
+       ret = frsh_init();
+       if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+       
+       sta_list_init_head(&priv.sta_list);
+
+       for (i=0; i<sp.number; i++) {
+               p[num] = malloc(sizeof(*p[0]));
+               if (!p[num]) PERROR_AND_EXIT(ret, "malloc");
+               *p[num] = sp;
+               p[num]->id = num;
+               ret = fwp_admctrl_utilization_test(p[num]);
+               if (!ret)
+                       num++;
+               else {
+                       PERROR_FRESCOR(ret, "fwp_admctrl_utilization_test");
+                       free(p[num]);
+                       break;
+               }
+       }
+
        return 0;
 }