]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_frescan/test_frescan_bwres_negotiate_in_master.c
add the infraestructure for storing the negotiated contracts and performing the analy...
[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 "frescan.h"
6 #include "frescan_bwres.h"
7
8 #define ERROR(s) {perror (s); exit (-1);}
9
10 #define NETWORK 0
11 #define LOCAL_NODE 0
12
13 int main ()
14 {
15         int ret;
16         frescan_init_params_t init_params;
17         frescan_ss_t ss;
18         frescan_contract_t contract;
19         bool accepted;
20         frescan_server_params_t server_params;
21
22         init_params.net = NETWORK;
23         init_params.node = LOCAL_NODE;
24         init_params.tx_fp_max_prio = 10;
25         init_params.rx_num_of_channels = 10;
26         init_params.rx_channel_max_prio = NULL;
27
28         printf("Initializing FRESCAN\n");
29         ret = frescan_init(&init_params);
30         if (ret != 0) ERROR ("could not init FRESCAN");
31
32         printf("Initializing BWRES\n");
33         ret = frescan_bwres_init(NETWORK);
34         if (ret != 0) ERROR ("could not init BWRES");
35
36         contract.min_values.budget = 5;
37         contract.min_values.period.tv_sec  = 3;
38         contract.min_values.period.tv_nsec = 69;
39         contract.prio = 7;
40
41         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
42         if (ret != 0) ERROR ("could not negotiate");
43
44         if (accepted) {
45                 printf("The contract was accepted, ss:%u\n", ss);
46                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
47                 if (ret != 0) ERROR ("could not get servers data");
48
49                 printf("B:%u, T=(%u,%u), P:%u\n",
50                        server_params.values.budget,
51                        server_params.values.period.tv_sec,
52                        server_params.values.period.tv_nsec,
53                        server_params.prio);
54         } else {
55                 printf("The contract was not accepted\n");
56         }
57
58         while (1) {
59                 sleep(1);
60         }
61
62         return 0;
63 }
64
65