]> rtime.felk.cvut.cz Git - frescor/fna.git/commitdiff
fna tests
authorsangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 25 Jun 2007 15:34:48 +0000 (15:34 +0000)
committersangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 25 Jun 2007 15:34:48 +0000 (15:34 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@510 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_rtep/Makefile [new file with mode: 0644]
src_rtep/rtep_fna_c.c [new file with mode: 0644]
src_rtep/rtep_frsh_fna_c.c [new file with mode: 0644]
src_rtep/tests/Makefile [new file with mode: 0644]
src_rtep/tests/base_disk.img [new file with mode: 0755]
src_rtep/tests/mkvirtualdisk [new file with mode: 0755]
src_rtep/tests/test_c_frsh.c [new file with mode: 0644]
src_rtep/tests/test_c_rtep_fna.c [new file with mode: 0644]
src_rtep/tests/test_c_rtep_fna.c.old [new file with mode: 0644]
src_rtep/tests/test_c_rtep_frsh_fna.c [new file with mode: 0644]

diff --git a/src_rtep/Makefile b/src_rtep/Makefile
new file mode 100644 (file)
index 0000000..75cba8d
--- /dev/null
@@ -0,0 +1,23 @@
+.PHONY: clean
+
+MARTE_PATH=$(HOME)/marte
+CC=mgcc
+GNAT=mgnatmake
+POSIX_PATH = $(MARTE_PATH)/posix5
+ADA_INCLUDES = -I$(POSIX_PATH) -I$(MARTE_PATH)/drivers/rt-ep/lib
+ADA_FLAGS = -gnata -gnato -g # -gnatn -gnatp -O3
+C_INCLUDES = -I$(MARTE_PATH)/drivers/rt-ep/ -I../include -I../../frsh/include
+C_FLAGS = -DRTEP -DMARTE_OS -g -Wall
+
+librtepfna:
+       @exec echo -e "\n>> Building RTEP FNA:";
+       @mgcc -c $(C_FLAGS) rtep_fna_c.c $(C_INCLUDES) 1> /dev/null
+       @mgcc -c $(C_FLAGS) rtep_frsh_fna_c.c $(C_INCLUDES) 1> /dev/null
+       @ar -rc librtepfna.a *.o
+       @exec echo "  [OK]"
+
+clean:
+       @exec echo -e "\n>> Cleaning up RTEP FNA directories:";
+       @find \( -name '*.[oa]' -or -name '*.ali' -or -name '*~*' -or -name 'mprogram*' \
+       -or -name '*.exe' \) -print -delete
+       @exec echo "  [OK]"
diff --git a/src_rtep/rtep_fna_c.c b/src_rtep/rtep_fna_c.c
new file mode 100644 (file)
index 0000000..1efea4d
--- /dev/null
@@ -0,0 +1,955 @@
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politécnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//
+//  based on previous work (FSF) done in the FIRST project
+//
+//   Copyright (C) 2005  Mälardalen University, SWEDEN
+//                       Scuola Superiore S.Anna, ITALY
+//                       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
+//
+//  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 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.
+// -----------------------------------------------------------------------
+
+//==============================================
+//  ******** ****     **     **
+//  **///// /**/**   /**    ****
+//  **      /**//**  /**   **//**
+//  ******* /** //** /**  **  //**
+//  **////  /**  //**/** **********
+//  **      /**   //****/**//////**
+//  **      /**    //***/**     /**
+//  /       //      /// //      //
+//
+// FNA(Frescor Network Adaptation layer), pronounced "efe ene a"
+//==============================================================
+
+#ifndef _RTEP_FNA_H_
+#define _RTEP_FNA_H_
+
+#include "fna.h"
+#include "rtep.h" // for rtep_adainit, rtep_valid_multicast_id, ..
+#include "rtep_bandwith_reservation.h" // for rtep_bwres_*
+#include <malloc.h> // for malloc and free
+
+//////////////////////////////////////////////////////////////////////
+//           INITIALIZATION
+//////////////////////////////////////////////////////////////////////
+
+/**
+ * fna_init()
+ *
+ * This function will be hooked to the frsh_init function and it is
+ * intented to initialize the protocol and its structures.
+ *
+ * @param[in]  resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_ALREADY_INITIALIZED:
+ *      if the function has already been called before (with success) \n
+ *
+ **/
+int fna_init(const frsh_resource_id_t resource_id)
+{
+   rtep_adainit(); // init Ada bindings
+   return rtep_bwres_init();
+}
+
+///////////////////////////////////////////////////////////////////
+//           VIRTUAL RESOURCES
+///////////////////////////////////////////////////////////////////
+
+/**
+ * fna_contract_negotiate()
+ *
+ * The operation negotiates a contract and if accepted it will return
+ * a fna_vres_id_t. It will also check that the given contract_id is unique
+ * within the network.
+ *
+ * If the on-line admission test is enabled, it determines whether the
+ * contract can be admitted or not based on the current contracts
+ * established in the network. Then it creates the vres and
+ * recalculates all necessary parameters for the contracts already
+ * present in the system.
+ *
+ * This is a potentially blocking operation, it returns when the
+ * system has either rejected the contract, or admitted it and made it
+ * effective.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] contract  The contract parameters to negotiate
+ * @param[out] vres The internal virtual resource id
+ *
+ * @return
+ *   0 if there are no errors (in this case it also means contract accepted) \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_TOO_MANY_VRES: if there is no space for more vres \n
+ *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+ *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_contract_negotiate
+      (const frsh_resource_id_t resource_id,
+       const frsh_contract_t *contract,
+       fna_vres_id_t *vres)
+{
+   rtep_bwres_contract_t rtep_contract;
+   rtep_bwres_vres_t *rtep_vres;
+   int accepted;
+
+   // convert FRSH contract to RTEP BWRES contract
+   rtep_contract.period_max = contract->period_max;
+   rtep_contract.deadline = contract->deadline;
+   rtep_contract.prio = contract->preemption_level;
+   // in RTEP BWRES, budget is given in number of packets. We do a little trick
+   // in the function bytes_to_network_budget to use a the field tv_sec from the
+   // timespec in frsh_contract to store the budget in bytes directly
+   rtep_contract.budget_min = contract->budget_min.tv_sec;
+
+   // create an internal vres. The fna vres id is a pointer to void which
+   // we transform internally to a pointer to a vres structure
+   rtep_vres = (rtep_bwres_vres_t *)malloc(sizeof(rtep_bwres_vres_t));
+
+   // negotiate the contract
+   accepted = rtep_bwres_contract_negotiate (&rtep_contract, rtep_vres);
+
+   // vres is a pointer to void *, so we change void * for the new *rtep_vres
+   if (accepted == 0){
+      *vres = (void *)rtep_vres;
+   }else{
+      free(rtep_vres);
+   }
+
+   return accepted;
+}
+
+/**
+ * fna_contract_renegotiate_sync()
+ *
+ * The operation renegotiates a contract for an existing vres. If
+ * the on-line admission test is enabled it determines whether the
+ * contract can be admitted or not based on the current contracts
+ * established in the system. If it cannot be admitted, the old
+ * contract remains in effect and an error is returned. If it can be
+ * admitted, it recalculates all necessary parameters for the
+ * contracts already present in the system and returns zero. This is a
+ * potentially blocking operation; it returns when the system has
+ * either rejected the new contract, or admitted it and made it
+ * effective.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id to renegotiate
+ * @param[in] new_contract The new contract
+ *
+ *  @return
+ *   0 if there are no errors (in this case it also means contract accepted) \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+ *   FNA_ERR_CONTRACT_REJECTED: if the contract is not accepted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_contract_renegotiate_sync
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       const frsh_contract_t *new_contract)
+{
+   return 0;
+}
+
+/**
+ * fna_contract_renegotiate_async()
+ *
+ * The operation enqueues a renegotiate operation for an existing
+ * vres, and returns immediately. The renegotiate operation is
+ * performed asynchronously, as soon as it is practical; meanwhile the
+ * system operation will continue normally. When the renegotiation is
+ * made, if the on-line admission test is enabled it determines
+ * whether the contract can be admitted or not based on the current
+ * contracts established in the system. If it cannot be admitted, the
+ * old contract remains in effect. If it can be admitted, it
+ * recalculates all necessary parameters for the contracts already
+ * present in the system.
+ *
+ * When the operation is completed, notification is made to the
+ * caller, if requested, via a signal. The status of the operation (in
+ * progress, admitted, rejected) can be checked with the
+ * frsh_vres_get_renegotiation_status() operation.  The argument
+ * sig_notify can be FRSH_NULL_SIGNAL (no notification), or any FRSH
+ * signal value and in this case signal_info is to be sent with the signal.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id to renegotiate
+ * @param[in] new_contract The new contract
+ * @param[in] signal_to_notify  Signal number to use to notify vres of
+ * the negotiation result. If FRSH_NULL_SIGNAL,  no signal will be raised.
+ * @param[in] signal_info: Associated info that will come with the signal.
+ * This parameter will be ignored if signal_to_notify == FRSH_NULL_SIGNAL.
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_CONTRACT_ID_ALREADY_EXISTS: contract_id is not unique \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL, or sig_notify is neither
+ *      NULL nor a valid POSIX signal \n
+ *
+ **/
+int fna_contract_renegotiate_async
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       const frsh_contract_t *new_contract,
+       frsh_signal_t signal_to_notify,
+       frsh_signal_info_t signal_info)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_get_renegotiation_status()
+ *
+ * The operation reports on the status of the last renegotiation
+ * operation enqueued for the specified vres. It is callable even
+ * after notification of the completion of such operation, if
+ * requested.
+ *
+ * If the vres is not and has not been involved in any of the
+ * frsh_contract_renegotiate_async() or frsh_group_change_mode_async()
+ * operations, the status returned is FNA_NOT_REQUESTED
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id we want the status from
+ * @param[in] renegotiation_status The status of the last renegotiation on
+ * vres (FRSH_RS_IN_PROGRESS, FRSH_RS_REJECTED, FRSH_RS_ADMITTED,
+ * FRSH_RS_NOT_REQUESTED)
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_vres_get_renegotiation_status
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       frsh_renegotiation_status_t *renegotiation_status)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_destroy()
+ *
+ * The operation eliminates the specified vres
+ * and recalculates all necessary parameters for the contracts
+ * remaining in the system. This is a potentially blocking operation;
+ * it returns when the system has made the changes effective.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id to destroy
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_vres_destroy
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_get_contract()
+ *
+ * This operation stores the contract parameters currently associated
+ * with the specified vres in the variable pointed to by
+ * contract. It returns an error if the vres_id is not recognised.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id
+ * @param[out] contract  The contract parameters that we want
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_vres_get_contract
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       frsh_contract_t *contract)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_get_usage()
+ *
+ * This function gets the execution time spent by all messages that have been
+ * sent through the specified vres.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id
+ * @param[out] usage  Execution time spent by this vres
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_vres_get_usage
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       struct timespec *usage)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_get_remaining_budget()
+ *
+ * This function stores in the variable pointed to by budget the
+ * remaining execution-time budget associated with the specified
+ * vres in the present period.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id
+ * @param[out] remaining_budget  The remaining budget for this period
+ *
+ *  @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_vres_get_remaining_budget
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       struct timespec *remaining_budget)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_get_budget_and_period()
+ *
+ * This function gets the budget and period associated with the specified vres
+ * for each period. If one of these pointers is NULL, the corresponding
+ * information is not stored.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id
+ * @param[out] budget The budget associated to vres
+ * @param[out] period  The period associated to vres
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if both pointers are NULL \n
+ *
+ **/
+int fna_vres_get_budget_and_period
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       struct timespec *budget,
+       struct timespec *period)
+{
+   return 0;
+}
+
+/*@}*/
+
+///////////////////////////////////////////////////////////////////
+//           SPARE CAPACITY FUNCIONS
+///////////////////////////////////////////////////////////////////
+
+/**
+ * @defgroup fnaspare FNA Spare Capacity
+ * @ingroup fna
+ *
+ * The following functions are used to get spare capacity data
+ *
+ * @{
+ **/
+
+/**
+ * fna_resource_get_capacity()
+ *
+ * This operation gets the spare capacity currently assigned to a importance
+ * level. If we divide this value by UINT32_MAX we will get the network
+ * utilization associated to the spare capacity of a importance level.
+ *
+ * The following is typically in stdint.h: \n
+ *  - typedef unsigned int uint32_t;  \n
+ *  - # define UINT32_MAX  (4294967295U)  \n
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] importance The importance we want the capacity of
+ * @param[out] capacity The spare capacity for that importance level
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_resource_get_capacity
+      (const frsh_resource_id_t resource_id,
+       const int importance,
+       uint32_t *capacity)
+{
+   return 0;
+}
+
+/**
+ * fna_resource_get_total_weight()
+ *
+ * This function gets the sum of the weight parameters for all vres in a
+ * network of an importance level.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] importance The importance we want the total weight of
+ * @param[out] total_weight The total weight for that importance level
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_resource_get_total_weight
+      (const frsh_resource_id_t resource_id,
+       const int importance,
+       int *total_weight)
+{
+   return 0;
+}
+
+/**
+ * fna_vres_decrease_capacity()
+ *
+ * This function allows to ask for less budget and period than what we
+ * received. The request must be compatible with the rest of contract
+ * parameters of the vres. If we want to recover the released capacity
+ * we will need to renegotiate.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] vres The internal virtual resource id
+ * @param[in] new_budget The new_budget
+ * @param[in] new_period The new Period
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_CONTRACTED_VRES: if the vres is not contracted \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FNA_ERR_CONTRACT_REJECTED: if it is incompatible with the current
+ *      contract \n
+ *
+ **/
+int fna_vres_decrease_capacity
+      (const frsh_resource_id_t resource_id,
+       const fna_vres_id_t vres,
+       const struct timespec new_budget,
+       const struct timespec new_period)
+{
+   return 0;
+}
+
+///////////////////////////////////////////////////////////////////
+//           SEND RECEIVE OPERATIONS
+///////////////////////////////////////////////////////////////////
+
+/**
+ * fna_send_sync()
+ *
+ * Similar to previous function but now the sending thread gets blocked
+ * until the message is already sent to the network.
+ *
+ * @param[in] endpoint The send endpoint we are sending through. It must
+ *    be bound to a virtual resource (resource_id is in the endpoint).
+ * @param[in] msg The message we want to send
+ * @param[in] size The size in bytes of the message
+ *
+ * @returns
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+ *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+ *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+ *
+ **/
+int fna_send_sync
+   (const fna_send_endpoint_t *endpoint,
+    const void *msg,
+    const size_t size)
+{
+   return 0;
+}
+
+/**
+ * fna_send_async()
+ *
+ * This operation sends a message stored in msg and of length size
+ * through the given send endpoint. The operation is non-blocking and
+ * returns immediately.
+ *
+ * @param[in] endpoint The send endpoint we are sending through. It must
+ *    be bound to a virtual resource (resource_id is in the endpoint).
+ * @param[in] msg The message we want to send
+ * @param[in] size The size in bytes of the message
+ *
+ * @returns
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_BOUND: if endpoint is not bound to a valid vres \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FNA_ERR_TOO_LARGE: if the message is too large for the network protocol \n
+ *   FNA_ERR_BUFFER_FULL: if the message has been discarded because
+ *   the queue is full (and does not have the policy FNA_QP_OLDEST) \n
+ *
+ **/
+int fna_send_async
+   (const fna_send_endpoint_t *endpoint,
+    const void *msg,
+    const size_t size)
+{
+   return 0;
+}
+
+/**
+ * fna_receive_sync()
+ *
+ * This operation is used to receive messages from the network with a
+ * blocking behavior (if there are no messages this operation blocks
+ * the calling thread).
+ *
+ * When a message is available, it is copied to buffer (up to its size).
+ * The number of bytes copied is returned in received_bytes. The rest
+ * of the bytes of that message will be lost or not depending on the
+ * protocol (FNA_ERR_NO_SPACE will be returned if it is).
+ *
+ * The function fails with FNA_ERR_NO_SPACE if the buffersize is
+ * too small for the message received.  In this case the message is
+ * lost.
+ *
+ * Messages arriving at a receiver buffer that is full will be handled
+ * according to the queueing policy of the endpoint (overwrite oldest,
+ * discard it,etc).
+ *
+ * @param[in] endpoint The receive endpoint we are receiving from.
+ *    (resource_id is in the endpoint).
+ * @param[out] buffer Buffer for storing the received message
+ * @param[in] buffer_size The size in bytes of this buffer
+ * @param[out] received_bytes The actual number of received bytes
+ * @param[out] from Address of the sender node
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+ *      provided buffer. \n
+ *
+ **/
+int fna_receive_sync
+      (const frsh_receive_endpoint_t *endpoint,
+       void *buffer,
+       const size_t buffer_size,
+       size_t *received_bytes,
+       frsh_network_address_t *from)
+{
+   return 0;
+}
+
+/**
+ * fna_receive_async()
+ *
+ * This operation is similar to the previous one but it works in a non
+ * blocking (asynchronous) fashion.  If no message is available it
+ * returns with error FNA_NO_MESSAGE.
+ *
+ * @param[in] endpoint The receive endpoint we are receiving from.
+ *    (resource_id is in the endpoint).
+ * @param[out] buffer Buffer for storing the received message
+ * @param[in] buffer_size The size in bytes of this buffer
+ * @param[out] received_bytes The actual number of received bytes
+ * @param[out] from Address of the sender node
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *   FNA_ERR_NO_SPACE: if the message size is bigger than the
+ *      provided buffer. \n
+ *   FNA_NO_MESSAGE: if no messages are available in the queue. \n
+ *
+ **/
+int fna_receive_async
+      (const frsh_receive_endpoint_t *endpoint,
+       void *buffer,
+       const size_t buffer_size,
+       size_t *received_bytes,
+       frsh_network_address_t *from)
+{
+   return 0;
+}
+
+/**
+ * fna_send_endpoint_get_status()
+ *
+ * This function tells the number of messages still pending in the
+ * endpoint queue, whether the network is up or down with some
+ * optional information which is protocol_dependent.
+ *
+ * @param[in] endpoint The send endpoint (resource_id is in the endpoint).
+ * @param[out] number_of_pending_messages The number of pending messages
+ * @param[out] network_status How is the network (up, down..)
+ * @param[out] protocol_status Protocol dependent status info
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_send_endpoint_get_status
+   (const fna_send_endpoint_t *endpoint,
+    int *number_of_pending_messages,
+    frsh_endpoint_network_status *network_status,
+    frsh_protocol_status_t *protocol_status)
+{
+   return 0;
+}
+
+/**
+ * fna_receive_endpoint_create_callback()
+ *
+ * This operation is a called from frsh_receive_endpoint_create with a
+ * receive_endpoint structure already filled.
+ *
+ * Receiving endpoints are not bound to any network vres, this is
+ * because don't originate any traffic.
+ *
+ * @param[in] endpoint the endpoint object.
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ **/
+int fna_receive_endpoint_create_callback
+      (const frsh_receive_endpoint_t *endpoint)
+{
+   return 0;
+}
+
+/**
+ * fna_receive_endpoint_get_pending_messages
+ *
+ * This function tells the number of messages still pending in the
+ * endpoint queue, whether the network is up or down and some optional
+ * information which is protocol dependent.
+ *
+ * @param[in] endpoint The receive endpoint (resource_id is in the endpoint).
+ * @param[out] number_of_pending_messages The number of pending messages
+ * @param[out] network_status How is the network (up, down..)
+ * @param[out] protocol_status Protocol dependent status info
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_receive_endpoint_get_status
+      (const frsh_receive_endpoint_t *endpoint,
+       int *number_of_pending_messages,
+       frsh_endpoint_network_status *network_status,
+       frsh_protocol_status_t *protocol_status)
+{
+   return 0;
+}
+
+//////////////////////////////////////////////////////////////////////
+//           NETWORK CONFIGURATION FUNCTIONS
+//////////////////////////////////////////////////////////////////////
+
+/**
+ * fna_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
+ * 'resource_id' and sending it to 'destination'.
+ *
+ * If the application needs to send bigger messages it will have to
+ * split them.
+ *
+ * Some protocols, like IP, are capable of sending large messages
+ * (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
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or destination is
+ *   invalid \n
+ *
+ **/
+int fna_network_get_max_message_size
+      (const frsh_resource_id_t resource_id,
+       const frsh_network_address_t destination,
+       size_t *max_size)
+{
+   int is_multicast;
+
+   if (max_size == NULL) {
+      return -1;
+   }
+
+   is_multicast = rtep_valid_multicast_id ((rtep_station_id_t) destination);
+   if (is_multicast) {
+      *max_size = MULTICAST_MTU;
+   } else {
+      *max_size = MAX_RTEP_MTU;
+   }
+   return 0;
+}
+
+/**
+ * fna_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 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
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or nbytes is less
+ *   than zero \n
+ *
+ **/
+int fna_network_bytes_to_budget
+      (const frsh_resource_id_t resource_id,
+       const size_t nbytes,
+       struct timespec *budget)
+{
+   int number_of_packets;
+
+   if (budget == NULL || nbytes < 0) {
+      return -1;
+   }
+
+   // we measure the budget in number of RTEP packets of maximum size
+   number_of_packets = nbytes / MAX_RTEP_MTU + 1;
+   // we store the budget in number of packets instead of in time. We
+   // use a field in the timespec structure.
+   budget->tv_sec = number_of_packets;
+
+   return 0;
+}
+
+/**
+ * fna_network_budget_to_bytes()
+ *
+ * This operation converts a temporal budget into a number of bytes for
+ * a specific network. Network overheads are not included.
+ *
+ * @param[in] resource_id The network
+ * @param[in] budget The network budget for nbytes
+ * @param[out] nbytes Number of bytes
+ *
+ * @return
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL or budget refers to
+ *   an invalid time value \n
+ *
+ **/
+int fna_network_budget_to_bytes
+      (const frsh_resource_id_t resource_id,
+       const struct timespec *budget,
+       size_t *nbytes)
+{
+   int number_of_packets;
+
+   if (budget == NULL || nbytes == NULL) {
+      return -1;
+   }
+   number_of_packets = budget->tv_sec;
+   *nbytes = number_of_packets * MAX_RTEP_MTU;
+   return 0;
+}
+
+/**
+ * fna_network_get_min_effective_budget()
+ *
+ * This operation gets the minimum effective budget for a network. Each message
+ * consumes a contracted budget in "chunks" (i.e: packets) that we call
+ * 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:
+ *
+ *   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 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
+ *   0 if there are no errors \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if resource id does not represent
+ *   a network accessible from the current processing node \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int fna_network_get_min_effective_budget
+      (const frsh_resource_id_t resource_id,
+       struct timespec *budget)
+{
+   if (budget == NULL) {
+      return -1;
+   }
+   budget->tv_sec = 1;
+   return 0;
+}
+
+#endif // _RTEP_FNA_H_
+
diff --git a/src_rtep/rtep_frsh_fna_c.c b/src_rtep/rtep_frsh_fna_c.c
new file mode 100644 (file)
index 0000000..1cd5f5f
--- /dev/null
@@ -0,0 +1,187 @@
+#include "frsh_fna.h"
+#include "rtep_bandwith_reservation.h"
+
+//////////////////////////////////////////////////////////////////////
+//           MAPPING FUNCTIONS
+//////////////////////////////////////////////////////////////////////
+
+/**
+ * frsh_XXXX_map_network_address()
+ *
+ * To map a XXXX protocol network address into a FRSH address.
+ * The protocol must keep this mapping consistent. Instead of using a function
+ * a hardwired mapping could be used.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] in_address The network address we want to map to a frsh address
+ * @param[out] out_address The FRSH abstract network address
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int frsh_rtep_map_network_address
+      (const frsh_resource_id_t resource_id,
+       const rtep_station_id_t in_address,
+       frsh_network_address_t *out_address)
+{
+   if (out_address == NULL) return -1;
+   *out_address = in_address;
+   return 0;
+}
+
+/**
+ * frsh_XXXX_map_stream_id()
+ *
+ * To map a XXXX protocol network stream, port, channel... into a FRSH stream.
+ * The protocol must keep this mapping consistent. Instead of using a function
+ * a hardwired mapping could be used.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] in_stream The network stream we want to map to a FRSH stream
+ * @param[out] out_stream The FRSH abstract network stream
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int frsh_rtep_map_stream_id
+      (const frsh_resource_id_t resource_id,
+       const rtep_channel_t in_stream,
+       frsh_stream_id_t *out_stream)
+{
+   if (out_stream == NULL) return -1;
+   *out_stream = in_stream;
+   return 0;
+}
+
+///////////////////////////////////////////////////////////////////
+//           NEGOTIATION SERVICE PARAMETERS
+///////////////////////////////////////////////////////////////////
+
+/**
+ * frsh_XXXX_negotiation_messages__vres_renegotiate()
+ *
+ * This function allows the application to change the minimum period
+ * of the negotiation messages sent through the network. It is similar
+ * to the service thread but for the network messages. We do not provide
+ * budget here because the size of the negotiation messages is fixed.
+ *
+ * This change is similar to a renegotiation so a schedulability test
+ * must be done to see if the change can be accepted or not.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] period The new period for negotiation messages
+ * @param[out] accepted If the change has been accepted or not
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+
+int frsh_rtep_negotiation_messages_vres_renegotiate
+      (const frsh_resource_id_t resource_id,
+       const struct timespec *period)
+{
+   return rtep_bwres_renegotiate_negotiation_period(period);
+}
+
+/**
+ * frsh_XXXX_negotiation_messages_vres_get_period()
+ *
+ * This function gets the minimum period of the negotiation messages
+ * sent through the network.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[out] period The period for negotiation messages
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int frsh_rtep_negotiation_messages_vres_get_period
+      (const frsh_resource_id_t resource_id,
+       struct timespec *period)
+{
+   return rtep_bwres_get_negotiation_period (period);
+}
+
+/**
+ * frsh_XXXX_service_thread_vres_renegotiate()
+ *
+ * This function allows the application to change the period and
+ * budget of the service thread that makes the negotiations and
+ * schedulability tests in a network.
+ *
+ * The service thread starts with a default budget and period that
+ * should be configurable
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[in] budget The new budget for the service thread
+ * @param[in] period The new period for the service thread
+ * @param[out] accepted If the negotiation has been accepted or not
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int frsh_rtep_service_thread_vres_renegotiate
+   (const frsh_resource_id_t resource_id,
+    const struct timespec *budget,
+    const struct timespec *period,
+    bool *accepted)
+{
+   return -1;
+}
+
+/**
+ * frsh_XXXX_service_thread_vres_get_budget_and_period()
+ *
+ * This function gets the budget and period of a service thread.
+ *
+ * @param[in] resource_id The network we are referring to (a protocol
+ * could be able to handle several networks at the same time)
+ * @param[out] budget The budget of the service thread
+ * @param[out] period The period of the service thread
+ *
+ * @return
+ *   FNA_NO_ERROR: in this case it also means contract accepted \n
+ *   FNA_ERR_INTERNAL_ERROR: protocol dependent internal errors \n
+ *   FNA_ERR_NOT_INITIALIZED: if the protocol is not initialized \n
+ *   FNA_ERR_RESOURCE_ID_INVALID: if we are not in charge of resource_id \n
+ *   FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n
+ *
+ **/
+int frsh_rtep_service_thread_vres_get_budget_and_period
+      (const frsh_resource_id_t resource_id,
+       struct timespec *budget,
+       struct timespec *period)
+{
+   return -1;
+}
+
diff --git a/src_rtep/tests/Makefile b/src_rtep/tests/Makefile
new file mode 100644 (file)
index 0000000..47469e9
--- /dev/null
@@ -0,0 +1,72 @@
+.PHONY: clean
+
+MARTE_PATH=$(HOME)/marte
+CC=mgcc
+GNAT=mgnatmake
+POSIX_PATH = $(MARTE_PATH)/posix5
+ADA_INCLUDES = -I$(POSIX_PATH) -I$(MARTE_PATH)/drivers/rt-ep/lib
+ADA_FLAGS = -gnata -gnato -g # -gnatn -gnatp -O3
+C_INCLUDES = -I$(MARTE_PATH)/drivers/rt-ep/ -I../../include -I../../../frsh/include
+C_FLAGS = -DRTEP -DMARTE_OS -g -Wall
+
+%:
+       @exec echo -en "\n>> Compiling $@: ";
+       @if [ -f $@.c ]; then $(CC) $(C_FLAGS) $@.c $(C_INCLUDES) -L../ -lrtepfna -L$(MARTE_PATH)/drivers/rt-ep/ -lrtep 1> /dev/null; fi
+       @if [ -f $@.adb ]; then $(GNAT) $(ADA_FLAGS) $@.adb $(ADA_INCLUDES) 1> /dev/null; fi
+       @exec echo "  [OK]";
+
+export:
+       @cp $(MARTE_PATH)/mprogram .
+       @cp mprogram /home/dsl/export/mprogram_right
+       @cp mprogram /home/dsl/export/mprogram_left
+       @cp mprogram /home/dsl/export/mprogram_middle
+
+create_emulator_imgs:
+       @cp base_disk.img master.img
+       @cp base_disk.img slave.img
+       @cp base_disk.img other_slave.img
+
+qemu_1:
+       @cp $(MARTE_PATH)/mprogram .
+       @mv slave.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img slave.img
+       qemu -hda slave.img &
+
+qemu_2:
+       @cp $(MARTE_PATH)/mprogram .
+       @mv slave.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img slave.img
+       @mv master.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img master.img
+       qemu -hda slave.img -net nic,macaddr=00:0E:0C:5B:1D:BD,model=rtl8139 -net socket,mcast=230.0.0.1:1234 &
+# qemu -hda slave.img -net nic,macaddr=00:02:44:35:66:5B,model=rtl8139 -net socket,mcast=230.0.0.1:1234 &
+       @sleep 2
+       qemu -hda master.img -net nic,macaddr=00:0E:0C:5B:1E:28,model=rtl8139 -net socket,mcast=230.0.0.1:1234
+# qemu -hda master.img -net nic,macaddr=00:02:44:3B:6A:BE,model=rtl8139 -net socket,mcast=230.0.0.1:1234
+
+qemu_3:
+       @cp $(MARTE_PATH)/mprogram .
+       @mv master.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img master.img
+       @mv slave.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img slave.img
+       @mv other_slave.img disk.img
+       @./mkvirtualdisk
+       @mv disk.img other_slave.img
+       qemu -hda master.img -net nic,macaddr=00:0E:0C:5B:1E:28,model=rtl8139 -net socket,mcast=230.0.0.1:1234 &
+       qemu -hda slave.img -net nic,macaddr=00:0E:0C:5B:1D:BD,model=rtl8139 -net socket,mcast=230.0.0.1:1234 &
+       qemu -hda other_slave.img -net nic,macaddr=00:02:44:3C:08:21,model=rtl8139 -net socket,mcast=230.0.0.1:1234 &
+
+clean:
+       @exec echo -e "\n>> Cleaning up RTEP FNA TESTS directory:";
+       @find \( -name '*.[oa]' -or -name '*.ali' -or -name '*~*' -or -name 'mprogram*' \
+       -or -name '*.exe' \) -print -delete
+       @rm -fv master.img
+       @rm -fv slave.img
+       @rm -fv other_slave.img
+       @exec echo "  [OK]"
diff --git a/src_rtep/tests/base_disk.img b/src_rtep/tests/base_disk.img
new file mode 100755 (executable)
index 0000000..b6daadc
Binary files /dev/null and b/src_rtep/tests/base_disk.img differ
diff --git a/src_rtep/tests/mkvirtualdisk b/src_rtep/tests/mkvirtualdisk
new file mode 100755 (executable)
index 0000000..47ceb20
--- /dev/null
@@ -0,0 +1,5 @@
+losetup -o32256 /dev/loop/0 disk.img &&
+mount -o loop /dev/loop0  mnt &&
+cp -f mprogram mnt/mprogram &&
+umount mnt &&
+losetup -d /dev/loop/0
diff --git a/src_rtep/tests/test_c_frsh.c b/src_rtep/tests/test_c_frsh.c
new file mode 100644 (file)
index 0000000..fa99861
--- /dev/null
@@ -0,0 +1,70 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <misc/error_checks.h>
+#include <misc/load.h>
+#include "../rtep.h"
+#include "../frsh/fna/include/fna.h"
+
+int main ()
+{
+   uint16_t me;
+   int ret;
+
+   adjust ();
+   rtep_adainit();
+
+   // ret = pthread_setschedprio (pthread_self(),5);
+
+   // FRSH_Distributed.Init;
+   rtep_fna_init();
+
+   // Ada.Text_Io.Put_Line ("I am "&RTEP.Station_ID'Image (RP.Get_Station_ID));
+   me = rtep_get_station_id();
+   printf ("I am: %u\n", me);
+
+   // FRSH_Distributed.Set_Basic_Parameters
+   //    (Contract, Budget_Min, Period_Max, Deadline);
+   ret = frsh_contract_set_basic_parameters
+      (&contract, b_min, per_max_sec, per_max_nsec, deadline);
+
+   // FRSH_Distributed.Set_Priority (Contract, Prio);
+   ret = rtep_frsh_contract_set_priority (&contract, prio);
+
+   // FRSH_Distributed.Negotiate_Contract
+   //    (Contract, Vres, Accepted);
+   ret = rtep_fna_vres_create (&contract, &vres, &acccepted);
+
+   // if not Accepted then
+   //    Ada.Text_Io.Put_Line ("Contract Not Accepted");
+   //    return;
+   // end if;
+   if (!accepted) {
+      printf ("contract not accepted\n");
+      return -1;
+   }
+
+   // Ada.Text_Io.Put_Line ("Contract Accepted");
+   printf ("contract accepted\n");
+
+   // S_Id := FRSH_Distributed.Get_Server_Id (Vres);
+   // loop
+   //    RP.Send_Info
+   //       (Destination_Station_ID  => Dest_Id,
+   //       Channel_ID              => Chan,
+   //       Data => RTEP_Streams.To_Stream_Element_Array ("Hello World"),
+   //       Id                      => S_Id,
+   //       Blocking                => True);
+   //    Next_Time := Ada.Real_Time."+" (Next_Time, Period_Max);
+   //    delay until Next_Time;
+   // end loop;
+   ret = rtep_frsh_create_send_endpoint (&endpoint, dest, chan, vres);
+
+   while (1) {
+      ret = rtep_fna_send_async (&endpoint, msg, size);
+      ret = rtep_fna_receive_sync (&endpoint, msg, size, &received_bytes);
+   }
+   // finalization
+   rtep_adafinal();
+   return 0;
+}
diff --git a/src_rtep/tests/test_c_rtep_fna.c b/src_rtep/tests/test_c_rtep_fna.c
new file mode 100644 (file)
index 0000000..d7597e9
--- /dev/null
@@ -0,0 +1,114 @@
+#include <misc/assert.h> // for assert
+#include <stdio.h> // for printf
+#include <time.h> // for timespec
+
+#include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT
+#include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
+#include "fna.h" // for fna_*
+#include "frsh_fna.h" // for frsh_rtep_*
+#include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+#include "frsh_core.h" // for frsh_contract_*
+
+int main ()
+{
+   int err;
+   rtep_station_id_t normal_station, multicast_station;
+   frsh_network_address_t frsh_address;
+   char multicast_name[] = "broadcast";
+   size_t max_size, max_multicast_size, budget_bytes, nbytes;
+   struct timespec budget_timespec, period_max;
+   frsh_contract_t frsh_contract;
+   frsh_contract_label_t label = "dani";
+   fna_vres_id_t vres;
+
+   printf("--------------------------------------------------\n");
+   printf("1.- fna_init\n");
+   printf("--------------------------------------------------\n");
+   err=fna_init(FRSH_RESOURCE_ID_DEFAULT);
+   assert(err == 0);
+
+   printf("--------------------------------------------------\n");
+   printf("2.- fna_network_get_max_message_size\n");
+   printf("--------------------------------------------------\n");
+   // get broadcast address for FRESCOR
+   multicast_station = rtep_get_station_id_by_name
+         ((uint8_t *)multicast_name, sizeof(multicast_name)-1);
+   err=frsh_rtep_map_network_address
+         (FRSH_RESOURCE_ID_DEFAULT, multicast_station, &frsh_address);
+   assert (err == 0);
+   // maximum size per message for a broadcast address
+   err=fna_network_get_max_message_size
+         (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_multicast_size);
+   printf("Max multicast message size: %d\n", max_multicast_size);
+   assert (err == 0);
+   assert (max_multicast_size == MULTICAST_MTU);
+
+   // now the same with a normal address (i.e: 2)
+   normal_station = 2;
+   err=frsh_rtep_map_network_address
+         (FRSH_RESOURCE_ID_DEFAULT, normal_station, &frsh_address);
+   assert (err == 0);
+   // maximum size per message for a normal address
+   err=fna_network_get_max_message_size
+         (FRSH_RESOURCE_ID_DEFAULT, frsh_address, &max_size);
+   printf("Max message size: %d\n", max_size);
+   assert (err == 0);
+   assert (max_size == MAX_RTEP_MTU);
+
+   printf("--------------------------------------------------\n");
+   printf("3.- fna_network_budget_to_bytes\n");
+   printf("--------------------------------------------------\n");
+   nbytes = 1700;
+   err=fna_network_bytes_to_budget
+         (FRSH_RESOURCE_ID_DEFAULT, nbytes, &budget_timespec);
+   assert (err == 0);
+
+   err=fna_network_budget_to_bytes
+         (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+   assert (err == 0);
+   printf("%d user bytes -> %d budget bytes\n", nbytes, budget_bytes);
+
+   printf("--------------------------------------------------\n");
+   printf("4.- fna_network_get_min_effective_budget\n");
+   printf("--------------------------------------------------\n");
+   err=fna_network_get_min_effective_budget
+         (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec);
+   assert (err == 0);
+
+   err=fna_network_budget_to_bytes
+         (FRSH_RESOURCE_ID_DEFAULT, &budget_timespec, &budget_bytes);
+   assert (err == 0);
+   printf("Minimum effective budget: %d\n", budget_bytes);
+
+   printf("--------------------------------------------------\n");
+   printf("5.- fna_contract_negotiate\n");
+   printf("--------------------------------------------------\n");
+   err=frsh_contract_init(&frsh_contract);
+   assert (err == 0);
+
+   period_max.tv_sec = 3;
+   period_max.tv_nsec = 0;
+
+   err=frsh_contract_set_basic_params
+         (&frsh_contract,
+          &budget_timespec,
+          &period_max,
+          FRSH_WT_INDETERMINATE,
+          FRSH_CT_REGULAR);
+   assert (err == 0);
+
+   err=frsh_contract_set_resource_and_label
+         (&frsh_contract,
+          FRSH_RT_NETWORK,
+          FRSH_RESOURCE_ID_DEFAULT,
+          label);
+   assert (err == 0);
+
+   err=fna_contract_negotiate
+         (FRSH_RESOURCE_ID_DEFAULT,
+          &frsh_contract,
+          &vres);
+   assert (err == 0);
+
+   return 0;
+}
diff --git a/src_rtep/tests/test_c_rtep_fna.c.old b/src_rtep/tests/test_c_rtep_fna.c.old
new file mode 100644 (file)
index 0000000..e36facf
--- /dev/null
@@ -0,0 +1,106 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <misc/error_checks.h>
+#include <unistd.h>
+#include "rtep.h"
+
+static uint16_t channel = 3;
+
+
+/* receiver_task */
+static void *receiver_task (void *arg)
+{
+   const int MAX_SIZE = 1500;
+   uint8_t buffer[MAX_SIZE+1];
+   size_t received_bytes;
+   frsh_endpoint_queueing_info_t queueing_info;
+   frsh_protocol_info_t protocol_info;
+   frsh_receive_endpoint_t endpoint;
+//    uint16_t station;
+//    uint8_t prio;
+
+   printf ("receiver_task\n");
+
+   /* create the receive endpoint (TODO: should be done using FRSH api) */
+   endpoint.network_id = 0;
+   endpoint.stream_id = (frsh_stream_id_t)channel;
+   endpoint.queueing_info = queueing_info;
+   endpoint.protocol_info = protocol_info;
+   CHKE_FATAL (rtep_fna_receive_endpoint_create_callback(&endpoint));
+
+   while (1) {
+      CHKE_FATAL (rtep_fna_receive_sync (&endpoint, (void *)buffer, MAX_SIZE,
+         &received_bytes));
+
+      buffer[received_bytes] = 0;
+//       printf ("received data from: %u  with prio: %u last: %d data: ",
+//               station, prio, last);
+//       printf ("received %s\n",buffer);
+      fputs ((char *)buffer, stdout);
+   }
+}
+
+int main ()
+{
+   uint16_t me;
+   uint16_t dest_station;
+   char dest_station_name[] = "broadcast";
+   char msg_broadcast[] = "Hi All!\n";
+   frsh_contract_t contract;
+   uint16_t budget_min = 3;
+   struct timespec period_max = {10, 0};
+   struct timespec deadline = period_max;
+   fna_vres_id_t vres;
+   fna_send_endpoint_t send_endpoint;
+   uint8_t prio = 8;
+   int accepted;
+   pthread_t th;
+   pthread_attr_t attr;
+
+   /* initialization */
+   rtep_adainit();
+   CHKE_FATAL (rtep_fna_init(0));
+
+   me = rtep_get_station_id();
+   printf ("I am: %u\n", me);
+
+   /* create a thread that receives messages */
+   CHKE_FATAL( pthread_attr_init (&attr) );
+   CHKE_FATAL( pthread_create (&th, &attr, receiver_task, NULL) );
+
+   /* set contract params (TODO: should be done using FRSH api) */
+   contract.budget_min = budget_min;
+   contract.period_max = period_max;
+   contract.deadline = deadline;
+   contract.prio = prio;
+
+   /* negotiate the contract */
+   accepted = rtep_fna_contract_negotiate (0, &contract, &vres);
+
+   if (accepted != 0) {
+      printf ("contract not accepted\n");
+      return -1;
+   }
+   printf ("contract accepted\n");
+
+   /* create the send endpoint (TODO: should be done using FRSH api) */
+   dest_station = rtep_get_station_id_by_name
+         ((uint8_t *)dest_station_name, sizeof(dest_station_name)-1);
+
+   send_endpoint.network_id = 0;
+   send_endpoint.destination = (frsh_network_address_t)dest_station;
+   send_endpoint.stream_id = (frsh_stream_id_t)channel;
+   send_endpoint.vres = vres;
+
+   /* send messages */
+   while (1) {
+      printf ("sending a message\n");
+      rtep_fna_send_async(&send_endpoint, msg_broadcast, sizeof(msg_broadcast));
+      sleep (2);
+   }
+
+   // finalization
+   rtep_adafinal();
+   return 0;
+}
diff --git a/src_rtep/tests/test_c_rtep_frsh_fna.c b/src_rtep/tests/test_c_rtep_frsh_fna.c
new file mode 100644 (file)
index 0000000..73afc9a
--- /dev/null
@@ -0,0 +1,59 @@
+#include <misc/assert.h> // for assert
+#include <stdio.h> // for printf
+
+#include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT
+#include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t
+#include "fna.h" // for fna_init
+#include "frsh_fna.h" // for frsh_rtep_*
+#include "rtep.h" // for rtep_station_id_t, rtep_channel_t
+
+int main ()
+{
+   int err;
+   rtep_station_id_t rtep_station = 3;
+   frsh_network_address_t frsh_address;
+   rtep_channel_t in_stream = 7;
+   frsh_stream_id_t out_stream;
+   struct timespec neg_period = {2,0};
+   struct timespec get_period = {0,0};
+
+   printf("1.- fna_init\n");
+   printf("--------------------------------------------------\n");
+   err=fna_init(FRSH_RESOURCE_ID_DEFAULT);
+   assert(err == 0);
+
+   printf("2.- frsh_rtep_map_network_address\n");
+   printf("--------------------------------------------------\n");
+   err=frsh_rtep_map_network_address
+         (FRSH_RESOURCE_ID_DEFAULT, rtep_station, &frsh_address);
+   assert(err == 0);
+   printf("rtep_address: %d, frsh_address: %d\n", rtep_station, frsh_address);
+   assert(rtep_station == frsh_address);
+
+   printf("3.- frsh_rtep_map_stream_id\n");
+   printf("--------------------------------------------------\n");
+   err=frsh_rtep_map_stream_id
+         (FRSH_RESOURCE_ID_DEFAULT, in_stream, &out_stream);
+   assert(err == 0);
+   printf("rtep_channel: %d, frsh_stream: %d\n", in_stream, out_stream);
+   assert(in_stream == out_stream);
+
+   printf("4.- frsh_rtep_negotiation_messages_vres_renegotiate period\n");
+   printf("--------------------------------------------------\n");
+   err=frsh_rtep_negotiation_messages_vres_get_period
+         (FRSH_RESOURCE_ID_DEFAULT, &get_period);
+   assert(err == 0);
+   printf("get_period sec=%d nsec=%d\n", get_period.tv_sec, get_period.tv_nsec);
+
+   err=frsh_rtep_negotiation_messages_vres_renegotiate
+         (FRSH_RESOURCE_ID_DEFAULT, &neg_period);
+   printf("renegotiation accepted: %d\n", !err);
+   assert(err == 0);
+
+   err=frsh_rtep_negotiation_messages_vres_get_period
+         (FRSH_RESOURCE_ID_DEFAULT, &get_period);
+   assert(err == 0);
+   printf("get_period sec=%d nsec=%d\n", get_period.tv_sec, get_period.tv_nsec);
+
+   return 0;
+}