From: Martin Molnar Date: Mon, 9 Jun 2008 13:19:03 +0000 (+0200) Subject: Incorporate fwp_configuration into fwp_mngt_init X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fwp.git/commitdiff_plain/8c1522218ac073c59948461fb39f673345957a6f Incorporate fwp_configuration into fwp_mngt_init --- diff --git a/fwp/lib/core/fwp_endpoint.c b/fwp/lib/core/fwp_endpoint.c index e0ff000..e640f8a 100644 --- a/fwp/lib/core/fwp_endpoint.c +++ b/fwp/lib/core/fwp_endpoint.c @@ -205,8 +205,8 @@ err: * On error, negative error code is returned. * */ -int fwp_receive_endpoint_create(unsigned int port, int flags, - fwp_endpoint_d_t *epointdp) +int fwp_receive_endpoint_create(/*unsigned int node,*/ unsigned int port, + int flags, fwp_endpoint_d_t *epointdp) { fwp_endpoint_t *epoint; int sockd; diff --git a/fwp/lib/core/fwp_endpoint.h b/fwp/lib/core/fwp_endpoint.h index 51b7ef7..fb22537 100644 --- a/fwp/lib/core/fwp_endpoint.h +++ b/fwp/lib/core/fwp_endpoint.h @@ -4,6 +4,8 @@ #include "fwp_util.h" #include "fwp_msgb.h" +#define FWP_ANY_NODE INADDR_ANY + typedef enum { FWP_EPOINT_DATA = 0, FWP_EPOINT_MNGT = 1, @@ -24,7 +26,9 @@ int fwp_endpoint_get_params(unsigned int *node, unsigned int *port, int *flags, int fwp_send_endpoint_create(unsigned int node, unsigned int port, int flags, fwp_endpoint_d_t *epointdp); -int fwp_receive_endpoint_create(unsigned int port, int flags, fwp_endpoint_d_t *epointdp); +int fwp_receive_endpoint_create(/*unsigned int node,*/ unsigned int port, + int flags, fwp_endpoint_d_t *epointdp); + int fwp_send_endpoint_bind(fwp_endpoint_d_t epointd, fwp_vres_d_t vresd); int fwp_send_endpoint_unbind(fwp_endpoint_d_t epointd); diff --git a/fwp/lib/fwp.h b/fwp/lib/fwp.h index a46c4a5..15a745a 100644 --- a/fwp/lib/fwp.h +++ b/fwp/lib/fwp.h @@ -24,8 +24,7 @@ static inline int fwp_init() if ((rv = fwp_endpoint_table_init(fwp_configuration.max_endpoints)) || (rv = fwp_vres_table_init(fwp_configuration.max_vres)) || - (rv = fwp_mngt_init()) || - (rv = fwp_mngt_connect())) + (rv = fwp_mngt_init()) ) return rv; return 0; diff --git a/fwp/lib/fwp_conf.h b/fwp/lib/fwp_conf.h index 172236d..18c29b1 100644 --- a/fwp/lib/fwp_conf.h +++ b/fwp/lib/fwp_conf.h @@ -8,9 +8,14 @@ typedef struct { -// unsigned int interface; unsigned int max_vres; unsigned int max_endpoints; + char my_addr[16]; + unsigned int my_stream_id; + char mngr_addr[16]; + unsigned int mngr_stream_id; + unsigned int my_node_id; + unsigned int mngr_node_id; } fwp_configuration_table_t; extern fwp_configuration_table_t fwp_configuration; diff --git a/fwp/lib/fwp_confdefs.h b/fwp/lib/fwp_confdefs.h index 8a3d249..3ab5dda 100644 --- a/fwp/lib/fwp_confdefs.h +++ b/fwp/lib/fwp_confdefs.h @@ -3,11 +3,6 @@ #include "fwp_conf.h" -/** IP Address of interface FWP operates */ -#ifndef CONFUGURE_FWP_IF -#define CONFIGURE_FWP_IF 127.0.0.1 -#endif - /** Number of ACs */ #ifndef CONFUGURE_FWP_AC_NUM #define CONFIGURE_FWP_AC_NUM 4 @@ -33,9 +28,32 @@ #define CONFIGURE_FWP_ENDPOINTS_MAXIMUM 50 #endif +/** IP Address of interface FWP operates on */ +#ifndef CONFIGURE_FWP_MY_ADDR +#define CONFIGURE_FWP_MY_ADDR "127.0.0.1" +#endif + +#ifndef CONFIGURE_FWP_MY_STREAM_ID +#define CONFIGURE_FWP_MY_STREAM_ID 0 +#endif + +#ifndef CONFIGURE_FWP_MNGR_ADDR +#define CONFIGURE_FWP_MNGR_ADDR "255.255.255.255" +#endif + +#ifndef CONFIGURE_FWP_MNGR_STREAM_ID +#define CONFIGURE_FWP_MNGR_STREAM_ID 3000 +#endif + fwp_configuration_table_t fwp_configuration = { CONFIGURE_FWP_VRES_MAXIMUM, - CONFIGURE_FWP_ENDPOINTS_MAXIMUM + CONFIGURE_FWP_ENDPOINTS_MAXIMUM, + CONFIGURE_FWP_MY_ADDR, + CONFIGURE_FWP_MY_STREAM_ID, + CONFIGURE_FWP_MNGR_ADDR, + CONFIGURE_FWP_MNGR_STREAM_ID, + 0, + 0 }; diff --git a/fwp/lib/fwp_fna.c b/fwp/lib/fwp_fna.c index 6a7f3e3..29e9d09 100644 --- a/fwp/lib/fwp_fna.c +++ b/fwp/lib/fwp_fna.c @@ -97,6 +97,14 @@ int fwp_fna_receive_async(const fna_endpoint_data_t *endpoint, void *buffer, from, MSG_DONTWAIT); } +int fwp_fna_receive_endpoint_created (void) +{ + INADDR_ANY + fwp_receive_endpoint_create(fwp_configuration.my_node_id,..); + +} + + int fwp_fna_vres_destroy(const frsh_resource_id_t resource_id, const fna_vres_id_t vres) { diff --git a/fwp/lib/mngt/fwp_mngt.c b/fwp/lib/mngt/fwp_mngt.c index c549d84..41791dc 100644 --- a/fwp/lib/mngt/fwp_mngt.c +++ b/fwp/lib/mngt/fwp_mngt.c @@ -1,5 +1,7 @@ +#include "fwp_conf.h" #include "fwp_mngt.h" +#include /* * Global mngt variables */ @@ -80,6 +82,17 @@ int fwp_mngt_connect() fwp_msg_type_t msg_type; + /* Create discovery endpoint */ + FWP_DEBUG("Service vres created\n"); + fwp_mngt_service_vres_create(&fwp_participant_mngr->vresd); + + FWP_DEBUG("Discovery send endpoint created\n"); + fwp_send_endpoint_create(fwp_participant_mngr->id.node_id, + fwp_participant_mngr->stream_id, + 0, &fwp_participant_mngr->epointd); + 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)); @@ -126,14 +139,25 @@ int fwp_mngt_init() fwp_participant_info_t my_info, mngr_info; unsigned int node_id; int flags; + char *value; /* Create fwp_participant_this */ - my_info.id.node_id = inet_addr("127.0.0.1"); + + my_info.id.node_id = inet_addr(fwp_configuration.my_addr); + if (my_info.id.node_id == inet_addr("127.0.0.1")) { + /* 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 = 0; + my_info.stream_id = fwp_configuration.my_stream_id; fwp_participant_this = fwp_participant_create(&my_info); - fwp_receive_endpoint_create(0, 0, &fwp_participant_this->epointd); + fwp_receive_endpoint_create(my_info.stream_id, 0, + &fwp_participant_this->epointd); /* FIXME fwp_endpoint_get_params(&(fwp_participant_this->id.node_id), &fwp_participant_this->stream_id, @@ -149,23 +173,32 @@ int fwp_mngt_init() fwp_participant_this->stream_id); /* Create fwp_participant_mngr */ - mngr_info.id.node_id = inet_addr("127.0.0.1"); - /*mngr_info.id.node_id = inet_addr("255.255.255.255");*/ - mngr_info.id.app_id = getpid(); - mngr_info.stream_id = FWP_MNGR_STREAM_ID; - - fwp_participant_mngr = fwp_participant_create(&mngr_info); - /* Create discovery endpoint */ - FWP_DEBUG("Service vres created\n"); - fwp_mngt_service_vres_create(&fwp_participant_mngr->vresd); + mngr_info.id.node_id = inet_addr(fwp_configuration.mngr_addr); + FWP_DEBUG("mngr node=%s node_id=%d\n", + fwp_configuration.mngr_addr, + mngr_info.id.node_id); + if (mngr_info.id.node_id == inet_addr("255.255.255.255")) { + /* if default then check env variable */ + value = getenv("FWP_MNGR_ADDR"); + if (value) { + mngr_info.id.node_id = inet_addr(value); + } + } + 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; - FWP_DEBUG("Discovery send endpoint created\n"); - fwp_send_endpoint_create(fwp_participant_mngr->id.node_id, - fwp_participant_mngr->stream_id, - 0, &fwp_participant_mngr->epointd); - fwp_send_endpoint_bind(fwp_participant_mngr->epointd, - fwp_participant_mngr->vresd); + 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_create(&mngr_info); + /* Connet to FWP manager */ + fwp_mngt_connect(); + } return 0; } diff --git a/fwp/mngr/fwp_mngr.c b/fwp/mngr/fwp_mngr.c index 2d0c007..33c0da1 100644 --- a/fwp/mngr/fwp_mngr.c +++ b/fwp/mngr/fwp_mngr.c @@ -1,6 +1,8 @@ +#define CONFIGURE_FWP_MY_STREAM_ID 3000 +#define CONFIGURE_FWP_MNGR_ADDR "127.0.0.1" #include "fwp_confdefs.h" -#include "fwp_mngt.h" +#include "fwp.h" #include "fwp_participant_table.h" #include "fwp_admctrl.h" @@ -215,6 +217,7 @@ void fwp_mngr_main_loop() } } +#if 0 int fwp_mngr_init() { fwp_participant_info_t my_info; @@ -241,10 +244,11 @@ int fwp_mngr_init() return 0; } +#endif int main() { - if (fwp_mngr_init()) { + if (fwp_init()) { fprintf(stderr,"FWP manager initialization failed.\n"); exit(1); } diff --git a/fwp/tests/fwp_mngrtest/fwp_mngrtest.c b/fwp/tests/fwp_mngrtest/fwp_mngrtest.c index 9deca70..6287d7b 100644 --- a/fwp/tests/fwp_mngrtest/fwp_mngrtest.c +++ b/fwp/tests/fwp_mngrtest/fwp_mngrtest.c @@ -1,3 +1,5 @@ +#define CONFIGURE_FWP_MNGR_ADDR "127.0.0.1" + #include "fwp_confdefs.h" #include "fwp.h"