]> rtime.felk.cvut.cz Git - frescor/frsh-include.git/blobdiff - frsh_distributed.h
Added prototype for frsh_contract_destroy()
[frescor/frsh-include.git] / frsh_distributed.h
index 08bc9c431ac266019b3a5f6600ab8dbb6b80aeac..ef602d872401c4aca88bf87ecb1810905b6ec9aa 100644 (file)
@@ -1,5 +1,5 @@
 // -----------------------------------------------------------------------
-//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//  Copyright (C) 2006 - 2009 FRESCOR consortium partners:
 //
 //    Universidad de Cantabria,              SPAIN
 //    University of York,                    UK
 //   FSF API web pages: http://marte.unican.es/fsf/docs
 //                      http://shark.sssup.it/contrib/first/docs/
 //
-//  This file is part of FRSH API
+//   This file is part of FRSH (FRescor ScHeduler)
 //
-//  FRSH API is free software; you can  redistribute it and/or  modify
-//  it under the terms of  the GNU General Public License as published by
-//  the Free Software Foundation;  either  version 2, or (at  your option)
-//  any later version.
+//  FRSH is free software; you can redistribute it and/or modify it
+//  under terms of the GNU General Public License as published by the
+//  Free Software Foundation; either version 2, or (at your option) any
+//  later version.  FRSH is distributed in the hope that it will be
+//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//  General Public License for more details. You should have received a
+//  copy of the GNU General Public License along with FRSH; see file
+//  COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
+//  Cambridge, MA 02139, USA.
 //
-//  FRSH API  is distributed  in  the hope  that  it  will  be useful,  but
-//  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
-//  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
-//  General Public License for more details.
-//
-//  You should have  received a  copy of  the  GNU  General Public License
-//  distributed  with  FRSH API;  see file COPYING.   If not,  write to the
-//  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
-//  02111-1307, USA.
-//
-//  As a special exception, if you include this header file into source
-//  files to be compiled, this header file does not by itself cause
-//  the resulting executable to be covered by the GNU General Public
-//  License.  This exception does not however invalidate any other
-//  reasons why the executable file might be covered by the GNU General
-//  Public License.
+//  As a special exception, including FRSH header files in a file,
+//  instantiating FRSH generics or templates, or linking other files
+//  with FRSH objects to produce an executable application, does not
+//  by itself cause the resulting executable application to be covered
+//  by the GNU General Public License. This exception does not
+//  however invalidate any other reasons why the executable file might be
+//  covered by the GNU Public License.
 // -----------------------------------------------------------------------
 //frsh_distributed.h
 //==============================================
 #include "frsh_distributed_types.h"
 #include "frsh_core_types.h"
 
+FRSH_CPP_BEGIN_DECLS
+
+// this global variable is assigned by frsh_distributed_init()
+extern frsh_resource_id_t THE_FRSH_CPU_ID;
+
+typedef enum {
+        FRSH_NETPF_FRESCAN      = 0,
+        FRSH_NETPF_RTEP         = 1,
+        FRSH_NETPF_UNIX         = 2,
+        FRSH_NETPF_FWP          = 3,
+        FRSH_NETPF_CLUSTER_TREE = 4,
+        FRSH_NETPF_ITEM         = 5,
+} frsh_netpf_t;
+
 /**
  * @defgroup distributed Distributed module
  *
  * This module defines the functions and typedefs for use in
  * distributed applications.
  *
- * Each network is identified by its network_id and FRSH hides its
+ * Each network is identified by its resource_id and FRSH hides its
  * characteristics completely.  The type of network is implied with
  * its ID via a configuration table defined at compile time.
  *
  *
  * 1.  Map (internally in FRSH implementation)
  *     -   node--> network_addresses
- *     -   network --> network_id's
+ *     -   network --> resource_id's
  *     -   unidirectional communication channel --> stream_id
  *     -   other config --> protocol_info.
  *
  *          -  Other protocol dependent function in protocol_contract_info.
  *     2.2. Create a send_endpoint per any unidirectional stream that will
  *          be used in sending
- *          network_id --> the network through which the stream will
+ *          resource_id --> the network through which the stream will
  *                       flow (this is extra info needed for coherency
  *                       with the bind).
  *          destinator --> network_address of the destination.
  *     and the network contract will be canceled.
  **/
 
