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.
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.
18 #include <assert.h> // for assert
19 #include <stdio.h> // for printf
20 #include <time.h> // for timespec
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_*
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";
41 printf("--------------------------------------------------\n");
42 printf("1.- fna_init\n");
43 printf("--------------------------------------------------\n");
44 err=fna_init(FRSH_RESOURCE_ID_DEFAULT);
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);
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);
61 assert (max_multicast_size == MULTICAST_MTU);
63 // now the same with a normal address (i.e: 2)
65 err=frsh_rtep_map_network_address
66 (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
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);
73 assert (max_size == MAX_RTEP_MTU);
75 printf("--------------------------------------------------\n");
76 printf("3.- fna_network_budget_to_bytes\n");
77 printf("--------------------------------------------------\n");
79 err=fna_network_bytes_to_budget
80 (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
83 err=fna_network_budget_to_bytes
84 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
86 printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
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);
95 err=fna_network_budget_to_bytes
96 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
98 printf("Minimum effective budget: %d\n", budget_bytes);
100 printf("--------------------------------------------------\n");
101 printf("5.- fna_contract_negotiate\n");
102 printf("--------------------------------------------------\n");
103 err=frsh_contract_init(&frsh_contract);
106 period_max.tv_sec = 3;
107 period_max.tv_nsec = 0;
109 err=frsh_contract_set_basic_params
113 FRSH_WT_INDETERMINATE,
117 err=frsh_contract_set_resource_and_label
120 FRSH_RESOURCE_ID_DEFAULT,
124 err=fna_contract_negotiate
125 (FRSH_RESOURCE_ID_DEFAULT,