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 // -----------------------------------------------------------------------
53 //==============================================
54 // ******** **** ** **
55 // **///// /**/** /** ****
56 // ** /**//** /** **//**
57 // ******* /** //** /** ** //**
58 // **//// /** //**/** **********
59 // ** /** //****/**//////**
60 // ** /** //***/** /**
63 // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
64 //==============================================================
67 * unix fna implementation
69 * In the following functions we implement a DUMMY FNA implementation without
70 * contracts or real-time requirements just for testing purposes. We provide
71 * send/receive capabilities between Linux processes through UNIX domain
74 * The goal is to run FRSH on several processes by using the Linux_lib arch
75 * of MaRTE OS or Partikle to simulate a distributed system in a single PC.
77 * The main tricks of the implementation are the following:
79 * - In Unix sockets the address is just a path (a string) so there is no
80 * such a concept of streams.
81 * - when the user negotiates a contract it must provide, as protocol
82 * dependent information, the destination so we can create and bind a
84 * - The created socket id is stored as the 'vres'
85 * - On the receiving part, when the user creates the receive endpoint, it
86 * must provide the receiving path as endpoint information so we can
87 * create a socket to receive from that path.
88 * - Both informations are passed as an integer for a static array called
89 * "the_unix_socket_paths" where we configure statically the unix paths.
90 * They are passed using the void * fields as if they where integers.
94 #include <malloc.h> /* for malloc and free */
96 #include "unix_fna.h" /* function prototypes */
98 #include <sys/socket.h>
99 #include <sys/un.h> /* struct sockaddr_un */
103 #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args)
105 #define DEBUG(x,args...)
108 //////////////////////////////////////////////////////////////////////
110 //////////////////////////////////////////////////////////////////////
112 char *the_unix_socket_paths[MX_UNIX_SOCKET_PATHS] = {
126 int unix_fna_init(const frsh_resource_id_t resource_id)
128 DEBUG("NOT IMPLEMENTED\n");
132 ///////////////////////////////////////////////////////////////////
134 ///////////////////////////////////////////////////////////////////
137 * unix_fna_contract_negotiate()
141 int unix_fna_contract_negotiate(const frsh_resource_id_t resource_id,
142 const frsh_contract_t *contract,
146 struct sockaddr_un sender_addr;
149 DEBUG("Creating and binding the unix socket\n");
151 sock = socket(AF_UNIX, SOCK_DGRAM, 0);
154 unix_path_index = (int)contract->protocol_info.body;
156 memset(&sender_addr, 0, sizeof(sender_addr));
157 sender_addr.sun_family = AF_UNIX;
158 strcpy(sender_addr.sun_path, the_unix_socket_paths[unix_path_index]);
160 err = bind(sock, (struct sockaddr *)&sender_addr, sizeof(sender_addr));
163 *vres = (fna_vres_id_t)sock;
169 * unix_fna_contract_renegotiate_sync()
173 int unix_fna_contract_renegotiate_sync(const frsh_resource_id_t resource_id,
174 const fna_vres_id_t vres,
175 const frsh_contract_t *new_contract)
177 DEBUG("NOT IMPLEMENTED\n");
182 * unix_fna_contract_renegotiate_async()
186 int unix_fna_contract_renegotiate_async(const frsh_resource_id_t resource_id,
187 const fna_vres_id_t vres,
188 const frsh_contract_t *new_contract,
189 frsh_signal_t signal_to_notify,
190 frsh_signal_info_t signal_info)
192 DEBUG("NOT IMPLEMENTED\n");
197 * unix_fna_vres_get_renegotiation_status()
201 int unix_fna_vres_get_renegotiation_status(const frsh_resource_id_t resource_id,
202 const fna_vres_id_t vres,
203 frsh_renegotiation_status_t *renegotiation_status)
205 DEBUG("NOT IMPLEMENTED\n");
210 * unix_fna_vres_destroy()
214 int unix_fna_vres_destroy(const frsh_resource_id_t resource_id,
215 const fna_vres_id_t vres)
217 DEBUG("NOT IMPLEMENTED\n");
222 * unix_fna_vres_get_contract()
226 int unix_fna_vres_get_contract(const frsh_resource_id_t resource_id,
227 const fna_vres_id_t vres,
228 frsh_contract_t *contract)
230 DEBUG("NOT IMPLEMENTED\n");
235 * unix_fna_vres_get_usage()
239 int unix_fna_vres_get_usage(const frsh_resource_id_t resource_id,
240 const fna_vres_id_t vres,
241 struct timespec *usage)
243 DEBUG("NOT IMPLEMENTED\n");
248 * unix_fna_vres_get_remaining_budget()
252 int unix_fna_vres_get_remaining_budget(const frsh_resource_id_t resource_id,
253 const fna_vres_id_t vres,
254 struct timespec *remaining_budget)
256 DEBUG("NOT IMPLEMENTED\n");
261 * unix_fna_vres_get_budget_and_period()
265 int unix_fna_vres_get_budget_and_period(const frsh_resource_id_t resource_id,
266 const fna_vres_id_t vres,
267 struct timespec *budget,
268 struct timespec *period)
270 DEBUG("NOT IMPLEMENTED\n");
274 ///////////////////////////////////////////////////////////////////
275 // SPARE CAPACITY FUNCIONS
276 ///////////////////////////////////////////////////////////////////
279 * unix_fna_resource_get_capacity()
283 int unix_fna_resource_get_capacity(const frsh_resource_id_t resource_id,
284 const int importance,
287 DEBUG("NOT IMPLEMENTED\n");
292 * unix_fna_resource_get_total_weight()
296 int unix_fna_resource_get_total_weight(const frsh_resource_id_t resource_id,
297 const int importance,
300 DEBUG("NOT IMPLEMENTED\n");
305 * unix_fna_vres_decrease_capacity()
309 int unix_fna_vres_decrease_capacity(const frsh_resource_id_t resource_id,
310 const fna_vres_id_t vres,
311 const struct timespec new_budget,
312 const struct timespec new_period)
314 DEBUG("NOT IMPLEMENTED\n");
318 ///////////////////////////////////////////////////////////////////
319 // SEND RECEIVE OPERATIONS
320 ///////////////////////////////////////////////////////////////////
323 * unix_fna_send_sync()
327 int unix_fna_send_sync(const fna_endpoint_data_t *endpoint,
331 DEBUG("NOT IMPLEMENTED\n");
336 * unix_fna_send_async()
340 int unix_fna_send_async(const fna_endpoint_data_t *endpoint,
345 struct sockaddr_un receiver_addr;
348 DEBUG("send async\n");
350 assert(endpoint->is_bound);
352 memset(&receiver_addr, 0, sizeof(receiver_addr));
353 receiver_addr.sun_family = AF_UNIX;
354 strcpy(receiver_addr.sun_path,
355 the_unix_socket_paths[endpoint->destination]);
357 sent_bytes = sendto(endpoint->vres, /* the socket */
361 (struct sockaddr *) &receiver_addr,
362 sizeof(receiver_addr));
364 assert(sent_bytes >= 0);
370 * unix_fna_receive_sync()
374 int unix_fna_receive_sync(const fna_endpoint_data_t *endpoint,
376 const size_t buffer_size,
377 size_t *received_bytes,
378 frsh_network_address_t *from)
380 struct sockaddr_un sender_addr;
384 DEBUG("receive sync\n");
386 from_len = sizeof(sender_addr);
387 recv_bytes = recvfrom(endpoint->vres, /* the socket */
391 (struct sockaddr *)&sender_addr,
394 assert(recv_bytes >= 0);
396 *received_bytes = recv_bytes;
397 /* TODO: fill from */
403 * unix_fna_receive_async()
407 int unix_fna_receive_async(const fna_endpoint_data_t *endpoint,
409 const size_t buffer_size,
410 size_t *received_bytes,
411 frsh_network_address_t *from)
413 DEBUG("NOT IMPLEMENTED\n");
418 * unix_fna_send_endpoint_get_status()
422 int unix_fna_send_endpoint_get_status(const fna_endpoint_data_t *endpoint,
423 int *number_of_pending_messages,
424 frsh_endpoint_network_status_t *network_status,
425 frsh_protocol_status_t *protocol_status)
427 DEBUG("NOT IMPLEMENTED\n");
432 * unix_fna_receive_endpoint_created()
435 int unix_fna_receive_endpoint_created(fna_endpoint_data_t *endpoint)
438 struct sockaddr_un receiver_addr;
441 DEBUG("creating the socket to receive\n");
443 sock = socket(AF_UNIX, SOCK_DGRAM, 0);
446 unix_path_index = (int)endpoint->protocol_info.body;
448 memset(&receiver_addr, 0, sizeof(receiver_addr));
449 receiver_addr.sun_family = AF_UNIX;
450 strcpy(receiver_addr.sun_path, the_unix_socket_paths[unix_path_index]);
452 err = bind(sock, (struct sockaddr *)&receiver_addr, sizeof(receiver_addr));
455 endpoint->vres = sock;
461 * unix_fna_receive_endpoint_get_pending_messages
465 int unix_fna_receive_endpoint_get_status(const fna_endpoint_data_t *endpoint,
466 int *number_of_pending_messages,
467 frsh_endpoint_network_status_t *network_status,
468 frsh_protocol_status_t *protocol_status)
470 DEBUG("NOT IMPLEMENTED\n");
474 //////////////////////////////////////////////////////////////////////
475 // NETWORK CONFIGURATION FUNCTIONS
476 //////////////////////////////////////////////////////////////////////
479 * unix_fna_network_get_max_message_size()
483 int unix_fna_network_get_max_message_size(const frsh_resource_id_t resource_id,
484 const frsh_network_address_t destination,
487 DEBUG("NOT IMPLEMENTED\n");
492 * unix_fna_network_bytes_to_budget()
496 int unix_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
498 struct timespec *budget)
500 DEBUG("NOT IMPLEMENTED\n");
505 * unix_fna_network_budget_to_bytes()
509 int unix_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
510 const struct timespec *budget,
513 DEBUG("NOT IMPLEMENTED\n");
518 * unix_fna_network_get_min_eff_budget()
522 int unix_fna_network_get_min_eff_budget(const frsh_resource_id_t resource_id,
523 struct timespec *budget)
525 DEBUG("NOT IMPLEMENTED\n");
529 // GLOBAL variable to install the network protocol in FRESCOR
531 fna_operations_t unix_fna_operations = {
532 .fna_init = unix_fna_init,
533 .fna_contract_negotiate = unix_fna_contract_negotiate,
534 .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync,
535 .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async,
536 .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status,
537 .fna_vres_destroy = unix_fna_vres_destroy,
538 .fna_vres_get_contract = unix_fna_vres_get_contract,
539 .fna_vres_get_usage = unix_fna_vres_get_usage,
540 .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget,
541 .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period,
542 .fna_resource_get_capacity = unix_fna_resource_get_capacity,
543 .fna_resource_get_total_weight = unix_fna_resource_get_total_weight,
544 .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity,
545 .fna_send_sync = unix_fna_send_sync,
546 .fna_send_async = unix_fna_send_async,
547 .fna_receive_sync = unix_fna_receive_sync,
548 .fna_receive_async = unix_fna_receive_async,
549 .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status,
550 .fna_receive_endpoint_created = unix_fna_receive_endpoint_created,
551 .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status,
552 .fna_network_get_max_message_size = unix_fna_network_get_max_message_size,
553 .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget,
554 .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes,
555 .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget