gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34255 - gnunet/src/sensor


From: gnunet
Subject: [GNUnet-SVN] r34255 - gnunet/src/sensor
Date: Mon, 1 Sep 2014 19:17:29 +0200

Author: otarabai
Date: 2014-09-01 19:17:29 +0200 (Mon, 01 Sep 2014)
New Revision: 34255

Added:
   gnunet/src/sensor/profiler.py
Modified:
   gnunet/src/sensor/gnunet-sensor-profiler.c
Log:
sensor: towards profiler


Modified: gnunet/src/sensor/gnunet-sensor-profiler.c
===================================================================
--- gnunet/src/sensor/gnunet-sensor-profiler.c  2014-09-01 15:44:38 UTC (rev 
34254)
+++ gnunet/src/sensor/gnunet-sensor-profiler.c  2014-09-01 17:17:29 UTC (rev 
34255)
@@ -19,16 +19,6 @@
 */
 
 /**
- * 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
  * @author Omar Tarabai
@@ -41,6 +31,11 @@
 #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
  */
 struct PeerInfo
@@ -150,7 +145,7 @@
  * 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;
 
@@ -308,7 +303,6 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n");
   GNUNET_TESTBED_operation_done (op);
   dashboard_service_started = GNUNET_YES;
-  //TODO:
 }
 
 
@@ -418,6 +412,18 @@
 
 
 /**
+ * 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
  *
  * @param cls the callback closure from functions generating an operation
@@ -440,9 +446,12 @@
               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);
+  }
 }
 
 
@@ -575,7 +584,7 @@
 
   if (GNUNET_OK != verify_args ())
   {
-    do_shutdown ();
+    do_shutdown (NULL, NULL);
     return;
   }
   cfg = GNUNET_CONFIGURATION_create ();
@@ -584,6 +593,8 @@
                                          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);
 }

Added: gnunet/src/sensor/profiler.py
===================================================================
--- gnunet/src/sensor/profiler.py                               (rev 0)
+++ gnunet/src/sensor/profiler.py       2014-09-01 17:17:29 UTC (rev 34255)
@@ -0,0 +1,57 @@
+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()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]