#include <fres_contract_type.h>
#include <fres_sa_scenario.h>
#include <fwp_res.h>
+#include <fwp_vres.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <ul_list.h>
#include <ul_log.h>
#include <ul_logreg.h>
+#include <stdio.h>
+#include <wvtest.h>
typedef struct fwp_sta {
long long client_mac_addr;
int main(void)
{
- fwp_sta_t *new_to_add;
+ fwp_sta_t *new_to_add1,*new_to_add2,*new_to_add3;
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 *fwp_block = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
+ fres_block_fwp *fwp_block1 = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
+ fres_block_fwp *fwp_block2 = (fres_block_fwp*)malloc(sizeof(fres_block_fwp));
+ 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 = fres_sa_contract_new();
- struct fres_sa_contract *contract3 = 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 = fres_contract_new();
- struct fres_contract *c3 = 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_fwp_sched *fwp_sched;
+ 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");
timing_reqs->deadline = fosa_msec_to_rel_time(50);
fres_contract_add_timing_reqs(c1, timing_reqs);
- strcpy(label->label, "Contract2");
- fres_contract_add_label(c2, label);
- resource->resource_type = FRSH_RT_NETWORK;
- resource->resource_id = 12;
- fres_contract_add_resource(c2, resource);
-
- basic->budget = fosa_msec_to_rel_time(1);
- basic->period = fosa_msec_to_rel_time(100);
- basic->workload = FRSH_WT_SYNCHRONIZED;
- basic->contract_type = FRSH_CT_REGULAR;
- fres_contract_add_basic(c2, basic);
-
- timing_reqs->d_equals_t = CORBA_FALSE;
- timing_reqs->deadline = fosa_msec_to_rel_time(50);
- fres_contract_add_timing_reqs(c2, timing_reqs);
-
- strcpy(label->label, "Contract3");
- fres_contract_add_label(c3, label);
- resource->resource_type = FRSH_RT_NETWORK;
- resource->resource_id = 12;
- fres_contract_add_resource(c3, 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(c3, basic);
-
- timing_reqs->d_equals_t = CORBA_FALSE;
- timing_reqs->deadline = fosa_msec_to_rel_time(50);
- fres_contract_add_timing_reqs(c3, timing_reqs);
-
- fwp_block->mac_address = 1;
- fres_contract_add_block(c1, FRES_BLOCK_FWP, fwp_block);
- fwp_block->mac_address = 2;
- fres_contract_add_block(c2, FRES_BLOCK_FWP, fwp_block);
- fwp_block->mac_address = 3;
- fres_contract_add_block(c3, FRES_BLOCK_FWP, fwp_block);
-
- //TODO: add contract id
- //fres_contract_id_t *id;
- //id = (fres_contract_id_t *)malloc(sizeof(fres_contract_id_t));
- c1->id = 1;
- c2->id = 2;
- c3->id = 3;
+ 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;
+
+ c1->id = *id1;
+ c2->id = *id2;
+ c3->id = *id3;
contract1->contract = contract1->new = c1;
- contract1->id = 1;
+ contract1->id = *id1;
contract2->contract = contract2->new = c2;
- contract2->id = 2;
+ contract2->id = *id2;
contract3->contract = contract3->new = c3;
- contract3->id = 3;
+ 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*/
+ /*Information about stations*/
sta_list_init_head(&priv.sta_list);
- new_to_add = (fwp_sta_t*)malloc(sizeof(fwp_sta_t));
- new_to_add->rate = 1;
- new_to_add->client_mac_addr = 1;
- sta_list_ins_tail(&priv.sta_list, new_to_add);
- new_to_add->rate = 64;
- new_to_add->client_mac_addr = 2;
- sta_list_ins_tail(&priv.sta_list, new_to_add);
- new_to_add->rate = 16;
- new_to_add->client_mac_addr = 3;
- sta_list_ins_tail(&priv.sta_list, new_to_add);
-
- /* tested function */
+ 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);
- /* TODO: print results
- contract1 = fres_sa_scenario_find_contract(scenario, i);
+ /*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);
- printf("%d\n", fwp_sched->ac_id);
+ 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);
- printf("%d\n", fwp_sched->ac_id);
+ if(fwp_sched != NULL)
+ WVPASSEQ(fwp_sched->ac_id, FWP_AC_BK);
+ else goto not_schedulable;
+
fwp_sched = fres_contract_get_block(contract3->contract, FRES_BLOCK_FWP_SCHED);
- printf("%d\n", fwp_sched->ac_id);
- */
+ if(fwp_sched != NULL)
+ WVPASSEQ(fwp_sched->ac_id, FWP_AC_VI);
+ else goto not_schedulable;
- if(schedulable)
- printf("ACCEPTED\n");
- else
- printf("REJECTED\n");
+ WVPASSEQ(schedulable, 1);
+not_schedulable:
return 0;
}