Prechádzať zdrojové kódy

use testbed methods to alter underlaylinkmodel

xrs 4 rokov pred
rodič
commit
bcd3109587

+ 38 - 12
src/cadet/test_cadeT.c

@@ -63,6 +63,23 @@
 
 static int kx_initiator;
 static struct GNUNET_TESTBED_UnderlayLinkModel *model;
+static int msg_count;
+static struct GNUNET_SCHEDULER_Task *task;
+
+enum RES {
+  RECEIVED_MESSAGE = 1
+};
+
+enum RES check;
+
+static void
+set_data_loss_rate (int rate)
+{
+  GNUNET_TESTBED_underlaylinkmodel_set_link (model,
+                                             test_peers[0].testbed_peer,
+                                             0, rate, 100);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s: %i loss.\n", __func__, rate);
+}
 
 static void
 send_message ()
@@ -73,13 +90,26 @@ send_message ()
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
 
-  envelope = GNUNET_MQ_msg_extra (msg, 10000,
+  envelope = GNUNET_MQ_msg_extra (msg, 1000,
                                   GNUNET_MESSAGE_TYPE_DUMMY);
   data = (int *) &msg[1];
   *data = 1000;
 
   GNUNET_MQ_send (GNUNET_CADET_get_mq (test_peers[0].channel), 
                   envelope);
+
+  msg_count++;
+
+  switch (msg_count) 
+  {
+    case 2: set_data_loss_rate (100); break;
+    case 4: set_data_loss_rate (0); break;
+  }
+
+  if (msg_count < 5)
+    task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
+                                         &send_message,
+                                         NULL);
 }
 
 int
@@ -94,16 +124,9 @@ handle_message (void *cls,
                 const struct GNUNET_MessageHeader *msg)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
+  GNUNET_CADET_receive_done (test_peers[1].channel);
 
-/*
-  model = GNUNET_TESTBED_underlaylinkmodel_create (test_peers[1].testbed_peer,
-                                                   GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST);
-  GNUNET_TESTBED_underlaylinkmodel_set_link (model,
-                                             test_peers[0].testbed_peer,
-                                             0, 100, 0);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s: Modified link model.\n", __func__);
-*/
-  send_message();
+  check = RECEIVED_MESSAGE;
 }
 
 /**
@@ -116,6 +139,10 @@ run_test ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
 
+  // Init underlay link model to manipulate links
+  model = GNUNET_TESTBED_underlaylinkmodel_create (test_peers[1].testbed_peer,
+                                                   GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST);
+
   kx_initiator = (0 < GNUNET_memcmp (&test_peers[0].id, &test_peers[1].id)) ? 1 : 0;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
@@ -123,8 +150,7 @@ run_test ()
               GNUNET_i2s (&test_peers[kx_initiator].id),
               kx_initiator);
 
-  for (int i=0; i<10; i++)
-    send_message();
+  send_message();
 }
 
 

+ 15 - 7
src/cadet/test_cadeT_util.c

@@ -40,6 +40,11 @@ static struct GNUNET_TESTBED_Operation *testbed_info_req[REQUESTED_PEERS];
  */
 static struct GNUNET_HashCode hashed_portname;
 
+/**
+ * Port handle.
+ */
+struct GNUNET_CADET_Port *port;
+
 /**
  * Result of the test.
  */
@@ -78,6 +83,9 @@ disconnect_from_peer (void *cls,
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
 
+  if (0 == strncmp ("listening_peer", cls, sizeof (cls)))
+    GNUNET_CADET_close_port (port);
+
   GNUNET_CADET_disconnect (cadet);
 }
 
@@ -120,6 +128,7 @@ handle_port_connects (void *cls,
                       struct GNUNET_CADET_Channel *channel,
                       const struct GNUNET_PeerIdentity *source)
 {
+  test_peers[1].channel = channel;
   return NULL;
 }
 
@@ -134,12 +143,11 @@ setup_listening_peer (void *cls,
                       const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_CADET_Handle *cadet;
-  struct GNUNET_CADET_Port *port;
   struct GNUNET_MQ_MessageHandler msg_handlers[] = {
-    GNUNET_MQ_hd_fixed_size (message,
-                             GNUNET_MESSAGE_TYPE_DUMMY,
-                             struct GNUNET_MessageHeader,
-                             NULL),
+    GNUNET_MQ_hd_var_size (message,
+                           GNUNET_MESSAGE_TYPE_DUMMY,
+                           struct GNUNET_MessageHeader,
+                           NULL),
     GNUNET_MQ_handler_end ()
   };
 
@@ -198,13 +206,13 @@ connect_to_service (void *cb_cls,
                                       "cadet", 
                                       &check_test_readyness, NULL,
                                       &setup_listening_peer,
-                                      &disconnect_from_peer, NULL);
+                                      &disconnect_from_peer, "listening_peer");
     testbed_to_svc[0] = 
       GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer,
                                       "cadet",
                                       &check_test_readyness, NULL,
                                       &setup_initiating_peer,
-                                      &disconnect_from_peer, NULL);
+                                      &disconnect_from_peer, "initiating_peer");
   }
 }
 

+ 11 - 4
src/cadet/test_cadeT_util.h

@@ -33,12 +33,19 @@
 
 int test_result;
 
-void prepare_test ();
+void 
+prepare_test ();
 
-void run_test ();
+void 
+run_test ();
 
-void handle_message (void *cls,
-                     const struct GNUNET_MessageHeader *msg);
+void 
+handle_message (void *cls,
+                const struct GNUNET_MessageHeader *msg);
+
+int
+check_message (void *cls,
+               const struct GNUNET_MessageHeader *message);
 
 /**
  * Structure for storing information of testbed peers.

+ 2 - 1
src/testbed/Makefile.am

@@ -102,7 +102,8 @@ libgnunettestbed_la_SOURCES = \
   testbed_api_test.c \
   testbed_api_topology.c testbed_api_topology.h \
   testbed_api_sd.c testbed_api_sd.h \
-  testbed_api_barriers.c
+  testbed_api_barriers.c \
+  testbed_api_underlay.c 
 libgnunettestbed_la_LIBADD = $(XLIB) \
  $(top_builddir)/src/statistics/libgnunetstatistics.la \
  $(top_builddir)/src/transport/libgnunettransport.la \

+ 5 - 3
src/testbed/testbed_api_underlay.c

@@ -24,9 +24,11 @@
  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
  */
 
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testbed_service.h"
 #include "testbed_api_peers.h"
 
-
 /**
  * An underlay link
  */
@@ -101,7 +103,7 @@ struct GNUNET_TESTBED_UnderlayLinkModel
    * the type of this model
    */
   enum GNUNET_TESTBED_UnderlayLinkModelType type;
-}
+};
 
 
 /**
@@ -236,7 +238,7 @@ GNUNET_TESTBED_underlaylinkmodel_free (struct
   model->peer->underlay_model_exists = 0;
   free_entries (model);
   free_link_properties (model);
-  gnunet_free (model);
+  GNUNET_free (model);
 }