]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_rtep/tests/test_c_rtep_fna.c
big commint with a lot of changes, see files
[frescor/fna.git] / src_rtep / tests / test_c_rtep_fna.c
1 /*
2  * test_c_rtep_fna.c
3  *
4  * Goal:
5  *
6  * The goal of this program is to test the RTEP implementation of the functions
7  * defined at fna.h without passing through the FRSH interface.
8  *
9  * Algorithm:
10  *
11  * We have two nodes, a sender and a receiver. The sender negotiates a contract,
12  * send info to the receiver, then renegotiates the contract and finally it
13  * cancels the contract.
14  *
15  */
16
17
18 #include <assert.h> // for assert
19 #include <stdio.h> // for printf
20 #include <time.h> // for timespec
21
22 #include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT
23 #include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
24 #include "fna.h" // for fna_*
25 #include "frsh_fna.h" // for frsh_rtep_*
26 #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
27 #include "frsh_core.h" // for frsh_contract_*
28
29 int main ()
30 {
31    int err;
32    rtep_station_id_t normal_station, multicast_station;
33    frsh_network_address_t frsh_address;
34    char multicast_name[] = "broadcast";
35    size_t max_size, max_multicast_size, budget_bytes, nbytes;
36    struct timespec budget_timespec, period_max;
37    frsh_contract_t frsh_contract;
38    frsh_contract_label_t label = "dani";
39    fna_vres_id_t vres;
40
41    printf("--------------------------------------------------\n");
42    printf("1.- fna_init\n");
43    printf("--------------------------------------------------\n");
44    err=fna_init(FRSH_RESOURCE_ID_DEFAULT);
45    assert(err == 0);
46
47    printf("--------------------------------------------------\n");
48    printf("2.- fna_network_get_max_message_size\n");
49    printf("--------------------------------------------------\n");
50    // get broadcast address for FRESCOR
51    multicast_station = rtep_get_station_id_by_name
52          ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
53    err=frsh_rtep_map_network_address
54          (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
55    assert (err == 0);
56    // maximum size per message for a broadcast address
57    err=fna_network_get_max_message_size
58          (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
59    printf("Max multicast message size: %d\n", max_multicast_size);
60    assert (err == 0);
61    assert (max_multicast_size == MULTICAST_MTU);
62
63    // now the same with a normal address (i.e: 2)
64    normal_station = 2;
65    err=frsh_rtep_map_network_address
66          (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
67    assert (err == 0);
68    // maximum size per message for a normal address
69    err=fna_network_get_max_message_size
70          (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
71    printf("Max message size: %d\n", max_size);
72    assert (err == 0);
73    assert (max_size == MAX_RTEP_MTU);
74
75    printf("--------------------------------------------------\n");
76    printf("3.- fna_network_budget_to_bytes\n");
77    printf("--------------------------------------------------\n");
78    nbytes = 1700;
79    err=fna_network_bytes_to_budget
80          (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
81    assert (err == 0);
82
83    err=fna_network_budget_to_bytes
84          (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
85    assert (err == 0);
86    printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
87
88    printf("--------------------------------------------------\n");
89    printf("4.- fna_network_get_min_effective_budget\n");
90    printf("--------------------------------------------------\n");
91    err=fna_network_get_min_effective_budget
92          (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
93    assert (err == 0);
94
95    err=fna_network_budget_to_bytes
96          (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
97    assert (err == 0);
98    printf("Minimum effective budget: %d\n", budget_bytes);
99
100    printf("--------------------------------------------------\n");
101    printf("5.- fna_contract_negotiate\n");
102    printf("--------------------------------------------------\n");
103    err=frsh_contract_init(&frsh_contract);
104    assert (err == 0);
105
106    period_max.tv_sec = 3;
107    period_max.tv_nsec = 0;
108
109    err=frsh_contract_set_basic_params
110          (&frsh_contract,
111           &budget_timespec,
112           &period_max,
113           FRSH_WT_INDETERMINATE,
114           FRSH_CT_REGULAR);
115    assert (err == 0);
116
117    err=frsh_contract_set_resource_and_label
118          (&frsh_contract,
119           FRSH_RT_NETWORK,
120           FRSH_RESOURCE_ID_DEFAULT,
121           label);
122    assert (err == 0);
123
124    err=fna_contract_negotiate
125          (FRSH_RESOURCE_ID_DEFAULT,
126           &frsh_contract,
127           &vres);
128    assert (err == 0);
129
130    return 0;
131 }