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_core.h" // for frsh_contract_set_xxx
74 #include "frsh_core_types.h" // for FRSH_NETWORK_ID_DEFAULT
75 #include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
77 #include "fna.h" // for fna_vres_id_t
78 #include "frsh_fna.h" // for frsh_rtep_*
79 #include "rtep_fna.h" // for rtep_fna_operations
81 #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
86 rtep_station_id_t me, normal_station, multicast_station;
87 frsh_network_address_t frsh_address;
88 char multicast_name[] = "broadcast";
89 size_t max_size, max_multicast_size, budget_bytes, nbytes;
90 struct timespec budget_timespec, period_max;
91 frsh_contract_t frsh_contract;
93 fna_endpoint_data_t endpoint;
94 const int MSG_BUFFER_MX = 10;
95 char msg_buffer[MSG_BUFFER_MX];
99 printf("--------------------------------------------------\n");
100 printf("1.- fna_init\n");
101 printf("--------------------------------------------------\n");
102 err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT);
105 printf("--------------------------------------------------\n");
106 printf("2.- fna_network_get_max_message_size\n");
107 printf("--------------------------------------------------\n");
108 // get broadcast address for FRESCOR
109 multicast_station = rtep_get_station_id_by_name
110 ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
112 err = frsh_rtep_map_network_address
113 (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
116 // maximum size per message for a broadcast address
117 err=rtep_fna_operations.fna_network_get_max_message_size
118 (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
119 printf("Max multicast message size: %d\n", max_multicast_size);
121 assert (max_multicast_size == MULTICAST_MTU);
123 // now the same with a normal address (i.e: 2)
125 err=frsh_rtep_map_network_address
126 (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
129 // maximum size per message for a normal address
130 err=rtep_fna_operations.fna_network_get_max_message_size
131 (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
132 printf("Max message size: %d\n", max_size);
134 assert (max_size == MAX_RTEP_MTU);
136 printf("--------------------------------------------------\n");
137 printf("3.- fna_network_budget_to_bytes\n");
138 printf("--------------------------------------------------\n");
140 err=rtep_fna_operations.fna_network_bytes_to_budget
141 (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
144 err=rtep_fna_operations.fna_network_budget_to_bytes
145 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
147 printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
149 printf("--------------------------------------------------\n");
150 printf("4.- fna_network_get_min_effective_budget\n");
151 printf("--------------------------------------------------\n");
152 err=rtep_fna_operations.fna_network_get_min_eff_budget
153 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
156 err=rtep_fna_operations.fna_network_budget_to_bytes
157 (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
159 printf("Minimum effective budget: %d\n", budget_bytes);
162 me = rtep_get_station_id();
166 printf("--------------------------------------------------\n");
167 printf("5.- fna_contract_negotiate\n");
168 printf("--------------------------------------------------\n");
170 period_max.tv_sec = 3;
171 period_max.tv_nsec = 0;
173 // Create the contract
174 frsh_contract.workload = FRSH_WT_INDETERMINATE;
175 frsh_contract.granularity = FRSH_DEFAULT_GRANULARITY;
176 frsh_contract.weight = FRSH_DEFAULT_WEIGHT;
177 frsh_contract.importance = FRSH_DEFAULT_IMPORTANCE;
178 frsh_contract.resource_id = FRSH_RESOURCE_ID_DEFAULT;
179 frsh_contract.resource_type = FRSH_RT_NETWORK;
181 frsh_contract.budget_min = budget_timespec;
182 frsh_contract.period_max = period_max;
183 frsh_contract.d_equals_t = true;
184 frsh_contract.preemption_level = 4;
186 // Negotiate the contract
187 err = rtep_fna_operations.fna_contract_negotiate
188 (FRSH_RESOURCE_ID_DEFAULT, &frsh_contract, &vres);
190 printf("Contract accepted\n");
192 // Bind the vres to an endpoint
193 endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE;
194 endpoint.vres = vres;
195 endpoint.is_bound = true;
196 endpoint.destination = 2; // only for send_endpoints
197 endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
198 endpoint.stream_id = 7;
204 printf("sending message\n");
206 msg_counter = msg_counter + 1;
207 msg_size = snprintf(msg_buffer, MSG_BUFFER_MX-1, "MSG %d", msg_counter);
209 err = rtep_fna_operations.fna_send_async
210 (&endpoint, msg_buffer, msg_size);
214 size_t received_bytes;
215 frsh_network_address_t from;
217 endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE;
218 endpoint.is_bound = false;
219 endpoint.resource_id = FRSH_RESOURCE_ID_DEFAULT;
220 endpoint.stream_id = 7;
223 printf("blocking to receive\n");
224 err = rtep_fna_operations.fna_receive_sync
225 (&endpoint, msg_buffer, MSG_BUFFER_MX, &received_bytes, &from);
228 msg_buffer[received_bytes] = '\0';
230 printf("msg received: %s\n", msg_buffer);