-
-#define FRSH_DISTRIBUTED_MODULE_SUPPORTED       1
+/**
+ * frsh_distributed_init(void)
+ *
+ * This operation initializes all the installed networks and the structures
+ * that are necessary for the distributed module. Currently it is called by
+ * frsh_init so it is not necessary that the user calls it again.
+ *
+ *   0: No error \n
+ *   FRSH_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *
+ **/
+int frsh_distributed_init(void);
 
 //////////////////////////////////////////////////////////////////////
 //           CONTRACT ASPECTS
  **/
 
 /**
- * frsh_network_message_get_max_size()
+ * frsh_network_get_max_message_size()
  *
  * This operation gives the maximum number of bytes that can be sent
  * at a time through the send function when using the network designated by
  * split them.
  *
  * Some protocols, like IP, are capable of sending large messages
- * (and use fragmentation internally) but other protocols doesn't
- * provide fragmentation features.
+ * (and use fragmentation internally) but other protocols don't.
  *
  * @param[in] resource_id The network we want the tx time from.
  * @param[in] destination The destination address
  * @param[out] max_size The maximum number of bytes for each message
  *
  * @return
- *   FRSH_NO_ERROR: in this case it also means contract accepted \n
+ *   FRSH_NO_ERROR \n
  *   FRSH_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
  *   FRSH_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
- *   FRSH_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
- *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FRSH_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
+ *   invalid \n
  *
  **/
-int frsh_network_message_get_max_size
+int frsh_network_get_max_message_size
    (const frsh_resource_id_t resource_id,
     const frsh_network_address_t destination,
     size_t *max_size);
@@ -196,25 +218,27 @@ int frsh_network_message_get_max_size
  * frsh_network_bytes_to_budget()
  *
  * This operation converts a number of bytes into a temporal budget for
- * a specific network. Network overheads are not included here but internally
- * when negotiating a specific contract.
+ * a specific network. Network overheads are not included here but are
+ * considered internally when negotiating a specific contract.
  *
  * @param[in] resource_id The network
  * @param[in] nbytes Number of bytes
  * @param[out] budget The network budget for nbytes
  *
  * @return
- *   FRSH_NO_ERROR: in this case it also means contract accepted \n
+ *   FRSH_NO_ERROR \n
  *   FRSH_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
  *   FRSH_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
- *   FRSH_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
- *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FRSH_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
+ *   than zero \n
  *
  **/
 int frsh_network_bytes_to_budget
    (const frsh_resource_id_t resource_id,
     const size_t nbytes,
-    struct timespec *budget);
+    frsh_rel_time_t *budget);
 
 /**
  * frsh_network_budget_to_bytes()
@@ -227,16 +251,18 @@ int frsh_network_bytes_to_budget
  * @param[out] nbytes Number of bytes
  *
  * @return
- *   FRSH_NO_ERROR: in this case it also means contract accepted \n
+ *   FRSH_NO_ERROR \n
  *   FRSH_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
  *   FRSH_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
- *   FRSH_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
- *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FRSH_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
+ *   an invalid time value \n
  *
  **/
 int frsh_network_budget_to_bytes
    (const frsh_resource_id_t resource_id,
-    const struct timespec *budget,
+    const frsh_rel_time_t *budget,
     size_t *nbytes);
 
 /**
@@ -244,31 +270,32 @@ int frsh_network_budget_to_bytes
  *
  * This operation gets the minimum effective budget for a network. Each message
  * consumes a contracted budget in "chunks" (i.e: packets) that we call
- * effective budget.
+ * minimum effective budget.
  *
  * A negotiated contract, for N bytes in a period T, means that there is a
  * virtual resource that reserves for the user:
  *
- *         (N bytes)/budget_to_bytes(min_effective_budget) "CHUNKS"
+ *   Ceiling ((N bytes) / budget_to_bytes (min_effective_budget)) "CHUNKS"
  *
  * Note that if the user decides not to send these N bytes at once but, say,
- * one byte at a time, it will consume more "CHUNKS" and the reserved budget
- * will become exhausted before sending all the bytes.
+ * one byte at a time, it will consume one "CHUNK" at a time and the reserved
+ * budget will become exhausted before sending all the bytes.
  *
  * @param[in] resource_id The network
  * @param[out] budget The network budget
  *
  * @return
- *   FRSH_NO_ERROR: in this case it also means contract accepted \n
+ *   FRSH_NO_ERROR \n
  *   FRSH_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
  *   FRSH_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
- *   FRSH_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FRSH_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
  *   FRSH_ERR_BAD_ARGUMENT: if pointers are NULL \n
  *
  **/
 int frsh_network_get_min_effective_budget
    (const frsh_resource_id_t resource_id,
-    struct timespec *budget);
+    frsh_rel_time_t *budget);
 
 /**
  * frsh_contract_set_queueing_info()
@@ -301,10 +328,100 @@ int frsh_contract_set_protocol_info(frsh_protocol_info_t protocol_info,
  *
  * We get protocol info from the contract
  **/
