1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 FRESCOR consortium partners:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politécnica 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 for a link to partners' websites
18 // 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 // FSF API web pages: http://marte.unican.es/fsf/docs
32 // http://shark.sssup.it/contrib/first/docs/
34 // This file is part of FRSH API
36 // FRSH API is free software; you can redistribute it and/or modify
37 // it under the terms of the GNU General Public License as published by
38 // the Free Software Foundation; either version 2, or (at your option)
41 // FRSH API is distributed in the hope that it will be useful, but
42 // WITHOUT ANY WARRANTY; without even the implied warranty of
43 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 // General Public License for more details.
46 // You should have received a copy of the GNU General Public License
47 // distributed with FRSH API; see file COPYING. If not, write to the
48 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
51 // As a special exception, if you include this header file into source
52 // files to be compiled, this header file does not by itself cause
53 // the resulting executable to be covered by the GNU General Public
54 // License. This exception does not however invalidate any other
55 // reasons why the executable file might be covered by the GNU General
57 // -----------------------------------------------------------------------
59 //==============================================
60 // ******** **** ** **
61 // **///// /**/** /** ****
62 // ** /**//** /** **//**
63 // ******* /** //** /** ** //**
64 // **//// /** //**/** **********
65 // ** /** //****/**//////**
66 // ** /** //***/** /**
69 // FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
70 //==============================================================
76 #include "rtep.h" // for rtep_adainit, rtep_valid_multicast_id, ..
77 #include "rtep_bandwith_reservation.h" // for rtep_bwres_*
78 #include <malloc.h> // for malloc and free
80 //////////////////////////////////////////////////////////////////////
82 //////////////////////////////////////////////////////////////////////
87 * This function will be hooked to the frsh_init function and it is
88 * intented to initialize the protocol and its structures.
90 * @param[in] resource_id The network we are referring to (a protocol
91 * could be able to handle several networks at the same time)
94 * 0 if there are no errors \n
95 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
96 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
97 * FNA_ERR_ALREADY_INITIALIZED:
98 * if the function has already been called before (with success) \n
101 int fna_init(const frsh_resource_id_t resource_id)
103 rtep_adainit(); // init Ada bindings
104 return rtep_bwres_init();
107 ///////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////
112 * fna_contract_negotiate()
114 * The operation negotiates a contract and if accepted it will return
115 * a fna_vres_id_t. It will also check that the given contract_id is unique
116 * within the network.
118 * If the on-line admission test is enabled, it determines whether the
119 * contract can be admitted or not based on the current contracts
120 * established in the network. Then it creates the vres and
121 * recalculates all necessary parameters for the contracts already
122 * present in the system.
124 * This is a potentially blocking operation, it returns when the
125 * system has either rejected the contract, or admitted it and made it
128 * @param[in] resource_id The network we are referring to (a protocol
129 * could be able to handle several networks at the same time)
130 * @param[in] contract The contract parameters to negotiate
131 * @param[out] vres The internal virtual resource id
134 * 0 if there are no errors (in this case it also means contract accepted) \n
135 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
136 * FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
137 * FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
138 * FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
139 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
140 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
141 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
144 int fna_contract_negotiate
145 (const frsh_resource_id_t resource_id,
146 const frsh_contract_t *contract,
149 rtep_bwres_contract_t rtep_contract;
150 rtep_bwres_vres_t *rtep_vres;
153 // convert FRSH contract to RTEP BWRES contract
154 rtep_contract.period_max = contract->period_max;
155 rtep_contract.deadline = contract->deadline;
156 rtep_contract.prio = contract->preemption_level;
157 // in RTEP BWRES, budget is given in number of packets. We do a little trick
158 // in the function bytes_to_network_budget to use a the field tv_sec from the
159 // timespec in frsh_contract to store the budget in bytes directly
160 rtep_contract.budget_min = contract->budget_min.tv_sec;
162 // create an internal vres. The fna vres id is a pointer to void which
163 // we transform internally to a pointer to a vres structure
164 rtep_vres = (rtep_bwres_vres_t *)malloc(sizeof(rtep_bwres_vres_t));
166 // negotiate the contract
167 accepted = rtep_bwres_contract_negotiate (&rtep_contract, rtep_vres);
169 // vres is a pointer to void *, so we change void * for the new *rtep_vres
171 *vres = (void *)rtep_vres;
180 * fna_contract_renegotiate_sync()
182 * The operation renegotiates a contract for an existing vres. If
183 * the on-line admission test is enabled it determines whether the
184 * contract can be admitted or not based on the current contracts
185 * established in the system. If it cannot be admitted, the old
186 * contract remains in effect and an error is returned. If it can be
187 * admitted, it recalculates all necessary parameters for the
188 * contracts already present in the system and returns zero. This is a
189 * potentially blocking operation; it returns when the system has
190 * either rejected the new contract, or admitted it and made it
193 * @param[in] resource_id The network we are referring to (a protocol
194 * could be able to handle several networks at the same time)
195 * @param[in] vres The internal virtual resource id to renegotiate
196 * @param[in] new_contract The new contract
199 * 0 if there are no errors (in this case it also means contract accepted) \n
200 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
201 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
202 * FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
203 * FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
204 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
205 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
206 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
209 int fna_contract_renegotiate_sync
210 (const frsh_resource_id_t resource_id,
211 const fna_vres_id_t vres,
212 const frsh_contract_t *new_contract)
218 * fna_contract_renegotiate_async()
220 * The operation enqueues a renegotiate operation for an existing
221 * vres, and returns immediately. The renegotiate operation is
222 * performed asynchronously, as soon as it is practical; meanwhile the
223 * system operation will continue normally. When the renegotiation is
224 * made, if the on-line admission test is enabled it determines
225 * whether the contract can be admitted or not based on the current
226 * contracts established in the system. If it cannot be admitted, the
227 * old contract remains in effect. If it can be admitted, it
228 * recalculates all necessary parameters for the contracts already
229 * present in the system.
231 * When the operation is completed, notification is made to the
232 * caller, if requested, via a signal. The status of the operation (in
233 * progress, admitted, rejected) can be checked with the
234 * frsh_vres_get_renegotiation_status() operation. The argument
235 * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
236 * signal value and in this case signal_info is to be sent with the signal.
238 * @param[in] resource_id The network we are referring to (a protocol
239 * could be able to handle several networks at the same time)
240 * @param[in] vres The internal virtual resource id to renegotiate
241 * @param[in] new_contract The new contract
242 * @param[in] signal_to_notify Signal number to use to notify vres of
243 * the negotiation result. If FRSH_NULL_SIGNAL, no signal will be raised.
244 * @param[in] signal_info: Associated info that will come with the signal.
245 * This parameter will be ignored if signal_to_notify == FRSH_NULL_SIGNAL.
248 * 0 if there are no errors \n
249 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
250 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
251 * FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
252 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
253 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
254 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL, or sig_notify is neither
255 * NULL nor a valid POSIX signal \n
258 int fna_contract_renegotiate_async
259 (const frsh_resource_id_t resource_id,
260 const fna_vres_id_t vres,
261 const frsh_contract_t *new_contract,
262 frsh_signal_t signal_to_notify,
263 frsh_signal_info_t signal_info)
269 * fna_vres_get_renegotiation_status()
271 * The operation reports on the status of the last renegotiation
272 * operation enqueued for the specified vres. It is callable even
273 * after notification of the completion of such operation, if
276 * If the vres is not and has not been involved in any of the
277 * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
278 * operations, the status returned is FNA_NOT_REQUESTED
280 * @param[in] resource_id The network we are referring to (a protocol
281 * could be able to handle several networks at the same time)
282 * @param[in] vres The internal virtual resource id we want the status from
283 * @param[in] renegotiation_status The status of the last renegotiation on
284 * vres (FRSH_RS_IN_PROGRESS, FRSH_RS_REJECTED, FRSH_RS_ADMITTED,
285 * FRSH_RS_NOT_REQUESTED)
288 * 0 if there are no errors \n
289 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
290 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
291 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
292 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
293 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
296 int fna_vres_get_renegotiation_status
297 (const frsh_resource_id_t resource_id,
298 const fna_vres_id_t vres,
299 frsh_renegotiation_status_t *renegotiation_status)
307 * The operation eliminates the specified vres
308 * and recalculates all necessary parameters for the contracts
309 * remaining in the system. This is a potentially blocking operation;
310 * it returns when the system has made the changes effective.
312 * @param[in] resource_id The network we are referring to (a protocol
313 * could be able to handle several networks at the same time)
314 * @param[in] vres The internal virtual resource id to destroy
317 * 0 if there are no errors \n
318 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
319 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
320 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
321 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
322 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
326 (const frsh_resource_id_t resource_id,
327 const fna_vres_id_t vres)
333 * fna_vres_get_contract()
335 * This operation stores the contract parameters currently associated
336 * with the specified vres in the variable pointed to by
337 * contract. It returns an error if the vres_id is not recognised.
339 * @param[in] resource_id The network we are referring to (a protocol
340 * could be able to handle several networks at the same time)
341 * @param[in] vres The internal virtual resource id
342 * @param[out] contract The contract parameters that we want
345 * 0 if there are no errors \n
346 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
347 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
348 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
349 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
350 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
353 int fna_vres_get_contract
354 (const frsh_resource_id_t resource_id,
355 const fna_vres_id_t vres,
356 frsh_contract_t *contract)
362 * fna_vres_get_usage()
364 * This function gets the execution time spent by all messages that have been
365 * sent through the specified vres.
367 * @param[in] resource_id The network we are referring to (a protocol
368 * could be able to handle several networks at the same time)
369 * @param[in] vres The internal virtual resource id
370 * @param[out] usage Execution time spent by this vres
373 * 0 if there are no errors \n
374 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
375 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
376 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
377 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
378 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
381 int fna_vres_get_usage
382 (const frsh_resource_id_t resource_id,
383 const fna_vres_id_t vres,
384 struct timespec *usage)
390 * fna_vres_get_remaining_budget()
392 * This function stores in the variable pointed to by budget the
393 * remaining execution-time budget associated with the specified
394 * vres in the present period.
396 * @param[in] resource_id The network we are referring to (a protocol
397 * could be able to handle several networks at the same time)
398 * @param[in] vres The internal virtual resource id
399 * @param[out] remaining_budget The remaining budget for this period
402 * 0 if there are no errors \n
403 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
404 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
405 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
406 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
407 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
410 int fna_vres_get_remaining_budget
411 (const frsh_resource_id_t resource_id,
412 const fna_vres_id_t vres,
413 struct timespec *remaining_budget)
419 * fna_vres_get_budget_and_period()
421 * This function gets the budget and period associated with the specified vres
422 * for each period. If one of these pointers is NULL, the corresponding
423 * information is not stored.
425 * @param[in] resource_id The network we are referring to (a protocol
426 * could be able to handle several networks at the same time)
427 * @param[in] vres The internal virtual resource id
428 * @param[out] budget The budget associated to vres
429 * @param[out] period The period associated to vres
432 * 0 if there are no errors \n
433 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
434 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
435 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
436 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
437 * FNA_ERR_BAD_ARGUMENT: if both pointers are NULL \n
440 int fna_vres_get_budget_and_period
441 (const frsh_resource_id_t resource_id,
442 const fna_vres_id_t vres,
443 struct timespec *budget,
444 struct timespec *period)
451 ///////////////////////////////////////////////////////////////////
452 // SPARE CAPACITY FUNCIONS
453 ///////////////////////////////////////////////////////////////////
456 * @defgroup fnaspare FNA Spare Capacity
459 * The following functions are used to get spare capacity data
465 * fna_resource_get_capacity()
467 * This operation gets the spare capacity currently assigned to a importance
468 * level. If we divide this value by UINT32_MAX we will get the network
469 * utilization associated to the spare capacity of a importance level.
471 * The following is typically in stdint.h: \n
472 * - typedef unsigned int uint32_t; \n
473 * - # define UINT32_MAX (4294967295U) \n
475 * @param[in] resource_id The network we are referring to (a protocol
476 * could be able to handle several networks at the same time)
477 * @param[in] importance The importance we want the capacity of
478 * @param[out] capacity The spare capacity for that importance level
481 * 0 if there are no errors \n
482 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
483 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
484 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
485 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
488 int fna_resource_get_capacity
489 (const frsh_resource_id_t resource_id,
490 const int importance,
497 * fna_resource_get_total_weight()
499 * This function gets the sum of the weight parameters for all vres in a
500 * network of an importance level.
502 * @param[in] resource_id The network we are referring to (a protocol
503 * could be able to handle several networks at the same time)
504 * @param[in] importance The importance we want the total weight of
505 * @param[out] total_weight The total weight for that importance level
508 * 0 if there are no errors \n
509 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
510 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
511 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
512 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
515 int fna_resource_get_total_weight
516 (const frsh_resource_id_t resource_id,
517 const int importance,
524 * fna_vres_decrease_capacity()
526 * This function allows to ask for less budget and period than what we
527 * received. The request must be compatible with the rest of contract
528 * parameters of the vres. If we want to recover the released capacity
529 * we will need to renegotiate.
531 * @param[in] resource_id The network we are referring to (a protocol
532 * could be able to handle several networks at the same time)
533 * @param[in] vres The internal virtual resource id
534 * @param[in] new_budget The new_budget
535 * @param[in] new_period The new Period
538 * 0 if there are no errors \n
539 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
540 * FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
541 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
542 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
543 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
544 * FNA_ERR_CONTRACT_REJECTED: if it is incompatible with the current
548 int fna_vres_decrease_capacity
549 (const frsh_resource_id_t resource_id,
550 const fna_vres_id_t vres,
551 const struct timespec new_budget,
552 const struct timespec new_period)
557 ///////////////////////////////////////////////////////////////////
558 // SEND RECEIVE OPERATIONS
559 ///////////////////////////////////////////////////////////////////
564 * Similar to previous function but now the sending thread gets blocked
565 * until the message is already sent to the network.
567 * @param[in] endpoint The send endpoint we are sending through. It must
568 * be bound to a virtual resource (resource_id is in the endpoint).
569 * @param[in] msg The message we want to send
570 * @param[in] size The size in bytes of the message
573 * 0 if there are no errors \n
574 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
575 * FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
576 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
577 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
578 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
579 * FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
580 * FNA_ERR_BUFFER_FULL: if the message has been discarded because
581 * the queue is full (and does not have the policy FNA_QP_OLDEST) \n
585 (const fna_send_endpoint_t *endpoint,
595 * This operation sends a message stored in msg and of length size
596 * through the given send endpoint. The operation is non-blocking and
597 * returns immediately.
599 * @param[in] endpoint The send endpoint we are sending through. It must
600 * be bound to a virtual resource (resource_id is in the endpoint).
601 * @param[in] msg The message we want to send
602 * @param[in] size The size in bytes of the message
605 * 0 if there are no errors \n
606 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
607 * FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
608 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
609 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
610 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
611 * FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
612 * FNA_ERR_BUFFER_FULL: if the message has been discarded because
613 * the queue is full (and does not have the policy FNA_QP_OLDEST) \n
617 (const fna_send_endpoint_t *endpoint,
627 * This operation is used to receive messages from the network with a
628 * blocking behavior (if there are no messages this operation blocks
629 * the calling thread).
631 * When a message is available, it is copied to buffer (up to its size).
632 * The number of bytes copied is returned in received_bytes. The rest
633 * of the bytes of that message will be lost or not depending on the
634 * protocol (FNA_ERR_NO_SPACE will be returned if it is).
636 * The function fails with FNA_ERR_NO_SPACE if the buffersize is
637 * too small for the message received. In this case the message is
640 * Messages arriving at a receiver buffer that is full will be handled
641 * according to the queueing policy of the endpoint (overwrite oldest,
644 * @param[in] endpoint The receive endpoint we are receiving from.
645 * (resource_id is in the endpoint).
646 * @param[out] buffer Buffer for storing the received message
647 * @param[in] buffer_size The size in bytes of this buffer
648 * @param[out] received_bytes The actual number of received bytes
649 * @param[out] from Address of the sender node
652 * 0 if there are no errors \n
653 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
654 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
655 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
656 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
657 * FNA_ERR_NO_SPACE: if the message size is bigger than the
658 * provided buffer. \n
662 (const frsh_receive_endpoint_t *endpoint,
664 const size_t buffer_size,
665 size_t *received_bytes,
666 frsh_network_address_t *from)
672 * fna_receive_async()
674 * This operation is similar to the previous one but it works in a non
675 * blocking (asynchronous) fashion. If no message is available it
676 * returns with error FNA_NO_MESSAGE.
678 * @param[in] endpoint The receive endpoint we are receiving from.
679 * (resource_id is in the endpoint).
680 * @param[out] buffer Buffer for storing the received message
681 * @param[in] buffer_size The size in bytes of this buffer
682 * @param[out] received_bytes The actual number of received bytes
683 * @param[out] from Address of the sender node
686 * 0 if there are no errors \n
687 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
688 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
689 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
690 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
691 * FNA_ERR_NO_SPACE: if the message size is bigger than the
692 * provided buffer. \n
693 * FNA_NO_MESSAGE: if no messages are available in the queue. \n
696 int fna_receive_async
697 (const frsh_receive_endpoint_t *endpoint,
699 const size_t buffer_size,
700 size_t *received_bytes,
701 frsh_network_address_t *from)
707 * fna_send_endpoint_get_status()
709 * This function tells the number of messages still pending in the
710 * endpoint queue, whether the network is up or down with some
711 * optional information which is protocol_dependent.
713 * @param[in] endpoint The send endpoint (resource_id is in the endpoint).
714 * @param[out] number_of_pending_messages The number of pending messages
715 * @param[out] network_status How is the network (up, down..)
716 * @param[out] protocol_status Protocol dependent status info
719 * 0 if there are no errors \n
720 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
721 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
722 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
723 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
726 int fna_send_endpoint_get_status
727 (const fna_send_endpoint_t *endpoint,
728 int *number_of_pending_messages,
729 frsh_endpoint_network_status *network_status,
730 frsh_protocol_status_t *protocol_status)
736 * fna_receive_endpoint_create_callback()
738 * This operation is a called from frsh_receive_endpoint_create with a
739 * receive_endpoint structure already filled.
741 * Receiving endpoints are not bound to any network vres, this is
742 * because don't originate any traffic.
744 * @param[in] endpoint the endpoint object.
747 * 0 if there are no errors \n
748 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
749 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
750 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
751 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
753 int fna_receive_endpoint_create_callback
754 (const frsh_receive_endpoint_t *endpoint)
760 * fna_receive_endpoint_get_pending_messages
762 * This function tells the number of messages still pending in the
763 * endpoint queue, whether the network is up or down and some optional
764 * information which is protocol dependent.
766 * @param[in] endpoint The receive endpoint (resource_id is in the endpoint).
767 * @param[out] number_of_pending_messages The number of pending messages
768 * @param[out] network_status How is the network (up, down..)
769 * @param[out] protocol_status Protocol dependent status info
772 * 0 if there are no errors \n
773 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
774 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
775 * FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
776 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
779 int fna_receive_endpoint_get_status
780 (const frsh_receive_endpoint_t *endpoint,
781 int *number_of_pending_messages,
782 frsh_endpoint_network_status *network_status,
783 frsh_protocol_status_t *protocol_status)
788 //////////////////////////////////////////////////////////////////////
789 // NETWORK CONFIGURATION FUNCTIONS
790 //////////////////////////////////////////////////////////////////////
793 * fna_network_get_max_message_size()
795 * This operation gives the maximum number of bytes that can be sent
796 * at a time through the send function when using the network designated by
797 * 'resource_id' and sending it to 'destination'.
799 * If the application needs to send bigger messages it will have to
802 * Some protocols, like IP, are capable of sending large messages
803 * (and use fragmentation internally) but other protocols don't.
805 * @param[in] resource_id The network we want the tx time from.
806 * @param[in] destination The destination address
807 * @param[out] max_size The maximum number of bytes for each message
810 * 0 if there are no errors \n
811 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
812 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
813 * FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
814 * a network accessible from the current processing node \n
815 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
819 int fna_network_get_max_message_size
820 (const frsh_resource_id_t resource_id,
821 const frsh_network_address_t destination,
826 if (max_size == NULL) {
830 is_multicast = rtep_valid_multicast_id ((rtep_station_id_t) destination);
832 *max_size = MULTICAST_MTU;
834 *max_size = MAX_RTEP_MTU;
840 * fna_network_bytes_to_budget()
842 * This operation converts a number of bytes into a temporal budget for
843 * a specific network. Network overheads are not included here but are
844 * considered internally when negotiating a specific contract.
846 * @param[in] resource_id The network
847 * @param[in] nbytes Number of bytes
848 * @param[out] budget The network budget for nbytes
851 * 0 if there are no errors \n
852 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
853 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
854 * FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
855 * a network accessible from the current processing node \n
856 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
860 int fna_network_bytes_to_budget
861 (const frsh_resource_id_t resource_id,
863 struct timespec *budget)
865 int number_of_packets;
867 if (budget == NULL || nbytes < 0) {
871 // we measure the budget in number of RTEP packets of maximum size
872 number_of_packets = nbytes / MAX_RTEP_MTU + 1;
873 // we store the budget in number of packets instead of in time. We
874 // use a field in the timespec structure.
875 budget->tv_sec = number_of_packets;
881 * fna_network_budget_to_bytes()
883 * This operation converts a temporal budget into a number of bytes for
884 * a specific network. Network overheads are not included.
886 * @param[in] resource_id The network
887 * @param[in] budget The network budget for nbytes
888 * @param[out] nbytes Number of bytes
891 * 0 if there are no errors \n
892 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
893 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
894 * FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
895 * a network accessible from the current processing node \n
896 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
897 * an invalid time value \n
900 int fna_network_budget_to_bytes
901 (const frsh_resource_id_t resource_id,
902 const struct timespec *budget,
905 int number_of_packets;
907 if (budget == NULL || nbytes == NULL) {
910 number_of_packets = budget->tv_sec;
911 *nbytes = number_of_packets * MAX_RTEP_MTU;
916 * fna_network_get_min_effective_budget()
918 * This operation gets the minimum effective budget for a network. Each message
919 * consumes a contracted budget in "chunks" (i.e: packets) that we call
920 * minimum effective budget.
922 * A negotiated contract, for N bytes in a period T, means that there is a
923 * virtual resource that reserves for the user:
925 * Ceiling ((N bytes) / budget_to_bytes (min_effective_budget)) "CHUNKS"
927 * Note that if the user decides not to send these N bytes at once but, say,
928 * one byte at a time, it will consume one "CHUNK" at a time and the reserved
929 * budget will become exhausted before sending all the bytes.
931 * @param[in] resource_id The network
932 * @param[out] budget The network budget
935 * 0 if there are no errors \n
936 * FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
937 * FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
938 * FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
939 * a network accessible from the current processing node \n
940 * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
943 int fna_network_get_min_effective_budget
944 (const frsh_resource_id_t resource_id,
945 struct timespec *budget)
947 if (budget == NULL) {
954 #endif // _RTEP_FNA_H_