]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/frsh_fwp/fwp_fna.c
e26dd26504e43a026f20ae661e6427ff944be0bb
[frescor/fwp.git] / fwp / lib / frsh_fwp / fwp_fna.c
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FWP (Frescor WLAN Protocol)                      */
26 /*                                                                        */
27 /* FWP is free software; you can redistribute it and/or modify it         */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FWP is distributed in the hope that it will be         */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FWP; see file        */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FWP header files in a file,          */
39 /* instantiating FWP generics or templates, or linking other files        */
40 /* with FWP objects to produce an executable application, does not        */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46 #include <fna.h>
47 #include <fres_vres.h>
48 #include <frsh_forb.h>
49 #include "fwp_endpoint.h"
50 #include "fwp_vres.h"
51 #include "fwp.h"
52 #include "fwp_res.h"
53 #include "fwp_utils.h"
54 #include "fwp_debug.h"
55
56 int fwp_fna_init(const frsh_resource_id_t resource_id)
57 {
58         int rv;
59
60         if ((rv = fwp_init()))
61                 return rv;
62
63         return fra_fwp_init();
64 }
65
66 int fwp_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
67                         const frsh_rel_time_t *budget, size_t *nbytes)
68 {
69         *nbytes = budget->tv_nsec;
70         return 0;       
71 }
72
73 int fwp_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
74                         const size_t nbytes, frsh_rel_time_t *budget)
75 {
76         budget->tv_nsec = nbytes;
77         budget->tv_sec = 0;
78         return 0;
79 }
80
81 int fwp_fna_send_endpoint_created(fna_endpoint_data_t  *endpoint)
82 {
83         unsigned int node, port;
84         fwp_endpoint_attr_t *attr;
85         fwp_endpoint_t *fwp_epoint;
86         int rv;
87         frsh_send_endpoint_protocol_info_t *spi;
88         
89         node = (unsigned int) endpoint->destination;
90         port = (unsigned int) endpoint->stream_id;
91         attr = NULL;
92         
93         spi = &endpoint->endpoint_protocol_info.send;
94         if (spi->size == sizeof(fwp_endpoint_attr_t))
95                 attr = (fwp_endpoint_attr_t*)spi->body; 
96         rv = fwp_send_endpoint_create(node, port, attr, &fwp_epoint);
97         endpoint->protocol_info.body = fwp_epoint;
98         return rv;
99 }
100
101 int fwp_fna_receive_endpoint_created(fna_endpoint_data_t  *endpoint)
102 {
103         unsigned int node,port;
104         fwp_endpoint_attr_t *attr;
105         fwp_endpoint_t *fwp_epoint;
106         int rv;
107
108         node = (unsigned int) endpoint->destination;
109         port = (unsigned int) endpoint->stream_id;
110         attr = (fwp_endpoint_attr_t*) endpoint->protocol_info.body; 
111         rv = fwp_receive_endpoint_create(port, attr, &fwp_epoint);
112         if (rv)
113                 return rv;
114         
115         endpoint->protocol_info.body = fwp_epoint;
116         fwp_endpoint_get_params(fwp_epoint, &node, &port, attr);
117         endpoint->stream_id = port;
118         FWP_DEBUG("PORT= %d\n", port);
119
120         return 0;
121 }
122
123 int fwp_fna_send_endpoint_bind(fna_endpoint_data_t *endpoint, fna_vres_id_t vres)
124 {
125         return fwp_send_endpoint_bind(endpoint->protocol_info.body, 
126                                         (fwp_vres_d_t) vres->priv);
127 }
128
129 int fwp_fna_send_endpoint_unbind(fna_endpoint_data_t *endpoint)
130 {
131         return fwp_send_endpoint_unbind(endpoint->protocol_info.body);
132 }
133
134 int fwp_fna_endpoint_destroy(fna_endpoint_data_t  *endpoint)
135 {       
136         return fwp_endpoint_destroy(endpoint->endpoint_protocol_info.send.body);
137 }
138
139 /** FNA send routine */
140 int fwp_fna_send(const fna_endpoint_data_t *endpoint, const void *msg, 
141                         const size_t size)
142 {
143         fwp_endpoint_t *fwp_epoint;
144
145         fwp_epoint = endpoint->protocol_info.body;
146         return fwp_send(fwp_epoint, msg, size);
147 }
148
149 int fwp_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg, 
150                         const size_t size)
151 {
152         fwp_endpoint_t *fwp_epoint;
153
154         fwp_epoint = endpoint->protocol_info.body;
155         return fwp_send(fwp_epoint, msg, size);
156 }
157
158 int fwp_fna_send_async(const fna_endpoint_data_t *endpoint,const void *msg,
159                    const size_t size)
160 {
161         fwp_endpoint_t *fwp_epoint;
162
163         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;    
164         return fwp_send(fwp_epoint, msg, size); /* FIXME */
165 }
166
167 /** FNA receive routines */
168 int fwp_fna_receive(const fna_endpoint_data_t *endpoint,
169                         void *buffer, const size_t buffer_size,
170                         size_t *received_bytes, frsh_network_address_t *from)
171 {
172         unsigned int from_addr;
173         ssize_t len;
174         fwp_endpoint_t *fwp_epoint;
175         int flags = 0;
176         
177         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
178         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
179         if (len < 0) 
180                 return len;
181         
182         *received_bytes = len;
183         *from = from_addr;
184         
185         return 0;
186 }
187
188 int fwp_fna_receive_sync(const fna_endpoint_data_t *endpoint, void *buffer, 
189                          const size_t buffer_size, size_t *received_bytes, 
190                          frsh_network_address_t *from)
191 {
192         unsigned int from_addr;
193         ssize_t len;
194         fwp_endpoint_t *fwp_epoint;
195         int flags = 0;
196         
197         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
198         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
199         if (len < 0) 
200                 return len;
201
202         if (received_bytes)
203                 *received_bytes = len;
204         if (from)
205                 *from = from_addr;
206         
207         return 0;
208 }
209
210 int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer, 
211                          const size_t buffer_size, size_t *received_bytes, 
212                          frsh_network_address_t *from)
213 {
214         unsigned int from_addr;
215         ssize_t len;
216         fwp_endpoint_t *fwp_epoint;
217         int flags = 0;
218         
219         fwp_epoint = (fwp_endpoint_t*) endpoint->protocol_info.body;
220         len = fwp_recv(fwp_epoint, buffer, buffer_size, &from_addr, flags);
221         if (len < 0) 
222                 return len;
223
224         if (received_bytes)
225                 *received_bytes = len;
226         if (from)
227                 *from = from_addr;
228         
229         return 0;
230 }
231
232 int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id,
233                      const fna_vres_id_t vres)
234 {
235 //      return fwp_vres_close(vres);    
236         return 0;
237 }
238
239 fna_operations_t fwp_fna_operations = {
240     .fna_init = fwp_fna_init,
241     .fna_contract_negotiate = NULL,
242     .fna_contract_renegotiate_sync = NULL,
243     .fna_contract_renegotiate_async = NULL,
244     .fna_vres_get_renegotiation_status = NULL,
245     .fna_vres_destroy = fwp_fna_vres_destroy,
246     .fna_vres_get_contract = NULL,
247     .fna_vres_get_usage = NULL,
248     .fna_vres_get_remaining_budget = NULL,
249     .fna_vres_get_budget_and_period = NULL,
250     .fna_resource_get_capacity = NULL,
251     .fna_resource_get_total_weight = NULL,
252     .fna_vres_decrease_capacity = NULL,
253     .fna_send_sync = NULL,
254     .fna_send_async = fwp_fna_send_async,
255     .fna_receive_sync = fwp_fna_receive_sync,
256     .fna_receive_async = fwp_fna_receive_async,
257     .fna_send_endpoint_get_status = NULL,
258     .fna_endpoint_destroy = fwp_fna_endpoint_destroy,
259     .fna_send_endpoint_created = fwp_fna_send_endpoint_created,
260     .fna_send_endpoint_bind = fwp_fna_send_endpoint_bind,
261     .fna_send_endpoint_unbind = fwp_fna_send_endpoint_unbind,
262     .fna_receive_endpoint_created = fwp_fna_receive_endpoint_created,
263     .fna_receive_endpoint_get_status = NULL,
264     .fna_network_get_max_message_size = NULL,
265     .fna_network_bytes_to_budget = fwp_fna_network_bytes_to_budget,
266     .fna_network_budget_to_bytes = fwp_fna_network_budget_to_bytes,
267     .fna_network_get_min_eff_budget = NULL
268 };
269