diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-18 11:57:41 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-18 11:57:41 +0000 |
commit | 41c3bd8aabf10fd3e893319bc9c622c3d268cad9 (patch) | |
tree | 9114fc02a6182c19b17b0935a22a8a76742e2e7f | |
parent | d30455e79ea8c89dd460470c03aaeb8d43cbf997 (diff) | |
download | gnunet-41c3bd8aabf10fd3e893319bc9c622c3d268cad9.tar.gz gnunet-41c3bd8aabf10fd3e893319bc9c622c3d268cad9.zip |
sensor: update to test case + fix
-rw-r--r-- | src/sensor/Makefile.am | 3 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_reporting.c | 58 | ||||
-rw-r--r-- | src/sensor/test_gnunet-service-sensor_reporting.c | 88 | ||||
-rw-r--r-- | src/sensor/test_gnunet-service-sensor_reporting.conf | 10 |
4 files changed, 126 insertions, 33 deletions
diff --git a/src/sensor/Makefile.am b/src/sensor/Makefile.am index 4c19fc7f4..305b91aad 100644 --- a/src/sensor/Makefile.am +++ b/src/sensor/Makefile.am | |||
@@ -83,7 +83,8 @@ libgnunet_plugin_sensor_model_gaussian_la_DEPENDENCIES = \ | |||
83 | libgnunetsensor.la | 83 | libgnunetsensor.la |
84 | 84 | ||
85 | check_PROGRAMS = \ | 85 | check_PROGRAMS = \ |
86 | test_sensor_api | 86 | test_sensor_api \ |
87 | test_gnunet-service-sensor_reporting | ||
87 | 88 | ||
88 | if ENABLE_TEST_RUN | 89 | if ENABLE_TEST_RUN |
89 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 90 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c index a2015f48e..6267e9f2a 100644 --- a/src/sensor/gnunet-service-sensor_reporting.c +++ b/src/sensor/gnunet-service-sensor_reporting.c | |||
@@ -480,7 +480,7 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid) | |||
480 | cadetp->channel = | 480 | cadetp->channel = |
481 | GNUNET_CADET_channel_create (cadet, cadetp, &pid, | 481 | GNUNET_CADET_channel_create (cadet, cadetp, &pid, |
482 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, | 482 | GNUNET_APPLICATION_TYPE_SENSORDASHBOARD, |
483 | GNUNET_CADET_OPTION_DEFAULT); | 483 | GNUNET_CADET_OPTION_RELIABLE); |
484 | cadetp->mq = GNUNET_CADET_mq_create (cadetp->channel); | 484 | cadetp->mq = GNUNET_CADET_mq_create (cadetp->channel); |
485 | GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp); | 485 | GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp); |
486 | return cadetp; | 486 | return cadetp; |
@@ -585,9 +585,10 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
585 | { | 585 | { |
586 | struct GNUNET_SENSOR_AnomalyReportMessage *arm; | 586 | struct GNUNET_SENSOR_AnomalyReportMessage *arm; |
587 | struct GNUNET_SENSOR_SensorInfo *sensor; | 587 | struct GNUNET_SENSOR_SensorInfo *sensor; |
588 | struct AnomalyInfo *ai; | 588 | struct AnomalyInfo *my_anomaly_info; |
589 | struct CadetPeer *cadetp; | 589 | struct CadetPeer *cadetp; |
590 | int peer_in_list; | 590 | int peer_anomalous; |
591 | int peer_in_anomalous_list; | ||
591 | 592 | ||
592 | arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; | 593 | arm = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; |
593 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); | 594 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &arm->sensorname_hash); |
@@ -600,34 +601,39 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other, | |||
600 | GNUNET_i2s (other)); | 601 | GNUNET_i2s (other)); |
601 | return GNUNET_OK; | 602 | return GNUNET_OK; |
602 | } | 603 | } |
603 | ai = get_anomaly_info_by_sensor (sensor); | 604 | my_anomaly_info = get_anomaly_info_by_sensor (sensor); |
604 | GNUNET_assert (NULL != ai); | 605 | GNUNET_assert (NULL != my_anomaly_info); |
605 | peer_in_list = | 606 | peer_in_anomalous_list = |
606 | GNUNET_CONTAINER_multipeermap_contains (ai->anomalous_neighbors, other); | 607 | GNUNET_CONTAINER_multipeermap_contains |
607 | if (GNUNET_YES == ai->anomalous) | 608 | (my_anomaly_info->anomalous_neighbors, other); |
609 | peer_anomalous = ntohs (arm->anomalous); | ||
610 | if (GNUNET_YES == peer_anomalous) | ||
608 | { | 611 | { |
609 | if (GNUNET_YES == peer_in_list) | 612 | if (GNUNET_YES == peer_in_anomalous_list) /* repeated positive report */ |
610 | GNUNET_break_op (0); | 613 | GNUNET_break_op (0); |
611 | else | 614 | else |
612 | GNUNET_CONTAINER_multipeermap_put (ai->anomalous_neighbors, other, NULL, | 615 | GNUNET_CONTAINER_multipeermap_put (my_anomaly_info->anomalous_neighbors, |
616 | other, NULL, | ||
613 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 617 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
614 | } | 618 | } |
615 | else | 619 | else |
616 | { | 620 | { |
617 | if (GNUNET_NO == peer_in_list) | 621 | if (GNUNET_NO == peer_in_anomalous_list) /* repeated negative report */ |
618 | GNUNET_break_op (0); | 622 | GNUNET_break_op (0); |
619 | else | 623 | else |
620 | GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors, other); | 624 | GNUNET_CONTAINER_multipeermap_remove_all |
625 | (my_anomaly_info->anomalous_neighbors, other); | ||
621 | } | 626 | } |
622 | /* Send anomaly update to collection point */ | 627 | /* Send anomaly update to collection point only if I have the same anomaly */ |
623 | if (NULL != ai->sensor->collection_point && | 628 | if (GNUNET_YES == my_anomaly_info->anomalous && |
624 | GNUNET_YES == ai->sensor->report_anomalies) | 629 | NULL != sensor->collection_point && |
630 | GNUNET_YES == sensor->report_anomalies) | ||
625 | { | 631 | { |
626 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 632 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
627 | "Sending anomaly report to collection point `%s'.\n", | 633 | "Neighbor update triggered sending anomaly report to collection point `%s'.\n", |
628 | GNUNET_i2s (ai->sensor->collection_point)); | 634 | GNUNET_i2s (sensor->collection_point)); |
629 | cadetp = get_cadet_peer (*ai->sensor->collection_point); | 635 | cadetp = get_cadet_peer (*sensor->collection_point); |
630 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); | 636 | send_anomaly_report (cadetp->mq, my_anomaly_info, GNUNET_NO); |
631 | } | 637 | } |
632 | return GNUNET_OK; | 638 | return GNUNET_OK; |
633 | } | 639 | } |
@@ -687,6 +693,8 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
687 | 693 | ||
688 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | 694 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) |
689 | return; | 695 | return; |
696 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Core peer `%s' disconnected.\n", | ||
697 | GNUNET_i2s (peer)); | ||
690 | neighborhood--; | 698 | neighborhood--; |
691 | corep = corep_head; | 699 | corep = corep_head; |
692 | while (NULL != corep) | 700 | while (NULL != corep) |
@@ -716,6 +724,8 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
716 | 724 | ||
717 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) | 725 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&mypeerid, peer)) |
718 | return; | 726 | return; |
727 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to core peer `%s'.\n", | ||
728 | GNUNET_i2s (peer)); | ||
719 | neighborhood++; | 729 | neighborhood++; |
720 | corep = GNUNET_new (struct CorePeer); | 730 | corep = GNUNET_new (struct CorePeer); |
721 | corep->peer_id = (struct GNUNET_PeerIdentity *) peer; | 731 | corep->peer_id = (struct GNUNET_PeerIdentity *) peer; |
@@ -725,11 +735,13 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
725 | ai = ai_head; | 735 | ai = ai_head; |
726 | while (NULL != ai) | 736 | while (NULL != ai) |
727 | { | 737 | { |
728 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
729 | "Updating newly connected neighbor `%s' with anomalous sensor.\n", | ||
730 | GNUNET_i2s (peer)); | ||
731 | if (GNUNET_YES == ai->anomalous) | 738 | if (GNUNET_YES == ai->anomalous) |
739 | { | ||
740 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
741 | "Updating newly connected neighbor `%s' with anomalous sensor.\n", | ||
742 | GNUNET_i2s (peer)); | ||
732 | send_anomaly_report (corep->mq, ai, GNUNET_YES); | 743 | send_anomaly_report (corep->mq, ai, GNUNET_YES); |
744 | } | ||
733 | ai = ai->next; | 745 | ai = ai->next; |
734 | } | 746 | } |
735 | } | 747 | } |
@@ -839,7 +851,7 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor, | |||
839 | GNUNET_YES == ai->sensor->report_anomalies) | 851 | GNUNET_YES == ai->sensor->report_anomalies) |
840 | { | 852 | { |
841 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 853 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
842 | "Sending anomaly report to collection point `%s'.\n", | 854 | "Local anomaly update triggered sending anomaly report to collection point `%s'.\n", |
843 | GNUNET_i2s (ai->sensor->collection_point)); | 855 | GNUNET_i2s (ai->sensor->collection_point)); |
844 | cadetp = get_cadet_peer (*ai->sensor->collection_point); | 856 | cadetp = get_cadet_peer (*ai->sensor->collection_point); |
845 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); | 857 | send_anomaly_report (cadetp->mq, ai, GNUNET_NO); |
diff --git a/src/sensor/test_gnunet-service-sensor_reporting.c b/src/sensor/test_gnunet-service-sensor_reporting.c index 969ab16ec..3905e8876 100644 --- a/src/sensor/test_gnunet-service-sensor_reporting.c +++ b/src/sensor/test_gnunet-service-sensor_reporting.c | |||
@@ -40,6 +40,12 @@ | |||
40 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | 40 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * How long to wait between starting everything and forcing anomalies to give | ||
44 | * the peer enough time to stabilize. | ||
45 | */ | ||
46 | #define ANOMALY_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | ||
47 | |||
48 | /** | ||
43 | * Information about a test peer | 49 | * Information about a test peer |
44 | */ | 50 | */ |
45 | struct TestPeer | 51 | struct TestPeer |
@@ -75,6 +81,16 @@ struct TestPeer | |||
75 | */ | 81 | */ |
76 | struct GNUNET_TESTBED_Operation *sensor_op; | 82 | struct GNUNET_TESTBED_Operation *sensor_op; |
77 | 83 | ||
84 | /** | ||
85 | * Sensor service handle | ||
86 | */ | ||
87 | struct GNUNET_SENSOR_Handle *sensor; | ||
88 | |||
89 | /** | ||
90 | * GNUNET scheduler task that forces the anomaly after a stabilization delay | ||
91 | */ | ||
92 | GNUNET_SCHEDULER_TaskIdentifier delay_task; | ||
93 | |||
78 | }; | 94 | }; |
79 | 95 | ||
80 | /** | 96 | /** |
@@ -119,14 +135,19 @@ static struct TestPeer *peer_tail; | |||
119 | static int started_peers = 0; | 135 | static int started_peers = 0; |
120 | 136 | ||
121 | /** | 137 | /** |
138 | * Number of peers reported anomalies with full list of anomalous neighbors | ||
139 | */ | ||
140 | static int reported_peers = 0; | ||
141 | |||
142 | /** | ||
122 | * TESTBED operation connecting us to peerstore service | 143 | * TESTBED operation connecting us to peerstore service |
123 | */ | 144 | */ |
124 | struct GNUNET_TESTBED_Operation *peerstore_op; | 145 | static struct GNUNET_TESTBED_Operation *peerstore_op; |
125 | 146 | ||
126 | /** | 147 | /** |
127 | * Handle to the peerstore service | 148 | * Handle to the peerstore service |
128 | */ | 149 | */ |
129 | struct GNUNET_PEERSTORE_Handle *peerstore; | 150 | static struct GNUNET_PEERSTORE_Handle *peerstore; |
130 | 151 | ||
131 | /** | 152 | /** |
132 | * Task used to shutdown / expire the test | 153 | * Task used to shutdown / expire the test |
@@ -139,6 +160,28 @@ static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | |||
139 | static int ok = 1; | 160 | static int ok = 1; |
140 | 161 | ||
141 | 162 | ||
163 | static void | ||
164 | destroy_peer (struct TestPeer *peer) | ||
165 | { | ||
166 | if (GNUNET_SCHEDULER_NO_TASK != peer->delay_task) | ||
167 | { | ||
168 | GNUNET_SCHEDULER_cancel (peer->delay_task); | ||
169 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
170 | } | ||
171 | if (NULL != peer->sensor_op) | ||
172 | { | ||
173 | GNUNET_TESTBED_operation_done (peer->sensor_op); | ||
174 | peer->sensor_op = NULL; | ||
175 | } | ||
176 | if (NULL != peer->wc) | ||
177 | { | ||
178 | GNUNET_PEERSTORE_watch_cancel (peer->wc); | ||
179 | peer->wc = NULL; | ||
180 | } | ||
181 | GNUNET_free (peer); | ||
182 | } | ||
183 | |||
184 | |||
142 | /** | 185 | /** |
143 | * Shutdown task | 186 | * Shutdown task |
144 | * | 187 | * |
@@ -148,7 +191,15 @@ static int ok = 1; | |||
148 | static void | 191 | static void |
149 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 192 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
150 | { | 193 | { |
151 | //TODO: destroy list of peers | 194 | struct TestPeer *peer; |
195 | |||
196 | peer = peer_head; | ||
197 | while (NULL != peer) | ||
198 | { | ||
199 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, peer); | ||
200 | destroy_peer (peer); | ||
201 | peer = peer_head; | ||
202 | } | ||
152 | if (NULL != peerstore_op) | 203 | if (NULL != peerstore_op) |
153 | { | 204 | { |
154 | GNUNET_TESTBED_operation_done (peerstore_op); | 205 | GNUNET_TESTBED_operation_done (peerstore_op); |
@@ -162,7 +213,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
162 | * Write new temp sensor directory with a sensor updated with collection point | 213 | * Write new temp sensor directory with a sensor updated with collection point |
163 | * peer id | 214 | * peer id |
164 | */ | 215 | */ |
165 | void | 216 | static void |
166 | write_new_sensor_dir (struct TestPeer *cp_peer) | 217 | write_new_sensor_dir (struct TestPeer *cp_peer) |
167 | { | 218 | { |
168 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; | 219 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; |
@@ -208,12 +259,33 @@ peerstore_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, | |||
208 | "Anomalous: %d\n" "Anomalous neigbors: %f.\n", | 259 | "Anomalous: %d\n" "Anomalous neigbors: %f.\n", |
209 | GNUNET_i2s (&peer->peer_id), anomaly->anomalous, | 260 | GNUNET_i2s (&peer->peer_id), anomaly->anomalous, |
210 | anomaly->anomalous_neighbors); | 261 | anomaly->anomalous_neighbors); |
211 | //TODO | 262 | if (1 == anomaly->anomalous_neighbors) |
263 | reported_peers++; | ||
264 | if (reported_peers == NUM_PEERS) | ||
265 | { | ||
266 | ok = 0; | ||
267 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
268 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
269 | } | ||
212 | return GNUNET_YES; | 270 | return GNUNET_YES; |
213 | } | 271 | } |
214 | 272 | ||
215 | 273 | ||
216 | /** | 274 | /** |
275 | * Task that pushes fake anomalies to running peers | ||
276 | */ | ||
277 | static void | ||
278 | force_anomaly_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
279 | { | ||
280 | struct TestPeer *peer = cls; | ||
281 | |||
282 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
283 | GNUNET_SENSOR_force_anomaly (peer->sensor, (char *) sensor_name, GNUNET_YES, | ||
284 | NULL, NULL); | ||
285 | } | ||
286 | |||
287 | |||
288 | /** | ||
217 | * Callback to be called when sensor service connect operation is completed | 289 | * Callback to be called when sensor service connect operation is completed |
218 | * | 290 | * |
219 | * @param cls the callback closure from functions generating an operation | 291 | * @param cls the callback closure from functions generating an operation |
@@ -229,8 +301,9 @@ sensor_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
229 | struct TestPeer *peer = cls; | 301 | struct TestPeer *peer = cls; |
230 | struct GNUNET_SENSOR_Handle *sensor = ca_result; | 302 | struct GNUNET_SENSOR_Handle *sensor = ca_result; |
231 | 303 | ||
232 | GNUNET_SENSOR_force_anomaly (sensor, (char *) sensor_name, GNUNET_YES, NULL, | 304 | peer->sensor = sensor; |
233 | NULL); | 305 | peer->delay_task = |
306 | GNUNET_SCHEDULER_add_delayed (ANOMALY_DELAY, &force_anomaly_task, peer); | ||
234 | } | 307 | } |
235 | 308 | ||
236 | 309 | ||
@@ -399,6 +472,7 @@ peer_info_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
399 | peer = GNUNET_new (struct TestPeer); | 472 | peer = GNUNET_new (struct TestPeer); |
400 | 473 | ||
401 | peer->testbed_peer = testbed_peer; | 474 | peer->testbed_peer = testbed_peer; |
475 | peer->delay_task = GNUNET_SCHEDULER_NO_TASK; | ||
402 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); | 476 | GNUNET_CRYPTO_get_peer_identity (pinfo->result.cfg, &peer->peer_id); |
403 | if (NULL == peer_head) /* First peer (collection point) */ | 477 | if (NULL == peer_head) /* First peer (collection point) */ |
404 | { | 478 | { |
diff --git a/src/sensor/test_gnunet-service-sensor_reporting.conf b/src/sensor/test_gnunet-service-sensor_reporting.conf index 4dc073856..0d1907c9e 100644 --- a/src/sensor/test_gnunet-service-sensor_reporting.conf +++ b/src/sensor/test_gnunet-service-sensor_reporting.conf | |||
@@ -2,7 +2,7 @@ | |||
2 | OVERLAY_TOPOLOGY = CLIQUE | 2 | OVERLAY_TOPOLOGY = CLIQUE |
3 | 3 | ||
4 | [arm] | 4 | [arm] |
5 | DEFAULTSERVICES = core | 5 | DEFAULTSERVICES = topology dht cadet |
6 | 6 | ||
7 | [sensor] | 7 | [sensor] |
8 | SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/ | 8 | SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/ |
@@ -10,4 +10,10 @@ SENSOR_DIR = /tmp/test-gnunet-service-sensor-reporting/ | |||
10 | START_MONITORING = NO | 10 | START_MONITORING = NO |
11 | START_REPORTING = YES | 11 | START_REPORTING = YES |
12 | START_ANALYSIS = NO | 12 | START_ANALYSIS = NO |
13 | START_UPDATE = NO \ No newline at end of file | 13 | START_UPDATE = NO |
14 | |||
15 | [transport] | ||
16 | PLUGINS = unix | ||
17 | |||
18 | [nat] | ||
19 | USE_LOCALADDR = YES | ||