aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-12-03 16:46:58 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-12-03 16:46:58 +0000
commit2ee48eea42eca9d2dc7dc4d58ab9cf3f2dbb5066 (patch)
tree8fce122235044be5e6ec93e3372ee5de9a4c7548 /src/testbed/testbed_api_testbed.c
parentf31790d110d6eed2aa78f336f96cc2240bd44c39 (diff)
downloadgnunet-2ee48eea42eca9d2dc7dc4d58ab9cf3f2dbb5066.tar.gz
gnunet-2ee48eea42eca9d2dc7dc4d58ab9cf3f2dbb5066.zip
host compatibility check in GNUNET_TESTBED_run() and fixes
Diffstat (limited to 'src/testbed/testbed_api_testbed.c')
-rw-r--r--src/testbed/testbed_api_testbed.c165
1 files changed, 127 insertions, 38 deletions
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index 05debd98c..845672bd6 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -188,6 +188,11 @@ struct RunContext
188 struct GNUNET_TESTBED_Host **hosts; 188 struct GNUNET_TESTBED_Host **hosts;
189 189
190 /** 190 /**
191 * The handle for whether a host is habitable or not
192 */
193 struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles;
194
195 /**
191 * Array of peers which we create 196 * Array of peers which we create
192 */ 197 */
193 struct GNUNET_TESTBED_Peer **peers; 198 struct GNUNET_TESTBED_Peer **peers;
@@ -239,7 +244,8 @@ struct RunContext
239 unsigned int num_hosts; 244 unsigned int num_hosts;
240 245
241 /** 246 /**
242 * Number of registered hosts 247 * Number of registered hosts. Also used as a counter while checking
248 * habitabillity of hosts
243 */ 249 */
244 unsigned int reg_hosts; 250 unsigned int reg_hosts;
245 251
@@ -352,6 +358,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
352 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rc->register_hosts_task); 358 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rc->register_hosts_task);
353 GNUNET_assert (NULL == rc->reg_handle); 359 GNUNET_assert (NULL == rc->reg_handle);
354 GNUNET_assert (NULL == rc->peers); 360 GNUNET_assert (NULL == rc->peers);
361 GNUNET_assert (NULL == rc->hc_handles);
355 GNUNET_assert (RC_PEERS_DESTROYED == rc->state); 362 GNUNET_assert (RC_PEERS_DESTROYED == rc->state);
356 if (NULL != rc->c) 363 if (NULL != rc->c)
357 GNUNET_TESTBED_controller_disconnect (rc->c); 364 GNUNET_TESTBED_controller_disconnect (rc->c);
@@ -392,9 +399,18 @@ shutdown_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
392 struct RunContext *rc = cls; 399 struct RunContext *rc = cls;
393 struct DLLOperation *dll_op; 400 struct DLLOperation *dll_op;
394 unsigned int peer; 401 unsigned int peer;
402 unsigned int nhost;
395 403
396 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task); 404 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rc->shutdown_run_task);
397 rc->shutdown_run_task = GNUNET_SCHEDULER_NO_TASK; 405 rc->shutdown_run_task = GNUNET_SCHEDULER_NO_TASK;
406 if (NULL != rc->hc_handles)
407 {
408 for (nhost = 0; nhost < rc->num_hosts; nhost++)
409 if (NULL != rc->hc_handles[nhost])
410 GNUNET_TESTBED_is_host_habitable_cancel (rc->hc_handles[nhost]);
411 GNUNET_free (rc->hc_handles);
412 rc->hc_handles = NULL;
413 }
398 /* Stop register hosts task if it is running */ 414 /* Stop register hosts task if it is running */
399 if (GNUNET_SCHEDULER_NO_TASK != rc->register_hosts_task) 415 if (GNUNET_SCHEDULER_NO_TASK != rc->register_hosts_task)
400 { 416 {
@@ -788,6 +804,7 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
788 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n"); 804 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Testbed startup failed\n");
789 return; 805 return;
790 } 806 }
807 GNUNET_CONFIGURATION_destroy (rc->cfg);
791 rc->cfg = GNUNET_CONFIGURATION_dup (cfg); 808 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
792 event_mask = rc->event_mask; 809 event_mask = rc->event_mask;
793 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 810 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
@@ -807,6 +824,57 @@ controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
807 824
808 825
809/** 826/**
827 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
828 * inform whether the given host is habitable or not. The Handle returned by
829 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
830 *
831 * @param cls NULL
832 * @param host the host whose status is being reported; will be NULL if the host
833 * given to GNUNET_TESTBED_is_host_habitable() is NULL
834 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
835 */
836static void
837host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host, int status)
838{
839 struct RunContext *rc = cls;
840 unsigned int nhost;
841
842 for (nhost = 0; nhost < rc->num_hosts; nhost++)
843 {
844 if (host == rc->hosts[nhost])
845 break;
846 }
847 GNUNET_assert (nhost != rc->num_hosts);
848 rc->hc_handles[nhost] = NULL;
849 rc->reg_hosts++;
850 if (rc->reg_hosts < rc->num_hosts)
851 return;
852 GNUNET_free (rc->hc_handles);
853 rc->hc_handles = NULL;
854 rc->h = rc->hosts[0];
855 rc->num_hosts--;
856 if (0 < rc->num_hosts)
857 rc->hosts = &rc->hosts[1];
858 else
859 {
860 GNUNET_free (rc->hosts);
861 rc->hosts = NULL;
862 }
863 /* FIXME: If we are starting controller on different host 127.0.0.1 may not ab
864 correct */
865 rc->cproc =
866 GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, rc->cfg,
867 &controller_status_cb, rc);
868 if (NULL == rc->cproc)
869 {
870 LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot start the master controller"));
871 GNUNET_SCHEDULER_cancel (rc->shutdown_run_task);
872 rc->shutdown_run_task = GNUNET_SCHEDULER_add_now (&shutdown_run, rc);
873 }
874}
875
876
877/**
810 * Convenience method for running a testbed with 878 * Convenience method for running a testbed with
811 * a single call. Underlay and overlay topology 879 * a single call. Underlay and overlay topology
812 * are configured using the "UNDERLAY" and "OVERLAY" 880 * are configured using the "UNDERLAY" and "OVERLAY"
@@ -844,6 +912,7 @@ GNUNET_TESTBED_run (const char *host_filename,
844 char *topology; 912 char *topology;
845 unsigned long long random_links; 913 unsigned long long random_links;
846 unsigned int hid; 914 unsigned int hid;
915 unsigned int nhost;
847 916
848 GNUNET_assert (NULL != cc); 917 GNUNET_assert (NULL != cc);
849 GNUNET_assert (num_peers > 0); 918 GNUNET_assert (num_peers > 0);
@@ -857,22 +926,16 @@ GNUNET_TESTBED_run (const char *host_filename,
857 { 926 {
858 LOG (GNUNET_ERROR_TYPE_WARNING, 927 LOG (GNUNET_ERROR_TYPE_WARNING,
859 _("No hosts loaded. Need at least one host\n")); 928 _("No hosts loaded. Need at least one host\n"));
860 return; 929 goto error_cleanup;
861 } 930 }
862 rc->h = rc->hosts[0];
863 rc->num_hosts--;
864 if (0 < rc->num_hosts)
865 rc->hosts = &rc->hosts[1];
866 } 931 }
867 else 932 else
868 rc->h = GNUNET_TESTBED_host_create (NULL, NULL, 0); 933 {
869 GNUNET_assert (NULL != rc->h); 934 rc->hosts = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *));
870 /* FIXME: If we are starting controller on different host 127.0.0.1 may not ab 935 rc->hosts[0] = GNUNET_TESTBED_host_create (NULL, NULL, 0);
871 correct */ 936 rc->num_hosts = 1;
872 rc->cproc = 937 }
873 GNUNET_TESTBED_controller_start ("127.0.0.1", rc->h, cfg, 938 rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
874 &controller_status_cb, rc);
875 GNUNET_assert (NULL != rc->cproc);
876 rc->num_peers = num_peers; 939 rc->num_peers = num_peers;
877 rc->event_mask = event_mask; 940 rc->event_mask = event_mask;
878 rc->event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 941 rc->event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
@@ -881,8 +944,8 @@ GNUNET_TESTBED_run (const char *host_filename,
881 rc->master = master; 944 rc->master = master;
882 rc->master_cls = master_cls; 945 rc->master_cls = master_cls;
883 rc->state = RC_INIT; 946 rc->state = RC_INIT;
884 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE; 947 rc->topology = GNUNET_TESTBED_TOPOLOGY_NONE;
885 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", 948 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (rc->cfg, "testbed",
886 "OVERLAY_TOPOLOGY", 949 "OVERLAY_TOPOLOGY",
887 &topology)) 950 &topology))
888 { 951 {
@@ -894,51 +957,77 @@ GNUNET_TESTBED_run (const char *host_filename,
894 } 957 }
895 GNUNET_free (topology); 958 GNUNET_free (topology);
896 } 959 }
897 if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology) 960 switch (rc->topology)
898 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING == rc->topology)
899 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD == rc->topology))
900 { 961 {
901 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed", 962 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
963 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
964 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
965 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (rc->cfg, "testbed",
902 "OVERLAY_RANDOM_LINKS", 966 "OVERLAY_RANDOM_LINKS",
903 &random_links)) 967 &random_links))
904 { 968 {
905 /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS 969 /* OVERLAY option RANDOM & SMALL_WORLD_RING requires OVERLAY_RANDOM_LINKS
906 option to be set to the number of random links to be established */ 970 option to be set to the number of random links to be established */
907 GNUNET_break (0); 971 GNUNET_break (0);
908 GNUNET_free (rc); 972 goto error_cleanup;
909 return;
910 } 973 }
911 if (random_links > UINT32_MAX) 974 if (random_links > UINT32_MAX)
912 { 975 {
913 GNUNET_break (0); /* Too big number */ 976 GNUNET_break (0); /* Too big number */
914 GNUNET_TESTBED_host_destroy (rc->h); 977 goto error_cleanup;
915 for (hid = 0; hid < rc->num_hosts; hid++)
916 GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
917 GNUNET_free_non_null (rc->hosts);
918 GNUNET_free (rc);
919 return;
920 } 978 }
921 rc->random_links = (unsigned int) random_links; 979 rc->random_links = (unsigned int) random_links;
922 } 980 break;
923 else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology) 981 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
924 { 982 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (rc->cfg, "testbed",
925 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
926 "TOPOLOGY_FILE", 983 "TOPOLOGY_FILE",
927 &rc->topo_file)) 984 &rc->topo_file))
928 { 985 {
929 /* You need to set TOPOLOGY_FILE option to a topolog file */ 986 /* You need to set TOPOLOGY_FILE option to a topolog file */
930 GNUNET_break (0); 987 GNUNET_break (0);
931 GNUNET_TESTBED_host_destroy (rc->h); 988 goto error_cleanup;
932 for (hid = 0; hid < rc->num_hosts; hid++) 989 }
933 GNUNET_TESTBED_host_destroy (rc->hosts[hid]); 990 break;
934 GNUNET_free_non_null (rc->hosts); 991 default:
935 GNUNET_free (rc); 992 /* Do nothing */
936 return; 993 break;
994 }
995 rc->hc_handles = GNUNET_malloc (sizeof (struct
996 GNUNET_TESTBED_HostHabitableCheckHandle *)
997 * rc->num_hosts);
998 for (nhost = 0; nhost < rc->num_hosts; nhost++)
999 {
1000 if (NULL == (rc->hc_handles[nhost] =
1001 GNUNET_TESTBED_is_host_habitable (rc->hosts[nhost], rc->cfg,
1002 &host_habitable_cb,
1003 rc)))
1004 {
1005 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %s cannot start testbed\n",
1006 GNUNET_TESTBED_host_get_hostname_ (rc->hosts[nhost]));
1007 for (nhost = 0; nhost < rc->num_hosts; nhost++)
1008 if (NULL != rc->hc_handles[nhost])
1009 GNUNET_TESTBED_is_host_habitable_cancel (rc->hc_handles[nhost]);
1010 GNUNET_free (rc->hc_handles);
1011 rc->hc_handles = NULL;
1012 goto error_cleanup;
937 } 1013 }
938 } 1014 }
939 rc->shutdown_run_task = 1015 rc->shutdown_run_task =
940 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1016 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
941 &shutdown_run, rc); 1017 &shutdown_run, rc);
1018 return;
1019
1020 error_cleanup:
1021 if (NULL != rc->h)
1022 GNUNET_TESTBED_host_destroy (rc->h);
1023 if (NULL != rc->hosts)
1024 {
1025 for (hid = 0; hid < rc->num_hosts; hid++)
1026 if (NULL != rc->hosts[hid])
1027 GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
1028 GNUNET_free (rc->hosts);
1029 }
1030 GNUNET_free (rc);
942} 1031}
943 1032
944 1033