]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_frescan/test_frescan_bwres_negotiate_in_slave.c
small changes in tests for frescan
[frescor/fna.git] / tests / tests_frescan / test_frescan_bwres_negotiate_in_slave.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 1
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         frescan_server_params_t server_params;
23         bool accepted;
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         ret = frsh_contract_init(&contract);
41         if (ret != 0) PUT_ERROR ("could not init contract");
42
43         ret = frescan_fna_network_bytes_to_budget (NETWORK, 10, &budget_min);
44         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
45
46         period_max = frsh_msec_to_rel_time(3369); // 3,369 secs
47
48         ret = frsh_contract_set_basic_params
49                         (&contract,
50                          &budget_min,
51                          &period_max,
52                          FRSH_WT_INDETERMINATE,
53                          FRSH_CT_REGULAR);
54         if (ret != 0) PUT_ERROR ("could not set basic params");
55
56 #if !FRSH_AUTOMATIC_PRIO_ASSIGN_ENABLE
57         ret = frsh_contract_set_preemption_level(&contract, 5);
58         if (ret != 0) PUT_ERROR ("could not set preemption level");
59 #endif
60
61         printf("Negotiating a contract\n");
62         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
63         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
64
65         if (accepted) {
66                 printf("The contract was accepted, ss:%u\n", ss);
67                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
68                 if (ret != 0) PUT_ERROR ("could not get servers data");
69
70                 printf("B:%u, T=(%u,%u), P:%u\n",
71                        server_params.budget,
72                        server_params.period.tv_sec,
73                        server_params.period.tv_nsec,
74                        server_params.prio);
75         } else {
76                 printf("The contract was not accepted\n");
77         }
78
79         while (1) {
80                 sleep(1);
81         }
82
83         return 0;
84 }
85
86