operation and peer_destroy
authorSree Harsha Totakura <totakura@in.tum.de>
Sun, 8 Jul 2012 20:28:46 +0000 (20:28 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Sun, 8 Jul 2012 20:28:46 +0000 (20:28 +0000)
src/testbed/testbed_api.c
src/testbed/testbed_api.h
src/testbed/testbed_api_peers.c
src/testbed/testbed_api_peers.h

index 159b43dafb6d5166a3d7765fcd918dfba30d916f..b290e748cf547f7ce536c1f643500c89bbccfb91 100644 (file)
  *        This library is supposed to make it easier to write
  *        testcases and script large-scale benchmarks.
  * @author Christian Grothoff
+ * @author Sree Harsha Totakura
  */
+
+
 #include "platform.h"
 #include "gnunet_testbed_service.h"
 #include "gnunet_core_service.h"
@@ -34,6 +37,7 @@
 #include <zlib.h>
 
 #include "testbed.h"
+#include "testbed_api.h"
 #include "testbed_api_hosts.h"
 
 /**
@@ -234,6 +238,34 @@ struct GNUNET_TESTBED_HostRegistrationHandle
 };
 
 
+/**
+ * The global operation id counter
+ */
+uint64_t GNUNET_TESTBED_operation_id;
+
+/**
+ * The head of the operation queue
+ */
+struct GNUNET_TESTBED_Operation *op_head;
+
+/**
+ * The tail of the operation queue
+ */
+struct GNUNET_TESTBED_Operation *op_tail;
+
+
+/**
+ * Adds an operation to the queue of operations
+ *
+ * @param op the operation to add
+ */
+void
+GNUNET_TESTBED_operation_add (struct GNUNET_TESTBED_Operation *op)
+{
+  GNUNET_CONTAINER_DLL_insert_tail (op_head, op_tail, op);
+}
+
+
 /**
  * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
  * controller (testbed service)
index aee284c40b897bacbbb217af9247d9a5e8f353c4..53e4607ff3140df6b3347f5a67c1f7b0e0f1d002 100644 (file)
 #ifndef TESTBED_API_H
 #define TESTBED_API_H
 
+
+/**
+ * Enumeration of operations
+ */
+enum OperationType
+  {
+    /**
+     * Peer destroy operation
+     */
+    OP_PEER_DESTROY
+  };
+
+
+/**
+ * The counter for generating unique operation ids. Use its current value and
+ * increment it (defined in testbed_api.c)
+ */
+extern uint64_t GNUNET_TESTBED_operation_id;
+
+/**
+ * Testbed operation structure
+ */
+struct GNUNET_TESTBED_Operation
+{
+  /**
+   * next pointer for DLL
+   */
+  struct GNUNET_TESTBED_Operation *next;
+
+  /**
+   * prev pointer for DLL
+   */
+  struct GNUNET_TESTBED_Operation *prev;
+
+  /**
+   * The ID for the operation;
+   */
+  uint64_t operation_id;
+
+  /**
+   * The type of operation
+   */
+  enum OperationType type;
+
+  /**
+   * Data specific to OperationType
+   */
+  void *data;
+};
+
+
 /**
  * Queues a message in send queue for sending to the service
  *
@@ -51,4 +102,13 @@ size_t
 GNUNET_TESTBED_compress_config (const char *config, size_t size,
                                 char **xconfig);
 
+
+/**
+ * Adds an operation to the queue of operations
+ *
+ * @param op the operation to add
+ */
+void
+GNUNET_TESTBED_operation_add (struct GNUNET_TESTBED_Operation *op);
+
 #endif
index 844510cda8d5d145a0f8745120d6e2232e72df00..c225c7d12a58e635e7d8351c8630af4c0a974510 100644 (file)
@@ -272,6 +272,38 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
 }
 
 
+/**
+ * Destroy the given peer; the peer should have been
+ * stopped first (if it was started).
+ *
+ * @param peer peer to stop
+ * @return handle to the operation
+ */
+struct GNUNET_TESTBED_Operation *
+GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
+{
+  struct GNUNET_TESTBED_Operation *op;
+  struct PeerDestroyData *data;
+  struct GNUNET_TESTBED_PeerDestroyMessage *msg;
+  
+  data = GNUNET_malloc (sizeof (struct PeerDestroyData));
+  data->peer = peer;
+  op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
+  op->operation_id = GNUNET_TESTBED_operation_id++;
+  op->type = OP_PEER_DESTROY;
+  op->data = data;
+  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
+  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
+  msg->peer_id = peer->unique_id;
+  msg->operation_id = GNUNET_htonll (op->operation_id);
+  GNUNET_TESTBED_operation_add (op);
+  GNUNET_TESTBED_queue_message (peer->controller, 
+                                (struct GNUNET_MessageHeader *) msg);
+  return op;
+}
+
+
 /**
  * Manipulate the P2P underlay topology by configuring a link
  * between two peers.  
index ea42c981056ca15f1025857d868c84bdce8677bb..3a9244fc2ca4767b96b42089f76c4e4c2eafb18d 100644 (file)
 #include "gnunet_helper_lib.h"
 
 
+/**
+ * Data for the OperationType OP_PEER_DESTROY;
+ */
+struct PeerDestroyData
+{
+  struct GNUNET_TESTBED_Peer *peer;
+};
+
+
 /**
  * Create the given peer at the specified host using the given
  * controller.  If the given controller is not running on the target