CFLAGS += -Wall -D_REENTRANT -g -D_FWP_INTERNALS_
-SUBDIRS= core frsh_fwp
+SUBDIRS= fwp frsh_fwp
+++ /dev/null
-#lib_LIBRARIES = fwp
-CFLAGS += -Wall -D_REENTRANT -g -D_FWP_INTERNALS_ -DFWP_WITH_CONTNEGT
-SUBDIRS= tests
-#LDFLAGS = -lpthread -lrt
-#fwp_SOURCES = fwp_utils.c fwp_vres.c fwp_msgb.c fwp_msgq.c\
- fwp_endpoint.c
-
-include_HEADERS= fwp_vres.h fwp_msgb.h fwp_msgq.h \
- fwp_utils.h fwp_endpoint.h
-
-#lib_LOADLIBES+= pthread rt
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = FWP
PROJECT_NUMBER =
-OUTPUT_DIRECTORY = _compiled/doc
+OUTPUT_DIRECTORY = doc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
+++ /dev/null
-# Generic directory or leaf node makefile for OCERA make framework
-
-ifndef MAKERULES_DIR
-MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
-endif
-
-ifeq ($(MAKERULES_DIR),)
-all : default
-.DEFAULT::
- @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
-else
-include $(MAKERULES_DIR)/Makefile.rules
-endif
-
+++ /dev/null
-#lib_LIBRARIES = fwpmngt
-CFLAGS += -Wall -D_REENTRANT -g -D_FWP_INTERNALS_
-#LDFLAGS = -lpthread -lrt
-#fwpmngt_SOURCES = fwp_msg.c fwp_mngt.c
-
-include_HEADERS= fwp_msg.h fwp_participant.h fwp_mngt.h fwp_contract.h\
- fwp_contract_table.h
-
-#lib_LOADLIBES+= fwp ulut
-#lib_LOADLIBES+= pthread rt
+++ /dev/null
-/**
- * \file fwp_contract.c
- *
- * Routines for manipulation with contract
- *
- */
-#include "fwp_msg.h"
-#include "fwp_contract.h"
-#include "fwp_contract_table.h"
-#include "fwp_mngt.h"
-#include <pthread.h>
-
-static int fwp_contract_is_reserved(fwp_contract_d_t contract)
-{
- return (contract->status == FWP_CONT_RESERVED);
-}
-
-int fwp_contract_is_negotiated(fwp_contract_d_t contract)
-{
- return (contract->status == FWP_CONT_NEGOTIATED);
-}
-
-/**
- * Negotiates contract for application. Negotiation request is sent to
- * fwp agent and then waits for response.
- *
- * \param[in] contractd Descriptor of the contract to negotiate
- * \param[out] vresd Vres descriptor after the contract was accepted
- *
- * \return
- * If successful, the function returns zero and vres descriptor is
- * stored in vresdp parameter, otherwise -1 is returned and errno is set appropriately. If the contract is not negotiated EAGAIN
- * error is returned.
- */
-/*int fwp_contract_negotiate(fwp_contract_d_t contractd, void *vresdp) */
-int fwp_contract_negotiate(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp)
-{
- int ret;
- ret = fwp_contract_reserve(contractd);
- if (ret < 0)
- return ret;
- if (!fwp_contract_is_reserved(contractd)) {
- errno = EAGAIN;
- return -1;
- }
-
- fwp_contract_commit(contractd, vresdp);
- return 0;
-}
-
-/**
- * Allocates a contract and VRES and inserts the contract to
- * contract_table.
- *
- * \param[in] contract User-level contract
- *
- * \return On success, returns contract descriptor, on error NULL is returned.
- *
- */
-/*fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract, resource_d_t resource)*/
-fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract)
-{
- fwp_contract_data_t *contdata;
-
- contdata = fwp_contract_data_new();
- if (!contdata)
- return NULL;
- /* To be compatible: reserve vres, get its id, and store it to
- * condata->id
- */
- contdata->vresd = fwp_vres_alloc();
- if (!contdata->vresd) {
- fwp_contract_data_delete(contdata);
- return NULL;
- }
-
- contdata->id = fwp_vres_get_id(contdata->vresd);
-
- memcpy(&contdata->contract, contract, sizeof(*contract));
- contdata->status = FWP_CONT_NOTNEGOTIATED;
- /* Add to contract table */
- fwp_contract_table_insert(&fwp_participant_this->contract_table,
- contdata);
-
- FWP_DEBUG("Contract id=%d stored in table\n", contdata->id);
- return contdata;
-}
-
-/**
- * Destroys contract
- *
- * \param[in] contractd Contract descriptor
- *
- * \return On success, returns zero.
- * On error, returns negative error code.
- *
- */
-int fwp_contract_destroy(fwp_contract_d_t contractd)
-{
- fwp_contract_data_t *contdata = contractd;
-
- if (contdata->status != FWP_CONT_NOTNEGOTIATED) {
- errno = EINVAL;
- return -1;
- }
-
- if (fwp_vres_destroy(contdata->vresd)) {
- errno = EPERM;
- return -1;
- }
-
- /* FIXME: Shouldn't be the contract deleted from
- * contract_table here? */
- fwp_contract_data_delete(contdata);
- return 0;
-}
-
-/**
- * Reserves contract
- *
- * \param[in] contractd Contract descriptor
- *
- * \return On success, returns zero.
- * On error, returns negative error code.
- *
- */
-int fwp_contract_reserve(fwp_contract_d_t contractd)
-{
- fwp_contract_data_t *contdata = contractd;
- fwp_msgb_t *msgb;
- fwp_msg_type_t msg_type;
- fwp_participant_id_t participant_id;
- int ret;
-
- /*contdata = fwp_contract_table_find(&fwp_participant_this->contract_table,
- contract_id);*/
- /* Send contract to manager */
- msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_contracthdr) +
- sizeof(struct fwp_msg_contract) +
- sizeof(struct fwp_vres_params));
-
- /* reserve place for header */
- fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
- /*Add contract header*/
- fwp_msg_contracthdr_in(msgb->tail, contdata->id, contdata->status);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_contracthdr));
- /* Add contract params */
- fwp_msg_contract_in(msgb->tail, &contdata->contract);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_contract));
-
- ret = fwp_mngt_send(FWP_MSG_RESERVE, msgb,
- fwp_participant_this, fwp_participant_mngr);
- if (ret < 0)
- return ret;
- ret = fwp_mngt_recv(&msg_type, &participant_id, msgb);
- if (ret < 0)
- return ret;
- fwp_msg_contracthdr_out(msgb->data, &contdata->id, &contdata->status);
- fwp_msgb_pull(msgb, sizeof(struct fwp_msg_contracthdr));
-
- if (contdata->status == FWP_CONT_RESERVED) {
- fwp_msg_vres_params_out(msgb->data, &contdata->vres_params);
- FWP_DEBUG("Received vres params budget=%d period=%d ac=%d \n",
- contdata->vres_params.budget,
- contdata->vres_params.period_usec,
- contdata->vres_params.ac_id);
- fwp_msgb_pull(msgb, sizeof(struct fwp_msg_vres_params));
- }
-
- FWP_DEBUG("STATUS = %d\n", contdata->status);
- return 0;
-}
-
-/**
- * Commits contract
- *
- * \param[in] contractd Contract descriptor
- * \param[out] vresd Descriptor of vres
- *
- * \return On success, returns zero.
- * On error, returns -1 and sets errno appropriately.
- *
- */
-int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp)
-{
- fwp_contract_data_t *contdata = contractd;
- fwp_msgb_t *msgb;
- int ret;
-
- /* Send COMMIT to manager */
- msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_contracthdr));
- fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
- fwp_msg_contracthdr_in(msgb->tail, contdata->id, contdata->status);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_contracthdr));
- FWP_DEBUG("Commit contract id =%d\n", contdata->id);
-
- ret = fwp_mngt_send(FWP_MSG_COMMIT, msgb,
- fwp_participant_this, fwp_participant_mngr);
- if (ret < 0)
- return ret;
-
- contdata->status = FWP_CONT_NEGOTIATED;
- /* Set parameters of vres
- * and activate it if needed */
- ret = fwp_vres_set_params(contdata->vresd, &contdata->vres_params);
- if (ret < 0)
- return ret;
- *vresdp = contdata->vresd;
-
- return 0;
-}
-
-/**
- * Cancels contract
- *
- * \param[in] contractd Contract descriptor
- *
- * \return On success, returns zero.
- * On error, returns negative error code.
- *
- */
-int fwp_contract_cancel(fwp_contract_d_t contractd)
-{
- fwp_contract_data_t *contdata = contractd;
- fwp_msgb_t *msgb;
-
- if (contdata->status != FWP_CONT_NEGOTIATED) {
- errno = EINVAL;
- return -1;
- }
-
- /* Send CANCEL to manager */
- msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_contracthdr));
- fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
- fwp_msg_contracthdr_in(msgb->tail, contdata->id, contdata->status);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_contracthdr));
- FWP_DEBUG("Cancel contract id =%d\n", contdata->id);
-
- fwp_mngt_send(FWP_MSG_CANCEL, msgb,
- fwp_participant_this, fwp_participant_mngr);
-
- contdata->status = FWP_CONT_NOTNEGOTIATED;
- fwp_vres_destroy(contdata->vresd);
- /*contdata->vresd = NULL_vresd;*/
-
- /*TODO: error handling */
- return 0;
-}
+++ /dev/null
-#ifndef _FWP_CONTRACT_H
-#define _FWP_CONTRACT_H
-
-#include "fwp_vres.h"
-
-/*
- *typedef struct mfrsh_contract_ops{
- * fwp_contract_d_t (*create)(fwp_contract_t *contract);
- * int (*destroy)(fwp_contract_t *contract);
- * int (*reserve)(fwp_contract_d_t contractd);
- * int (*commit)(fwp_contract_d_t contractd);
- * int (*cancel)(fwp_contract_d_t contractd);
- * int (*commute)(fwp_contract_d_t origin,
- * fwp_contract_d_t contractd);
- *} mfrsh_contract_ops_t;
- *
- * typedef struct mfrsh_contract_d {
- * mfrsh_resource_id_t resource_id;
- * mfrsh_contract_id_t contract_id;
- *}
- */
-
-/**
- * FWP contract.
- * It is an external representation of contract intented for application
- * programmer.
- *
- */
-typedef
-struct fwp_contract {
- int budget; /**< bytes per period */
- int period_usec; /**< all time units are in microseconds */
- int deadline_usec;
-} fwp_contract_t;
-
-struct fwp_contract_data;
-typedef struct fwp_contract_data* fwp_contract_d_t;
-
-fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract);
-int fwp_contract_destroy(fwp_contract_d_t contractd);
-int fwp_contract_negotiate(fwp_contract_d_t contract, fwp_vres_d_t *vresdp);
-int fwp_contract_cancel(fwp_contract_d_t contractd);
-int fwp_contract_is_negotiated(fwp_contract_d_t contract);
-int fwp_contract_cancel(fwp_contract_d_t contractd);
-
-#ifdef _FWP_INTERNALS_
-
-#include "ul_gavlcust.h"
-#include "ul_list.h"
-#include <stdlib.h>
-
-/**< Contract Status */
-/*typedef enum {
- FWP_CONT_INVALID = 0,
- FWP_CONT_REQUESTED = 1,
- FWP_CONT_REJECTED = 2,
- FWP_CONT_NEGOTIATED = 3,
- FWP_CONT_ACCEPTED = 4
-} fwp_contract_status_t;*/
-
-typedef enum {
- FWP_CONT_NOTNEGOTIATED = 0,
- FWP_CONT_RESERVED = 1,
- FWP_CONT_NEGOTIATED = 2
-} fwp_contract_status_t;
-
-typedef struct fwp_contract_data fwp_contract_data_t;
-typedef fwp_vres_id_t fwp_contract_id_t;
-
-/**
- * FWP contract.
- * This is an internal representation of contract in every FWP application.
- */
-struct fwp_contract_data {
- fwp_contract_id_t id;
- /** contract specified by user */
- fwp_contract_t contract;
- /** parameters from contract negotiated for vres */
- fwp_vres_params_t vres_params;
- /* * the address of agent from that the contract comes */
- /*fwp_transaction_id_t trans_id;*/
- /* pointer to fwp_vres or fwp_participant */
- /*void *priv; */
- fwp_vres_d_t vresd;
- fwp_contract_status_t status;
- /** For future: exclude (replaced) contract
- fwp_contract_d_t contex; */
-
- ul_list_node_t list_node;
- gavl_node_t tree_node;
- /* owner,
- * acls*/
-};
-
-static inline fwp_contract_data_t* fwp_contract_data_new()
-{
- fwp_contract_data_t *contdata = malloc(sizeof (fwp_contract_data_t));
- if (!contdata)
- return NULL;
- return memset(contdata,'\0', sizeof(fwp_contract_data_t));
-}
-
-static inline void fwp_contract_data_delete(fwp_contract_data_t* contdata)
-{
- free(contdata);
-}
-
-int fwp_contract_reserve(fwp_contract_d_t contractd);
-int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp);
-
-/* TODO: Implement fwp_contract_set_state function
- * int fwp_contract_set_state(fwp_contract_state_t state)
- * */
-
-#endif /*_FWP_INTERNALS_ */
-#endif /*_FWP_CONTRACT_H */
+++ /dev/null
-#include "fwp_contract_table.h"
-#include <pthread.h>
-
-GAVL_CUST_NODE_INT_DEC(_fwp_contract_table, fwp_contract_table_t,
- fwp_contract_data_t, fwp_contract_id_t, contract_tree,
- tree_node, id, gavl_cmp_int);
-
-GAVL_CUST_NODE_INT_IMP(_fwp_contract_table, fwp_contract_table_t,
- fwp_contract_data_t, fwp_contract_id_t, contract_tree,
- tree_node, id, gavl_cmp_int);
-
-void fwp_contract_table_init(struct fwp_contract_table *tbl)
-{
- tbl->id_counter = 0;
- _fwp_contract_table_init_root_field(tbl);
- pthread_mutex_init(&tbl->lock, NULL); /* fast mutex */
- tbl->nr_contracts = 0;
-}
-
-int fwp_contract_table_insert(fwp_contract_table_t *tbl,
- fwp_contract_data_t *contdata)
-{
- unsigned int id = tbl->id_counter++;
-
- pthread_mutex_lock(&tbl->lock);
- contdata->vres_params.id = id;
- _fwp_contract_table_insert(tbl, contdata);
- tbl->nr_contracts++;
- pthread_mutex_unlock(&tbl->lock);
-
- return id;
-}
-
-fwp_contract_data_t* fwp_contract_table_find(fwp_contract_table_t *tbl,
- unsigned int id)
-{
- return _fwp_contract_table_find(tbl, &id);
-}
-
-int fwp_contract_table_delete(fwp_contract_table_t *tbl,
- fwp_contract_data_t *contdata)
-{
- int rv;
-
- pthread_mutex_lock(&tbl->lock);
- rv = _fwp_contract_table_delete(tbl, contdata);
- tbl->nr_contracts--;
- pthread_mutex_unlock(&tbl->lock);
-
- return rv;
-}
-
-fwp_contract_data_t*
-fwp_contract_table_foreach_begin(fwp_contract_table_t *tbl)
-{
- pthread_mutex_lock(&tbl->lock);
- return _fwp_contract_table_first(tbl);
-}
-
-fwp_contract_data_t*
-fwp_contract_table_foreach_next(fwp_contract_table_t *tbl,
- fwp_contract_data_t *current)
-{
- return _fwp_contract_table_next(tbl, current);
-}
-
-void fwp_contract_table_foreach_end(fwp_contract_table_t *tbl)
-{
- pthread_mutex_unlock(&tbl->lock);
-}
+++ /dev/null
-#ifndef _FWP_CONTRACT_TABLE_H
-#define _FWP_CONTRACT_TABLE_H
-
-#include "fwp_contract.h"
-#include "ul_list.h"
-#include "ul_gavlcust.h"
-
-/**
- * List of contract_data structures
- *
- */
-/*typedef
-struct fwp_contract_list {
- ul_list_head_t head;
-} fwp_contract_list_t;
-
-UL_LIST_CUST_DEC(fwp_contract_list, fwp_contract_list_t, fwp_contract_data_t,
- head, list_node);
-*/
-
-
-/**
- * Table of contract_data structures
- *
- */
-typedef
-struct fwp_contract_table {
- unsigned int nr_contracts;
- pthread_mutex_t lock;
- /*gavl_cust_root_field_t contract_tree;*/
- unsigned int id_counter;
- /*ul_list_head_t cont_list;*/
- gavl_node_t *contract_tree;
-} fwp_contract_table_t;
-
-void fwp_contract_table_init(fwp_contract_table_t *tbl);
-int fwp_contract_table_insert(fwp_contract_table_t *tbl,
- fwp_contract_data_t *contdata);
-fwp_contract_data_t*
-fwp_contract_table_find(fwp_contract_table_t *tbl, unsigned int id);
-
-int fwp_contract_table_delete(fwp_contract_table_t *tbl,
- fwp_contract_data_t *contdata);
-
-fwp_contract_data_t* fwp_contract_table_foreach_begin(fwp_contract_table_t *tbl);
-fwp_contract_data_t* fwp_contract_table_foreach_next(fwp_contract_table_t *tbl, fwp_contract_data_t *current);
-void fwp_contract_table_foreach_end(fwp_contract_table_t *tbl);
-
-
-
-#endif /* _FWP_CONTRACT_TABLE_H */
+++ /dev/null
-#include "fwp_conf.h"
-#include "fwp_mngt.h"
-#include "fwp_endpoint.h"
-
-/**
- * Global mngt variables
- */
-
-/**< Pointer to participant of this application */
-fwp_participant_t *fwp_participant_this;
-/**< Pointer to manager participant */
-fwp_participant_t *fwp_participant_mngr;
-
-static fwp_contract_t fwp_service_contract = {
- .budget = 100,
- .period_usec = 30,
- .deadline_usec = 1000*1000
-};
-
-static fwp_vres_params_t fwp_service_vres_params = {
- .id = 0,
- .ac_id = FWP_AC_BK,
- .budget = 100,
- .period_usec = 30,
-};
-
-/**
- * Send management message to participant
- *
- */
-int fwp_mngt_send(fwp_msg_type_t type,fwp_msgb_t *msgb,
- fwp_participant_t *source, fwp_participant_t *dest)
-{
- int ret;
-
- fwp_msgb_push(msgb, sizeof(struct fwp_msg_header));
- fwp_msg_header_in(msgb->data, type, msgb->len, source->id);
-
- ret = fwp_send(dest->epointd, msgb->data, msgb->len, 0);
-
- return ret;
-}
-
-/**
- * Receives management message from participant
- *
- */
-int fwp_mngt_recv(fwp_msg_type_t *type, fwp_participant_id_t *participant_id,
- fwp_msgb_t *msgb)
-{
- int size;
-
- fwp_msgb_reset_data(msgb);
- size = fwp_recv(fwp_participant_this->epointd, msgb->data,
- msgb->buffer_size, 0);
- if (size < 0)
- return size;
- fwp_msgb_put(msgb, size);
-
- fwp_msg_header_out(msgb->data, type, participant_id);
- fwp_msgb_pull(msgb, sizeof(struct fwp_msg_header));
-
- FWP_DEBUG("Received msg: type=%d from nodeid=%d appid=%d\n", *type,
- participant_id->node_id, participant_id->app_id);
-
- return 0;
-}
-
-int fwp_mngt_service_vres_create(fwp_contract_d_t* contd, fwp_vres_d_t* vresdp)
-{
- fwp_contract_d_t contractd;
- fwp_contract_data_t* contdata;
- int ret;
-
- /*if ((fwp_vres_create(&fwp_service_vres_params, vresdp) < 0)) {
- fprintf(stderr,"Unable to open service vres\n");
- return -1;
- }*/
-
- contractd = fwp_contract_create(&fwp_service_contract);
- contdata = contractd;
- if (!contdata)
- return -1;
-
- /* TODO: Consider to call _fwp_contract_commit */
- contdata->status = FWP_CONT_NEGOTIATED;
- /* Set parameters of vres
- * and activate it if needed */
- ret = fwp_vres_set_params(contdata->vresd, &fwp_service_vres_params);
- if (ret < 0) {
- int e = errno;
- fwp_contract_destroy(contractd);
- errno = e;
- return ret;
- }
- *vresdp = contdata->vresd;
-
- FWP_DEBUG("Service vres negotiated\n");
- *contd = contractd;
- return 0;
-}
-
-/**
- * Launches discovery/connect process to
- * introduce itself to fwp manager and get description of manager
- * */
-int fwp_mngt_connect()
-{
- fwp_participant_info_t my_info, mngr_info;
- fwp_participant_id_t participant_id;
- fwp_msgb_t *msgb;
- fwp_msg_type_t msg_type;
- fwp_endpoint_attr_t attr;
- int ret, e;
-
- fwp_endpoint_attr_init(&attr);
- fwp_endpoint_attr_setreliability(&attr, FWP_MNGT_RELIABILITY);
-
- /* Create discovery endpoint */
- FWP_DEBUG("Service vres created\n");
- fwp_mngt_service_vres_create(&fwp_participant_mngr->service_contract,
- &fwp_participant_mngr->vresd);
-
- FWP_DEBUG("Discovery send endpoint created\n");
- ret = fwp_send_endpoint_create(fwp_participant_mngr->id.node_id,
- fwp_participant_mngr->stream_id,
- &attr, &fwp_participant_mngr->epointd);
- if (ret != 0) {
- e = errno;
- goto err_vres;
- }
-
- fwp_send_endpoint_bind(fwp_participant_mngr->epointd,
- fwp_participant_mngr->vresd);
-
- /* prepare hello message */
- msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_hello));
- fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
-
- my_info.id = fwp_participant_this->id;
- my_info.stream_id = fwp_participant_this->stream_id;
-
- fwp_msg_hello_in(msgb->tail, &my_info);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_hello));
-
- /* Send hello to manager */
- ret = fwp_mngt_send(FWP_MSG_HELLO, msgb,
- fwp_participant_this, fwp_participant_mngr);
- if (ret < 0) {
- e = errno;
- goto err_ep;
- }
-
- /* receive hello from manager */
- alarm(3); /* Timeout in secconds */
- ret = fwp_mngt_recv(&msg_type, &participant_id, msgb);
- alarm(0);
- if (ret < 0) {
- if (errno == EINTR) e = ETIMEDOUT;
- else e = errno;
- goto err_ep;
- }
- FWP_DEBUG("Received HELLO msg from nodeid= %d appid= %d\n",
- participant_id.node_id, participant_id.app_id);
-
- /* Process hello msg from manager */
- fwp_msg_hello_out(msgb->data, &mngr_info);
- fwp_participant_mngr->id = mngr_info.id;
- fwp_participant_mngr->stream_id = mngr_info.stream_id;
- FWP_DEBUG("Received HELLO msg contains nodeid= %d appid= %d\n",
- mngr_info.id.node_id, mngr_info.id.app_id);
-
- /* unbind and delete discovery mngr send endpoint */
- fwp_send_endpoint_unbind(fwp_participant_mngr->epointd);
- fwp_endpoint_destroy(fwp_participant_mngr->epointd);
-
- /* Create mngt send endpoint to manager */
- ret = fwp_send_endpoint_create(fwp_participant_mngr->id.node_id,
- fwp_participant_mngr->stream_id, &attr,
- &fwp_participant_mngr->epointd);
- if (ret != 0) {
- e = errno;
- goto err_vres;
- }
-
- FWP_DEBUG("Management send endpoint created\n");
- fwp_send_endpoint_bind(fwp_participant_mngr->epointd,
- fwp_participant_mngr->vresd);
- return 0;
-err_ep:
- fwp_send_endpoint_unbind(fwp_participant_mngr->epointd);
- fwp_endpoint_destroy(fwp_participant_mngr->epointd);
-err_vres:
- fwp_vres_destroy(fwp_participant_mngr->vresd);
- errno = e;
- return ret;
-}
-/**
- * Disconnect from manager
- *
- */
-int fwp_mngt_disconnect()
-{
- fwp_msgb_t *msgb;
-
- msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_contracthdr));
- fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
-
- /* Say GoodBye to manager */
- FWP_DEBUG("Send BYE to manager\n");
- fwp_mngt_send(FWP_MSG_BYE, msgb,
- fwp_participant_this, fwp_participant_mngr);
-
- fwp_send_endpoint_unbind(fwp_participant_this->epointd);
- fwp_endpoint_destroy(fwp_participant_this->epointd);
- fwp_vres_destroy(fwp_participant_this->vresd);
- /* TODO: iterate through contract table and delete contracts */
-
- return 0;
-}
-
-/* TODO: Add atexti handler to remove all contracts on application
- * exit/crash. */
-
-/**
- * FWP Management initialization
- * - creates and initializes fwp_participant_this
- * - creates and initializes fwp_participant_mngr
- * - calls fwp_mngt
- */
-int fwp_mngt_init()
-{
- fwp_participant_info_t my_info, mngr_info;
- unsigned int node_id;
- fwp_endpoint_attr_t attr;
- char *value;
- int ret;
-
- fwp_endpoint_attr_init(&attr);
- fwp_endpoint_attr_setreliability(&attr, FWP_MNGT_RELIABILITY);
-
- /* Create fwp_participant_this */
- my_info.id.node_id = inet_addr(fwp_configuration.my_addr);
- if (my_info.id.node_id == inet_addr(FWP_MY_ADDR_DEFAULT)) {
- /* if default then check env variable */
- value = getenv("FWP_MY_ADDR");
- if (value) {
- my_info.id.node_id = inet_addr(value);
- }
- }
- fwp_configuration.my_node_id = my_info.id.node_id;
- my_info.id.app_id = getpid();
- my_info.stream_id = fwp_configuration.my_stream_id;
-
- fwp_participant_this = fwp_participant_new(&my_info);
- ret = fwp_receive_endpoint_create(my_info.stream_id, &attr,
- &fwp_participant_this->epointd);
- if (ret != 0)
- return ret;
- /* FIXME
- fwp_endpoint_get_params(&(fwp_participant_this->id.node_id),
- &fwp_participant_this->stream_id,
- &flags,
- fwp_participant_this->epointd);
- */
- fwp_endpoint_get_params(fwp_participant_this->epointd,
- &node_id,
- &fwp_participant_this->stream_id,
- &attr);
- FWP_DEBUG("Participant_this created node_id id= %d stream id= %d\n",
- fwp_participant_this->id.node_id,
- fwp_participant_this->stream_id);
-
- /* Create fwp_participant_mngr */
-
- mngr_info.id.node_id = inet_addr(fwp_configuration.mngr_addr);
- /* Env. variable always overrides configured settings */
- value = getenv("FWP_MNGR_ADDR");
- if (value) {
- mngr_info.id.node_id = inet_addr(value);
- }
- FWP_DEBUG("mngr node=%s node_id=%d\n",
- fwp_configuration.mngr_addr,
- mngr_info.id.node_id);
- fwp_configuration.mngr_node_id = mngr_info.id.node_id;
- mngr_info.id.app_id = getpid();
- mngr_info.stream_id = fwp_configuration.mngr_stream_id;
-
- if ((mngr_info.id.node_id == inet_addr("127.0.0.1")) &&
- (my_info.stream_id == mngr_info.stream_id)) {
- /* I am a manager */
- FWP_DEBUG("I am FWP manager\n");
- fwp_participant_mngr = fwp_participant_this;
- } else {
- fwp_participant_mngr = fwp_participant_new(&mngr_info);
- /* Connet to FWP manager */
- ret = fwp_mngt_connect();
- if (ret != 0)
- return ret;
- }
-
- return 0;
-}
+++ /dev/null
-/* FWP Lib communication routines */
-#ifndef _FWP_MNGT_H
-#define _FWP_MNGT_H
-
-#ifdef _FWP_INTERNALS_
-
-#include "fwp_vres.h"
-#include "fwp_msg.h"
-#include "fwp_participant.h"
-
-#define FWP_MNGR_STREAM_ID 3000
-#define FWP_MNGT_DISCOVERY_STREAM_ID 3000
-#define FWP_MNGT_RELIABILITY FWP_EPOINT_RELIABLE
-
-/**< Pointer to participant of this application*/
-extern fwp_participant_t *fwp_participant_this;
-/**< Pointer to manager participant record*/
-extern fwp_participant_t *fwp_participant_mngr;
-
-int fwp_mngt_send(fwp_msg_type_t type,fwp_msgb_t *msgb,
- fwp_participant_t *source, fwp_participant_t *dest);
-int fwp_mngt_recv(fwp_msg_type_t *type, fwp_participant_id_t *participant_id,
- fwp_msgb_t *msgb);
-
-int fwp_mngt_service_vres_create(fwp_contract_d_t* contd, fwp_vres_d_t* vresdp);
-
-#endif /* _FWP_INTERNALS_ */
-
-int fwp_mngt_init();
-int fwp_mngt_connect();
-int fwp_mngt_disconnect();
-
-#endif /* _FWP_MNGT_H */
-
+++ /dev/null
-#include "fwp_msg.h"
-
-/**
- * \file fwp_msg.c
- *
- * Routines for serializing and deserializing FWP messages.
- *
- * (It should be in separate library.)
- *
- */
-
-void fwp_msg_header_in(unsigned char *data, fwp_msg_type_t type,
- size_t length, fwp_participant_id_t participant_id
- )
-{
- struct fwp_msg_header* msg_header;
-
- msg_header = (struct fwp_msg_header*) data;
- /*header = (struct fwp_msg_header*)
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));*/
-
- msg_header->type = htons(type);
- msg_header->node_id = htonl(participant_id.node_id);
- msg_header->app_id = htonl(participant_id.app_id);
- msg_header->length = htons((uint16_t)length);
-}
-
-void fwp_msg_header_out(unsigned char *data, fwp_msg_type_t *type,
- fwp_participant_id_t *participant_id)
-{
- struct fwp_msg_header *msg_header;
-
- msg_header = (struct fwp_msg_header*) data;
- /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_header));*/
- *type = ntohs(msg_header->type);
- participant_id->node_id = ntohl(msg_header->node_id);
- participant_id->app_id = ntohl(msg_header->app_id);
-}
-
-void fwp_msg_contracthdr_in(unsigned char *data, fwp_contract_id_t id,
- fwp_contract_status_t status)
-{
- struct fwp_msg_contracthdr* msg_contracthdr;
-
- msg_contracthdr = (struct fwp_msg_contracthdr*) data;
-
- msg_contracthdr->id = htonl(id);
- msg_contracthdr->status = status;
-}
-
-void fwp_msg_contracthdr_out(unsigned char *data, fwp_contract_id_t *id,
- fwp_contract_status_t *status)
-{
- struct fwp_msg_contracthdr* msg_contracthdr;
-
- msg_contracthdr = (struct fwp_msg_contracthdr*) data;
-
- *id = ntohl(msg_contracthdr->id);
- *status = msg_contracthdr->status;
-}
-
-void fwp_msg_contract_in(unsigned char *data, fwp_contract_t *cont)
-{
- struct fwp_msg_contract* msg_contract;
-
- msg_contract = (struct fwp_msg_contract*) data;
- /*msgcnt = (struct fwp_msg_contract*)
- fwp_msgb_put(msgb,sizeof(struct fwp_msg_contract));*/
-
- msg_contract->budget = htons(cont->budget);
- msg_contract->period_usec = htonl(cont->period_usec);
- msg_contract->deadline_usec = htonl(cont->deadline_usec);
-}
-
-void fwp_msg_contract_out(unsigned char *data, fwp_contract_t *cont)
-{
- struct fwp_msg_contract* msg_contract;
-
- msg_contract = (struct fwp_msg_contract*) data;
- /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/
-
- cont->budget = ntohs(msg_contract->budget);
- cont->period_usec = ntohl(msg_contract->period_usec);
- cont->deadline_usec = ntohl(msg_contract->deadline_usec);
-}
-
-void fwp_msg_vres_params_in(unsigned char *data, fwp_vres_params_t *vparams)
-{
- struct fwp_msg_vres_params* msg_vparams;
-
- msg_vparams = (struct fwp_msg_vres_params*) data;
- /*msgcnt = (struct fwp_msg_contract*)
- fwp_msgb_put(msgb,sizeof(struct fwp_msg_contract));*/
-
- msg_vparams->ac_id = vparams->ac_id;
- msg_vparams->budget = htons(vparams->budget);
- msg_vparams->period_usec = htonl(vparams->period_usec);
-}
-
-void fwp_msg_vres_params_out(unsigned char *data, fwp_vres_params_t *vparams)
-{
- struct fwp_msg_vres_params* msg_vparams;
-
- msg_vparams = (struct fwp_msg_vres_params*) data;
- /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/
-
- vparams->ac_id = msg_vparams->ac_id;
- vparams->budget = ntohs(msg_vparams->budget);
- vparams->period_usec = ntohl(msg_vparams->period_usec);
-}
-
-void fwp_msg_hello_in(unsigned char *data,
- fwp_participant_info_t *participant_info)
-{
- struct fwp_msg_hello* msg_hello;
-
- msg_hello = (struct fwp_msg_hello*) data;
- /*header = (struct fwp_msg_header*)
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));*/
-
- msg_hello->node_id = htonl(participant_info->id.node_id);
- msg_hello->app_id = htonl(participant_info->id.app_id);
- msg_hello->stream_id= htons(participant_info->stream_id);
-}
-
-void fwp_msg_hello_out(unsigned char *data,
- fwp_participant_info_t *participant_info)
-{
- struct fwp_msg_hello *msg_hello;
-
- msg_hello = (struct fwp_msg_hello*) data;
- /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_header));*/
- participant_info->id.node_id = ntohl(msg_hello->node_id);
- participant_info->id.app_id = ntohl(msg_hello->app_id);
- participant_info->stream_id = ntohs(msg_hello->stream_id);
-}
+++ /dev/null
-#ifndef _FWP_MSG_H
-#define _FWP_MSG_H
-
-#include <stdint.h>
-
-#include "fwp_contract.h"
-#include "fwp_vres.h"
-#include "fwp_participant.h"
-
-typedef enum {
- FWP_MSG_HELLO = 1,
- FWP_MSG_BYE = 2,
- FWP_MSG_RESERVE = 3,
- FWP_MSG_COMMIT = 4,
- FWP_MSG_CANCEL = 5
-} fwp_msg_type_t;
-
-struct fwp_msg_header{
- uint16_t type;
- uint16_t length; /**< Length of the whole message (including this header) */
- uint32_t node_id;
- uint32_t app_id; /**< application id */
-}__attribute__((packed));
-
-struct fwp_msg_contracthdr{
- uint32_t id;
- uint8_t status;
-}__attribute__((packed));
-
-struct fwp_msg_contract{
- uint16_t budget; /**< bits per second */
- uint32_t period_usec; /**< all time units are in microseconds */
- uint32_t deadline_usec;
-}__attribute__((packed));
-
-struct fwp_msg_vres_params{
- uint16_t budget; /**< bits per second */
- uint32_t period_usec; /**< all time units are in microseconds */
- uint8_t ac_id; /**< AC id ~ priority of vres */
-}__attribute__((packed));
-
-struct fwp_msg_hello {
- int32_t node_id;
- int32_t app_id;
- uint16_t stream_id;
-}__attribute__((packed));
-
-void fwp_msg_header_in(unsigned char *data, fwp_msg_type_t type,
- size_t length, fwp_participant_id_t participant_id);
-void fwp_msg_header_out(unsigned char *data, fwp_msg_type_t *type,
- fwp_participant_id_t *participant_id);
-
-void fwp_msg_contracthdr_in(unsigned char *data, fwp_contract_id_t id,
- fwp_contract_status_t status);
-void fwp_msg_contracthdr_out(unsigned char *data, fwp_contract_id_t *id,
- fwp_contract_status_t *status);
-
-void fwp_msg_contract_in(unsigned char *data, fwp_contract_t *cont);
-void fwp_msg_contract_out(unsigned char *data, fwp_contract_t *cont);
-
-void fwp_msg_vres_params_in(unsigned char *data, fwp_vres_params_t *vparams);
-void fwp_msg_vres_params_out(unsigned char *data, fwp_vres_params_t *vparams);
-
-void fwp_msg_hello_in(unsigned char *data,
- fwp_participant_info_t *participant_info);
-void fwp_msg_hello_out(unsigned char *data,
- fwp_participant_info_t *participant_info);
-
-#endif /* _FWP_MSG_H */
+++ /dev/null
-#ifndef _FWP_PARTICIPANT_H
-#define _FWP_PARTICIPANT_H
-
-#include "fwp_contract_table.h"
-#include "fwp_endpoint.h"
-#include "ul_gavlcust.h"
-
-typedef
-struct fwp_participant_id {
- /*unsigned int address_family */
- unsigned int node_id;
- unsigned int app_id;
-} fwp_participant_id_t;
-
-typedef
-/*struct fwp_participant_conf {*/
-struct fwp_participant_info {
- fwp_participant_id_t id;
- unsigned int stream_id;
-} fwp_participant_info_t;
-
-/**
- * Participant of FWP
- *
- */
-typedef
-struct fwp_participant {
- fwp_participant_id_t id;
- unsigned int stream_id;
- fwp_endpoint_d_t epointd; /**< endpoint descriptor for communication*/
- fwp_contract_d_t service_contract; /**< Service contract descriptor */
- fwp_vres_d_t vresd; /**< service vres descriptor */
- gavl_node_t participant_tree_node;
- fwp_contract_table_t contract_table; /**< participant`s contract table */
- /*fwp_resource_list resource_list; or
- *void *resources; or
- *void *data_priv; */
-} fwp_participant_t;
-
-static inline fwp_participant_t*
-fwp_participant_new(fwp_participant_info_t *participant_info)
-{
- fwp_participant_t *participant;
-
- participant = (fwp_participant_t*) malloc(sizeof(fwp_participant_t));
- if (!participant)
- return NULL;
-
- participant->id = participant_info->id;
- participant->stream_id = participant_info->stream_id;
-
- fwp_contract_table_init(&participant->contract_table);
- return participant;
-}
-
-static inline void fwp_participant_delete(fwp_participant_t *participant)
-{
- free(participant);
-}
-
-#endif /*_FWP_PARTICIPANT_H */
+++ /dev/null
-/**
- * \file fwp_resource.h
- *
- * NOT USED!!
- *
- *
- */
-#ifndef _FWP_RESOURCE_H
-#define _FWP_RESOURCE_H
-
-typedef unsigned int fwp_resource_id_t;
-typedef unsigned int fwp_resource_d_t;
-
-/*typedef struct fwp_resource_d {
- unsigned int major;
- unsigned int minor;
-} fwp_resource_d_t; */
-
-typedef struct fwp_resource {
- char name[10];
- fwp_resource_id_t id;
- fwp_participant_t *participant_my;
- fwp_participant_t *participant_mngr;
- void *contract_ops;
- void *fna_ops;
- void *contract_table;
-} fwp_resource_t;
-
-#endif /* _FWP_RESOURCE_H */