]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - resources/cluster_tree/frm_cluster_tree.c
Merge branch 'master' of rtime.felk.cvut.cz:/var/git/frescor/frsh_forb.git
[frescor/frsh.git] / resources / cluster_tree / frm_cluster_tree.c
1 #include <frm_generic.h>
2 #include <forb.h>
3 #include <error.h>
4 #include <errno.h>
5 #include <fres_sa_scenario.h>
6 #include <stdbool.h>
7 #include <ul_log.h>
8 #include <stdio.h>
9 #include <frsh_distributed.h>
10 #include "functions.h"
11 #include <cluster_tree.h>
12
13 struct cluster_tree {
14         TOPOLOGY_PARAMS topology;
15 };
16
17 struct cluster_tree configuration = {
18         .topology = {
19                 .max_routers = 2,
20                 .max_end_nodes = 3,
21                 .height = 3,
22                 .h_sink = 2,
23                 .BO = 6,
24                 .SO = 2,
25                 .L_CFP = 14,
26                 .sensing_cap = FALSE,
27         }
28 };
29
30
31 int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedulable)
32 {
33         struct cluster_tree *configuration = priv;
34         TOPOLOGY_PARAMS *topology = &configuration->topology;
35         struct fres_sa_contract *c;
36         APPLICATION_PARAMS application_params;
37         int i, ret;
38         OUTPUT_PARAMS output_params;
39
40         application_params.ack_enable = FALSE;
41         application_params.mpdu = 120;
42         application_params.number_of_alfas = scenario->num_contracts;
43
44         application_params.alfa_data =
45                 (ALFA *)malloc((application_params.number_of_alfas)*sizeof(ALFA));
46         if (application_params.alfa_data == NULL) return -1;
47
48         i = 0;
49         fres_sa_scenario_for_each_contract(scenario, c) {
50                 fres_block_cluster_tree_traffic *traffic;
51                 ALFA *alfa = &application_params.alfa_data[i++];
52                 traffic = fres_contract_get_block(c->contract,
53                                                   FRES_BLOCK_CLUSTER_TREE_TRAFFIC);
54                 alfa->r = traffic->r;
55                 alfa->b = traffic->b;
56         }
57         output_params.buffer_requirements =
58                 (int *) malloc((topology->height+topology->h_sink+2)*sizeof(int));
59         if (output_params.buffer_requirements == NULL)
60                 return -1;
61
62         output_params.number_of_time_slots =
63                 (int *) malloc((topology->height+topology->h_sink)*sizeof(int));
64         if(output_params.number_of_time_slots == NULL) 
65                 return -1;
66
67         /* Call the real admission test */
68         ret = ct_wsn(*topology, application_params, &output_params);
69         if(ret == -1)
70         {
71                 *schedulable = false;
72                 printf("error-code: %d\n", output_params.error_params.error_code);
73         } else {
74                 /* TODO: Compare deadlines with the result */
75                 *schedulable = true;
76         }
77
78         free((void *)output_params.number_of_time_slots);
79         free((void *)output_params.buffer_requirements);
80         free((void *)application_params.alfa_data);
81                 
82         return 0;
83 }
84
85 static const struct fres_res_manager frm = {
86         .res_type = FRSH_RT_NETWORK,
87         .res_id = FRSH_NETPF_CLUSTER_TREE,
88         .admission_test = admission_test,
89         .priv = &configuration,
90 };
91
92
93 int main(int argc, char *argv[])
94 {
95         forb_orb orb;
96         int ret;
97
98         orb = forb_init(&argc, &argv, "frm_cluster_tree");
99         if (!orb) error(1, errno, "forb_init");
100
101         fres_block_register_cluster_tree();
102
103         ret = frm_register_and_run(orb, &frm);
104
105         if (ret != 0) {
106                 error(1, errno, "frm_generic_run failed");
107         }
108         
109         return 0;
110 }