aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-22 17:03:48 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-22 17:03:48 +0000
commit3238f6daafe108e9faaa56df8bc4c10ff8af56c2 (patch)
tree7748e9a4e7dda2282ab74de8bbdddb88c5ed2bfe
parentc2d88b4c711713ee4d5511cb30142aa4c7738548 (diff)
downloadgnunet-3238f6daafe108e9faaa56df8bc4c10ff8af56c2.tar.gz
gnunet-3238f6daafe108e9faaa56df8bc4c10ff8af56c2.zip
topology loading from file
-rw-r--r--src/testbed/Makefile.am14
-rw-r--r--src/testbed/overlay_topology.txt5
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c23
-rw-r--r--src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf81
-rw-r--r--src/testbed/testbed_api_testbed.c32
-rw-r--r--src/testbed/testbed_api_topology.c167
6 files changed, 311 insertions, 11 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 7230888dc..93ea4cf45 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -97,7 +97,8 @@ check_PROGRAMS = \
97 test_testbed_api_testbed_run_topologyring \ 97 test_testbed_api_testbed_run_topologyring \
98 test_testbed_api_testbed_run_topologysmallworldring \ 98 test_testbed_api_testbed_run_topologysmallworldring \
99 test_testbed_api_testbed_run_topology2dtorus \ 99 test_testbed_api_testbed_run_topology2dtorus \
100 test_testbed_api_testbed_run_topologysmallworld 100 test_testbed_api_testbed_run_topologysmallworld \
101 test_testbed_api_testbed_run_topologyfromfile
101 102
102if ENABLE_TEST_RUN 103if ENABLE_TEST_RUN
103 TESTS = \ 104 TESTS = \
@@ -118,7 +119,8 @@ if ENABLE_TEST_RUN
118 test_testbed_api_testbed_run_topologyring \ 119 test_testbed_api_testbed_run_topologyring \
119 test_testbed_api_testbed_run_topologysmallworldring \ 120 test_testbed_api_testbed_run_topologysmallworldring \
120 test_testbed_api_testbed_run_topology2dtorus \ 121 test_testbed_api_testbed_run_topology2dtorus \
121 test_testbed_api_testbed_run_topologysmallworld 122 test_testbed_api_testbed_run_topologysmallworld \
123 test_testbed_api_testbed_run_topologyfromfile
122endif 124endif
123 125
124test_testbed_api_hosts_SOURCES = \ 126test_testbed_api_hosts_SOURCES = \
@@ -234,6 +236,12 @@ test_testbed_api_testbed_run_topologysmallworld_LDADD = \
234 $(top_builddir)/src/util/libgnunetutil.la \ 236 $(top_builddir)/src/util/libgnunetutil.la \
235 libgnunettestbed.la 237 libgnunettestbed.la
236 238
239test_testbed_api_testbed_run_topologyfromfile_SOURCES = \
240 test_testbed_api_testbed_run.c
241test_testbed_api_testbed_run_topologyfromfile_LDADD = \
242 $(top_builddir)/src/util/libgnunetutil.la \
243 libgnunettestbed.la
244
237EXTRA_DIST = \ 245EXTRA_DIST = \
238 test_testbed_api.conf \ 246 test_testbed_api.conf \
239 test_testbed_api_testbed_run_topologyring.conf \ 247 test_testbed_api_testbed_run_topologyring.conf \
@@ -243,4 +251,6 @@ EXTRA_DIST = \
243 test_testbed_api_testbed_run_topologysmallworldring.conf \ 251 test_testbed_api_testbed_run_topologysmallworldring.conf \
244 test_testbed_api_testbed_run_topology2dtorus.conf \ 252 test_testbed_api_testbed_run_topology2dtorus.conf \
245 test_testbed_api_testbed_run_topologysmallworld.conf \ 253 test_testbed_api_testbed_run_topologysmallworld.conf \
254 test_testbed_api_testbed_run_topologyfromfile.conf \
255 overlay_topology.txt \
246 sample_hosts.txt \ No newline at end of file 256 sample_hosts.txt \ No newline at end of file
diff --git a/src/testbed/overlay_topology.txt b/src/testbed/overlay_topology.txt
new file mode 100644
index 000000000..420dbb6a6
--- /dev/null
+++ b/src/testbed/overlay_topology.txt
@@ -0,0 +1,5 @@
1
21:2|3
33:4| 0| 1
42: 3|1|0
50: 2
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index 48c212401..3e75469ff 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -232,7 +232,12 @@ enum Stage
232 /** 232 /**
233 * Final success stage 233 * Final success stage
234 */ 234 */
235 SUCCESS 235 SUCCESS,
236
237 /**
238 * Optional stage for marking test to be skipped
239 */
240 SKIP
236}; 241};
237 242
238/** 243/**
@@ -874,8 +879,8 @@ run (void *cls, char *const *args, const char *cfgfile,
874 (void) PRINTF ("%s", 879 (void) PRINTF ("%s",
875 "Unable to run the test as this system is not configured " 880 "Unable to run the test as this system is not configured "
876 "to use password less SSH logins to localhost.\n" 881 "to use password less SSH logins to localhost.\n"
877 "Marking test as successful\n"); 882 "Skipping test\n");
878 result = SUCCESS; 883 result = SKIP;
879 return; 884 return;
880 } 885 }
881 cfg = GNUNET_CONFIGURATION_dup (config); 886 cfg = GNUNET_CONFIGURATION_dup (config);
@@ -908,9 +913,17 @@ main (int argc, char **argv)
908 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 913 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
909 "test_testbed_api_3peers_3controllers", "nohelp", 914 "test_testbed_api_3peers_3controllers", "nohelp",
910 options, &run, NULL); 915 options, &run, NULL);
911 if ((GNUNET_OK != ret) || (SUCCESS != result)) 916 if (GNUNET_OK != ret)
917 return 1;
918 switch (result)
919 {
920 case SUCCESS:
921 return 0;
922 case SKIP:
923 return 77; /* Mark test as skipped */
924 default:
912 return 1; 925 return 1;
913 return 0; 926 }
914} 927}
915 928
916/* end of test_testbed_api_3peers_3controllers.c */ 929/* end of test_testbed_api_3peers_3controllers.c */
diff --git a/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf b/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf
new file mode 100644
index 000000000..9d91b7193
--- /dev/null
+++ b/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf
@@ -0,0 +1,81 @@
1[testbed]
2AUTOSTART = NO
3PORT = 12113
4ACCEPT_FROM = 127.0.0.1;
5HOSTNAME = localhost
6NEIGHBOUR_LIMIT = 100
7OVERLAY_TOPOLOGY = FROM_FILE
8TOPOLOGY_FILE = overlay_topology.txt
9PARALLEL_OVERLAY_CONNECT_THRESHOLD = 2
10#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args
11
12[fs]
13AUTOSTART = NO
14
15[resolver]
16AUTOSTART = NO
17
18[mesh]
19AUTOSTART = NO
20
21[dht]
22AUTOSTART = NO
23
24[block]
25plugins = dht test
26
27[dhtcache]
28QUOTA = 1 MB
29DATABASE = sqlite
30
31[transport]
32PLUGINS = tcp
33ACCEPT_FROM6 = ::1;
34ACCEPT_FROM = 127.0.0.1;
35NEIGHBOUR_LIMIT = 50
36PORT = 12365
37
38[ats]
39WAN_QUOTA_OUT = 3932160
40WAN_QUOTA_IN = 3932160
41
42[core]
43PORT = 12092
44AUTOSTART = YES
45
46[arm]
47DEFAULTSERVICES = core transport
48PORT = 12366
49
50[transport-tcp]
51TIMEOUT = 300 s
52PORT = 12368
53
54[TESTING]
55NUM_PEERS = 5
56WEAKRANDOM = YES
57HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
58MAX_CONCURRENT_SSH = 10
59USE_PROGRESSBARS = YES
60PEERGROUP_TIMEOUT = 2400 s
61
62[gnunetd]
63HOSTKEY = $SERVICEHOME/.hostkey
64
65[PATHS]
66SERVICEHOME = /tmp/test-testbed/
67
68[dns]
69AUTOSTART = NO
70
71[nse]
72AUTOSTART = NO
73
74[vpn]
75AUTOSTART = NO
76
77[nat]
78RETURN_LOCAL_ADDRESSES = YES
79
80[gns-helper-service-w32]
81AUTOSTART = NO
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index f99f72f84..f253cf799 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -182,6 +182,11 @@ struct RunContext
182 struct GNUNET_TESTBED_Operation *topology_operation; 182 struct GNUNET_TESTBED_Operation *topology_operation;
183 183
184 /** 184 /**
185 * The file containing topology data. Only used if the topology is set to 'FROM_FILE'
186 */
187 char *topo_file;
188
189 /**
185 * The event mask for the controller 190 * The event mask for the controller
186 */ 191 */
187 uint64_t event_mask; 192 uint64_t event_mask;
@@ -320,6 +325,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
320 GNUNET_free (dll_op); 325 GNUNET_free (dll_op);
321 } 326 }
322 } 327 }
328 GNUNET_free_non_null (rc->topo_file);
323 GNUNET_free (rc); 329 GNUNET_free (rc);
324} 330}
325 331
@@ -458,6 +464,18 @@ call_cc:
458 rc->random_links, 464 rc->random_links,
459 GNUNET_TESTBED_TOPOLOGY_OPTION_END); 465 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
460 } 466 }
467 else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology)
468 {
469 GNUNET_assert (NULL != rc->topo_file);
470 rc->topology_operation =
471 GNUNET_TESTBED_overlay_configure_topology (NULL,
472 rc->num_peers,
473 rc->peers,
474 &rc->num_oc,
475 rc->topology,
476 rc->topo_file,
477 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
478 }
461 else 479 else
462 rc->topology_operation = 480 rc->topology_operation =
463 GNUNET_TESTBED_overlay_configure_topology (NULL, 481 GNUNET_TESTBED_overlay_configure_topology (NULL,
@@ -666,7 +684,7 @@ GNUNET_TESTBED_run (const char *host_filename,
666 if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology) 684 if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology)
667 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING == rc->topology) 685 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING == rc->topology)
668 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD == rc->topology)) 686 || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD == rc->topology))
669 { 687 {
670 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed", 688 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed",
671 "OVERLAY_RANDOM_LINKS", 689 "OVERLAY_RANDOM_LINKS",
672 &random_links)) 690 &random_links))
@@ -685,6 +703,18 @@ GNUNET_TESTBED_run (const char *host_filename,
685 } 703 }
686 rc->random_links = (unsigned int) random_links; 704 rc->random_links = (unsigned int) random_links;
687 } 705 }
706 else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology)
707 {
708 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
709 "TOPOLOGY_FILE",
710 &rc->topo_file))
711 {
712 /* You need to set TOPOLOGY_FILE option to a topolog file */
713 GNUNET_break (0);
714 GNUNET_free (rc);
715 return;
716 }
717 }
688 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 718 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
689 &shutdown_run_task, rc); 719 &shutdown_run_task, rc);
690} 720}
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index a49cabd46..d2ecdf4de 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -502,9 +502,6 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
502 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999. 502 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
503 * 503 *
504 * @param tc the topology context 504 * @param tc the topology context
505 * @param links the number of random links to establish
506 * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
507 * create a new link array
508 */ 505 */
509static void 506static void
510gen_scale_free (struct TopologyContext *tc) 507gen_scale_free (struct TopologyContext *tc)
@@ -547,6 +544,159 @@ gen_scale_free (struct TopologyContext *tc)
547 544
548 545
549/** 546/**
547 * Generates topology from the given file
548 *
549 * @param tc the topology context
550 * @param filename the filename of the file containing topology data
551 */
552static void
553gen_topo_from_file (struct TopologyContext *tc, const char *filename)
554{
555 char *data;
556 char *end;
557 char *buf;
558 uint64_t fs;
559 uint64_t offset;
560 unsigned long int peer_id;
561 unsigned long int other_peer_id;
562 enum ParseState {
563
564 /**
565 * We read the peer index
566 */
567 PEER_INDEX,
568
569 /**
570 * We read the other peer indices
571 */
572 OTHER_PEER_INDEX,
573
574 } state;
575 int status;
576
577 status = GNUNET_SYSERR;
578 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
579 {
580 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename);
581 return;
582 }
583 if (GNUNET_OK !=
584 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
585 {
586 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"), filename);
587 return;
588 }
589 data = GNUNET_malloc (fs);
590 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
591 {
592 LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"),
593 filename);
594 goto _exit;
595 }
596
597 offset = 0;
598 state = PEER_INDEX;
599 buf = data;
600 while (offset < fs)
601 {
602 if (0 != isspace (data[offset]))
603 {
604 offset++;
605 continue;
606 }
607 switch (state)
608 {
609 case PEER_INDEX:
610 buf = strchr (&data[offset], ':');
611 if (NULL == buf)
612 {
613 LOG (GNUNET_ERROR_TYPE_ERROR,
614 _("Failed to read peer index from toology file: %s"), filename);
615 goto _exit;
616 }
617 *buf = '\0';
618 errno = 0;
619 peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
620 if (0 != errno)
621 {
622 LOG (GNUNET_ERROR_TYPE_ERROR,
623 _("Value in given topology file: %s out of range\n"), filename);
624 goto _exit;
625 }
626 if (&data[offset] == end)
627 {
628 LOG (GNUNET_ERROR_TYPE_ERROR,
629 _("Failed to read peer index from topology file: %s"), filename);
630 goto _exit;
631 }
632 if (tc->num_peers <= peer_id)
633 {
634 LOG (GNUNET_ERROR_TYPE_ERROR,
635 _("Topology file need more peers than the given ones\n"),
636 filename);
637 goto _exit;
638 }
639 state = OTHER_PEER_INDEX;
640 offset += ((unsigned int) (buf - &data[offset])) + 1;
641 break;
642 case OTHER_PEER_INDEX:
643 errno = 0;
644 other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
645 if (0 != errno)
646 {
647 LOG (GNUNET_ERROR_TYPE_ERROR,
648 _("Value in given topology file: %s out of range\n"), filename);
649 goto _exit;
650 }
651 if (&data[offset] == end)
652 {
653 LOG (GNUNET_ERROR_TYPE_ERROR,
654 _("Failed to read peer index from topology file: %s"), filename);
655 goto _exit;
656 }
657 if (tc->num_peers <= other_peer_id)
658 {
659 LOG (GNUNET_ERROR_TYPE_ERROR,
660 _("Topology file need more peers than the given ones\n"),
661 filename);
662 goto _exit;
663 }
664 tc->link_array_size++;
665 tc->link_array = GNUNET_realloc (tc->link_array,
666 sizeof (struct OverlayLink) *
667 tc->link_array_size);
668 offset += end - &data[offset];
669 make_link (&tc->link_array[tc->link_array_size - 1], peer_id,
670 other_peer_id, tc);
671 while (('\n' != data[offset]) && ('|' != data[offset])
672 && (offset < fs))
673 offset++;
674 if ('\n' == data[offset])
675 state = PEER_INDEX;
676 else if ('|' == data[offset])
677 {
678 state = OTHER_PEER_INDEX;
679 offset++;
680 }
681 break;
682 }
683 }
684 status = GNUNET_OK;
685
686 _exit:
687 GNUNET_free (data);
688 if (GNUNET_OK != status)
689 {
690 LOG (GNUNET_ERROR_TYPE_WARNING,
691 "Removing and link data read from the file\n");
692 tc->link_array_size = 0;
693 GNUNET_free_non_null (tc->link_array);
694 tc->link_array = NULL;
695 }
696}
697
698
699/**
550 * Configure overall network topology to have a particular shape. 700 * Configure overall network topology to have a particular shape.
551 * 701 *
552 * @param op_cls closure argument to give with the operation event 702 * @param op_cls closure argument to give with the operation event
@@ -686,6 +836,15 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
686 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: 836 case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
687 gen_scale_free (tc); 837 gen_scale_free (tc);
688 break; 838 break;
839 case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
840 {
841 const char *filename;
842
843 filename = va_arg (va, const char *);
844 GNUNET_assert (NULL != filename);
845 gen_topo_from_file (tc, filename);
846 }
847 break;
689 default: 848 default:
690 GNUNET_break (0); 849 GNUNET_break (0);
691 GNUNET_free (tc); 850 GNUNET_free (tc);
@@ -715,6 +874,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
715 GNUNET_TESTBED_operation_queue_insert_ 874 GNUNET_TESTBED_operation_queue_insert_
716 (c->opq_parallel_topology_config_operations, op); 875 (c->opq_parallel_topology_config_operations, op);
717 GNUNET_TESTBED_operation_begin_wait_ (op); 876 GNUNET_TESTBED_operation_begin_wait_ (op);
877 LOG (GNUNET_ERROR_TYPE_DEBUG,
878 "Generated %u connections\n", tc->link_array_size);
718 if (NULL != max_connections) 879 if (NULL != max_connections)
719 *max_connections = tc->link_array_size; 880 *max_connections = tc->link_array_size;
720 return op; 881 return op;