From e4c0f9d36f3c144e08a50b6d7e7a590e06c56d01 Mon Sep 17 00:00:00 2001 From: Martin Molnar Date: Mon, 2 Jun 2008 01:00:05 +0200 Subject: [PATCH] adding negt functions --- fwp/lib/core/fwp_vres.c | 48 +++++++++++++++++++- fwp/lib/core/fwp_vres.h | 6 +++ fwp/lib/mngt/fwp_contract.h | 2 + fwp/lib/mngt/fwp_contract_table.c | 11 ++++- fwp/lib/mngt/fwp_contract_table.h | 7 ++- fwp/lib/mngt/fwp_mngt.c | 74 +++++++++++++++++++------------ fwp/lib/mngt/fwp_msg.c | 24 ++++++---- fwp/lib/mngt/fwp_msg.h | 28 +++++++----- 8 files changed, 146 insertions(+), 54 deletions(-) diff --git a/fwp/lib/core/fwp_vres.c b/fwp/lib/core/fwp_vres.c index 8d1c721..380ca60 100644 --- a/fwp/lib/core/fwp_vres.c +++ b/fwp/lib/core/fwp_vres.c @@ -120,7 +120,14 @@ int fwp_vres_table_init(unsigned int nr_vres) return 0; } -static fwp_vres_t* fwp_vres_alloc() +fwp_vres_id_t fwp_vres_get_id(fwp_vres_d_t vresd) +{ + fwp_vres_t *vres = vresd; + + return (fwp_vres_table.entry - vres); +} + +fwp_vres_d_t fwp_vres_alloc() { int i; unsigned int nr_vres; @@ -148,6 +155,45 @@ static inline void fwp_vres_free(fwp_vres_t *vres) vres->status = FWP_VRES_FREE; } +int fwp_vres_set_params(fwp_vres_params_t *params, fwp_vres_d_t vresd) +{ + fwp_vres_t *vres = vresd; + int rv; + + /* copy vres paramters into vres structure */ + memcpy(&vres->params, params, sizeof(struct fwp_vres_params)); + if (vres->status != FWP_VRES_INACTIVE) { + /* Consider: hwo to change parameters when vres is in running + * state - restart thread, set vres_resched flag + */ + pthread_cancel(vres->tx_thread); + close(vres->ac_sockd); + /* or set vres_resched flag and return */ + } else{ + /* initialize msg queue */ + fwp_msgq_init(&vres->tx_queue); + } + /* open ac socket */ + if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) { + goto err; + } + vres->ac_sockd = rv; + + pthread_attr_init(&vres->tx_thread_attr); + if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr, + fwp_vres_tx_thread, (void*) vres)) != 0){ + goto err; + + } + vres->status = FWP_VRES_UNBOUND; + +/* return vres->params.id; */ + return 0; +err: + fwp_vres_free(vres); + return rv; +} + int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp) { int rv; diff --git a/fwp/lib/core/fwp_vres.h b/fwp/lib/core/fwp_vres.h index c82f588..073d5a3 100644 --- a/fwp/lib/core/fwp_vres.h +++ b/fwp/lib/core/fwp_vres.h @@ -41,10 +41,16 @@ struct fwp_vres_params { fwp_ac_t ac_id; /**< AC id ~ priority of vres */ } fwp_vres_params_t; +/* TODO: This functions must not be provided to user. Consider to move this functions + *to separate include file*/ int fwp_vres_table_init(unsigned int nr_vres); +fwp_vres_d_t fwp_vres_alloc(); +fwp_vres_id_t fwp_vres_get_id(fwp_vres_d_t vresd); +int fwp_vres_set_params(fwp_vres_params_t *params, fwp_vres_d_t vresd); int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp); int fwp_vres_destroy(fwp_vres_d_t vresd); +/* */ int _fwp_vres_send(fwp_vres_d_t vresd, struct fwp_msgb* msgb); int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_d_t epointd); diff --git a/fwp/lib/mngt/fwp_contract.h b/fwp/lib/mngt/fwp_contract.h index a45fc0e..82287d4 100644 --- a/fwp/lib/mngt/fwp_contract.h +++ b/fwp/lib/mngt/fwp_contract.h @@ -19,6 +19,8 @@ typedef enum { FWP_CONT_ACCEPTED = 4 } fwp_contract_status_t; +typedef fwp_vres_id_t fwp_contract_id_t; + /** * FWP contract. * It is an external representation of contract intented for application diff --git a/fwp/lib/mngt/fwp_contract_table.c b/fwp/lib/mngt/fwp_contract_table.c index a6c4f01..fa491d2 100644 --- a/fwp/lib/mngt/fwp_contract_table.c +++ b/fwp/lib/mngt/fwp_contract_table.c @@ -1,12 +1,19 @@ #include "fwp_contract_table.h" +#include "ul_gavl.h" GAVL_CUST_NODE_INT_DEC(_fwp_contract_table, fwp_contract_table_t, fwp_contract_data_t, unsigned int, contract_tree, - tree_node, vres_params.id, gavl_cmp_int); + tree_node, id, gavl_cmp_int); GAVL_CUST_NODE_INT_IMP(_fwp_contract_table, fwp_contract_table_t, fwp_contract_data_t, unsigned int, contract_tree, - tree_node, vres_params.id, gavl_cmp_int); + tree_node, id, gavl_cmp_int); + +fwp_contract_data_t* fwp_contract_data_new() +{ + return memset(malloc(sizeof (fwp_contract_data_t)),'\0', + sizeof(fwp_contract_data_t)); +} void fwp_contract_table_init(struct fwp_contract_table *tbl) { diff --git a/fwp/lib/mngt/fwp_contract_table.h b/fwp/lib/mngt/fwp_contract_table.h index 732875e..7b58d55 100644 --- a/fwp/lib/mngt/fwp_contract_table.h +++ b/fwp/lib/mngt/fwp_contract_table.h @@ -5,6 +5,7 @@ #include "fwp_vres.h" #include "ul_list.h" +#include "ul_gavl.h" #include "ul_gavlcust.h" #include @@ -17,7 +18,7 @@ */ typedef struct fwp_contract_data { - fwp_entity_id_t id; + fwp_contract_id_t id; /**< contract specified by user */ fwp_contract_t contract; /**< parameters from contract negotiated for vres */ @@ -25,7 +26,8 @@ struct fwp_contract_data { /**< the address of agent from that the contract comes */ /*fwp_transaction_id_t trans_id;*/ /* pointer to fwp_vres or fwp_participant */ - void *priv; + /*void *priv; */ + fwp_vres_d_t vresd; fwp_contract_status_t status; ul_list_node_t list_node; @@ -58,6 +60,7 @@ struct fwp_contract_table { 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); diff --git a/fwp/lib/mngt/fwp_mngt.c b/fwp/lib/mngt/fwp_mngt.c index 35c2605..ba65569 100644 --- a/fwp/lib/mngt/fwp_mngt.c +++ b/fwp/lib/mngt/fwp_mngt.c @@ -11,43 +11,15 @@ fwp_participant_t *fwp_participant_mngr; /*fwp_endpoint_d_t fwp_mngt_repointd;*/ /* temporarily*/ - - /** * struct resource { * char name[10]; * int id; * general_ops; * fna_ops; - * * } - * */ - -int fwp_negt_request(fwp_contract_t contract) -{ - fwp_msgb *msgb; - - - - -} - -#if 0 -int fwp_negt_reserve(tr_id_t tr_id) -{ - - -} - -int fwp_negt_commit(tr_id_t tr_id) -{ - - -} -#endif - int fwp_mngt_send(fwp_msg_type_t type,fwp_msgb_t *msgb, fwp_participant_t *source, fwp_participant_t *dest) { @@ -78,6 +50,49 @@ int fwp_mngt_recv(fwp_msg_type_t *type, fwp_participant_id_t *participant_id, return 0; } +int fwp_negt_request(fwp_contract_t *contract) +{ + fwp_msgb_t *msgb; + fwp_contract_data_t *contdata; + + contdata = fwp_contract_data_new(); + contdata->vresd = fwp_vres_alloc(); + contdata->id = fwp_vres_get_id(contdata->vresd); + memcpy(&contdata->contract, contract, sizeof(*contract)); + contdata->status = FWP_CONT_REQUESTED; + + /* Add to contract table */ + fwp_contract_table_insert(&fwp_participant_this->contract_table, + contdata); + /* Send contract to manager */ + msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) + + sizeof(struct fwp_msg_contract)); + fwp_msg_contract_deflate(msgb->data, contdata->id, &contdata->contract); + fwp_mngt_send(FWP_MSG_NEGT_REQ, msgb, + fwp_participant_this, fwp_participant_mngr); + return 0; +} + +int fwp_negt_reserve() +{ + fwp_msgb_t *msgb; + + msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header)); + fwp_mngt_send(FWP_MSG_NEGT_RESERVE, msgb, + fwp_participant_this, fwp_participant_mngr); + return 0; +} + +int fwp_negt_commit() +{ + fwp_msgb_t *msgb; + + msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header)); + fwp_mngt_send(FWP_MSG_NEGT_COMMIT, msgb, + fwp_participant_this, fwp_participant_mngr); + return 0; +} + int fwp_mngt_service_vres_create(fwp_vres_d_t* fwp_service_vresd) { struct fwp_vres_params fwp_service_vparams; @@ -153,7 +168,8 @@ void fwp_mngt_connect() int fwp_mngt_init() { fwp_participant_info_t my_info, mngr_info; - int node_id,flags; + unsigned int node_id; + int flags; /* Create fwp_participant_this */ my_info.id.node_id = inet_addr("127.0.0.1"); diff --git a/fwp/lib/mngt/fwp_msg.c b/fwp/lib/mngt/fwp_msg.c index 31797f6..a106bc4 100644 --- a/fwp/lib/mngt/fwp_msg.c +++ b/fwp/lib/mngt/fwp_msg.c @@ -31,28 +31,33 @@ void fwp_msg_header_inflate(unsigned char *data, fwp_msg_type_t *type, participant_id->app_id = ntohl(msg_header->app_id); } -void fwp_msg_contract_deflate(unsigned char *data, struct fwp_contract *cont) +void fwp_msg_contract_deflate(unsigned char *data, fwp_contract_id_t id, + struct fwp_contract *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->id = htons(id); msg_contract->budget = htons(cont->budget); msg_contract->period_usec = htonl(cont->period_usec); } -void fwp_msg_contract_inflate(unsigned char *data, struct fwp_contract *cont) +void fwp_msg_contract_inflate(unsigned char *data, fwp_contract_id_t *id, + struct fwp_contract *cont) { struct fwp_msg_contract* msg_contract; msg_contract = (struct fwp_msg_contract*) data; /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/ + *id = ntohs(msg_contract->id); cont->budget = ntohs(msg_contract->budget); cont->period_usec = ntohl(msg_contract->period_usec); } -void fwp_msg_vres_params_deflate(unsigned char *data, unsigned int status, +void fwp_msg_vres_params_deflate(unsigned char *data, fwp_contract_id_t id, + unsigned int status, fwp_vres_params_t *vparams) { struct fwp_msg_vres_params* msg_vparams; @@ -61,15 +66,16 @@ void fwp_msg_vres_params_deflate(unsigned char *data, unsigned int status, /*msgcnt = (struct fwp_msg_contract*) fwp_msgb_put(msgb,sizeof(struct fwp_msg_contract));*/ - msg_vparams->id = htons(vparams->id); - msg_vparams->ac_id = vparams->ac_id; + msg_vparams->id = htons(id); msg_vparams->status = status; - + + 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_inflate(unsigned char *data, unsigned int *status, +void fwp_msg_vres_params_inflate(unsigned char *data, fwp_contract_id_t *id, + unsigned int *status, fwp_vres_params_t *vparams) { struct fwp_msg_vres_params* msg_vparams; @@ -77,10 +83,10 @@ void fwp_msg_vres_params_inflate(unsigned char *data, unsigned int *status, msg_vparams = (struct fwp_msg_vres_params*) data; /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/ - vparams->id = ntohs(msg_vparams->id); - vparams->ac_id = msg_vparams->ac_id; + *id = ntohs(msg_vparams->id); *status = msg_vparams->status; + vparams->ac_id = msg_vparams->ac_id; vparams->budget = ntohs(msg_vparams->budget); vparams->period_usec = ntohl(msg_vparams->period_usec); } diff --git a/fwp/lib/mngt/fwp_msg.h b/fwp/lib/mngt/fwp_msg.h index b2b1d24..23d0265 100644 --- a/fwp/lib/mngt/fwp_msg.h +++ b/fwp/lib/mngt/fwp_msg.h @@ -8,11 +8,11 @@ #include "fwp_participant.h" typedef enum { - FWP_MSG_HELLO = 1<<1, - FWP_MSG_NEGREQ = 1<<2, - FWP_MSG_NEGRES = 1<<3, - FWP_MSG_RESERVE = 1<<4, - FWP_MSG_COMMIT = 1<<5 + FWP_MSG_HELLO = 1<<1, + FWP_MSG_NEGT_REQ = 1<<2, + FWP_MSG_NEGT_RES = 1<<3, + FWP_MSG_NEGT_RESERVE = 1<<4, + FWP_MSG_NEGT_COMMIT = 1<<5 } fwp_msg_type_t; @@ -22,13 +22,15 @@ struct fwp_msg_header{ uint32_t app_id; /**< application id */ }__attribute__((packed)); -struct fwp_msg_contract{ +struct fwp_msg_contract{ + uint16_t id; /**< id */ uint16_t budget; /**< bits per second */ uint32_t period_usec; /**< all time units are in microseconds */ + /*uint8_t status;*/ }__attribute__((packed)); struct fwp_msg_vres_params{ - uint16_t id; /**< STA-unique vres param id */ + uint16_t id; /**< id */ 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 */ @@ -46,12 +48,16 @@ void fwp_msg_header_deflate(unsigned char *data, fwp_msg_type_t type, void fwp_msg_header_inflate(unsigned char *data, fwp_msg_type_t *type, fwp_participant_id_t *participant_id); -void fwp_msg_contract_deflate(unsigned char *data, struct fwp_contract *cont); -void fwp_msg_contract_inflate(unsigned char *data, struct fwp_contract *cont); +void fwp_msg_contract_deflate(unsigned char *data, fwp_contract_id_t id, + struct fwp_contract *cont); +void fwp_msg_contract_inflate(unsigned char *data, fwp_contract_id_t *id, + struct fwp_contract *cont); -void fwp_msg_vres_params_deflate(unsigned char *data, unsigned int status, +void fwp_msg_vres_params_deflate(unsigned char *data, fwp_contract_id_t id, + unsigned int status, fwp_vres_params_t *vparams); -void fwp_msg_vres_params_inflate(unsigned char *data, unsigned int *status, +void fwp_msg_vres_params_inflate(unsigned char *data, fwp_contract_id_t *id, + unsigned int *status, fwp_vres_params_t *vparams); void fwp_msg_hello_deflate(unsigned char *data, -- 2.39.2