]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Incorporate fwp_configuration into fwp_mngt_init
authorMartin Molnar <molnar@sum.(none)>
Mon, 9 Jun 2008 13:19:03 +0000 (15:19 +0200)
committerMartin Molnar <molnar@sum.(none)>
Mon, 9 Jun 2008 13:19:03 +0000 (15:19 +0200)
fwp/lib/core/fwp_endpoint.c
fwp/lib/core/fwp_endpoint.h
fwp/lib/fwp.h
fwp/lib/fwp_conf.h
fwp/lib/fwp_confdefs.h
fwp/lib/fwp_fna.c
fwp/lib/mngt/fwp_mngt.c
fwp/mngr/fwp_mngr.c
fwp/tests/fwp_mngrtest/fwp_mngrtest.c

index e0ff000b579a4bfc44c0f8c3ab62975ad11612e6..e640f8a2adf2efe58647a0e5b2ca871b2f56d4e2 100644 (file)
@@ -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;
index 51b7ef74a486625d37f1d823abffca1f581693da..fb22537f4153b8e9d0c2b49169499ebf871772e8 100644 (file)
@@ -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);
 
index a46c4a558a83257b60eb9bbe78d7404da0999b25..15a745a253bc3f76bf720cb0a13334b44d72a931 100644 (file)
@@ -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;
index 172236db429eac35cde7c2a5575982ee1f647873..18c29b1b93be601fb70da25a4b2d7bc9cd8f5af1 100644 (file)
@@ -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;
index 8a3d249985edddd444d4a60ea28a7b7b99d31478..3ab5ddabc2e51c2c7cd910f8e583c9074c76a5e0 100644 (file)
@@ -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
 #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
 };
 
 
index 6a7f3e3da9b29dec9de1ed9354fb3bc685bebc5f..29e9d09f921f0a69449eac812e051216a5613beb 100644 (file)
@@ -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)
 {
index c549d84d8eb7b0f234f85999f3f9810251f7619b..41791dc18ea055268518428fa496852ea1b9d1fc 100644 (file)
@@ -1,5 +1,7 @@
+#include "fwp_conf.h"
 #include "fwp_mngt.h"
 
+#include <stdlib.h>
 /* 
  * 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;
 }
index 2d0c007056b67ca55770fba1c576e6c1742cf6d7..33c0da1bca513347ab4a03e95df46cf64bd7fa2d 100644 (file)
@@ -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);
        }
index 9deca70eb68fd6dd445d4683e3ac2707be389c7d..6287d7b4014aa4923c497584865b50bae52c3efe 100644 (file)
@@ -1,3 +1,5 @@
+#define CONFIGURE_FWP_MNGR_ADDR "127.0.0.1"
+
 #include "fwp_confdefs.h"
 #include "fwp.h"