Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Current state
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Mar 2006 15:59:53 +0000 (15:59 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Mar 2006 15:59:53 +0000 (15:59 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1945 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/gras/p2p/chord/.cvsignore [new file with mode: 0644]
examples/gras/p2p/chord/Makefile.am [new file with mode: 0644]
examples/gras/p2p/chord/chord.c [new file with mode: 0644]
examples/gras/p2p/chord/chord.h [new file with mode: 0644]
examples/gras/p2p/chord/chord_deployment.xml [new file with mode: 0644]
examples/gras/p2p/chord/test_rl.in [new file with mode: 0755]
examples/gras/p2p/chord/test_sg.in [new file with mode: 0755]

diff --git a/examples/gras/p2p/chord/.cvsignore b/examples/gras/p2p/chord/.cvsignore
new file mode 100644 (file)
index 0000000..8bdcc2e
--- /dev/null
@@ -0,0 +1,8 @@
+.deps .libs Makefile Makefile.in _*.c chord_node chord_simulator
+test_sg
+test_rl
+chord.Makefile.am
+chord.Makefile.local
+chord.Makefile.remote
+chord.deploy.sh
+chord.trace
diff --git a/examples/gras/p2p/chord/Makefile.am b/examples/gras/p2p/chord/Makefile.am
new file mode 100644 (file)
index 0000000..01a97c5
--- /dev/null
@@ -0,0 +1,20 @@
+INCLUDES= -I$(top_srcdir)/include
+TESTS= test_rl test_sg
+EXTRA_DIST=chord_deployment.xml $(TESTS)
+
+# AUTOMAKE variable definition
+noinst_PROGRAMS=chord_node chord_simulator
+
+chord_simulator_SOURCES=       _chord_simulator.c chord.c
+chord_simulator_LDADD= $(top_builddir)/src/libsimgrid.la
+
+chord_node_SOURCES=    _chord_client.c chord.c
+chord_node_LDADD=      $(top_builddir)/src/libgras.la
+
+# Take care of generatated sources
+NAME=chord
+PROCESSES=node
+include $(top_srcdir)/examples/temps-gras-stub.mk
+
+# Cruft
+include $(top_srcdir)/acmacro/dist-files.mk
diff --git a/examples/gras/p2p/chord/chord.c b/examples/gras/p2p/chord/chord.c
new file mode 100644 (file)
index 0000000..37d061e
--- /dev/null
@@ -0,0 +1,213 @@
+/* 
+ * vim:ts=2:sw=2:noexpandtab
+ */
+
+#include "chord.h"
+
+static void register_messages(){
+/*     gras_msgtype_declare("chord",gras_datadesc_by_symbol(s_pbio));*/
+       gras_msgtype_declare("chord_get_suc",gras_datadesc_by_symbol(s_get_suc));
+       gras_msgtype_declare("chord_rep_suc",gras_datadesc_by_symbol(s_rep_suc));
+}
+
+/* Global private data */
+typedef struct{
+       gras_socket_t sock; /* server socket on which I'm listening */
+       int id; /* my id number */
+       char host[1024]; /* my host name */
+       int port; /* port on which I'm listening FIXME */
+       int fingers; /* how many fingers */
+       finger_elem *finger; /* finger table */
+       char pre_host[1024]; /* predecessor host */
+       int pre_port; /* predecessor port */
+}node_data_t;
+
+
+int node(int argc,char **argv);
+
+/*static int node_cb_chord_handler(gras_socket_t expeditor,void *payload_data){
+       xbt_ex_t e;
+       pbio_t pbio_i=*(pbio_t*)payload_data;
+
+       node_data_t *globals=(node_data_t*)gras_userdata_get();
+
+       INFO4(">>> %d : received %d message from %s to %d <<<",globals->id,pbio_i.type,gras_socket_peer_name(expeditor),pbio_i.dest);
+
+
+
+}*/
+
+static int node_cb_get_suc_handler(gras_socket_t expeditor,void *payload_data){
+       xbt_ex_t e;
+       get_suc_t incoming=*(get_suc_t*)payload_data;
+       rep_suc_t outgoing;
+       node_data_t *globals=(node_data_t*)gras_userdata_get();
+       INFO2("Received a get_successor message from %s for %d",gras_socket_peer_name(expeditor),incoming.id);
+       if((globals->id==globals->finger[0].id)||(incoming.id>globals->id&&incoming.id<=globals->finger[0].id)){
+               outgoing.id=globals->finger[0].id;
+               snprintf(outgoing.host,1024,globals->finger[0].host);
+               outgoing.port=globals->finger[0].port;
+               INFO0("My successor is his successor!");
+       }else{
+               gras_socket_t temp_sock;
+               int contact=closest_preceding_node(incoming.id);
+               get_suc_t asking;asking.id=incoming.id;
+               TRY{
+                       temp_sock=gras_socket_client(globals->finger[contact].host,globals->finger[contact].port);
+               }CATCH(e){
+                       RETHROW0("Unable to connect!");
+               }
+               TRY{
+                       gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&asking);
+               }CATCH(e){
+                       RETHROW0("Unable to ask!");
+               }
+               gras_msg_wait(10.0,gras_msgtype_by_name("chord_rep_suc"),&temp_sock,&outgoing);
+       }
+
+       TRY{
+               gras_msg_send(expeditor,gras_msgtype_by_name("chord_rep_suc"),&outgoing);
+               INFO0("Successor information sent!");
+       }CATCH(e){
+               RETHROW2("%s:Timeout sending successor information to %s",globals->host,gras_socket_peer_name(expeditor));
+       }
+       gras_socket_close(expeditor);
+       return(1);
+}
+
+int closest_preceding_node(int id){
+       node_data_t *globals=(node_data_t*)gras_userdata_get();
+       int i;
+       for(i=globals->fingers-1;i>=0;i--){
+               if(globals->finger[i].id>globals->id&&globals->finger[i].id<id){
+                       return(i);
+               }
+       return(i);
+       }
+}
+
+
+void check_predecessor()
+{
+node_data_t *globals = (node_data_t*)gras_userdata_get();
+gras_socket_t temp_sock;
+if (globals->pre_host[0] == 0)
+       {
+       return;
+       }
+TRY
+       {
+       temp_sock = gras_socket_client( globals->pre_host, globals->pre_port );
+       }
+CATCH(e)
+       {
+       globals->pre_host[0] = 0;
+       globals->pre_port = 0;
+       }
+ping_t ping_kong;
+pong_t king_pong;
+ping_kong->id = 0;
+TRY
+       {
+       gras_msg_send( temp_sock, gras_msgtype_by_name("chord_ping"),&ping_kong);
+       }
+CATCH(e)
+       {
+       globals->pre_host[0] = 0;
+       globals->pre_port = 0;
+       }
+TRY
+       {
+       gras_msg_wait( 6969, gras_msgtype_by_name("chord_pong"), &temp_sock, &king_pong);
+       }
+CATCH(e)
+       {
+       globals->pre_host[0] = 0;
+       globals->pre_port = 0;
+       }
+gras_socket_close(temp_sock);
+}
+
+int node(int argc,char **argv){
+       node_data_t *globals=NULL;
+       gras_socket_t temp_sock,temp_sock2;
+
+       xbt_ex_t e;
+
+       int create=0;
+       int other_port;
+       char *other_host;
+
+       /* 1. Init the GRAS infrastructure and declare my globals */
+       gras_init(&argc,argv);
+       globals=gras_userdata_new(node_data_t);
+
+       globals->id=atoi(argv[1]);
+       globals->port=atoi(argv[2]);
+       globals->fingers=0;
+       globals->finger=NULL;
+       globals->pre_host[0]=0;
+       globals->pre_port=-1;
+       
+       snprintf(globals->host,1024,gras_os_myname());
+
+       if(argc==3){
+               create=1;
+       }else{
+               other_host=strndup(argv[3],1024);
+               other_port=atoi(argv[4]);
+       }
+       
+       globals->sock=gras_socket_server(globals->port);
+       gras_os_sleep(1.0);
+
+       register_messages();
+       register_messages();
+
+       globals->finger=(finger_elem*)calloc(1,sizeof(finger_elem));
+       INFO2("Launching node %s:%d",globals->host,globals->port);
+       if(create){
+               INFO0("→Creating ring");
+               globals->finger[0].id=globals->id;
+               snprintf(globals->finger[0].host,1024,globals->host);
+               globals->finger[0].port=globals->port;
+       }else{
+               INFO2("→Known node %s:%d",other_host,other_port);
+               INFO0("→Contacting to determine successor");
+               TRY{
+                       temp_sock=gras_socket_client(other_host,other_port);
+               }CATCH(e){
+                       RETHROW0("Unable to contact known host!");
+               }
+               get_suc_t get_suc_msg;get_suc_msg.id=globals->id;
+               TRY{
+                       gras_msg_send(temp_sock,gras_msgtype_by_name("chord_get_suc"),&get_suc_msg);
+               }CATCH(e){
+                       gras_socket_close(temp_sock);
+                       RETHROW0("Unable to contact known host to get successor!");
+               }
+               rep_suc_t rep_suc_msg;
+               TRY{
+                       INFO0("Waiting for reply!");
+                       gras_msg_wait(6000,gras_msgtype_by_name("chord_rep_suc"),&temp_sock2,&rep_suc_msg);
+               }CATCH(e){
+                       RETHROW2("%s: Error waiting for successor:%s",globals->host,e.msg);
+               }
+               globals->finger[0].id=rep_suc_msg.id;
+               snprintf(globals->finger[0].host,1024,rep_suc_msg.host);
+               globals->finger[0].port=rep_suc_msg.port;
+               INFO3("→Got successor : %d-%s:%d",globals->finger[0].id,globals->finger[0].host,globals->finger[0].port);
+               gras_socket_close(temp_sock);
+       }
+
+       gras_cb_register(gras_msgtype_by_name("chord_get_suc"),&node_cb_get_suc_handler);
+//     gras_cb_register(gras_msgtype_by_name("chord_ping"),&node_cb_ping_handler);
+
+       gras_msg_handle(60.0);
+
+       gras_socket_close(globals->sock);
+       free(globals);
+       gras_exit();
+       INFO0("Done");
+       return(0);
+}
diff --git a/examples/gras/p2p/chord/chord.h b/examples/gras/p2p/chord/chord.h
new file mode 100644 (file)
index 0000000..0cd2d37
--- /dev/null
@@ -0,0 +1,63 @@
+/* 
+ * vim:ts=2:sw=2:noexpandtab
+ */
+
+#include <gras.h>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(chord,"Messages specific to this example");
+
+typedef enum msg_typus{
+       PING,
+       PONG,
+       GET_PRE,
+       REP_PRE,
+       GET_SUC,
+       REP_SUC,
+       STD,
+}msg_typus;
+
+/*GRAS_DEFINE_TYPE(s_pbio,
+       struct s_pbio{
+               msg_typus type;
+               int dest;
+               char msg[1024];
+       };
+);
+typedef struct s_pbio pbio_t;*/
+
+GRAS_DEFINE_TYPE(s_ping,
+       struct s_ping{
+               int id;
+       };
+);
+typedef struct s_ping ping_t;
+
+GRAS_DEFINE_TYPE(s_pong,
+       struct s_pong{
+               int id;
+               int failed;
+       };
+);
+typedef struct s_pong pong_t;
+
+GRAS_DEFINE_TYPE(s_get_suc,
+       struct s_get_suc{
+               int id;
+       };
+);
+typedef struct s_get_suc get_suc_t;
+
+GRAS_DEFINE_TYPE(s_rep_suc,
+       struct s_rep_suc{
+               int id;
+               char host[1024];
+               int port;
+       };
+);
+typedef struct s_rep_suc rep_suc_t;
+
+typedef struct finger_elem{
+       int id;
+       char host[1024];
+       int port;
+}finger_elem;
diff --git a/examples/gras/p2p/chord/chord_deployment.xml b/examples/gras/p2p/chord/chord_deployment.xml
new file mode 100644 (file)
index 0000000..2e0aa71
--- /dev/null
@@ -0,0 +1,143 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform_description SYSTEM "surfxml.dtd">
+<platform_description>
+
+  <process host="Gatien" function="node">
+    <argument value="48"/>           <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="McGee"/>               <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="56"/>           <!-- +1 host number -->
+    <argument value="Laroche"/>      <!-- +1 host name -->
+    <argument value="56"/>           <!-- +2 host number -->
+    <argument value="Laroche"/>      <!-- +2 host name -->
+    <argument value="56"/>           <!-- +4 host number -->
+    <argument value="Laroche"/>      <!-- +4 host name -->
+<!--    <argument value="56"/>            +8 host number -->
+<!--    <argument value="Laroche"/>       +8 host name -->
+<!--    <argument value="56"/>            +16 host number -->
+<!--    <argument value="Laroche"/>       +16 host name -->
+<!--    <argument value="56"/>            +32 host number -->
+<!--    <argument value="Laroche"/>       +32 host name -->
+  </process>
+
+  <process host="McGee" function="node">
+    <argument value="42"/>           <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="iRMX"/>        <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="51"/>           <!-- +1 host number -->
+    <argument value="Gatien"/>       <!-- +1 host name -->
+    <argument value="51"/>           <!-- +2 host number -->
+    <argument value="Gatien"/>       <!-- +2 host name -->
+    <argument value="56"/>           <!-- +4 host number -->
+    <argument value="Laroche"/>      <!-- +4 host name -->
+    <argument value="56"/>           <!-- +8 host number -->
+    <argument value="Laroche"/>      <!-- +8 host name -->
+<!--    <argument value="56"/>            +16 host number -->
+<!--    <argument value="Laroche"/>       +16 host name -->
+<!--    <argument value="56"/>            +32 host number -->
+<!--    <argument value="Laroche"/>       +32 host name -->
+  </process>
+
+  <process host="iRMX" function="node">
+    <argument value="38"/>       <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="Geoff"/>               <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="48"/>           <!-- +1 host number -->
+    <argument value="McGee"/>        <!-- +1 host name -->
+    <argument value="48"/>           <!-- +2 host number -->
+    <argument value="McGee"/>        <!-- +2 host name -->
+    <argument value="48"/>           <!-- +4 host number -->
+    <argument value="McGee"/>        <!-- +4 host name -->
+    <argument value="51"/>           <!-- +8 host number -->
+    <argument value="Gatien"/>       <!-- +8 host name -->
+    <argument value="56"/>           <!-- +16 host number -->
+    <argument value="Laroche"/>      <!-- +16 host name -->
+<!--    <argument value="56"/>            +32 host number -->
+<!--    <argument value="Laroche"/>       +32 host name -->
+  </process>
+
+  <process host="Geoff" function="node">
+    <argument value="32"/>           <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="TeX"/>         <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="38"/>           <!-- +1 host number -->
+    <argument value="Disney"/>       <!-- +1 host name -->
+    <argument value="38"/>           <!-- +2 host number -->
+    <argument value="Disney"/>       <!-- +2 host name -->
+    <argument value="38"/>           <!-- +4 host number -->
+    <argument value="Disney"/>       <!-- +4 host name -->
+    <argument value="42"/>           <!-- +8 host number -->
+    <argument value="iRMX"/>         <!-- +8 host name -->
+    <argument value="48"/>           <!-- +16 host number -->
+    <argument value="McGee"/>        <!-- +16 host name -->
+<!--    <argument value="56"/>            +32 host number -->
+<!--    <argument value="Laroche"/>       +32 host name -->
+  </process>
+
+  <process host="TeX" function="node">
+    <argument value="21"/>           <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="Jean_Yves"/>    <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="32"/>           <!-- +1 host number -->
+    <argument value="Geoff"/>        <!-- +1 host name -->
+    <argument value="32"/>           <!-- +2 host number -->
+    <argument value="Geoff"/>        <!-- +2 host name -->
+    <argument value="32"/>           <!-- +4 host number -->
+    <argument value="Geoff"/>        <!-- +4 host name -->
+    <argument value="32"/>           <!-- +8 host number -->
+    <argument value="Geoff"/>        <!-- +8 host name -->
+    <argument value="38"/>           <!-- +16 host number -->
+    <argument value="Disney"/>       <!-- +16 host name -->
+    <argument value="56"/>           <!-- +32 host number -->
+    <argument value="Laroche"/>      <!-- +32 host name -->
+  </process>
+
+  <process host="Jean_Yves" function="node">
+    <argument value="14"/>           <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="Boivin"/>       <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="21"/>           <!-- +1 host number -->
+    <argument value="TeX"/>          <!-- +1 host name -->
+    <argument value="21"/>           <!-- +2 host number -->
+    <argument value="TeX"/>          <!-- +2 host name -->
+    <argument value="21"/>           <!-- +4 host number -->
+    <argument value="TeX"/>          <!-- +4 host name -->
+    <argument value="32"/>           <!-- +8 host number -->
+    <argument value="Geoff"/>        <!-- +8 host name -->
+    <argument value="32"/>           <!-- +16 host number -->
+    <argument value="Geoff"/>        <!-- +16 host name -->
+    <argument value="48"/>           <!-- +32 host number -->
+    <argument value="McGee"/>        <!-- +32 host name -->
+  </process>
+
+  <process host="Boivin" function="node">
+    <argument value="8"/>            <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+    <argument value="Jacquelin"/>    <!-- known host -->
+    <argument value="4000"/>         <!-- known port -->
+    <argument value="14"/>           <!-- +1 host number -->
+    <argument value="Jean_Yves"/>    <!-- +1 host name -->
+    <argument value="14"/>           <!-- +2 host number -->
+    <argument value="Jean_Yves"/>    <!-- +2 host name -->
+    <argument value="14"/>           <!-- +4 host number -->
+    <argument value="Jean_Yves"/>    <!-- +4 host name -->
+    <argument value="21"/>           <!-- +8 host number -->
+    <argument value="TeX"/>          <!-- +8 host name -->
+    <argument value="32"/>           <!-- +16 host number -->
+    <argument value="Geoff"/>        <!-- +16 host name -->
+    <argument value="42"/>           <!-- +32 host number -->
+    <argument value="iRMX"/>         <!-- +32 host name -->
+  </process>
+
+  <process host="Jacquelin" function="node">
+    <argument value="1"/>            <!-- my id -->
+    <argument value="4000"/>         <!-- my port -->
+  </process>
+
+</platform_description>
diff --git a/examples/gras/p2p/chord/test_rl.in b/examples/gras/p2p/chord/test_rl.in
new file mode 100755 (executable)
index 0000000..572f16d
--- /dev/null
@@ -0,0 +1,11 @@
+#! @BASH@ -e
+if [ x@EXEEXT@ = x ] ; then 
+#  exenv="libtool --mode=execute valgrind --show-reachable=yes --run-libc-freeres=no "
+  exenv=$SG_TEST_EXENV
+else
+  exenv=wine
+fi
+    
+$exenv ./chord_node@EXEEXT@ 4002 $@ &
+sleep 1
+$exenv ./chord_node@EXEEXT@ 127.0.0.1 4002 $@
diff --git a/examples/gras/p2p/chord/test_sg.in b/examples/gras/p2p/chord/test_sg.in
new file mode 100755 (executable)
index 0000000..67d9c24
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+if [ x = x ] ; then 
+  exenv=$SG_TEST_EXENV
+else
+  exenv=wine
+fi
+top_srcdir=/home/illogict/progs/simgrid/simgrid-3.0.1
+srcdir=`pwd`
+
+exec $exenv ./chord_simulator /home/illogict/progs/simgrid/simgrid-3.0.1/examples/msg/msg_platform.xml ~/progs/simgrid/simgrid-3.0.1/examples/gras/p2p/chord_t/chord_deployment.xml $@