]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c
b9d34e94c2edbd58f892eb74dabcf166ad386b82
[frescor/fna.git] / tests / tests_frescan / test_frescan_bwres_negotiate_in_master.c
1 #include <stdio.h>  // perror
2 #include <stdlib.h> // exit
3 #include <unistd.h>   // sleep
4
5 #include "frsh.h"
6
7 #include "frescan.h"
8 #include "frescan_bwres.h"
9 #include "frescan_servers.h"
10
11 #define PUT_ERROR(s) {perror (s); exit (-1);}
12
13 #define NETWORK 0
14 #define LOCAL_NODE 0
15
16 int main ()
17 {
18         int ret;
19         frescan_init_params_t init_params;
20         frescan_ss_t ss;
21         frsh_contract_t contract;
22         bool accepted;
23         frescan_server_params_t server_params;
24         frsh_rel_time_t budget_min, period_max;
25
26         init_params.net = NETWORK;
27         init_params.node = LOCAL_NODE;
28         init_params.tx_fp_max_prio = 10;
29         init_params.rx_num_of_channels = 10;
30         init_params.rx_channel_max_prio = NULL;
31
32         printf("Initializing FRESCAN\n");
33         ret = frescan_init(&init_params);
34         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
35
36         printf("Initializing BWRES\n");
37         ret = frescan_bwres_init(NETWORK);
38         if (ret != 0) PUT_ERROR ("could not init BWRES");
39
40         printf("Creating contract\n");
41
42         ret = frsh_contract_init(&contract);
43         if (ret != 0) PUT_ERROR ("could not init contract");
44
45         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
46         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
47
48         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
49
50         ret = frsh_contract_set_basic_params
51                         (&contract,
52                          &budget_min,
53                          &period_max,
54                          FRSH_WT_INDETERMINATE,
55                          FRSH_CT_REGULAR);
56         if (ret != 0) PUT_ERROR ("could not set basic params");
57
58 #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
59         printf("Setting preemption level manually to the contract\n");
60         ret = frsh_contract_set_preemption_level(&contract, 7);
61         if (ret != 0) PUT_ERROR ("could not set preemption level");
62 #endif
63
64         printf("Negotiating contract\n");
65
66         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
67         if (ret != 0) PUT_ERROR ("could not negotiate");
68
69         if (accepted) {
70                 printf("The contract was accepted, ss:%u\n", ss);
71                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
72                 if (ret != 0) PUT_ERROR ("could not get servers data");
73
74                 printf("B:%u, T=(%u,%u), P:%u\n",
75                        server_params.budget,
76                        server_params.period.tv_sec,
77                        server_params.period.tv_nsec,
78                        server_params.prio);
79         } else {
80                 printf("The contract was not accepted\n");
81         }
82
83         while (1) {
84                 sleep(1);
85         }
86
87         return 0;
88 }