Boston, MA 02111-1307, USA.
*/
-/**
- * TODO:
- * - Run X peers
- * - Rewrite interval time (optional)
- * - Run 1 dashboard
- * - Monitor dashboard records
- * - Prompt for anomalies when ready:
- * -- Cut Y peers (remove their connections to other X-Y peers but not the connections among themselves)
- */
-
/**
* @file sensor/gnunet-sensor-profiler.c
* @brief Profiler for the sensor service
#include "gnunet_sensor_service.h"
#include "gnunet_sensor_util_lib.h"
+/**
+ * Time to wait for the peer to startup completely
+ */
+#define PEER_STARTUP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+
/**
* Information about a single peer
*/
* Do clean up and shutdown scheduler
*/
static void
-do_shutdown () // TODO: schedule timeout shutdown
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n");
GNUNET_TESTBED_operation_done (op);
dashboard_service_started = GNUNET_YES;
- //TODO:
}
}
+/**
+ * This function is called after a delay which ensures that all peers are
+ * properly initialized
+ */
+static void
+peers_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers are ready.\n");
+ //TODO
+}
+
+
/**
* Callback to be called when sensor service is started
*
GNUNET_i2s (&peer->peer_id));
GNUNET_TESTBED_operation_done (op);
sensor_services_started++;
- if (sensor_services_started == num_peers) //TODO: remove
- do_shutdown ();
- //TODO
+ if (sensor_services_started == num_peers)
+ {
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (PEER_STARTUP_TIME, num_peers), &peers_ready,
+ NULL);
+ }
}
if (GNUNET_OK != verify_args ())
{
- do_shutdown ();
+ do_shutdown (NULL, NULL);
return;
}
cfg = GNUNET_CONFIGURATION_create ();
cfg, "TESTBED",
"OVERLAY_TOPOLOGY_FILE",
topology_file);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
+ NULL);
GNUNET_TESTBED_run (NULL, cfg, num_peers, 0, NULL, NULL, &test_master, NULL);
GNUNET_CONFIGURATION_destroy (cfg);
}
--- /dev/null
+import argparse
+import math
+import networkx
+import random
+import tempfile
+
+def get_args():
+ parser = argparse.ArgumentParser(description="Sensor profiler")
+ parser.add_argument('-p', '--peers', action='store', type=int, required=True,
+ help='Number of peers to run')
+ return parser.parse_args()
+
+def generate_topology(peers, links):
+ G = networkx.empty_graph(peers)
+ for i in range(0, links):
+ a = 0
+ b = 0
+ while a == b:
+ a = random.randint(0, peers)
+ b = random.randint(0, peers)
+ G.add_edge(a, b)
+ return G
+
+def create_topology_file(graph):
+ nodes = list()
+ for i in range(len(graph.edge)):
+ nodes.append(list())
+ for e in graph.edges():
+ nodes[e[0]].append(e[1])
+ print nodes
+ f = tempfile.NamedTemporaryFile(delete=False)
+ for i in range(len(nodes)):
+ if len(nodes[i]) == 0:
+ continue
+ f.write('%d:' % i)
+ f.write('|'.join(map(str,nodes[i])))
+ f.write('\n')
+ #f.close()
+ return f.name
+
+def main():
+ args = vars(get_args())
+ num_peers = args['peers']
+ if num_peers < 3:
+ print 'Min number of peers is 3'
+ return
+ num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2)
+ # Generate random topology
+ graph = generate_topology(num_peers, num_links)
+ print 'Generated random topology with %d peers and %d links' % (num_peers, num_links)
+ # Create TESTBED topology file
+ top_file = create_topology_file(graph)
+ print 'Created TESTBED topology file %s' % top_file
+ # Run c profiler
+
+if __name__ == "__main__":
+ main()