1 //----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 by the FRESCOR consortium:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
18 // The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // This file is part of FNA (Frescor Network Adaptation)
33 // FNA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version. FNA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FNA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
44 // As a special exception, including FNA header files in a file,
45 // instantiating FNA generics or templates, or linking other files
46 // with FNA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
58 * The goal of this program is to test the RTEP implementation of the functions
59 * defined at fna.h without passing through the FRSH interface.
63 * We have two nodes, a sender and a receiver. The sender negotiates a contract,
64 * send info to the receiver, then renegotiates the contract and finally it
65 * cancels the contract.
69 #include <assert.h> // for assert
70 #include <stdio.h> // for printf
71 #include <time.h> // for timespec
73 #include "frsh.h" // for frsh_contract_set_xxx, FRSH_NETWORK_ID_DEFAULT, frsh_network_address_t, frsh_stream_id_t
75 #include "fna.h" // for fna_vres_id_t
76 #include "frsh_fna.h" // for frsh_rtep_*
77 #include "rtep_fna.h" // for rtep_fna_operations
79 #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
84 rtep_station_id_t me, normal_station, multicast_station;
85 frsh_network_address_t frsh_address;
86 char multicast_name[] = "broadcast";
87 size_t max_size, max_multicast_size, budget_bytes, nbytes;
88 struct timespec budget_timespec, period_max;
89 frsh_contract_t frsh_contract;
91 fna_endpoint_data_t endpoint;
92 const int MSG_BUFFER_MX = 10;
93 char msg_buffer[MSG_BUFFER_MX];
97 printf("--------------------------------------------------\n");
98 printf("1.- fna_init\n");
99 printf("--------------------------------------------------\n");
100 err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
103 printf("--------------------------------------------------\n");
104 printf("2.- fna_network_get_max_message_size\n");
105 printf("--------------------------------------------------\n");
106 // get broadcast address for FRESCOR
107 multicast_station = rtep_get_station_id_by_name
108 ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
110 err = frsh_rtep_map_network_address
111 (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
114 // maximum size per message for a broadcast address
115 err=rtep_fna_operations.fna_network_get_max_message_size
116 (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
117 printf("Max multicast message size: %d\n", max_multicast_size);
119 assert (max_multicast_size == MULTICAST_MTU);
121 // now the same with a normal address (i.e: 2)
123 err=frsh_rtep_map_network_address
124 (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
127 // maximum size per message for a normal address
128 err=rtep_fna_operations.fna_network_get_max_message_size
129 (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
130 printf("Max message size: %d\n", max_size);
132 assert (max_size == MAX_RTEP_MTU);
134 printf("--------------------------------------------------\n");
135 printf("3.- fna_network_budget_to_bytes\n");
136 printf("--------------------------------------------------\n");
138 err=rtep_fna_operations.fna_network_bytes_to_budget
139 (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
142 err=rtep_fna_operations.fna_network_budget_to_bytes
143 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
145 printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
147 printf("--------------------------------------------------\n");
148 printf("4.- fna_network_get_min_effective_budget\n");
149 printf("--------------------------------------------------\n");
150 err=rtep_fna_operations.fna_network_get_min_eff_budget
151 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
154 err=rtep_fna_operations.fna_network_budget_to_bytes
155 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
157 printf("Minimum effective budget: %d\n", budget_bytes);
160 me = rtep_get_station_id();
164 printf("--------------------------------------------------\n");
165 printf("5.- fna_contract_negotiate\n");
166 printf("--------------------------------------------------\n");
168 period_max.tv_sec = 3;
169 period_max.tv_nsec = 0;
171 // Create the contract
172 frsh_contract.workload = FRSH_WT_INDETERMINATE;
173 frsh_contract.granularity = FRSH_DEFAULT_GRANULARITY;
174 frsh_contract.weight = FRSH_DEFAULT_WEIGHT;
175 frsh_contract.importance = FRSH_DEFAULT_IMPORTANCE;
176 frsh_contract.resource_id = FRSH_RESOURCE_ID_DEFAULT;
177 frsh_contract.resource_type = FRSH_RT_NETWORK;
179 frsh_contract.budget_min = budget_timespec;
180 frsh_contract.period_max = period_max;
181 frsh_contract.d_equals_t = true;
182 frsh_contract.preemption_level = 4;
184 // Negotiate the contract
185 err = rtep_fna_operations.fna_contract_negotiate
186 (FRSH_RESOURCE_ID_DEFAULT, &frsh_contract, &vres);
188 printf("Contract accepted\n");
190 // Bind the vres to an endpoint
191 endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
192 endpoint.vres = vres;
193 endpoint.is_bound = true;
194 endpoint.destination = 2; // only for send_endpoints
195 endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
196 endpoint.stream_id = 7;
202 printf("sending message\n");
204 msg_counter = msg_counter + 1;
205 msg_size = snprintf(msg_buffer, MSG_BUFFER_MX-1, "MSG %d", msg_counter);
207 err = rtep_fna_operations.fna_send_async
208 (&endpoint, msg_buffer, msg_size);
212 size_t received_bytes;
213 frsh_network_address_t from;
215 endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
216 endpoint.is_bound = false;
217 endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
218 endpoint.stream_id = 7;
221 printf("blocking to receive\n");
222 err = rtep_fna_operations.fna_receive_sync
223 (&endpoint, msg_buffer, MSG_BUFFER_MX, &received_bytes, &from);
226 msg_buffer[received_bytes] = '\0';
228 printf("msg received: %s\n", msg_buffer);