-int frsh_contract_get_protocol_info(frsh_contract_t contract,
+int frsh_contract_get_protocol_info(frsh_contract_t *contract,
                                     frsh_protocol_info_t *protocol_info);
 
+/**
+ * frsh_contract_marshal
+ *
+ * Convert a contract to a sequence of bytes of minimum size so it can
+ * be sent through the network with the minimum amount of bytes.
+ *
+ **/
+
+int frsh_contract_marshal(const frsh_contract_t *contract,
+                          unsigned char         *buffer,
+                          const size_t          buffer_size,
+                          size_t                *size);
+
+/**
+ * frsh_contract_unmarshal
+ *
+ * Convert a sequence of bytes generated by frsh_contract_marshal to a contract
+ *
+ **/
+
+int frsh_contract_unmarshal(frsh_contract_t      *contract,
+                            const unsigned char  *marshal_bytes,
+                            const size_t         size);
+
 /*@}*/
+//////////////////////////////////////////////////////////////////////
+//           TWO STEP NEGOTIATION
+//////////////////////////////////////////////////////////////////////
+
+/**
+ * @defgroup twostepnego Two Step Negotiation
+ * @ingroup distributed
+ *
+ * Using the core services of FRSH, contracts may be negotiated in a
+ * single step.
+ *
+ * An alternative two-step negotiation process is introduced in the
+ * distribution module: the first step involves the reservation of the
+ * resources, but without the right to use them, and the second step
+ * is the commitment to use those resources.
+ *
+ * The rationale behind this approach is that in distributed systems,
+ * when a distributed transaction is being negotiated the system
+ * should only commit the virtual resources that were negotiated with
+ * various nodes in the system if the results of all negotiations
+ * match together. This approach enhances the efficiency since the
+ * actual temporal values of the virtual resources on distributed
+ * nodes are only changed if the initiator of the distributed
+ * transaction is satisfied with the results of the negotiations.
+ *
+ * After the reservation, it is not necessary to change the actual
+ * virtual resource attributes (and modifying the schedule) on each
+ * node before the initiator of the distributed transaction knows the
+ * amount of available virtual resources. A renegotiation of a
+ * reserved virtual resource is possible, to harmonize for the
+ * available virtual resources in other parts of the system, before a
+ * final commitment is made.
+ *
+ * @{
+ **/
+
+
+/**
+ * frsh_contract_negotiate_reservation()
+ *
+ * Negotiate a service contract, obtaining a virtual resource id that
+ * represents a reservation of resources, but without the right to use
+ * those resources until the reservation is committed via
+ * frsh_vres_commit_reservation. In particular, this virtual resource
+ * cannot be bound until committed, but renegotiations are allowed for
+ * it.
+ */
+int frsh_contract_negotiate_reservation
+  (const frsh_contract_t *contract,
+   frsh_vres_id_t        *vres);
+
+/**
+ * frsh_vres_commit_reservation()
+ *
+ * Commit the resources reserved for a virtual resource through a
+ * frsh_contract_negotiate_reservation operation. The effects of
+ * subsequent calls to frsh_contract_negotiate_reservation and
+ * frsh_vres_commit_reservation are equivalent to a single call to
+ * frsh_contract_negotiate.
+ */
+int frsh_vres_commit_reservation
+   (const frsh_vres_id_t   vres);
+
+/* @} */
+
+
 
 //////////////////////////////////////////////////////////////////////
 //           TRANSMISSION SERVICES
@@ -329,7 +446,7 @@ int frsh_contract_get_protocol_info(frsh_contract_t contract,
  * through which, after the corresponding binding, it is possible to
  * send data to a unicast or multicast destination.
  *
- * @param[in] network_id  Identifier of the network referred in the
+ * @param[in] resource_id  Identifier of the network referred in the
  *                        network contract as a resource_id.
  * @param[in] destination    FRSH abstraction of the protocol address for the
  *                        destinator node.
@@ -343,10 +460,11 @@ int frsh_contract_get_protocol_info(frsh_contract_t contract,
  * @param[out] endpoint   Placeholder for the endpoint object.
  **/
 int frsh_send_endpoint_create
-  (frsh_resource_id_t     network_id,
-   frsh_network_address_t    destination,
-   frsh_stream_id_t       stream_id,
-   frsh_send_endpoint_t  *endpoint);
+        (frsh_resource_id_t     resource_id,
+         frsh_network_address_t    destination,
+         frsh_stream_id_t       stream_id,
+         frsh_send_endpoint_protocol_info_t protocol_info,
+         frsh_send_endpoint_t  *endpoint);
 
 /**
  * frsh_send_endpoint_get_params()
@@ -355,10 +473,11 @@ int frsh_send_endpoint_create
  * endpoint at creation time.
  **/
 int frsh_send_endpoint_get_params
-    (const frsh_send_endpoint_t  *endpoint,
-     frsh_resource_id_t        *network_id,
+    (const frsh_send_endpoint_t  endpoint,
+     frsh_resource_id_t        *resource_id,
      frsh_network_address_t       *destination,
-     frsh_stream_id_t          *stream);
+     frsh_stream_id_t          *stream,
+     frsh_send_endpoint_protocol_info_t  *protocol_info);
 
 /**
  * frsh_send_endpoint_destroy()
@@ -369,8 +488,7 @@ int frsh_send_endpoint_get_params
  * code.
  **/
 int frsh_send_endpoint_destroy
-     (frsh_send_endpoint_t  *endpoint);
-
+     (frsh_send_endpoint_t  endpoint);
 
 /**
  * frsh_send_endpoint_bind()
@@ -384,7 +502,7 @@ int frsh_send_endpoint_destroy
  * unbound from it and bound to the specified one.  However if a vres
  * is already bound to another endpoint an error is returned.
  *
- * A consistency check is done in which the network_id specified at
+ * A consistency check is done in which the resource_id specified at
  * endpoint creation must correspond to the resource_id of the vres
  * contract.
  *
@@ -398,7 +516,7 @@ int frsh_send_endpoint_destroy
  **/
 int frsh_send_endpoint_bind
   (frsh_vres_id_t      vres,
-   frsh_send_endpoint_t  *endpoint);
+   frsh_send_endpoint_t  endpoint);
 
 /**
  * frsh_send_endpoint_unbind()
@@ -411,7 +529,7 @@ int frsh_send_endpoint_bind
  *         FRSH_ERR_NOT_BOUND if the endpoint was not bound \n
  **/
 int frsh_send_endpoint_unbind
-  (frsh_send_endpoint_t  *endpoint);
+  (frsh_send_endpoint_t  endpoint);
 
 /**
  * frsh_send_endpoint_get_vres_id()
@@ -425,7 +543,7 @@ int frsh_send_endpoint_unbind
  *                               is NULL \n
  **/
 int frsh_send_endpoint_get_vres_id
-  (const frsh_send_endpoint_t  *endpoint,
+  (const frsh_send_endpoint_t  endpoint,
    frsh_vres_id_t            *vres);
 
 /**
@@ -449,9 +567,9 @@ int frsh_send_endpoint_get_vres_id
  *                            have the policy FRSH_QP_OLDEST \n
  **/
 int frsh_send_async
-  (const frsh_send_endpoint_t  *endpoint,
-   void                       *msg,
-   size_t                      size);
+  (const frsh_send_endpoint_t  endpoint,
+   const void                  *msg,
+   const size_t                size);
 
 /**
  * frsh_send_sync()
@@ -460,12 +578,10 @@ int frsh_send_async
  * until the message is processed.
  **/
 int frsh_send_sync
-  (const frsh_send_endpoint_t *endpoint,
-   void                       *msg,
+  (const frsh_send_endpoint_t endpoint,
+   const void                 *msg,
    size_t                      size);
 
-
-
 /**
  * frsh_send_endpoint_get_status()
  *
@@ -473,10 +589,11 @@ int frsh_send_sync
  * endpoint queue, whether the network is up or down with some
  * optional information which is protocol_dependent.
  **/
-int frsh_send_endpoint_get_status(const frsh_send_endpoint_t *endpoint,
-                                  int *number_pending_msg,
-                                  frsh_endpoint_network_status *network_status,
-                                  frsh_protocol_status_t *protocol_status);
+int frsh_send_endpoint_get_status
+        (const frsh_send_endpoint_t endpoint,
+         int *number_pending_msg,
+         frsh_endpoint_network_status_t *network_status,
+         frsh_protocol_status_t *protocol_status);
 
 /**
  * frsh_receive_endpoint_create()
@@ -488,11 +605,11 @@ int frsh_send_endpoint_get_status(const frsh_send_endpoint_t *endpoint,
  * because don't originate any traffic.
  *
  * Note that the protocol address is not needed for reception because
- * it can be determined internally by FRSH based on the network_id.
+ * it can be determined internally by FRSH based on the resource_id.
  *
  * Note also that messages may come from diferent originators.
  *
- * @param[in] network_id  Id of the network from which we listen.
+ * @param[in] resource_id  Id of the network from which we listen.
  * @param[in] stream_id  Id of the stream within the network.
  * @param[in] queueing_info Buffering information(queue size and
  *                          policy).
@@ -505,13 +622,12 @@ int frsh_send_endpoint_get_status(const frsh_send_endpoint_t *endpoint,
  *      valid \n
  **/
 int frsh_receive_endpoint_create
-  (frsh_resource_id_t        network_id,
+  (frsh_resource_id_t        resource_id,
    frsh_stream_id_t          stream_id,
    frsh_endpoint_queueing_info_t queueing_info,
-   frsh_protocol_info_t     protocol_info,
+   frsh_receive_endpoint_protocol_info_t protocol_info,
    frsh_receive_endpoint_t  *endpoint);
 
-
 /**
  * frsh_receive_endpoint_get_params()
  *
@@ -519,11 +635,11 @@ int frsh_receive_endpoint_create
  * endpoint at creation time.
  **/
 int frsh_receive_endpoint_get_params
-    (frsh_resource_id_t        *network_id,
+     (const frsh_receive_endpoint_t  endpoint,
+     frsh_resource_id_t        *resource_id,
      frsh_stream_id_t          *stream,
      frsh_endpoint_queueing_info_t   *queueing_info,
-     frsh_protocol_info_t      *protocol_info,
-     const frsh_receive_endpoint_t  *endpoint);
+     frsh_receive_endpoint_protocol_info_t   *protocol_info);
 
 /**
  * frsh_receive_endpoint_destroy()
@@ -534,7 +650,7 @@ int frsh_receive_endpoint_get_params
  * code.
  **/
 int frsh_receive_endpoint_destroy
-     (frsh_receive_endpoint_t  *endpoint);
+     (frsh_receive_endpoint_t  endpoint);
 
 
 /**
@@ -566,10 +682,11 @@ int frsh_receive_endpoint_destroy
  *       provided buffer \n
  **/
 int frsh_receive_sync
-  (const frsh_receive_endpoint_t  *endpoint,
-   void                          *buffer,
+  (const frsh_receive_endpoint_t  endpoint,
+   void                           *buffer,
    size_t                         buffer_size,
-   size_t                        *message_size);
+   size_t                         *message_size,
+   frsh_network_address_t         *from);
 
 /**
  * frsh_receive_async()
@@ -586,10 +703,11 @@ int frsh_receive_sync
  *       provided buffer \n
  **/
 int frsh_receive_async
-  (const frsh_receive_endpoint_t  *endpoint,
-   void                          *buffer,
+  (const frsh_receive_endpoint_t  endpoint,
+   void                           *buffer,
    size_t                         buffer_size,
-   size_t                        *message_size);
+   size_t                         *message_size,
+   frsh_network_address_t         *from);
 
 
 /**
@@ -599,14 +717,14 @@ int frsh_receive_async
  * endpoint queue, whether the network is up or down and some optional
  * information which is protocol dependent.
  **/
-int frsh_receive_endpoint_get_status(const frsh_receive_endpoint_t *endpoint,
-                                  int *number_pending_messages,
-                                  frsh_endpoint_network_status *network_status,
-                                  frsh_protocol_status_t *protocol_status);
-
-
+int frsh_receive_endpoint_get_status
+        (const frsh_receive_endpoint_t endpoint,
+         int *number_pending_messages,
+         frsh_endpoint_network_status_t *network_status,
+         frsh_protocol_status_t *protocol_status);
 
 /*@}*/
 
+FRSH_CPP_END_DECLS
 
 #endif // _FRSH_DISTRIBUTED_H_