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