aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2020-06-19 22:17:33 +0200
committerxrs <xrs@mail36.net>2020-06-19 22:17:33 +0200
commitbcd310958724db5e13b1f88f9316988c49ddb1b5 (patch)
treefa67d151a77c1b329c99eb6729ec694b552005fe /src
parent49cf7a8e893eaf7682ac12c7d0ea5ca4a6d1a73d (diff)
downloadgnunet-bcd310958724db5e13b1f88f9316988c49ddb1b5.tar.gz
gnunet-bcd310958724db5e13b1f88f9316988c49ddb1b5.zip
use testbed methods to alter underlaylinkmodel
Diffstat (limited to 'src')
-rw-r--r--src/cadet/test_cadeT.c50
-rw-r--r--src/cadet/test_cadeT_util.c22
-rw-r--r--src/cadet/test_cadeT_util.h15
-rw-r--r--src/testbed/Makefile.am3
-rw-r--r--src/testbed/testbed_api_underlay.c8
5 files changed, 71 insertions, 27 deletions
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c
index 97f315167..71170aa80 100644
--- a/src/cadet/test_cadeT.c
+++ b/src/cadet/test_cadeT.c
@@ -63,6 +63,23 @@
63 63
64static int kx_initiator; 64static int kx_initiator;
65static struct GNUNET_TESTBED_UnderlayLinkModel *model; 65static struct GNUNET_TESTBED_UnderlayLinkModel *model;
66static int msg_count;
67static struct GNUNET_SCHEDULER_Task *task;
68
69enum RES {
70 RECEIVED_MESSAGE = 1
71};
72
73enum RES check;
74
75static void
76set_data_loss_rate (int rate)
77{
78 GNUNET_TESTBED_underlaylinkmodel_set_link (model,
79 test_peers[0].testbed_peer,
80 0, rate, 100);
81 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s: %i loss.\n", __func__, rate);
82}
66 83
67static void 84static void
68send_message () 85send_message ()
@@ -73,13 +90,26 @@ send_message ()
73 90
74 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 91 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
75 92
76 envelope = GNUNET_MQ_msg_extra (msg, 10000, 93 envelope = GNUNET_MQ_msg_extra (msg, 1000,
77 GNUNET_MESSAGE_TYPE_DUMMY); 94 GNUNET_MESSAGE_TYPE_DUMMY);
78 data = (int *) &msg[1]; 95 data = (int *) &msg[1];
79 *data = 1000; 96 *data = 1000;
80 97
81 GNUNET_MQ_send (GNUNET_CADET_get_mq (test_peers[0].channel), 98 GNUNET_MQ_send (GNUNET_CADET_get_mq (test_peers[0].channel),
82 envelope); 99 envelope);
100
101 msg_count++;
102
103 switch (msg_count)
104 {
105 case 2: set_data_loss_rate (100); break;
106 case 4: set_data_loss_rate (0); break;
107 }
108
109 if (msg_count < 5)
110 task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
111 &send_message,
112 NULL);
83} 113}
84 114
85int 115int
@@ -94,16 +124,9 @@ handle_message (void *cls,
94 const struct GNUNET_MessageHeader *msg) 124 const struct GNUNET_MessageHeader *msg)
95{ 125{
96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 126 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
127 GNUNET_CADET_receive_done (test_peers[1].channel);
97 128
98/* 129 check = RECEIVED_MESSAGE;
99 model = GNUNET_TESTBED_underlaylinkmodel_create (test_peers[1].testbed_peer,
100 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST);
101 GNUNET_TESTBED_underlaylinkmodel_set_link (model,
102 test_peers[0].testbed_peer,
103 0, 100, 0);
104 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s: Modified link model.\n", __func__);
105*/
106 send_message();
107} 130}
108 131
109/** 132/**
@@ -116,6 +139,10 @@ run_test ()
116{ 139{
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
118 141
142 // Init underlay link model to manipulate links
143 model = GNUNET_TESTBED_underlaylinkmodel_create (test_peers[1].testbed_peer,
144 GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST);
145
119 kx_initiator = (0 < GNUNET_memcmp (&test_peers[0].id, &test_peers[1].id)) ? 1 : 0; 146 kx_initiator = (0 < GNUNET_memcmp (&test_peers[0].id, &test_peers[1].id)) ? 1 : 0;
120 147
121 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -123,8 +150,7 @@ run_test ()
123 GNUNET_i2s (&test_peers[kx_initiator].id), 150 GNUNET_i2s (&test_peers[kx_initiator].id),
124 kx_initiator); 151 kx_initiator);
125 152
126 for (int i=0; i<10; i++) 153 send_message();
127 send_message();
128} 154}
129 155
130 156
diff --git a/src/cadet/test_cadeT_util.c b/src/cadet/test_cadeT_util.c
index f2082a006..bf65aca32 100644
--- a/src/cadet/test_cadeT_util.c
+++ b/src/cadet/test_cadeT_util.c
@@ -41,6 +41,11 @@ static struct GNUNET_TESTBED_Operation *testbed_info_req[REQUESTED_PEERS];
41static struct GNUNET_HashCode hashed_portname; 41static struct GNUNET_HashCode hashed_portname;
42 42
43/** 43/**
44 * Port handle.
45 */
46struct GNUNET_CADET_Port *port;
47
48/**
44 * Result of the test. 49 * Result of the test.
45 */ 50 */
46int test_result = 0; 51int test_result = 0;
@@ -78,6 +83,9 @@ disconnect_from_peer (void *cls,
78 83
79 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
80 85
86 if (0 == strncmp ("listening_peer", cls, sizeof (cls)))
87 GNUNET_CADET_close_port (port);
88
81 GNUNET_CADET_disconnect (cadet); 89 GNUNET_CADET_disconnect (cadet);
82} 90}
83 91
@@ -120,6 +128,7 @@ handle_port_connects (void *cls,
120 struct GNUNET_CADET_Channel *channel, 128 struct GNUNET_CADET_Channel *channel,
121 const struct GNUNET_PeerIdentity *source) 129 const struct GNUNET_PeerIdentity *source)
122{ 130{
131 test_peers[1].channel = channel;
123 return NULL; 132 return NULL;
124} 133}
125 134
@@ -134,12 +143,11 @@ setup_listening_peer (void *cls,
134 const struct GNUNET_CONFIGURATION_Handle *cfg) 143 const struct GNUNET_CONFIGURATION_Handle *cfg)
135{ 144{
136 struct GNUNET_CADET_Handle *cadet; 145 struct GNUNET_CADET_Handle *cadet;
137 struct GNUNET_CADET_Port *port;
138 struct GNUNET_MQ_MessageHandler msg_handlers[] = { 146 struct GNUNET_MQ_MessageHandler msg_handlers[] = {
139 GNUNET_MQ_hd_fixed_size (message, 147 GNUNET_MQ_hd_var_size (message,
140 GNUNET_MESSAGE_TYPE_DUMMY, 148 GNUNET_MESSAGE_TYPE_DUMMY,
141 struct GNUNET_MessageHeader, 149 struct GNUNET_MessageHeader,
142 NULL), 150 NULL),
143 GNUNET_MQ_handler_end () 151 GNUNET_MQ_handler_end ()
144 }; 152 };
145 153
@@ -198,13 +206,13 @@ connect_to_service (void *cb_cls,
198 "cadet", 206 "cadet",
199 &check_test_readyness, NULL, 207 &check_test_readyness, NULL,
200 &setup_listening_peer, 208 &setup_listening_peer,
201 &disconnect_from_peer, NULL); 209 &disconnect_from_peer, "listening_peer");
202 testbed_to_svc[0] = 210 testbed_to_svc[0] =
203 GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer, 211 GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer,
204 "cadet", 212 "cadet",
205 &check_test_readyness, NULL, 213 &check_test_readyness, NULL,
206 &setup_initiating_peer, 214 &setup_initiating_peer,
207 &disconnect_from_peer, NULL); 215 &disconnect_from_peer, "initiating_peer");
208 } 216 }
209} 217}
210 218
diff --git a/src/cadet/test_cadeT_util.h b/src/cadet/test_cadeT_util.h
index 1c85abab6..b93804613 100644
--- a/src/cadet/test_cadeT_util.h
+++ b/src/cadet/test_cadeT_util.h
@@ -33,12 +33,19 @@
33 33
34int test_result; 34int test_result;
35 35
36void prepare_test (); 36void
37prepare_test ();
37 38
38void run_test (); 39void
40run_test ();
39 41
40void handle_message (void *cls, 42void
41 const struct GNUNET_MessageHeader *msg); 43handle_message (void *cls,
44 const struct GNUNET_MessageHeader *msg);
45
46int
47check_message (void *cls,
48 const struct GNUNET_MessageHeader *message);
42 49
43/** 50/**
44 * Structure for storing information of testbed peers. 51 * Structure for storing information of testbed peers.
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 62b49af78..62a8fb640 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -102,7 +102,8 @@ libgnunettestbed_la_SOURCES = \
102 testbed_api_test.c \ 102 testbed_api_test.c \
103 testbed_api_topology.c testbed_api_topology.h \ 103 testbed_api_topology.c testbed_api_topology.h \
104 testbed_api_sd.c testbed_api_sd.h \ 104 testbed_api_sd.c testbed_api_sd.h \
105 testbed_api_barriers.c 105 testbed_api_barriers.c \
106 testbed_api_underlay.c
106libgnunettestbed_la_LIBADD = $(XLIB) \ 107libgnunettestbed_la_LIBADD = $(XLIB) \
107 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 108 $(top_builddir)/src/statistics/libgnunetstatistics.la \
108 $(top_builddir)/src/transport/libgnunettransport.la \ 109 $(top_builddir)/src/transport/libgnunettransport.la \
diff --git a/src/testbed/testbed_api_underlay.c b/src/testbed/testbed_api_underlay.c
index 7e509fdfe..87c9a5a7c 100644
--- a/src/testbed/testbed_api_underlay.c
+++ b/src/testbed/testbed_api_underlay.c
@@ -24,9 +24,11 @@
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */ 25 */
26 26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_service.h"
27#include "testbed_api_peers.h" 30#include "testbed_api_peers.h"
28 31
29
30/** 32/**
31 * An underlay link 33 * An underlay link
32 */ 34 */
@@ -101,7 +103,7 @@ struct GNUNET_TESTBED_UnderlayLinkModel
101 * the type of this model 103 * the type of this model
102 */ 104 */
103 enum GNUNET_TESTBED_UnderlayLinkModelType type; 105 enum GNUNET_TESTBED_UnderlayLinkModelType type;
104} 106};
105 107
106 108
107/** 109/**
@@ -236,7 +238,7 @@ GNUNET_TESTBED_underlaylinkmodel_free (struct
236 model->peer->underlay_model_exists = 0; 238 model->peer->underlay_model_exists = 0;
237 free_entries (model); 239 free_entries (model);
238 free_link_properties (model); 240 free_link_properties (model);
239 gnunet_free (model); 241 GNUNET_free (model);
240} 242}
241 243
242 244