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
shared_LIBRARIES = frsh_fwp
CFLAGS += -D_FWP_INTERNALS_
-frsh_fwp_SOURCES += fwp_fna.c fwp_frs.c
+frsh_fwp_SOURCES += fwp_fna.c fwp_frs.c fwp_block.c
include_HEADERS= fwp_res.h fwp_fna.h
+frsh_fwp_CLIENT_IDL += fwp_idl.idl
+include_GEN_HEADERS= fwp_idl.h
lib_LOADLIBES+= fna frs
--- /dev/null
+#include <fwp_res.h>
+#include <fres_container.h>
+
+static const struct fres_block_desc fwp_sched_block_desc = {
+ .size = sizeof(fres_block_fwp_sched),
+ .serialize = (fres_block_serialize_fnc_t*)fres_block_fwp_sched_serialize,
+ .deserialize = (fres_block_deserialize_fnc_t*)fres_block_fwp_sched_deserialize,
+ .duplicate = fres_block_duplicate_default
+};
+
+int fres_block_register_fwp()
+{
+ return fres_block_register(FRES_BLOCK_FWP_SCHED,
+ &fwp_sched_block_desc);
+}
+
int fwp_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id,
const frsh_rel_time_t *budget, size_t *nbytes)
{
- *nbytes = budget->tv_sec;
+ *nbytes = budget->tv_nsec;
return 0;
}
int fwp_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id,
const size_t nbytes, frsh_rel_time_t *budget)
{
- budget->tv_sec = nbytes;
+ budget->tv_nsec = nbytes;
+ budget->tv_sec = 0;
return 0;
}
//#include <fwp_fna.h>
#include <frsh_distributed.h>
#include "fwp_res.h"
+#include "fwp_idl.h"
#include <stdio.h>
{
char id[40];
fres_block_basic *basic;
+ fres_block_fwp_sched *fwp_sched;
fwp_vres_params_t vparams;
fwp_vres_d_t fwp_vresd;
int rv;
/* Prepare vres parameters */
basic = fres_contract_get_basic(vres->contract);
+ fwp_sched = fres_contract_get_block(vres->contract, FRES_BLOCK_FWP_SCHED);
+
//fwp_fna_network_budget_to_bytes(FRSH_NETPF_FWP, &basic->budget, &vparams.budget);
vparams.budget = basic->budget.tv_nsec;
vparams.period = basic->period;
- vparams.ac_id = FWP_AC_VO;
+ vparams.ac_id = fwp_sched->ac_id;
/* Create vres */
if ((rv = fwp_vres_create(&vparams, &fwp_vresd))) {
return rv;
vres->priv = fwp_vresd;
fres_contract_id_to_string(id, &vres->contract->id, sizeof(id));
- printf("Creating FWP VRes (id=%s, period=%ld ms, budget=%ld bytes)\n",
- id, fosa_rel_time_to_msec(basic->period), vparams.budget);
+ printf("Creating FWP VRes (id=%s, period=%ld ms, budget=%ld bytes AC=%d)\n",
+ id, fosa_rel_time_to_msec(basic->period),
+ vparams.budget, vparams.ac_id);
return 0;
}
int frs_fwp_init(forb_orb orb, fres_contract_broker fcb, forb_executor_t *executor)
{
+ fres_block_register_fwp();
return frs_register(orb, fcb, executor, &fwp_scheduler);
}
--- /dev/null
+/**
+ * @file fwp_idl.idl
+ * @author Martin Molnar <molnam1@fel.cvut.cz>
+ * @date Thu Oct 30 14:27:12 2008
+ *
+ * @brief Contract data block for fwp resource
+ *
+ *
+ */
+module fres {
+ module block {
+ struct fwp_sched {
+ octet ac_id;
+ };
+ };
+};
#include <forb.h>
#include <fcb.h>
#include <frsh_distributed.h>
+#include "fwp_idl.h"
int frs_fwp_init(forb_orb orb, fres_contract_broker fcb, forb_executor_t *executor);
+int fres_block_register_fwp();
-#endif
+#endif /* FWP_RES_H */
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 */
bin_PROGRAMS = fwpmngr
-fwpmngr_SOURCES = fwp_mngr.c
+fwpmngr_SOURCES = fwp_mngr.c fwp_admctrl.c
fwpmngr_LIBS = frm forb contract fosa rt ulut fcb_client
#include_HEADERS = res_fwp.h
CFLAGS += -D_FWP_INTERNALS_
+lib_LOADLIBES+= frsh
--- /dev/null
+#include <fres_sa_scenario.h>
+#include <fwp.h>
+#include "fwp_idl.h"
+#include "fwp_admctrl.h"
+
+/* TODO: Find out the real value and determine what influences it (MTU
+ * of the interface minus header sizes?). */
+#define MTU 1472
+#define UDP_HEADER_SIZE 8
+#define IP_HEADER_SIZE 20
+#define LLC_HEADER_SIZE 2 /* ??? */
+#define MAC_HEADER_SIZE 26 /* With QoS field added */
+#define MAC_FCS_SIZE 4
+
+#define RTS_FRAME_SIZE 20
+#define CTS_FRAME_SIZE 14
+#define ACK_FRAME_SIZE 14
+
+#define BITRATE_BPS (1000*1000)
+#define ASLOTTIME_USEC 20 /* 802.11g-2003 p. 46 */
+#define ASIFSTIME_USEC 10
+#define ADIFSTIME_USEC (ASIFSTIME_USEC + 2*ASLOTTIME_USEC)
+#define AAIFSTIME_USEC(n) (ASIFSTIME_USEC + (n)*ASLOTTIME_USEC)
+
+#define TXTIME_USEC(bytes) ((int64_t)(bytes) * 8 * SEC_TO_USEC / BITRATE_BPS)
+
+
+/* Default values from 802.11e */
+const int aifsn[FWP_AC_NUM] = { 2, 2, 3, 7 };
+const int cwmin[FWP_AC_NUM] = { 3, 7, 15, 15 };
+
+/* Experimental konstants - weight of backoff */
+const int pisvejc[FWP_AC_NUM] = { 6, 5, 2, 2 };
+
+int fwp_reserved_utilization;
+
+/**
+ * Calucaltes frame duration in microseconds. If the real duration is
+ * represented by a fractional number, the value is rounded up.
+ *
+ * @param length Number of bytes in PSDU.
+ * @param rate_bps Transmit rate of PSDU. The rate should correspond
+ * to other parameters accoring to 19.3.2 (802.11g)
+ * @param erp_ofdm Whether Extended Rate PHY (part of 802.11g) and ERP-OFDM
+ * modulation is used.
+ * @param short_preamble Whether short preamble (HR/DSSS/short) is
+ * used (802.11b)
+ *
+ * @return The number of microseconds or a negative number in case of error.
+ */
+static int frame_duration(uint16_t length, int rate_bps, bool erp_ofdm, bool short_preamble)
+{
+ uint32_t duration_usec = 0;
+
+ if (!erp_ofdm) {
+ duration_usec = ((int64_t)(length) * 8 * SEC_TO_USEC / rate_bps);
+ if (short_preamble) {
+ /* For HR/DSSS/short (2, 5.5 and 11 Mbit,
+ * 802.11b-1999), also for DSSS-OFDM rates and
+ * ERP-PBCC rates.
+ * Preamble sent at 1 MBit, header at 2 Mbit */
+ duration_usec += 72/*bits*/+48/*bits*//2;
+ } else {
+ /* For DSSS PHY (1 and 2 Mbit rates,
+ * 802.11-1999) and for DSS-OFDM and ERP-PBCC
+ * rates. Always sent at 1 MBit */
+ duration_usec += 144/*bits*/+48/*bits*/;
+ }
+ } else {
+#define MBIT_TO_INDEX(rate_Mbps) ((rate_Mbps)/3 - 2)
+ const int N_dbps[] = {
+ [MBIT_TO_INDEX(6)] = 24,
+ [MBIT_TO_INDEX(9)] = 36,
+ [MBIT_TO_INDEX(12)] = 48,
+ [MBIT_TO_INDEX(18)] = 72,
+ [MBIT_TO_INDEX(24)] = 96,
+ [MBIT_TO_INDEX(36)] = 144,
+ [MBIT_TO_INDEX(48)] = 192,
+ [MBIT_TO_INDEX(54)] = 216
+ };
+ int rate_idx = MBIT_TO_INDEX(rate_bps/1000/1000);
+#undef MBIT_TO_INDEX
+ if (rate_idx < 0 ||
+ rate_idx >= sizeof(N_dbps)/sizeof(*N_dbps) ||
+ N_dbps[rate_idx] == 0)
+ return -1;
+
+ duration_usec += 16 + 4; /* Preamble, SIGNAL */
+ int bits =
+ 16 + /* SERVICE */
+ length * 8 +
+ 6; /* tail bits */
+ int Nsym = (bits + N_dbps[rate_idx] - 1)/N_dbps[rate_idx];
+
+ duration_usec += Nsym * 4;
+
+ duration_usec += 6; /* signal extension */
+ }
+ return duration_usec;
+}
+
+int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
+ bool *schedulable)
+{
+ int utilization = 0;
+
+ const int rate = 1*1000*1000;
+ const bool erp_ofdm = false;
+ const bool short_preamble = false;
+ struct fres_sa_contract *c, *c_new = NULL;
+ long int period_usec;
+ fres_block_basic *basic;
+ fres_block_fwp_sched *fwp_sched;
+
+ size_t bytes;
+ long int duration_usec, tmp_usec;
+ int fragments;
+ int ac = FWP_AC_VO;
+
+ fres_sa_scenario_for_each_contract(scenario, c) {
+ fres_block_basic *basic;
+ char id[40];
+ fres_contract_id_to_string(id, &c->contract->id, sizeof(id));
+ basic = fres_contract_get_basic(c->contract);
+
+ printf(" processing: id=%s, period=%ld ms, budget=%ld ms\n",
+ id,
+ fosa_rel_time_to_msec(basic->period),
+ fosa_rel_time_to_msec(basic->budget));
+
+ /* Calculate protocol overhead */
+ frsh_network_budget_to_bytes(FRSH_NETPF_FWP,&basic->budget,&bytes);
+ fragments = (bytes + MTU - 1) / MTU;
+
+ if (fragments == 0)
+ continue;
+
+ const int data_overhead = UDP_HEADER_SIZE + IP_HEADER_SIZE +
+ LLC_HEADER_SIZE + MAC_FCS_SIZE;
+
+ duration_usec = frame_duration(data_overhead + bytes%MTU, rate,
+ erp_ofdm, short_preamble);
+ tmp_usec = frame_duration(data_overhead + MTU, rate, erp_ofdm,
+ short_preamble);
+ duration_usec += tmp_usec*(fragments-1);
+ /* Add average backoff - assume there is no collision */
+ tmp_usec = ASLOTTIME_USEC*fragments*pisvejc[ac];
+ duration_usec += (aifsn[ac] + cwmin[ac]/2)*tmp_usec;
+ /* We use ACK and ignore burst */
+ tmp_usec = frame_duration(ACK_FRAME_SIZE, rate, erp_ofdm,
+ short_preamble) + ASIFSTIME_USEC;
+ duration_usec += fragments * tmp_usec;
+
+ /* TODO: If STA-to-STA, multiply it by two. Note that
+ * AP may use different values for backoff. */
+ duration_usec *= 2; /* For demo, we have always STA-to-STA */
+
+ basic = fres_contract_get_basic(c->contract);
+ period_usec = fosa_rel_time_to_msec(basic->period)*1000;
+ if (c->status == FRES_SA_CONTRACT_NEW) {
+ c_new = c;
+ if (period_usec == 0) {
+ goto not_schedulable;
+ }
+ }
+ utilization += (long long)(duration_usec * 10000) / period_usec;
+ }
+
+ if (!c_new) {
+ *schedulable = false;
+ return -1;
+ }
+ if (utilization >= 10000 * 96/100) {
+ goto not_schedulable;
+ }
+
+ basic = fres_contract_get_basic(c_new->contract);
+ /*int d = c->deadline_usec;*/
+ long int d = fosa_rel_time_to_msec(basic->period)*1000;
+ if (d <= 0) d = 100*1000*1000;
+ if (d < 50000) {
+ goto not_schedulable;
+ };
+
+ *schedulable = true;
+ fwp_sched = malloc(sizeof(*fwp_sched));
+ fwp_sched->ac_id =
+ d < 100*1000 ? FWP_AC_VO :
+ d < 500*1000 ? FWP_AC_VI :
+ d < 1000*1000 ? FWP_AC_BE :
+ FWP_AC_BK;
+ fres_contract_add_block(c_new->contract, FRES_BLOCK_FWP_SCHED, fwp_sched);
+ return 0;
+
+not_schedulable:
+ *schedulable = false;
+ return 0;
+}
--- /dev/null
+#ifndef _FWP_ADMCTRL_H
+#define _FWP_ADMCTRL_H
+
+#include <frsh_distributed.h>
+
+int fwp_admctrl_utilization(struct fres_sa_scenario *scenario, void *priv,
+ bool *schedulable);
+
+#endif /*_FWP_AMDCTRL_H */
#include <fres_sa_scenario.h>
#include <stdbool.h>
#include <ul_log.h>
-#include <frsh_distributed.h>
-#include "res_dummy.h"
+#include <fwp_res.h>
#include <stdio.h>
+#include "fwp_admctrl.h"
-struct dummy_data {
- int some_data;
-};
-
-
-int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedulable)
+int dummy_admission_test(struct fres_sa_scenario *scenario, void *priv,
+ bool *schedulable)
{
- struct dummy_data *data = priv;
struct fres_sa_contract *c;
- printf("Admission test:\n");
- data->some_data++;
+ printf("Dummy admission test:\n");
fres_sa_scenario_for_each_contract(scenario, c) {
fres_block_basic *basic;
return 0;
}
-struct dummy_data dummy_data;
-
static const struct fres_res_manager frm = {
.res_type = FRSH_RT_NETWORK,
.res_id = FRSH_NETPF_FWP,
- .admission_test = admission_test,
- .priv = &dummy_data
+ //.admission_test = dummy_admission_test,
+ .admission_test = fwp_admctrl_utilization,
+ .priv = NULL
};
int main(int argc, char *argv[])
orb = forb_init(&argc, &argv, "frm_fwp");
if (!orb) error(1, errno, "forb_init");
-
+
+ fres_block_register_fwp();
ret = frm_register_and_run(orb, &frm);
if (ret != 0) {