From 8af9412585b17289e8fa5ca905eaa33415927dc3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 11 Feb 2015 16:17:20 +0000 Subject: new testsuite, obsoleting (most of) the old one --- src/ats/Makefile.am | 521 +---------- src/ats/test_ats_api.c | 243 +++++ src/ats/test_ats_api_common.c | 302 ------- src/ats/test_ats_api_common.h | 90 -- ...elayed_service_performance_list_all_addresses.c | 303 ------- ...t_ats_api_delayed_service_performance_monitor.c | 305 ------- ...ts_api_delayed_service_scheduling_add_address.c | 240 ----- src/ats/test_ats_api_mlp.conf | 45 + .../test_ats_api_performance_list_all_addresses.c | 312 ------- ...ats_api_performance_list_all_addresses_active.c | 307 ------- .../test_ats_api_performance_list_peer_addresses.c | 331 ------- src/ats/test_ats_api_performance_monitor.c | 301 ------- ..._ats_api_performance_monitor_initial_callback.c | 302 ------- src/ats/test_ats_api_proportional.conf | 24 + src/ats/test_ats_api_ril.conf | 24 + src/ats/test_ats_api_scheduling_add_address.c | 231 ----- ...test_ats_api_scheduling_add_address_duplicate.c | 266 ------ .../test_ats_api_scheduling_add_address_inbound.c | 243 ----- src/ats/test_ats_api_scheduling_add_session.c | 237 ----- src/ats/test_ats_api_scheduling_destroy_address.c | 268 ------ src/ats/test_ats_api_scheduling_init.c | 176 ---- src/ats/test_ats_lib.c | 999 +++++++++++++++++++++ src/ats/test_ats_lib.h | 467 ++++++++++ src/ats/test_ats_mlp.conf | 2 +- src/ats/test_ats_solver_add_address.c | 265 ------ src/ats/test_ats_solver_add_address_and_request.c | 305 ------- ...t_ats_solver_alternative_after_delete_address.c | 455 ---------- src/ats/test_ats_solver_request_and_add_address.c | 274 ------ .../test_ats_solver_request_and_delete_address.c | 307 ------- 29 files changed, 1833 insertions(+), 6312 deletions(-) create mode 100644 src/ats/test_ats_api.c delete mode 100644 src/ats/test_ats_api_common.c delete mode 100644 src/ats/test_ats_api_common.h delete mode 100644 src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c delete mode 100644 src/ats/test_ats_api_delayed_service_performance_monitor.c delete mode 100644 src/ats/test_ats_api_delayed_service_scheduling_add_address.c create mode 100644 src/ats/test_ats_api_mlp.conf delete mode 100644 src/ats/test_ats_api_performance_list_all_addresses.c delete mode 100644 src/ats/test_ats_api_performance_list_all_addresses_active.c delete mode 100644 src/ats/test_ats_api_performance_list_peer_addresses.c delete mode 100644 src/ats/test_ats_api_performance_monitor.c delete mode 100644 src/ats/test_ats_api_performance_monitor_initial_callback.c create mode 100644 src/ats/test_ats_api_proportional.conf create mode 100644 src/ats/test_ats_api_ril.conf delete mode 100644 src/ats/test_ats_api_scheduling_add_address.c delete mode 100644 src/ats/test_ats_api_scheduling_add_address_duplicate.c delete mode 100644 src/ats/test_ats_api_scheduling_add_address_inbound.c delete mode 100644 src/ats/test_ats_api_scheduling_add_session.c delete mode 100644 src/ats/test_ats_api_scheduling_destroy_address.c delete mode 100644 src/ats/test_ats_api_scheduling_init.c create mode 100644 src/ats/test_ats_lib.c create mode 100644 src/ats/test_ats_lib.h delete mode 100644 src/ats/test_ats_solver_add_address.c delete mode 100644 src/ats/test_ats_solver_add_address_and_request.c delete mode 100644 src/ats/test_ats_solver_alternative_after_delete_address.c delete mode 100644 src/ats/test_ats_solver_request_and_add_address.c delete mode 100644 src/ats/test_ats_solver_request_and_delete_address.c (limited to 'src') diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 2a14ae73f..63917b907 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -18,23 +18,6 @@ if USE_COVERAGE AM_CFLAGS = -fprofile-arcs -ftest-coverage endif -#noinst_PROGRAMS = \ -# gnunet-ats-solver-eval - -if HAVE_LIBGLPK - GN_LIBGLPK = -lglpk - GN_MLP_LIB = libgnunet_plugin_ats_mlp.la - GN_MLP_PERF = perf_ats_mlp - GN_MLP_ADD_ADDRESS = test_ats_solver_add_address_mlp - GN_MLP_ADD_REQUEST_ADDRESS = test_ats_solver_add_address_and_request_mlp - GN_MLP_ADD_REQUEST_ADDRESS_DELAYED = test_ats_solver_add_address_and_request_delayed_mlp - GN_MLP_REQUEST_ADD_ADDRESS = test_ats_solver_request_and_add_address_mlp - GN_MLP_REQUEST_DELETE_ADDRESS = test_ats_solver_request_and_delete_address_mlp - GN_MLP_PREFERENCES_ADDRESS = test_ats_solver_preferences_mlp - GN_MLP_ALTERNATIVE_DELETE_ADDRESS = test_ats_solver_alternative_after_delete_address_mlp - GN_MLP_SOLVER_PERF = perf_ats_solver_mlp -endif - lib_LTLIBRARIES = libgnunetats.la plugin_LTLIBRARIES = \ @@ -42,21 +25,10 @@ plugin_LTLIBRARIES = \ $(GN_MLP_LIB) \ libgnunet_plugin_ats_ril.la -#gnunet_ats_solver_eval_SOURCES = \ -# gnunet-ats-solver-eval.c gnunet-ats-solver-eval.h \ -# gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ -# gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ -# gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ -# gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ -# gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ -# gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h \ -# gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ -# gnunet-service-ats_normalization.c -#gnunet_ats_solver_eval_LDADD = \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# libgnunetats.la \ -# $(top_builddir)/src/statistics/libgnunetstatistics.la \ -# $(LTLIBINTL) +if HAVE_LIBGLPK +plugin_LTLIBRARIES += \ + libgnunet_plugin_ats_mlp.la +endif libgnunetats_la_SOURCES = \ ats_api_connectivity.c \ @@ -90,7 +62,8 @@ libgnunet_plugin_ats_mlp_la_LIBADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la libgnunet_plugin_ats_mlp_la_LDFLAGS = \ - $(GN_PLUGIN_LDFLAGS) $(GN_LIBGLPK) + $(GN_PLUGIN_LDFLAGS) \ + -lglpk endif libgnunet_plugin_ats_ril_la_SOURCES = \ @@ -107,7 +80,7 @@ libexec_PROGRAMS = \ gnunet-service-ats gnunet_service_ats_SOURCES = \ - gnunet-service-ats.c gnunet-service-ats.h\ + gnunet-service-ats.c gnunet-service-ats.h \ gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ @@ -125,44 +98,12 @@ gnunet_service_ats_LDADD = \ if HAVE_TESTING TESTING_TESTS = \ - test_ats_api_scheduling_init \ - test_ats_api_scheduling_add_address \ - test_ats_api_scheduling_add_address_duplicate \ - test_ats_api_scheduling_add_address_inbound \ - test_ats_api_scheduling_destroy_address \ - test_ats_api_scheduling_add_session \ - test_ats_api_delayed_service_scheduling_add_address \ - test_ats_api_performance_list_all_addresses \ - test_ats_api_delayed_service_performance_list_all_addresses \ - test_ats_api_performance_list_peer_addresses \ - test_ats_api_performance_list_all_addresses_active \ - test_ats_api_performance_monitor \ - test_ats_api_delayed_service_performance_monitor \ - test_ats_api_performance_monitor_initial_callback \ - test_ats_solver_add_address_proportional \ - test_ats_solver_add_address_and_request_proportional \ - test_ats_solver_add_address_and_request_delayed_proportional\ - test_ats_solver_request_and_add_address_proportional \ - test_ats_solver_request_and_delete_address_proportional \ - test_ats_solver_alternative_after_delete_address_proportional \ - test_ats_solver_preferences_proportional \ - test_ats_solver_preferences_ril \ - $(GN_MLP_ADD_ADDRESS) \ - $(GN_MLP_ADD_REQUEST_ADDRESS) \ - $(GN_MLP_ADD_REQUEST_ADDRESS_DELAYED) \ - $(GN_MLP_REQUEST_ADD_ADDRESS) \ - $(GN_MLP_REQUEST_DELETE_ADDRESS) \ - $(GN_MLP_ALTERNATIVE_DELETE_ADDRESS) \ - $(GN_MLP_PREFERENCES_ADDRESS) \ - test_ats_solver_add_address_ril \ - test_ats_solver_add_address_and_request_ril \ - test_ats_solver_add_address_and_request_delayed_ril \ - test_ats_solver_request_and_add_address_ril \ - test_ats_solver_request_and_delete_address_ril \ - test_ats_solver_alternative_after_delete_address_ril \ - perf_ats_solver_proportional \ - $(GN_MLP_SOLVER_PERF) \ - perf_ats_solver_ril + test_ats_api_proportional \ + test_ats_api_ril +if HAVE_LIBGLPK +TESTING_TESTS += \ + test_ats_api_mlp +endif endif check_PROGRAMS = \ @@ -173,438 +114,36 @@ AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PAT TESTS = $(check_PROGRAMS) endif -# scheduling API tests - -test_ats_api_scheduling_init_SOURCES = \ - test_ats_api_scheduling_init.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_scheduling_init_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_scheduling_add_address_SOURCES = \ - test_ats_api_scheduling_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_scheduling_add_address_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_delayed_service_scheduling_add_address_SOURCES = \ - test_ats_api_delayed_service_scheduling_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_delayed_service_scheduling_add_address_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_scheduling_add_address_inbound_SOURCES = \ - test_ats_api_scheduling_add_address_inbound.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_scheduling_add_address_inbound_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_scheduling_add_address_duplicate_SOURCES = \ - test_ats_api_scheduling_add_address_duplicate.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_scheduling_add_address_duplicate_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_scheduling_destroy_address_SOURCES = \ - test_ats_api_scheduling_destroy_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_api_scheduling_destroy_address_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_scheduling_add_session_SOURCES = \ - test_ats_api_scheduling_add_session.c test_ats_api_common.c -test_ats_api_scheduling_add_session_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -# performance API tests - -test_ats_api_performance_list_all_addresses_SOURCES = \ - test_ats_api_performance_list_all_addresses.c -test_ats_api_performance_list_all_addresses_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_delayed_service_performance_list_all_addresses_SOURCES = \ - test_ats_api_delayed_service_performance_list_all_addresses.c -test_ats_api_delayed_service_performance_list_all_addresses_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_performance_list_peer_addresses_SOURCES = \ - test_ats_api_performance_list_peer_addresses.c -test_ats_api_performance_list_peer_addresses_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_performance_list_all_addresses_active_SOURCES = \ - test_ats_api_performance_list_all_addresses_active.c -test_ats_api_performance_list_all_addresses_active_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_performance_monitor_SOURCES = \ - test_ats_api_performance_monitor.c -test_ats_api_performance_monitor_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_api_delayed_service_performance_monitor_SOURCES = \ - test_ats_api_delayed_service_performance_monitor.c -test_ats_api_delayed_service_performance_monitor_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - - - -test_ats_api_performance_monitor_initial_callback_SOURCES = \ - test_ats_api_performance_monitor_initial_callback.c -test_ats_api_performance_monitor_initial_callback_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -# solver tests -test_ats_solver_add_address_proportional_SOURCES = \ - test_ats_solver_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -if HAVE_LIBGLPK -test_ats_solver_add_address_mlp_SOURCES = \ - test_ats_solver_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la -endif - -test_ats_solver_add_address_ril_SOURCES = \ - test_ats_solver_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_add_address_and_request_proportional_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_add_address_and_request_delayed_proportional_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_delayed_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_add_address_and_request_delayed_ril_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_delayed_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -if HAVE_LIBGLPK -test_ats_solver_add_address_and_request_mlp_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la -endif - -test_ats_solver_add_address_and_request_delayed_mlp_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_delayed_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_add_address_and_request_ril_SOURCES = \ - test_ats_solver_add_address_and_request.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_add_address_and_request_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - - -test_ats_solver_request_and_add_address_proportional_SOURCES = \ - test_ats_solver_request_and_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_add_address_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -if HAVE_LIBGLPK -test_ats_solver_request_and_add_address_mlp_SOURCES = \ - test_ats_solver_request_and_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_add_address_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la -endif - -test_ats_solver_request_and_add_address_ril_SOURCES = \ - test_ats_solver_request_and_add_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_add_address_ril_LDADD = \ +test_ats_api_proportional_SOURCES = \ + test_ats_api.c \ + test_ats_lib.c test_ats_lib.h +test_ats_api_proportional_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - - -test_ats_solver_request_and_delete_address_proportional_SOURCES = \ - test_ats_solver_request_and_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_delete_address_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -if HAVE_LIBGLPK -test_ats_solver_request_and_delete_address_mlp_SOURCES = \ - test_ats_solver_request_and_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_delete_address_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la -endif - -test_ats_solver_request_and_delete_address_ril_SOURCES = \ - test_ats_solver_request_and_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_request_and_delete_address_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - + libgnunetats.la -test_ats_solver_alternative_after_delete_address_proportional_SOURCES = \ - test_ats_solver_alternative_after_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_alternative_after_delete_address_proportional_LDADD = \ +test_ats_api_ril_SOURCES = \ + test_ats_api.c \ + test_ats_lib.c test_ats_lib.h +test_ats_api_ril_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_preferences_proportional_SOURCES = \ - test_ats_solver_preferences.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_preferences_proportional_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la + libgnunetats.la -if HAVE_LIBGLPK -test_ats_solver_alternative_after_delete_address_mlp_SOURCES = \ - test_ats_solver_alternative_after_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_alternative_after_delete_address_mlp_LDADD = \ +test_ats_api_mlp_SOURCES = \ + test_ats_api.c \ + test_ats_lib.c test_ats_lib.h +test_ats_api_mlp_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -test_ats_solver_preferences_mlp_SOURCES = \ - test_ats_solver_preferences.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_preferences_mlp_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la -endif - -test_ats_solver_alternative_after_delete_address_ril_SOURCES = \ - test_ats_solver_alternative_after_delete_address.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_alternative_after_delete_address_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - -#perf_ats_mlp_SOURCES = \ -# $(GN_MLP_SRC) perf_ats_mlp.c test_ats_api_common.c gnunet-service-ats_normalization.c -#perf_ats_mlp_LDADD = \ -# $(GN_LIBGLPK) \ -# $(top_builddir)/src/util/libgnunetutil.la \ -# $(top_builddir)/src/statistics/libgnunetstatistics.la \ -# libgnunetats.la - -perf_ats_solver_mlp_SOURCES = \ - perf_ats_solver.c \ - test_ats_api_common.c \ - gnunet-service-ats_normalization.c \ - gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ - gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ - gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ - gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ - gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ - gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ - gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h - -perf_ats_solver_mlp_LDADD = \ - $(GN_LIBGLPK) \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - libgnunetats.la - -perf_ats_solver_proportional_SOURCES = \ - perf_ats_solver.c \ - test_ats_api_common.c \ - gnunet-service-ats_normalization.c \ - gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ - gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ - gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ - gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ - gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ - gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ - gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h - -perf_ats_solver_proportional_LDADD = \ - $(GN_LIBGLPK) \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ - libgnunetats.la - -perf_ats_solver_ril_SOURCES = \ - perf_ats_solver.c \ - test_ats_api_common.c \ - gnunet-service-ats_normalization.c \ - gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ - gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ - gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ - gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ - gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ - gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ - gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h - -perf_ats_solver_ril_LDADD = \ - $(GN_LIBGLPK) \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la \ libgnunetats.la -test_ats_solver_preferences_ril_SOURCES = \ - test_ats_solver_preferences.c \ - test_ats_api_common.c test_ats_api_common.h -test_ats_solver_preferences_ril_LDADD = \ - $(top_builddir)/src/util/libgnunetutil.la \ - $(top_builddir)/src/testing/libgnunettesting.la \ - $(top_builddir)/src/hello/libgnunethello.la \ - libgnunetats.la \ - $(top_builddir)/src/statistics/libgnunetstatistics.la - EXTRA_DIST = \ ats.h \ test_delay \ - test_ats_api.conf \ - test_ats_api_delayed.conf \ - test_ats_mlp.conf \ - test_ats_solver_default.conf \ - test_ats_solver_proportional.conf \ - test_ats_solver_proportional.conf \ - test_ats_solver_mlp.conf \ - test_ats_solver_delayed_mlp.conf \ - test_ats_solver_ril.conf \ - test_ats_solver_delayed_ril.conf \ - perf_ats_solver_mlp.conf \ - test_ats_solver_delayed_mlp.conf \ - perf_ats_solver_proportional.conf \ - perf_ats_solver_ril.conf \ - perf_ats_solver.conf + test_ats_api_mlp.conf \ + test_ats_api_ril.conf \ + test_ats_api_proportional.conf diff --git a/src/ats/test_ats_api.c b/src/ats/test_ats_api.c new file mode 100644 index 000000000..97fdd65c1 --- /dev/null +++ b/src/ats/test_ats_api.c @@ -0,0 +1,243 @@ +/* + This file is part of GNUnet. + Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/test_ats_api.c + * @brief test ATS + * @author Christian Grothoff + */ +#include "platform.h" +#include "test_ats_lib.h" + +/** + * Global timeout for the testcase. + */ +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) + +/** + * Definition of the test as a sequence of commands. + */ +static struct Command test_commands[] = { + { + .code = CMD_ADD_ADDRESS, + .label = "add-address-0-0", + .details.add_address = { + .pid = 0, + .addr_num = 0, + .session = 0, + .properties = { + .scope = GNUNET_ATS_NET_LAN + } + } + }, + /* adding same address again should fail */ + { + .code = CMD_ADD_ADDRESS, + .label = "add-address-0-0:FAIL", + .details.add_address = { + .pid = 0, + .addr_num = 0, + .session = 0, + .properties = { + .scope = GNUNET_ATS_NET_LAN + }, + .expect_fail = 1 + } + }, + /* some solver still require explicit start */ + { + .code = CMD_REQUEST_CONNECTION_START, + .label = "request-0", + .details.request_connection_start = { + .pid = 0 + } + }, + /* check we got an address */ + { + .code = CMD_AWAIT_ADDRESS_SUGGESTION, + .details.await_address_suggestion = { + .add_label = "add-address-0-0" + } + }, + /* check monitor also got the address */ + { + .code = CMD_AWAIT_ADDRESS_INFORMATION, + .details.await_address_information = { + .add_label = "add-address-0-0" + } + }, + /* test session API */ + { + .code = CMD_ADD_SESSION, + .label = "add-session-0-0-1", + .details.add_session = { + .add_label ="add-address-0-0", + .session = 1 + } + }, + { + .code = CMD_DEL_SESSION, + .details.del_session = { + .add_session_label = "add-session-0-0-1", + } + }, + /* test preference API */ + { + .code = CMD_CHANGE_PREFERENCE, + .details.change_preference = { + .pid = 0 + /* FIXME: preference details */ + } + }, + { + .code = CMD_PROVIDE_FEEDBACK, + .details.provide_feedback = { + .pid = 0, + .scope = { 50LL } + /* FIXME: preference details */ + } + }, + /* test sanity check address listing */ + { + .code = CMD_LIST_ADDRESSES, + .details.list_addresses = { + .pid = 0, + .all = 1, + .min_calls = 2, // ? + .max_calls = 2, + .min_active_calls = 1, + .max_active_calls = 1 + } + }, + /* remove address testing */ + { + .code = CMD_DEL_ADDRESS, + .details.del_address = { + .add_label = "add-address-0-0" + } + }, + /* check we got disconnected */ + { + .code = CMD_AWAIT_DISCONNECT_SUGGESTION, + .details.await_disconnect_suggestion = { + .pid = 0 + } + }, + /* just for symmetry, also stop asking for the connection */ + { + .code = CMD_REQUEST_CONNECTION_STOP, + .details.request_connection_stop = { + .connect_label = "request-0", + } + }, + /* add address again */ + { + .code = CMD_ADD_ADDRESS, + .label = "add-address-0-0:1", + .details.add_address = { + .pid = 0, + .addr_num = 0, + .session = 0, + .properties = { + .scope = GNUNET_ATS_NET_LAN + } + } + }, + /* some solver still require explicit start */ + { + .code = CMD_REQUEST_CONNECTION_START, + .label = "request-0", + .details.request_connection_start = { + .pid = 0 + } + }, + /* check we got an address */ + { + .code = CMD_AWAIT_ADDRESS_SUGGESTION, + .details.await_address_suggestion = { + .add_label = "add-address-0-0:1" + } + }, + /* add alternative address */ + { + .code = CMD_ADD_ADDRESS, + .label = "add-address-0-1", + .details.add_address = { + .pid = 0, + .addr_num = 1, + .session = 0, + .properties = { + .scope = GNUNET_ATS_NET_LAN + } + } + }, + /* remove original address */ + { + .code = CMD_DEL_ADDRESS, + .details.del_address = { + .add_label = "add-address-0-0:1" + } + }, + /* check we switched to alternative address */ + { + .code = CMD_AWAIT_ADDRESS_SUGGESTION, + .details.await_address_suggestion = { + .add_label = "add-address-0-1" + } + }, + /* remove alternative address */ + { + .code = CMD_DEL_ADDRESS, + .details.del_address = { + .add_label = "add-address-0-1" + } + }, + /* check we got disconnected */ + { + .code = CMD_AWAIT_DISCONNECT_SUGGESTION, + .details.await_disconnect_suggestion = { + .pid = 0 + } + }, + /* just for symmetry, also stop asking for the connection */ + { + .code = CMD_REQUEST_CONNECTION_STOP, + .details.request_connection_stop = { + .connect_label = "request-0", + } + }, + /* Test ends successfully */ + { + .code = CMD_END_PASS + } +}; + + +int +main (int argc, + char *argv[]) +{ + return TEST_ATS_run (argc, + argv, + test_commands, + TIMEOUT); +} + + +/* end of file test_ats_api.c */ diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c deleted file mode 100644 index 2bfebaa6d..000000000 --- a/src/ats/test_ats_api_common.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_common.c - * @brief shared functions for ats test - * @author Christian Grothoff - * @author Matthias Wachs - */ - -#include "test_ats_api_common.h" -#define BIG_M_STRING "unlimited" - - -void -create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) -{ - - dest->plugin = GNUNET_strdup (plugin); - dest->session = session; - if (addrlen > 0) - { - dest->addr = GNUNET_malloc (addrlen); - memcpy (dest->addr, addr, addrlen); - } - else - dest->addr = NULL; - dest->addr_len = addrlen; -} - - -void -free_test_address (struct Test_Address *dest) -{ - GNUNET_free_non_null (dest->plugin); - dest->plugin = NULL; - GNUNET_free_non_null (dest->addr); - dest->addr = NULL; -} - - -int -compare_addresses (const struct GNUNET_HELLO_Address *address1, - void *session1, - const struct GNUNET_HELLO_Address *address2, - void *session2) -{ - if (0 != - memcmp (&address1->peer, - &address2->peer, - sizeof (struct GNUNET_PeerIdentity))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Suggestion with invalid peer id'\n"); - return GNUNET_SYSERR; - } - if (0 != strcmp (address1->transport_name, address2->transport_name)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Suggestion with invalid plugin'\n"); - return GNUNET_SYSERR; - } - if (address1->address_length != address2->address_length) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Suggestion with invalid address length\n"); - return GNUNET_SYSERR; - } - if (0 != memcmp (address1->address, address2->address, address2->address_length)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Suggestion with invalid address\n"); - return GNUNET_SYSERR; - } - if (session1 != session2) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Suggestion with invalid session1 %p vs session2 %p'\n", - session1, session2); - return GNUNET_SYSERR; - } - return GNUNET_OK; -} - - -int -compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, - const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should) -{ - unsigned int c_o; - unsigned int c_i; - uint32_t type1; - uint32_t type2; - uint32_t val1; - uint32_t val2; - int res = GNUNET_OK; - - for (c_o = 0; c_o < ats_count_is; c_o++) - { - for (c_i = 0; c_i < ats_count_should; c_i++) - { - type1 = ntohl(ats_is[c_o].type); - type2 = ntohl(ats_should[c_i].type); - if (type1 == type2) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS type `%s'\n", - GNUNET_ATS_print_property_type (type1)); - val1 = ntohl(ats_is[c_o].value); - val2 = ntohl(ats_should[c_i].value); - if (val1 != val2) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "ATS value `%s' not equal: %u != %u\n", - GNUNET_ATS_print_property_type (type1), - val1, val2); - res = GNUNET_SYSERR; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ATS value `%s' equal: %u == %u\n", - GNUNET_ATS_print_property_type (type1), - val1, val2); - } - } - } - } - return res; -} - - -/** - * Load quotas for networks from configuration - * - * @param cfg configuration handle - * @param out_dest where to write outbound quotas - * @param in_dest where to write inbound quotas - * @param dest_length length of inbound and outbound arrays - * @return number of networks loaded - */ -unsigned int -load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned long long *out_dest, - unsigned long long *in_dest, - int dest_length) -{ - char *entry_in = NULL; - char *entry_out = NULL; - char *quota_out_str; - char *quota_in_str; - int c; - int res; - - for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++) - { - in_dest[c] = 0; - out_dest[c] = 0; - GNUNET_asprintf (&entry_out, - "%s_QUOTA_OUT", - GNUNET_ATS_print_network_type (c)); - GNUNET_asprintf (&entry_in, - "%s_QUOTA_IN", - GNUNET_ATS_print_network_type (c)); - - /* quota out */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) - { - res = GNUNET_NO; - if (0 == strcmp(quota_out_str, BIG_M_STRING)) - { - out_dest[c] = GNUNET_ATS_MaxBandwidth; - res = GNUNET_YES; - } - if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) - res = GNUNET_YES; - if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c]))) - res = GNUNET_YES; - - if (GNUNET_NO == res) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), - GNUNET_ATS_print_network_type (c), - quota_out_str, - GNUNET_ATS_DefaultBandwidth); - out_dest[c] = GNUNET_ATS_DefaultBandwidth; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Outbound quota configure for network `%s' is %llu\n", - GNUNET_ATS_print_network_type (c), - out_dest[c]); - } - GNUNET_free (quota_out_str); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), - GNUNET_ATS_print_network_type (c), - GNUNET_ATS_DefaultBandwidth); - out_dest[c] = GNUNET_ATS_DefaultBandwidth; - } - - /* quota in */ - if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) - { - res = GNUNET_NO; - if (0 == strcmp(quota_in_str, BIG_M_STRING)) - { - in_dest[c] = GNUNET_ATS_MaxBandwidth; - res = GNUNET_YES; - } - if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) - res = GNUNET_YES; - if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c]))) - res = GNUNET_YES; - - if (GNUNET_NO == res) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), - GNUNET_ATS_print_network_type (c), - quota_in_str, - GNUNET_ATS_DefaultBandwidth); - in_dest[c] = GNUNET_ATS_DefaultBandwidth; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Inbound quota configured for network `%s' is %llu\n", - GNUNET_ATS_print_network_type (c), - in_dest[c]); - } - GNUNET_free (quota_in_str); - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), - GNUNET_ATS_print_network_type (c), - GNUNET_ATS_DefaultBandwidth); - out_dest[c] = GNUNET_ATS_DefaultBandwidth; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Loaded quota for network `%s' (in/out): %llu %llu\n", - GNUNET_ATS_print_network_type (c), - in_dest[c], - out_dest[c]); - GNUNET_free (entry_out); - GNUNET_free (entry_in); - } - return GNUNET_ATS_NetworkTypeCount; -} - -/** - * Create a ATS_address with the given information - * @param peer peer - * @param plugin_name plugin - * @param plugin_addr address - * @param plugin_addr_len address length - * @param session_id session - * @return the ATS_Address - */ -struct ATS_Address * -create_address (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id) -{ - struct ATS_Address *aa = NULL; - - aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1); - aa->peer = *peer; - aa->addr_len = plugin_addr_len; - aa->addr = &aa[1]; - aa->plugin = (char *) &aa[1] + plugin_addr_len; - memcpy (&aa[1], plugin_addr, plugin_addr_len); - memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1); - aa->session_id = session_id; - return aa; -} - -/* end of file test_ats_api_common.c */ diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h deleted file mode 100644 index 091eb59b6..000000000 --- a/src/ats/test_ats_api_common.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_common.h - * @brief shared definitions for ats testcases - * @author Christian Grothoff - * @author Matthias Wachs - */ - -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet-service-ats_addresses.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) - -struct Test_Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Properties properties; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Test_Address *addr; - - unsigned long long bw_out_assigned; - - unsigned long long bw_in_assigned; -}; - -void -free_test_address (struct Test_Address *dest); - -void -create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen); - - -int -compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, - const struct GNUNET_HELLO_Address *address2, void *session2); - - -struct ATS_Address * -create_address (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *plugin_addr, size_t plugin_addr_len, - uint32_t session_id); - -/** - * Load quotas for networks from configuration - * - * @param cfg configuration handle - * @param out_dest where to write outbound quotas - * @param in_dest where to write inbound quotas - * @param dest_length length of inbound and outbound arrays - * @return number of networks loaded - */ -unsigned int -load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned long long *out_dest, - unsigned long long *in_dest, - int dest_length); - -/* end of file test_ats_api_common.h */ diff --git a/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c b/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c deleted file mode 100644 index 348cbc3c4..000000000 --- a/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_delayed_service_performance_list_all_addresses.c - * @brief test performance API's address listing feature with a delayed service startup - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -struct GNUNET_ATS_AddressListHandle* phal; - -static int ret; - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -struct GNUNET_HELLO_Address p0_ha[2]; -struct GNUNET_HELLO_Address p1_ha[2]; -struct GNUNET_HELLO_Address *s_ha[2]; - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int counter = 0; - - if (NULL == address) - { - phal = 0; - if (4 == counter) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - GNUNET_SCHEDULER_add_now (end, NULL); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - return; - } - counter ++; -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added, connecting to performance\n"); - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - phal = GNUNET_ATS_performance_list_addresses (perf_ats, NULL, GNUNET_YES, &ats_perf_cb, NULL); - } - return GNUNET_OK; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (phal != NULL ) - { - GNUNET_ATS_performance_list_addresses_cancel (phal); - phal = NULL; - } - - if (perf_ats != NULL ) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - - - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api_delayed.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_delayed_service_performance_list_all_addresses.c */ diff --git a/src/ats/test_ats_api_delayed_service_performance_monitor.c b/src/ats/test_ats_api_delayed_service_performance_monitor.c deleted file mode 100644 index 2e3ff738f..000000000 --- a/src/ats/test_ats_api_delayed_service_performance_monitor.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_delayed_service_performance_monitor.c - * @brief test performance API's address monitor feature with a delayed service - * start up - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) -#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - - -static int ret; - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -static struct GNUNET_HELLO_Address p0_ha[2]; -static struct GNUNET_HELLO_Address p1_ha[2]; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int peer0 = GNUNET_NO; - static int peer1 = GNUNET_NO; - static int done = GNUNET_NO; - - if (NULL == address) - return; - - if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[0].id, sizeof (p[0].id)))) - { - peer0 = GNUNET_YES; - } - if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[1].id, sizeof (p[1].id)))) - { - peer1 = GNUNET_YES; - } - if ((peer0 == GNUNET_YES) && (peer1 = GNUNET_YES) && (GNUNET_NO == done)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Done\n"); - done = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&end, NULL); - - } -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added\n"); - } - - return GNUNET_OK; - -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) - -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (NULL != perf_ats) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api_delayed.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_delayed_service_performance_monitor.c */ diff --git a/src/ats/test_ats_api_delayed_service_scheduling_add_address.c b/src/ats/test_ats_api_delayed_service_scheduling_add_address.c deleted file mode 100644 index f08812341..000000000 --- a/src/ats/test_ats_api_delayed_service_scheduling_add_address.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_delayed_service_scheduling_add_address.c - * @brief test case to ensure messages are transmitted to ATS service when - * service startup is delayed - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if (1 == value) - { - GNUNET_SCHEDULER_add_now (&end, NULL); - } - return GNUNET_OK; -} - - -static void -end (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -got_initial_value (void *cls, int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, - &test_hello_address, - test_session, - test_ats_info, test_ats_count); -} - - -static int -dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", subsystem, name, value); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, - &got_initial_value, &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); - -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api_delayed.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_delayed_service_scheduling_add_address.c */ diff --git a/src/ats/test_ats_api_mlp.conf b/src/ats/test_ats_api_mlp.conf new file mode 100644 index 000000000..cabd5e71c --- /dev/null +++ b/src/ats/test_ats_api_mlp.conf @@ -0,0 +1,45 @@ +@INLINE@ ../../contrib/no_forcestart.conf + +[PATHS] +GNUNET_TEST_HOME = /tmp/test-ats-mlp/ + +[ats] +# Enable MLP mode (default: NO) +MODE = mlp +# Network specific inbound/outbound quotas +# UNSPECIFIED +UNSPECIFIED_QUOTA_IN = unlimited +UNSPECIFIED_QUOTA_OUT = unlimited +# LOOPBACK +LOOPBACK_QUOTA_IN = unlimited +LOOPBACK_QUOTA_OUT = unlimited +# LAN +LAN_QUOTA_IN = unlimited +LAN_QUOTA_OUT = unlimited +# WAN +WAN_QUOTA_IN = 64 KiB +WAN_QUOTA_OUT = 64 KiB +# WLAN +WLAN_QUOTA_IN = 4096 +WLAN_QUOTA_OUT = 4096 + +# MLP specific settings +ATS_MIN_INTERVAL = 15000 +ATS_EXEC_INTERVAL = 30000 + +# MLP defaults +# MLP_MAX_DURATION = 3 s +# MLP_MAX_ITERATIONS = 1024 +# MLP_COEFFICIENT_D = 1.0 +# MLP_COEFFICIENT_U = 1.0 +# MLP_COEFFICIENT_R = 1.0 +# MLP_MIN_BANDWIDTH = 1024 +# MLP_MIN_CONNECTIONS = 4 + +# MLP Debugging settings +DUMP_MLP = NO +DUMP_SOLUTION = NO +DUMP_OVERWRITE = NO +DUMP_MIN_PEERS = 0 +DUMP_MIN_ADDRS = 0 +DUMP_OVERWRITE = NO diff --git a/src/ats/test_ats_api_performance_list_all_addresses.c b/src/ats/test_ats_api_performance_list_all_addresses.c deleted file mode 100644 index 4c09a8948..000000000 --- a/src/ats/test_ats_api_performance_list_all_addresses.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_performance_list_addresses.c - * @brief test performance API's address listing feature - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -static struct GNUNET_ATS_AddressListHandle* phal; - -static int ret; - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -static struct GNUNET_HELLO_Address p0_ha[2]; -static struct GNUNET_HELLO_Address p1_ha[2]; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int counter = 0; - - if (NULL == address) - { - phal = 0; - if (4 == counter) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - GNUNET_SCHEDULER_add_now (end, NULL); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } - return; - } - counter++; -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added, connecting to performance\n"); - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - phal = GNUNET_ATS_performance_list_addresses (perf_ats, - NULL, - GNUNET_YES, - &ats_perf_cb, NULL); - } - return GNUNET_OK; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (phal != NULL ) - { - GNUNET_ATS_performance_list_addresses_cancel (phal); - phal = NULL; - } - - if (perf_ats != NULL ) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, - &address_suggest_cb, NULL); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_performance_list_addresses.c */ diff --git a/src/ats/test_ats_api_performance_list_all_addresses_active.c b/src/ats/test_ats_api_performance_list_all_addresses_active.c deleted file mode 100644 index 3c979716f..000000000 --- a/src/ats/test_ats_api_performance_list_all_addresses_active.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_performance_list_addresses.c - * @brief test performance API's address listing feature - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -static struct GNUNET_ATS_AddressListHandle* phal; - -static int ret; - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -static struct GNUNET_HELLO_Address p0_ha[2]; -static struct GNUNET_HELLO_Address p1_ha[2]; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int counter = 0; - if (NULL == address) - { - phal = 0; - if (0 == counter) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - GNUNET_SCHEDULER_add_now (end, NULL); - } - else - { - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - return; - } - else - { - if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) - { - GNUNET_break (0); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - } - counter ++; -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added, connecting to performance\n"); - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - phal = GNUNET_ATS_performance_list_addresses (perf_ats, &p[0].id, GNUNET_NO, ats_perf_cb, NULL); - } - return GNUNET_OK; -} - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (phal != NULL ) - { - GNUNET_ATS_performance_list_addresses_cancel (phal); - phal = NULL; - } - - if (perf_ats != NULL ) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - - - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_performance_list_addresses.c */ diff --git a/src/ats/test_ats_api_performance_list_peer_addresses.c b/src/ats/test_ats_api_performance_list_peer_addresses.c deleted file mode 100644 index 7e3f87745..000000000 --- a/src/ats/test_ats_api_performance_list_peer_addresses.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_performance_list_addresses.c - * @brief test performance API's address listing feature - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -static struct GNUNET_ATS_AddressListHandle* phal; - -static int ret; - - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -static struct GNUNET_HELLO_Address p0_ha[2]; -static struct GNUNET_HELLO_Address p1_ha[2]; - - -static void -end (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int counter = 0; - - if (NULL == address) - { - phal = NULL; - if (2 == counter) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Done\n"); - GNUNET_SCHEDULER_add_now (&end, - NULL); - } - else - { - fprintf (stderr, - "Expected 2 addresses, got %d\n", - counter); - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - } - return; - } - else - { - if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) - { - GNUNET_break (0); - GNUNET_SCHEDULER_shutdown (); - return; - } - } - counter ++; -} - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added, connecting to performance\n"); - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_shutdown (); - return GNUNET_SYSERR; - } - phal = GNUNET_ATS_performance_list_addresses (perf_ats, - &p[0].id, - GNUNET_YES, - &ats_perf_cb, NULL); - } - return GNUNET_OK; -} - - -static void -end (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - if (NULL != phal) - { - GNUNET_ATS_performance_list_addresses_cancel (phal); - phal = NULL; - } - if (NULL != perf_ats) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - GNUNET_free_non_null (p0_addresses[0].addr); - GNUNET_free_non_null (p0_addresses[1].addr); - GNUNET_free_non_null (p1_addresses[0].addr); - GNUNET_free_non_null (p1_addresses[1].addr); - - ret = 0; -} - - -static void -end_badly (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end (NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, - &address_suggest_cb, NULL); - if (NULL == sched_ats) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not setup peer!\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - - -int -main (int argc, char *argv[]) -{ - if (0 != - GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_performance_list_addresses.c */ diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c deleted file mode 100644 index 700615451..000000000 --- a/src/ats/test_ats_api_performance_monitor.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_performance_monitor.c - * @brief test performance API's address monitor feature - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) -#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -static int ret; - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -static struct GNUNET_HELLO_Address p0_ha[2]; -static struct GNUNET_HELLO_Address p1_ha[2]; - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int peer0 = GNUNET_NO; - static int peer1 = GNUNET_NO; - static int done = GNUNET_NO; - - if (NULL == address) - return; - - if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[0].id, sizeof (p[0].id)))) - { - peer0 = GNUNET_YES; - } - if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[1].id, sizeof (p[1].id)))) - { - peer1 = GNUNET_YES; - } - if ((peer0 == GNUNET_YES) && (peer1 = GNUNET_YES) && (GNUNET_NO == done)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Done\n"); - done = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&end, NULL); - - } -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added\n"); - } - - return GNUNET_OK; - -} - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) - -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (NULL != perf_ats) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_performance_monitor.c */ diff --git a/src/ats/test_ats_api_performance_monitor_initial_callback.c b/src/ats/test_ats_api_performance_monitor_initial_callback.c deleted file mode 100644 index 1e1af8821..000000000 --- a/src/ats/test_ats_api_performance_monitor_initial_callback.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_api_performance_monitor.c - * @brief test performance API's address monitor feature - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" - -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) -#define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) - -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Configuration handle - */ -static struct GNUNET_CONFIGURATION_Handle *cfg; - -/** - * ATS scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * ATS performance handle - */ -static struct GNUNET_ATS_PerformanceHandle *perf_ats; - -static int ret; - - -struct Address -{ - char *plugin; - size_t plugin_len; - - void *addr; - size_t addr_len; - - struct GNUNET_ATS_Information *ats; - int ats_count; - - void *session; -}; - -struct PeerContext -{ - struct GNUNET_PeerIdentity id; - - struct Address *addr; -}; - -static struct PeerContext p[2]; - -static struct Address p0_addresses[2]; -static struct Address p1_addresses[2]; - -struct GNUNET_HELLO_Address p0_ha[2]; -struct GNUNET_HELLO_Address p1_ha[2]; -struct GNUNET_HELLO_Address *s_ha[2]; - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -ats_perf_cb (void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count) -{ - static int peer0 = GNUNET_NO; - static int peer1 = GNUNET_NO; - static int done = GNUNET_NO; - - if (NULL == address) - return; - - if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) - { - peer0 ++; - } - if (0 == memcmp (&address->peer, &p[1].id, sizeof (p[1].id))) - { - peer1 ++; - } - if ((2 == peer0) && (2 == peer1) && (GNUNET_NO == done)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Done\n"); - done = GNUNET_YES; - GNUNET_SCHEDULER_add_now (&end, NULL); - - } -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (4 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added\n"); - - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - } - - return GNUNET_OK; - -} - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) - -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - if (die_task != NULL ) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (NULL != perf_ats) - { - GNUNET_ATS_performance_done (perf_ats); - perf_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - - GNUNET_free_non_null(p0_addresses[0].addr); - GNUNET_free_non_null(p0_addresses[1].addr); - GNUNET_free_non_null(p1_addresses[0].addr); - GNUNET_free_non_null(p1_addresses[1].addr); - - ret = 0; -} - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - ret = 1; - cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); - - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - /* set up peer 0 */ - memset (&p[0].id, '1', sizeof (p[0].id)); - p0_addresses[0].plugin = "test"; - p0_addresses[0].session = NULL; - p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); - p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; - - p0_ha[0].address = p0_addresses[0].addr; - p0_ha[0].address_length = p0_addresses[0].addr_len; - p0_ha[0].peer = p[0].id; - p0_ha[0].transport_name = p0_addresses[0].plugin; - - p0_addresses[1].plugin = "test"; - p0_addresses[1].session = NULL; - p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); - p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; - - p0_ha[1].address = p0_addresses[1].addr; - p0_ha[1].address_length = p0_addresses[1].addr_len; - p0_ha[1].peer = p[0].id; - p0_ha[1].transport_name = p0_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", - GNUNET_i2s (&p[0].id)); - - memset (&p[1].id, '2', sizeof (p[1].id)); - p1_addresses[0].plugin = "test"; - p1_addresses[0].session = NULL; - p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); - p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; - - p1_ha[0].address = p1_addresses[0].addr; - p1_ha[0].address_length = p1_addresses[0].addr_len; - p1_ha[0].peer = p[1].id; - p1_ha[0].transport_name = p1_addresses[0].plugin; - - p1_addresses[1].plugin = "test"; - p1_addresses[1].session = NULL; - p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); - p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; - - p1_ha[1].address = p1_addresses[1].addr; - p1_ha[1].address_length = p1_addresses[1].addr_len; - p1_ha[1].peer = p[1].id; - p1_ha[1].transport_name = p1_addresses[1].plugin; - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", - GNUNET_i2s (&p[1].id)); - - /* Add addresses */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); - if (sched_ats == NULL ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); - - GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); - GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); -} - -int -main (int argc, char *argv[]) -{ - if (0 - != GNUNET_TESTING_peer_run ("test_ats_api_performance", - "test_ats_api.conf", &run, NULL )) - return 1; - return ret; -} - -/* end of file test_ats_api_performance_monitor.c */ diff --git a/src/ats/test_ats_api_proportional.conf b/src/ats/test_ats_api_proportional.conf new file mode 100644 index 000000000..4f277e79f --- /dev/null +++ b/src/ats/test_ats_api_proportional.conf @@ -0,0 +1,24 @@ +@INLINE@ ../../contrib/no_forcestart.conf + +[PATHS] +GNUNET_TEST_HOME = /tmp/test-ats-proportional/ + +[ats] +# Enable PROPORTIONAL mode (default: NO) +MODE = proportional +# Network specific inbound/outbound quotas +# UNSPECIFIED +UNSPECIFIED_QUOTA_IN = unlimited +UNSPECIFIED_QUOTA_OUT = unlimited +# LOOPBACK +LOOPBACK_QUOTA_IN = unlimited +LOOPBACK_QUOTA_OUT = unlimited +# LAN +LAN_QUOTA_IN = unlimited +LAN_QUOTA_OUT = unlimited +# WAN +WAN_QUOTA_IN = 64 KiB +WAN_QUOTA_OUT = 64 KiB +# WLAN +WLAN_QUOTA_IN = 4096 +WLAN_QUOTA_OUT = 4096 diff --git a/src/ats/test_ats_api_ril.conf b/src/ats/test_ats_api_ril.conf new file mode 100644 index 000000000..0a424c458 --- /dev/null +++ b/src/ats/test_ats_api_ril.conf @@ -0,0 +1,24 @@ +@INLINE@ ../../contrib/no_forcestart.conf + +[PATHS] +GNUNET_TEST_HOME = /tmp/test-ats-ril/ + +[ats] +# Enable RIL mode (default: NO) +MODE = ril +# Network specific inbound/outbound quotas +# UNSPECIFIED +UNSPECIFIED_QUOTA_IN = unlimited +UNSPECIFIED_QUOTA_OUT = unlimited +# LOOPBACK +LOOPBACK_QUOTA_IN = unlimited +LOOPBACK_QUOTA_OUT = unlimited +# LAN +LAN_QUOTA_IN = unlimited +LAN_QUOTA_OUT = unlimited +# WAN +WAN_QUOTA_IN = 64 KiB +WAN_QUOTA_OUT = 64 KiB +# WLAN +WLAN_QUOTA_IN = 4096 +WLAN_QUOTA_OUT = 4096 diff --git a/src/ats/test_ats_api_scheduling_add_address.c b/src/ats/test_ats_api_scheduling_add_address.c deleted file mode 100644 index 7abd76e0d..000000000 --- a/src/ats/test_ats_api_scheduling_add_address.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_add_address.c - * @brief adding addresses with scheduling API - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -uint32_t test_ats_count; - - -static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (1 == value) - { - GNUNET_SCHEDULER_add_now (&end, NULL); - } - return GNUNET_OK; -} - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -got_initial_value (void *cls, int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); - -} - - -static int -dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", subsystem, name, value); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, - &got_initial_value, &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); - -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_add_address.c */ diff --git a/src/ats/test_ats_api_scheduling_add_address_duplicate.c b/src/ats/test_ats_api_scheduling_add_address_duplicate.c deleted file mode 100644 index 9cb456636..000000000 --- a/src/ats/test_ats_api_scheduling_add_address_duplicate.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_add_address.c - * @brief adding same addresses twice with scheduling API - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -static struct GNUNET_SCHEDULER_Task * wait_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (1 < value) - { - if (NULL != wait_task) - GNUNET_SCHEDULER_cancel (wait_task); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - } - if (1 == value) - { - if (NULL == wait_task) - wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &end, NULL); - } - return GNUNET_OK; -} - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Shutting down\n"); - wait_task = NULL; - - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static int -dummy_stat (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", subsystem, name, value); - return GNUNET_OK; -} - - -static void -got_initial_value (void *cls, int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - struct GNUNET_ATS_AddressRecord *ar; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", - test_session, "test", - strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, - &test_hello_address, test_session, - test_ats_info, test_ats_count); - /* Adding duplicate */ - GNUNET_log_skip (1, GNUNET_NO); - ar = GNUNET_ATS_address_add (sched_ats, - &test_hello_address, test_session, - test_ats_info, test_ats_count); - GNUNET_log_skip (0, GNUNET_YES); - GNUNET_assert (NULL == ar); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, - &got_initial_value, &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); - -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_add_address.c */ diff --git a/src/ats/test_ats_api_scheduling_add_address_inbound.c b/src/ats/test_ats_api_scheduling_add_address_inbound.c deleted file mode 100644 index aa62b4856..000000000 --- a/src/ats/test_ats_api_scheduling_add_address_inbound.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_add_address_inbound.c - * @brief adding addresses with scheduling API - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (1 == value) - { - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); - } - if (1 < value) - { - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - } - - return GNUNET_OK; -} - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -got_initial_value (void *cls, int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - create_test_address (&test_addr, "test-plugin", NULL, NULL, 0); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = NULL; - test_hello_address.address_length = 0; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, - &test_hello_address, NULL, - test_ats_info, test_ats_count); -} - - -static int -dummy_stat (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", - subsystem, - name, - value); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, - &got_initial_value, &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); - -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_add_address_inbound.c */ diff --git a/src/ats/test_ats_api_scheduling_add_session.c b/src/ats/test_ats_api_scheduling_add_session.c deleted file mode 100644 index 4b4f22a5d..000000000 --- a/src/ats/test_ats_api_scheduling_add_session.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_add_session.c - * @brief test adding a session to an existing addresses - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - -/** - * Address record we will modify with a session later. - */ -static struct GNUNET_ATS_AddressRecord *ar; - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - static int first_stat_cb = GNUNET_YES; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if ((GNUNET_YES == first_stat_cb) && (1 == value)) - { - GNUNET_ATS_address_add_session (ar, - (struct Session *) &test_session); - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); - } - if ((GNUNET_NO == first_stat_cb) && (1 == value)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS updated existing address\n"); - } - if (value > 1) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "ATS did not update existing address, but added 2nd address!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - } - - return GNUNET_OK; -} - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - ar = GNUNET_ATS_address_add (sched_ats, - &test_hello_address, NULL, - test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_add_session.c */ diff --git a/src/ats/test_ats_api_scheduling_destroy_address.c b/src/ats/test_ats_api_scheduling_destroy_address.c deleted file mode 100644 index 23321b83b..000000000 --- a/src/ats/test_ats_api_scheduling_destroy_address.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_destroy_address.c - * @brief test destroying addresses in automatic transport selection scheduling API - * @author Christian Grothoff - * @author Matthias Wachs - * - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task *die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Our address record. - */ -static struct GNUNET_ATS_AddressRecord *ar; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent); - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", - &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - free_test_address (&test_addr); - ret = 0; -} - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - static int initial_ats_stat_cb = GNUNET_YES; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - - if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO)) - { - GNUNET_SCHEDULER_add_now (&end, NULL); - } - if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES)) - { - initial_ats_stat_cb = GNUNET_NO; - } - if (1 == value) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Statistics observed address added, now destroying address\n"); - GNUNET_ATS_address_destroy (ar); - ar = NULL; - } - return GNUNET_OK; -} - - -static void -end_badly (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_shutdown (); -} - - -static void -got_initial_value (void *cls, - int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Statistics running, now adding address\n"); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, - &address_suggest_cb, NULL); - if (NULL == sched_ats) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_shutdown (); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, - "test", test_session, - "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - ar = GNUNET_ATS_address_add (sched_ats, - &test_hello_address, - test_session, - test_ats_info, - test_ats_count); -} - - -static int -dummy_stat (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", subsystem, name, value); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - GNUNET_STATISTICS_get (stats, - "ats", - "# addresses", - TIMEOUT, - &got_initial_value, - &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_destroy_address.c */ diff --git a/src/ats/test_ats_api_scheduling_init.c b/src/ats/test_ats_api_scheduling_init.c deleted file mode 100644 index 29446d913..000000000 --- a/src/ats/test_ats_api_scheduling_init.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010,2011 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -/** - * @file ats/test_ats_api_scheduling_init.c - * @brief test automatic transport selection scheduling API init/shutdown - * @author Christian Grothoff - * @author Matthias Wachs - * - */ -#include "platform.h" -#include "gnunet_ats_service.h" -#include "gnunet_testing_lib.h" -#include "ats.h" -#include "test_ats_api_common.h" -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Initial statistics get request handle - */ -struct GNUNET_STATISTICS_GetHandle *initial_get; - -/** - * Statistics handle - */ -struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - - -static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - if (0 == value) - { - GNUNET_SCHEDULER_add_now (&end, NULL); - } - return GNUNET_OK; -} - -static int -dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", - is_persistent ? "!" : " ", subsystem, name, value); - return GNUNET_OK; -} - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); - - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - ret = 0; -} - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -got_initial_value (void *cls, int success) -{ - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); - GNUNET_CONFIGURATION_destroy (cfg); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } -} - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", cfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - initial_get = GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, - &got_initial_value, &dummy_stat, - GNUNET_CONFIGURATION_dup (cfg)); -} - - -int -main (int argc, char *argv[]) -{ - ret = 0; - if (0 != GNUNET_TESTING_peer_run ("test-ats-api", - "test_ats_api.conf", - &run, NULL)) - return 1; - return ret; -} - -/* end of file test_ats_api_scheduling_init.c */ diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c new file mode 100644 index 000000000..74cff1e61 --- /dev/null +++ b/src/ats/test_ats_lib.c @@ -0,0 +1,999 @@ +/* + This file is part of GNUnet. + Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/test_ats_lib.c + * @brief test ATS library with a generic interpreter for running ATS tests + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_ats_service.h" +#include "gnunet_testing_lib.h" +#include "test_ats_lib.h" + +/** + * Information about the last address suggestion we got for a peer. + */ +struct AddressSuggestData +{ + /** + * Which session were we given? + */ + struct Session *session; + + /** + * What address was assigned? + */ + struct GNUNET_HELLO_Address *address; + + /** + * Outbound bandwidth assigned. + */ + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; + + /** + * Inbound bandwidth assigned. + */ + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + + /** + * Was the bandwidth assigned non-zero? + */ + int active; +}; + + +/** + * Information about the last address information we got for an address. + */ +struct AddressInformationData +{ + /** + * What address is this data about? + */ + struct GNUNET_HELLO_Address *address; + + /** + * Which properties were given? + */ + struct GNUNET_ATS_Properties properties; + + /** + * Outbound bandwidth reported. + */ + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; + + /** + * Inbound bandwidth reported. + */ + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; + + /** + * Was the address said to be 'active'? + */ + int active; +}; + + +/** + * Scheduling handle + */ +static struct GNUNET_ATS_SchedulingHandle *sched_ats; + +/** + * Connectivity handle + */ +static struct GNUNET_ATS_ConnectivityHandle *con_ats; + +/** + * Performance handle + */ +static struct GNUNET_ATS_PerformanceHandle *perf_ats; + +/** + * Handle for the interpreter task. + */ +static struct GNUNET_SCHEDULER_Task *interpreter_task; + +/** + * Map from peer identities to the last address suggestion + * `struct AddressSuggestData` we got for the respective peer. + */ +static struct GNUNET_CONTAINER_MultiPeerMap *p2asd; + +/** + * Map from peer identities to the last address information + * sets for all addresses of this peer. Each peer is mapped + * to one or more `struct AddressInformationData` entries. + */ +static struct GNUNET_CONTAINER_MultiPeerMap *p2aid; + +/** + * Global timeout for the test. + */ +static struct GNUNET_TIME_Relative TIMEOUT; + +/** + * Return value from #main(). + */ +static int ret; + +/** + * Current global command offset into the #commands array. + */ +static unsigned int off; + +/** + * Commands for the current test. + */ +static struct Command *test_commands; + + + +/** + * Free `struct AddressSuggestData` entry. + * + * @param cls NULL + * @param key ignored + * @param value the `struct AddressSuggestData` to release + * @return #GNUNET_OK (continue to iterate) + */ +static int +free_asd (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) +{ + struct AddressSuggestData *asd = value; + + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (p2asd, + key, + asd)); + GNUNET_free (asd->address); + GNUNET_free (asd); + return GNUNET_OK; +} + + +/** + * Free `struct AddressInformationData` entry. + * + * @param cls NULL + * @param key ignored + * @param value the `struct AddressSuggestData` to release + * @return #GNUNET_OK (continue to iterate) + */ +static int +free_aid (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) +{ + struct AddressInformationData *aid = value; + + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_remove (p2aid, + key, + aid)); + GNUNET_free (aid->address); + GNUNET_free (aid); + return GNUNET_OK; +} + + +/** + * Find latest address suggestion made for the given peer. + * + * @param pid peer to look up + * @return NULL if peer was never involved + */ +static struct AddressSuggestData * +find_address_suggestion (const struct GNUNET_PeerIdentity *pid) +{ + return GNUNET_CONTAINER_multipeermap_get (p2asd, + pid); +} + + +/** + * Closure for #match_address() + */ +struct MatchAddressContext +{ + /** + * Address to find. + */ + const struct GNUNET_HELLO_Address *addr; + + /** + * Where to return address information if found. + */ + struct AddressInformationData *ret; +}; + + +/** + * Find matching address information. + * + * @param cls a `struct MatchAddressContext` + * @param key unused + * @param value a `struct AddressInformationData` + * @return #GNUNET_OK if not found + */ +static int +match_address (void *cls, + const struct GNUNET_PeerIdentity *key, + void *value) +{ + struct MatchAddressContext *mac = cls; + struct AddressInformationData *aid = value; + + if (0 == GNUNET_HELLO_address_cmp (mac->addr, + aid->address)) + { + mac->ret = aid; + return GNUNET_NO; + } + return GNUNET_OK; +} + + +/** + * Find latest address information made for the given address. + * + * @param addr address to look up + * @return NULL if peer was never involved + */ +static struct AddressInformationData * +find_address_information (const struct GNUNET_HELLO_Address *addr) +{ + struct MatchAddressContext mac; + + mac.ret = NULL; + mac.addr = addr; + GNUNET_CONTAINER_multipeermap_get_multiple (p2aid, + &addr->peer, + &match_address, + &mac); + return mac.ret; +} + + +/** + * Task run to terminate the testcase. + * + * @param cls NULL + * @param tc unused + */ +static void +end (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (0 != ret) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Test failed at stage %u %s\n", + off, + (NULL != test_commands[off].label) + ? test_commands[off].label + : ""); + if (NULL != interpreter_task) + { + GNUNET_SCHEDULER_cancel (interpreter_task); + interpreter_task = NULL; + } + if (NULL != sched_ats) + { + GNUNET_ATS_scheduling_done (sched_ats); + sched_ats = NULL; + } + if (NULL != con_ats) + { + GNUNET_ATS_connectivity_done (con_ats); + con_ats = NULL; + } + if (NULL != perf_ats) + { + GNUNET_ATS_performance_done (perf_ats); + perf_ats = NULL; + } + if (NULL != p2asd) + { + GNUNET_CONTAINER_multipeermap_iterate (p2asd, + &free_asd, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (p2asd); + p2asd = NULL; + } + if (NULL != p2aid) + { + GNUNET_CONTAINER_multipeermap_iterate (p2aid, + &free_aid, + NULL); + GNUNET_CONTAINER_multipeermap_destroy (p2aid); + p2aid = NULL; + } +} + + +/** + * Main interpreter loop. Runs the steps of the test. + * + * @param cls NULL + * @param tc unused + */ +static void +interpreter (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * Run the interpreter next. + */ +static void +run_interpreter () +{ + if (NULL != interpreter_task) + GNUNET_SCHEDULER_cancel (interpreter_task); + interpreter_task = GNUNET_SCHEDULER_add_now (&interpreter, + NULL); +} + + +/** + * Initialize public key of a peer based on a single number. + * + * @param pid number to use as the basis + * @param pk resulting fake public key + */ +static void +make_peer (uint32_t pid, + struct GNUNET_PeerIdentity *pk) +{ + memset (pk, + (int) pid, + sizeof (struct GNUNET_PeerIdentity)); + memcpy (pk, + &pid, + sizeof (uint32_t)); +} + + +/** + * Generate a fake address based on the given parameters. + * + * @param pid number of the peer + * @param num number of the address at peer @a pid + * @param addr_flags flags to use for the address + * @return the address + */ +static struct GNUNET_HELLO_Address * +make_address (uint32_t pid, + uint32_t num, + enum GNUNET_HELLO_AddressInfo addr_flags) +{ + struct GNUNET_PeerIdentity pk; + uint32_t nbo; + + nbo = htonl (num); + make_peer (pid, + &pk); + return GNUNET_HELLO_address_allocate (&pk, + "test", + &nbo, + sizeof (nbo), + addr_flags); +} + + +/** + * Our dummy sessions. + */ +struct Session { + /** + * Field to avoid `0 == sizeof(struct Session)`. + */ + unsigned int non_empty; +}; + + +/** + * Create a session instance for ATS. + * + * @param i which session number to return + * @return NULL if @a i is 0, otherwise a pointer unique to @a i + */ +static struct Session * +make_session (unsigned int i) +{ + struct Session *baseptr = NULL; + + if (0 == i) + return NULL; + /* Yes, these are *intentionally* out-of-bounds, + and offset from NULL, as nobody should ever + use those other than to compare pointers! */ + return baseptr + i; +} + + +/** + * Find a @a code command before the global #off with the + * specified @a label. + * + * @param code opcode to look for + * @param label label to look for, NULL for none + * @return previous command with the matching label + */ +static struct Command * +find_command (enum CommandCode code, + const char *label) +{ + int i; + + if (NULL == label) + return NULL; + for (i=off-1;i>=0;i--) + if ( (code == test_commands[i].code) && + (0 == strcmp (test_commands[i].label, + label)) ) + return &test_commands[i]; + GNUNET_break (0); + return NULL; +} + + +/** + * Function called from #GNUNET_ATS_performance_list_addresses when + * we process a #CMD_LIST_ADDRESSES command. + * + * @param cls the `struct Command` that caused the call + * @param address the address, NULL if ATS service was disconnected + * @param address_active #GNUNET_YES if this address is actively used + * to maintain a connection to a peer; + * #GNUNET_NO if the address is not actively used; + * #GNUNET_SYSERR if this address is no longer available for ATS + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection + * @param prop performance data for the address + */ +static void +info_cb (void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *prop) +{ + struct Command *c = cls; + struct CommandListAddresses *cmd = &c->details.list_addresses; + + if (NULL == address) + { + cmd->alh = NULL; + /* we are done with the iteration, continue to execute */ + if ( (cmd->calls < cmd->min_calls) && + (cmd->active_calls < cmd->min_active_calls) ) + { + GNUNET_SCHEDULER_shutdown (); + return; + } + off++; + run_interpreter (); + return; + } + switch (address_active) + { + case GNUNET_YES: + cmd->active_calls++; + cmd->calls++; + break; + case GNUNET_NO: + cmd->calls++; + break; + case GNUNET_SYSERR: + return; + } + if ( (cmd->calls > cmd->max_calls) && + (cmd->active_calls < cmd->max_active_calls) ) + { + GNUNET_break (0); + GNUNET_ATS_performance_list_addresses_cancel (cmd->alh); + cmd->alh = NULL; + GNUNET_SCHEDULER_shutdown (); + return; + } +} + + +/** + * Main interpreter loop. Runs the steps of the test. + * + * @param cls NULL + * @param tc unused + */ +static void +interpreter (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) + +{ + struct Command *cmd; + + interpreter_task = NULL; + while (1) + { + cmd = &test_commands[off]; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "#%u: %d %s\n", + off, + (int) cmd->code, + (NULL != cmd->label) ? cmd->label : ""); + switch (cmd->code) + { + case CMD_END_PASS: + ret = 0; + GNUNET_SCHEDULER_shutdown (); + return; + case CMD_ADD_ADDRESS: + { + struct GNUNET_HELLO_Address *addr; + struct Session *session; + + addr = make_address (cmd->details.add_address.pid, + cmd->details.add_address.addr_num, + cmd->details.add_address.addr_flags); + session = make_session (cmd->details.add_address.session); + if (cmd->details.add_address.expect_fail) + GNUNET_log_skip (1, GNUNET_NO); + cmd->details.add_address.ar + = GNUNET_ATS_address_add (sched_ats, + addr, + session, + &cmd->details.add_address.properties); + GNUNET_free (addr); + if (cmd->details.add_address.expect_fail) + { + GNUNET_log_skip (0, GNUNET_YES); + } + else if (NULL == cmd->details.add_address.ar) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + off++; + break; + } + case CMD_DEL_ADDRESS: + { + struct Command *add; + + add = find_command (CMD_ADD_ADDRESS, + cmd->details.del_address.add_label); + GNUNET_assert (NULL != add->details.add_address.ar); + GNUNET_ATS_address_destroy (add->details.add_address.ar); + add->details.add_address.ar = NULL; + off++; + break; + } + case CMD_AWAIT_ADDRESS_SUGGESTION: + { + struct GNUNET_PeerIdentity pid; + struct GNUNET_HELLO_Address *addr; + struct Command *add; + struct AddressSuggestData *asd; + int done; + + make_peer (cmd->details.await_address_suggestion.pid, + &pid); + asd = find_address_suggestion (&pid); + if (NULL == asd) + return; + if (GNUNET_NO == asd->active) + return; + done = GNUNET_YES; + if (NULL != cmd->details.await_address_suggestion.add_label) + { + done = GNUNET_NO; + add = find_command (CMD_ADD_ADDRESS, + cmd->details.await_address_suggestion.add_label); + addr = make_address (add->details.add_address.pid, + add->details.add_address.addr_num, + add->details.add_address.addr_flags); + if ( (asd->session == + make_session (add->details.add_address.session)) && + (0 == + GNUNET_HELLO_address_cmp (addr, + asd->address)) ) + done = GNUNET_YES; + GNUNET_free (addr); + } + if (GNUNET_NO == done) + return; + off++; + break; + } + case CMD_AWAIT_DISCONNECT_SUGGESTION: + { + struct GNUNET_PeerIdentity pid; + struct AddressSuggestData *asd; + + make_peer (cmd->details.await_disconnect_suggestion.pid, + &pid); + asd = find_address_suggestion (&pid); + if (NULL == asd) + return; + if (GNUNET_NO == asd->active) + return; + off++; + break; + } + case CMD_REQUEST_CONNECTION_START: + { + struct GNUNET_PeerIdentity pid; + + make_peer (cmd->details.request_connection_start.pid, + &pid); + cmd->details.request_connection_start.csh + = GNUNET_ATS_connectivity_suggest (con_ats, + &pid); + off++; + break; + } + case CMD_REQUEST_CONNECTION_STOP: + { + struct Command *start; + + start = find_command (CMD_REQUEST_CONNECTION_START, + cmd->details.request_connection_stop.connect_label); + GNUNET_ATS_connectivity_suggest_cancel (start->details.request_connection_start.csh); + start->details.request_connection_start.csh = NULL; + off++; + break; + } + case CMD_AWAIT_ADDRESS_INFORMATION: + { + struct AddressInformationData *aid; + struct Command *add; + struct Command *update; + struct GNUNET_HELLO_Address *addr; + const struct GNUNET_ATS_Properties *cmp; + + add = find_command (CMD_ADD_ADDRESS, + cmd->details.await_address_information.add_label); + update = find_command (CMD_UPDATE_ADDRESS, + cmd->details.await_address_information.update_label); + addr = make_address (add->details.add_address.pid, + add->details.add_address.addr_num, + add->details.add_address.addr_flags); + aid = find_address_information (addr); + GNUNET_free (addr); + if (NULL == update) + cmp = &add->details.add_address.properties; + else + cmp = &update->details.update_address.properties; + if ( (NULL != aid) && + (0 == memcmp (cmp, + &aid->properties, + sizeof (struct GNUNET_ATS_Properties))) ) + { + off++; + break; + } + return; + } + case CMD_UPDATE_ADDRESS: + { + struct Command *add; + + add = find_command (CMD_ADD_ADDRESS, + cmd->details.update_address.add_label); + GNUNET_assert (NULL != add->details.add_address.ar); + GNUNET_ATS_address_update (add->details.add_address.ar, + &cmd->details.update_address.properties); + off++; + break; + } + case CMD_ADD_SESSION: + { + struct Command *add; + struct Session *session; + + add = find_command (CMD_ADD_ADDRESS, + cmd->details.add_session.add_label); + session = make_session (cmd->details.add_session.session); + GNUNET_assert (NULL != add->details.add_address.ar); + GNUNET_ATS_address_add_session (add->details.add_address.ar, + session); + off++; + break; + } + case CMD_DEL_SESSION: + { + struct Command *add_address; + struct Command *add_session; + struct Session *session; + + add_session = find_command (CMD_ADD_SESSION, + cmd->details.del_session.add_session_label); + add_address = find_command (CMD_ADD_ADDRESS, + add_session->details.add_session.add_label); + GNUNET_assert (NULL != add_address->details.add_address.ar); + session = make_session (add_session->details.add_session.session); + GNUNET_ATS_address_del_session (add_address->details.add_address.ar, + session); + off++; + break; + } + case CMD_CHANGE_PREFERENCE: + { + struct GNUNET_PeerIdentity pid; + + make_peer (cmd->details.change_preference.pid, + &pid); + GNUNET_ATS_performance_change_preference (perf_ats, + &pid, + GNUNET_ATS_PREFERENCE_END); + off++; + break; + } + case CMD_PROVIDE_FEEDBACK: + { + struct GNUNET_PeerIdentity pid; + + make_peer (cmd->details.provide_feedback.pid, + &pid); + GNUNET_ATS_performance_give_feedback (perf_ats, + &pid, + cmd->details.provide_feedback.scope, + GNUNET_ATS_PREFERENCE_END); + off++; + break; + } + case CMD_LIST_ADDRESSES: + { + struct GNUNET_PeerIdentity pid; + + make_peer (cmd->details.list_addresses.pid, + &pid); + cmd->details.list_addresses.alh + = GNUNET_ATS_performance_list_addresses (perf_ats, + &pid, + cmd->details.list_addresses.all, + &info_cb, + cmd); + return; + } + } /* end switch */ + } /* end while(1) */ +} + + +/** + * Signature of a function called by ATS with the current bandwidth + * and address preferences as determined by ATS. + * + * @param cls closure, should point to "asc-closure" + * @param peer for which we suggest an address, NULL if ATS connection died + * @param address suggested address (including peer identity of the peer), + * may be NULL to signal disconnect from peer + * @param session session to use, NULL to establish a new outgoing session + * @param bandwidth_out assigned outbound bandwidth for the connection, + * 0 to signal disconnect + * @param bandwidth_in assigned inbound bandwidth for the connection, + * 0 to signal disconnect + */ +static void +address_suggest_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address, + struct Session *session, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) +{ + const char *asc_cls = cls; + struct AddressSuggestData *asd; + + GNUNET_break (0 == strcmp (asc_cls, "asc-closure")); + if (NULL == peer) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Connection to ATS died, likely a crash!\n"); + GNUNET_SCHEDULER_shutdown (); +#if 0 + /* This is what we should do if we wanted to continue past + the ATS crash. */ + GNUNET_CONTAINER_multipeermap_iterate (p2asd, + &free_asd, + NULL); + GNUNET_CONTAINER_multipeermap_iterate (p2aid, + &free_aid, + NULL); +#endif + return; + } + + asd = find_address_suggestion (peer); + if (NULL == asd) + { + asd = GNUNET_new (struct AddressSuggestData); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put (p2asd, + peer, + asd, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } + if ( (0 == ntohl (bandwidth_out.value__)) && + (0 == ntohl (bandwidth_in.value__)) ) + asd->active = GNUNET_NO; + else + asd->active = GNUNET_YES; + asd->bandwidth_out = bandwidth_out; + asd->bandwidth_in = bandwidth_in; + asd->session = session; + GNUNET_free_non_null (asd->address); + asd->address = NULL; + if (NULL != address) + asd->address = GNUNET_HELLO_address_copy (address); + run_interpreter (); +} + + +/** + * Signature of a function that is called with QoS information about an address. + * + * @param cls closure, should point to "aic-closure" + * @param address the address, NULL if ATS service was disconnected + * @param address_active #GNUNET_YES if this address is actively used + * to maintain a connection to a peer; + * #GNUNET_NO if the address is not actively used; + * #GNUNET_SYSERR if this address is no longer available for ATS + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection + * @param prop performance data for the address + */ +static void +address_information_cb (void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *prop) +{ + const char *aic_cls = cls; + struct AddressInformationData *aid; + + GNUNET_break (0 == strcmp (aic_cls, "aic-closure")); + if (NULL == address) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Connection to ATS died, likely a crash!\n"); + GNUNET_CONTAINER_multipeermap_iterate (p2aid, + &free_aid, + NULL); + return; + } + + aid = find_address_information (address); + if (NULL == aid) + { + aid = GNUNET_new (struct AddressInformationData); + aid->address = GNUNET_HELLO_address_copy (address); + GNUNET_assert (GNUNET_YES == + GNUNET_CONTAINER_multipeermap_put (p2aid, + &address->peer, + aid, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); + } + aid->active = address_active; + aid->bandwidth_out = bandwidth_out; + aid->bandwidth_in = bandwidth_in; + aid->properties = *prop; + run_interpreter (); +} + + +/** + * Function run once the ATS service has been started. + * + * @param cls NULL + * @param cfg configuration for the testcase + * @param peer handle to the peer + */ +static void +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) +{ + p2asd = GNUNET_CONTAINER_multipeermap_create (128, + GNUNET_NO); + p2aid = GNUNET_CONTAINER_multipeermap_create (128, + GNUNET_NO); + GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &end, + NULL); + + sched_ats = GNUNET_ATS_scheduling_init (cfg, + &address_suggest_cb, + "asc-closure"); + if (NULL == sched_ats) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + con_ats = GNUNET_ATS_connectivity_init (cfg); + if (NULL == con_ats) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + perf_ats = GNUNET_ATS_performance_init (cfg, + &address_information_cb, + "aic-closure"); + if (NULL == perf_ats) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } + run_interpreter (); +} + + +/** + * Run ATS test. + * + * @param argc length of @a argv + * @param argv command line + * @param cmds commands to run with the interpreter + * @param timeout how long is the test allowed to take? + * @return 0 on success + */ +int +TEST_ATS_run (int argc, + char *argv[], + struct Command *cmds, + struct GNUNET_TIME_Relative timeout) +{ + char *test_filename = GNUNET_strdup (argv[0]); + char *sep; + char *config_file; + char *underscore; + + test_commands = cmds; + TIMEOUT = timeout; + if (NULL != (sep = strstr (test_filename, ".exe"))) + sep[0] = '\0'; + underscore = strrchr (test_filename, (int) '_'); + GNUNET_assert (NULL != underscore); + GNUNET_asprintf (&config_file, + "test_ats_api_%s.conf", + underscore + 1); + ret = 2; + if (0 != GNUNET_TESTING_peer_run ("test-ats-api", + config_file, + &run, NULL)) + ret = 1; + GNUNET_free (test_filename); + GNUNET_free (config_file); + return ret; +} + +/* end of test_ats_lib.c */ diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h new file mode 100644 index 000000000..590aac750 --- /dev/null +++ b/src/ats/test_ats_lib.h @@ -0,0 +1,467 @@ +/* + This file is part of GNUnet. + Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file ats/test_ats_lib.h + * @brief test ATS library with a generic interpreter for running ATS tests + * @author Christian Grothoff + */ +#ifndef TEST_ATS_LIB_H +#define TEST_ATS_LIB_H + +#include "gnunet_util_lib.h" +#include "gnunet_ats_service.h" +#include "gnunet_testing_lib.h" + + +/** + * Commands for the interpreter. + */ +enum CommandCode +{ + /** + * End the test (passing). + */ + CMD_END_PASS = 0, + + /** + * Call #GNUNET_ATS_address_add(). + */ + CMD_ADD_ADDRESS, + + /** + * Call #GNUNET_ATS_address_del(). + */ + CMD_DEL_ADDRESS, + + /** + * Wait for ATS to suggest address. + */ + CMD_AWAIT_ADDRESS_SUGGESTION, + + /** + * Wait for ATS to suggest disconnect. + */ + CMD_AWAIT_DISCONNECT_SUGGESTION, + + /** + * Ask ATS to connect to a peer, using + * #GNUNET_ATS_connectivity_suggest(). + */ + CMD_REQUEST_CONNECTION_START, + + /** + * Tell ATS we no longer need a connection to a peer, using + * #GNUNET_ATS_connectivity_suggest_cancel(). + */ + CMD_REQUEST_CONNECTION_STOP, + + /** + * Wait for certain address information to be provided. + */ + CMD_AWAIT_ADDRESS_INFORMATION, + + /** + * Update properties of an address, using + * #GNUNET_ATS_address_update(). + */ + CMD_UPDATE_ADDRESS, + + /** + * Add session to an address, using + * #GNUNET_ATS_address_add_session(). + */ + CMD_ADD_SESSION, + + /** + * Remove session from an address, using + * #GNUNET_ATS_address_del_session(). + */ + CMD_DEL_SESSION, + + /** + * Change performance preferences for a peer, testing + * #GNUNET_ATS_performance_change_preference(). + */ + CMD_CHANGE_PREFERENCE, + + /** + * Provide allocation quality feedback, testing + * #GNUNET_ATS_performance_give_feedback(). + */ + CMD_PROVIDE_FEEDBACK, + + /** + * Obtain list of all addresses, testing + * #GNUNET_ATS_performance_list_addresses(). + */ + CMD_LIST_ADDRESSES + + /* TODO: reserve bandwidth */ + +}; + + +/** + * Details for the #CMD_ADD_ADDRESS command. + */ +struct CommandAddAddress +{ + /** + * Number of the peer (used to generate PID). + */ + unsigned int pid; + + /** + * Number of the address (used to generate binary address). + */ + unsigned int addr_num; + + /** + * Session to supply, 0 for NULL. + */ + unsigned int session; + + /** + * Flags to set for the address. + */ + enum GNUNET_HELLO_AddressInfo addr_flags; + + /** + * Performance properties to supply. + */ + struct GNUNET_ATS_Properties properties; + + /** + * Expect the operation to fail (duplicate). + */ + int expect_fail; + + /** + * Here the result of the add address operation will be stored. + */ + struct GNUNET_ATS_AddressRecord *ar; +}; + + +/** + * Details for the #CMD_DEL_ADDRESS command. + */ +struct CommandDelAddress +{ + /** + * Label of the corresponding #CMD_ADD_ADDRESS that + * we are now to remove. + */ + const char *add_label; +}; + + +/** + * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. + */ +struct CommandAwaitAddressSuggestion +{ + /** + * For which peer do we expect a suggestion? + */ + unsigned int pid; + + /** + * If we expect the address suggested to match a particular + * addition, specify the label of the add operation here. Otherwise + * use NULL for "any" available address. + */ + const char *add_label; + +}; + + +/** + * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. + */ +struct CommandAwaitDisconnectSuggestion +{ + /** + * For which peer do we expect the disconnect? + */ + unsigned int pid; + +}; + + +/** + * Details for the #CMD_REQUEST_CONNECTION_START command. + */ +struct CommandRequestConnectionStart +{ + /** + * Identity of the peer we would like to connect to. + */ + unsigned int pid; + + /** + * Location where we store the handle returned from + * #GNUNET_ATS_connectivity_suggest(). + */ + struct GNUNET_ATS_ConnectivitySuggestHandle *csh; +}; + + +/** + * Details for the #CMD_REQUEST_CONNECTION_STOP command. + */ +struct CommandRequestConnectionStop +{ + /** + * Label of the corresponding #CMD_REQUEST_CONNECTION_START that + * we are now stopping. + */ + const char *connect_label; +}; + + +/** + * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. + */ +struct CommandAwaitAddressInformation +{ + /** + * For which address do we expect information? + * The address is identified by the respective + * label of the corresponding add operation. + */ + const char *add_label; + + /** + * Label of a possible update operation that may + * have modified the properties. NULL to use + * the properties from the @e add_label. + */ + const char *update_label; + +}; + + +/** + * Details for the #CMD_UPDATE_ADDRESS command. + */ +struct CommandUpdateAddress +{ + /** + * Label of the addresses's add operation. + */ + const char *add_label; + + /** + * Performance properties to supply. + */ + struct GNUNET_ATS_Properties properties; + +}; + + +/** + * Details for the #CMD_ADD_SESSION command. + */ +struct CommandAddSession +{ + /** + * Label of the addresses's add operation. + */ + const char *add_label; + + /** + * Session to supply. + */ + unsigned int session; + +}; + + +/** + * Details for the #CMD_DEL_SESSION command. + */ +struct CommandDelSession +{ + /** + * Label of the addresses's add operation. + */ + const char *add_session_label; + +}; + + +/** + * Details for the #CMD_CHANGE_PREFERENCE command. + */ +struct CommandChangePreference +{ + /** + * Identity of the peer we have a preference change towards. + */ + unsigned int pid; + + /* FIXME: preference details! */ + +}; + + +/** + * Details for the #CMD_PROVIDE_FEEDBACK command. + */ +struct CommandProvideFeedback +{ + /** + * Identity of the peer we have a feedback for. + */ + unsigned int pid; + + /** + * Over which timeframe does the feedback apply? + */ + struct GNUNET_TIME_Relative scope; + + /* FIXME: feedback details! */ +}; + + +/** + * Details for the #CMD_LIST_ADDRESSES command. + */ +struct CommandListAddresses +{ + /** + * Identity of the peer we want a list for. + */ + unsigned int pid; + + /** + * All addresses or just active? + */ + int all; + + /** + * Minimum number of addresses the callback may report. + */ + unsigned int min_calls; + + /** + * Maximum number of addresses the callback may report. + */ + unsigned int max_calls; + + /** + * Minimum number of active addresses the callback may report. + */ + unsigned int min_active_calls; + + /** + * Maximum number of active addresses the callback may report. + */ + unsigned int max_active_calls; + + /** + * Number of calls the command invoked the callback with + * an address marked as active. (Set by command). + */ + unsigned int active_calls; + + /** + * Number of calls the command invoked the callback with + * any address marked as available to ATS. (Set by command). + */ + unsigned int calls; + + /** + * Location where we store the return value from + * #GNUNET_ATS_performance_list_addresses(). + */ + struct GNUNET_ATS_AddressListHandle *alh; + +}; + + +/** + * A command for the test case interpreter. + */ +struct Command +{ + /** + * Command code to run. + */ + enum CommandCode code; + + /** + * Commands can be given a label so we can reference them later. + */ + const char *label; + + /** + * Additional arguments to commands, if any. + */ + union { + + struct CommandAddAddress add_address; + + struct CommandDelAddress del_address; + + struct CommandAwaitAddressSuggestion await_address_suggestion; + + struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion; + + struct CommandRequestConnectionStart request_connection_start; + + struct CommandRequestConnectionStop request_connection_stop; + + struct CommandAwaitAddressInformation await_address_information; + + struct CommandUpdateAddress update_address; + + struct CommandAddSession add_session; + + struct CommandDelSession del_session; + + struct CommandChangePreference change_preference; + + struct CommandProvideFeedback provide_feedback; + + struct CommandListAddresses list_addresses; + + } details; + +}; + + +/** + * Run ATS test. + * + * @param argc length of @a argv + * @param argv command line + * @param cmds commands to run with the interpreter + * @param timeout how long is the test allowed to take? + * @return 0 on success + */ +int +TEST_ATS_run (int argc, + char *argv[], + struct Command *cmds, + struct GNUNET_TIME_Relative timeout); + +#endif diff --git a/src/ats/test_ats_mlp.conf b/src/ats/test_ats_mlp.conf index 008bee904..51082ae93 100644 --- a/src/ats/test_ats_mlp.conf +++ b/src/ats/test_ats_mlp.conf @@ -1,5 +1,5 @@ [PATHS] -GNUNET_TEST_HOME = /tmp/test-ats-api-scheduling/ +GNUNET_TEST_HOME = /tmp/test-ats-mlp/ [ats] # Enable MLP mode (default: NO) diff --git a/src/ats/test_ats_solver_add_address.c b/src/ats/test_ats_solver_add_address.c deleted file mode 100644 index b2f0eacd2..000000000 --- a/src/ats/test_ats_solver_add_address.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_solver_add_address.c - * @brief solver test: add address - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" -#include "gnunet_ats_service.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static int -stat_cb (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent); - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - free_test_address (&test_addr); - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - /* ignored in this test */ -} - - -static int -stat_cb (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if (1 == value) - { - GNUNET_SCHEDULER_add_now (&end, NULL); - } - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", mycfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); - if (NULL == sched_ats) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - char *sep; - char *src_filename = GNUNET_strdup (__FILE__); - char *test_filename = GNUNET_strdup (argv[0]); - char *config_file; - char *solver; - - ret = 0; - - if (NULL == (sep = (strstr (src_filename,".c")))) - { - GNUNET_break (0); - return -1; - } - sep[0] = '\0'; - - if (NULL != (sep = strstr (test_filename, ".exe"))) - sep[0] = '\0'; - - if (NULL == (solver = strstr (test_filename, src_filename))) - { - GNUNET_break (0); - return -1; - } - solver += strlen (src_filename) +1; - - if (0 == strcmp(solver, "proportional")) - { - config_file = "test_ats_solver_proportional.conf"; - } - else if (0 == strcmp(solver, "mlp")) - { - config_file = "test_ats_solver_mlp.conf"; - } - else if ((0 == strcmp(solver, "ril"))) - { - config_file = "test_ats_solver_ril.conf"; - } - else - { - GNUNET_break (0); - GNUNET_free (src_filename); - GNUNET_free (test_filename); - return 1; - } - - GNUNET_free (src_filename); - GNUNET_free (test_filename); - - if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", - config_file, &run, NULL )) - return GNUNET_SYSERR; - - return ret; -} - -/* end of file test_ats_solver_add_address.c */ diff --git a/src/ats/test_ats_solver_add_address_and_request.c b/src/ats/test_ats_solver_add_address_and_request.c deleted file mode 100644 index 1a3545967..000000000 --- a/src/ats/test_ats_solver_add_address_and_request.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - This file is part of GNUnet. - Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_solver_add_address.c - * @brief solver test: add address, request address and wait for suggest - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" -#include "gnunet_ats_service.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task *die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Connectivity handle - */ -static struct GNUNET_ATS_ConnectivityHandle *connect_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static int -stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent); - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - if (NULL != connect_ats) - { - GNUNET_ATS_connectivity_done (connect_ats); - connect_ats = NULL; - } - - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_assert (NULL != address); - GNUNET_assert (NULL == session); - GNUNET_assert (ntohl(bandwidth_in.value__) > 0); - GNUNET_assert (ntohl(bandwidth_out.value__) > 0); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received sugggestion for peer `%s'\n", - GNUNET_i2s (peer)); - GNUNET_SCHEDULER_add_now (&end, NULL); -} - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if (NULL == sh) - sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", mycfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - - connect_ats = GNUNET_ATS_connectivity_init (mycfg); - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, - &test_hello_address, NULL, - test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - char *sep; - char *src_filename = GNUNET_strdup (__FILE__); - char *test_filename = GNUNET_strdup (argv[0]); - char *config_file; - char *solver; - int delayed = GNUNET_NO; - - ret = 0; - - if (NULL == (sep = (strstr (src_filename,".c")))) - { - GNUNET_break (0); - return -1; - } - sep[0] = '\0'; - - if (NULL != (sep = strstr (test_filename, ".exe"))) - sep[0] = '\0'; - - if (NULL == (solver = strstr (test_filename, src_filename))) - { - GNUNET_break (0); - return -1; - } - - solver += strlen (src_filename) +1; - - if (NULL != strstr (solver, "delayed_")) - { - delayed = GNUNET_YES; - solver += strlen ("delayed_"); - } - - if (0 == strcmp(solver, "proportional")) - { - if (delayed) - config_file = "test_ats_solver_delayed_proportional.conf"; - else - config_file = "test_ats_solver_proportional.conf"; - } - else if (0 == strcmp(solver, "mlp")) - { - if (delayed) - config_file = "test_ats_solver_delayed_mlp.conf"; - else - config_file = "test_ats_solver_mlp.conf"; - } - else if ((0 == strcmp(solver, "ril"))) - { - if (delayed) - config_file = "test_ats_solver_delayed_ril.conf"; - else - config_file = "test_ats_solver_ril.conf"; - } - else - { - GNUNET_break (0); - GNUNET_free (src_filename); - GNUNET_free (test_filename); - FPRINTF (stderr, "Invalid test name or configuration not found `%s'\n",src_filename); - return 1; - } - - GNUNET_free (src_filename); - GNUNET_free (test_filename); - - if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", - config_file, &run, NULL )) - return GNUNET_SYSERR; - - return ret; -} - -/* end of file test_ats_solver_add_address.c */ diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c deleted file mode 100644 index 77c903f1c..000000000 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ /dev/null @@ -1,455 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_solver_alternative_after_delete_address.c - * @brief solver test: add 2 addresses, request address, delete, expect alternative - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" -#include "gnunet_ats_service.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Connectivity handle - */ -static struct GNUNET_ATS_ConnectivityHandle *connect_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Alternative test address - */ -static struct Test_Address alt_test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address alt_test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - -/** - * Test state - */ -static int addresses_added; - -static int first_address_suggested; - -static int first_address_deleted; - -static int second_address_deleted; - -static int second_address_suggested = GNUNET_YES; - -static struct GNUNET_HELLO_Address *first_suggestion; - -static struct GNUNET_HELLO_Address *second_suggestion; - -/** - * 1st Address we will destroy. - */ -static struct GNUNET_ATS_AddressRecord *ar; - -/** - * 2nd Address we will destroy. - */ -static struct GNUNET_ATS_AddressRecord *ar2; - - -static int -stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent); - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - if (NULL != connect_ats) - { - GNUNET_ATS_connectivity_done (connect_ats); - connect_ats = NULL; - } - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - GNUNET_STATISTICS_watch_cancel (stats, - "ats", - "# addresses", - &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - free_test_address (&test_addr); - GNUNET_free_non_null (first_suggestion); - first_suggestion = NULL; - GNUNET_free_non_null (second_suggestion); - second_suggestion = NULL; - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -end_badly_now () -{ - if (NULL != die_task) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - GNUNET_SCHEDULER_add_now (&end_badly, NULL); -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received a sugggestion for peer `%s'\n", - GNUNET_i2s (peer)); - if (GNUNET_NO == first_address_suggested) - { - if (NULL == first_suggestion) - { - if ((NULL == address) || (NULL != session)) - { - GNUNET_break (0); - end_badly_now (); - return; - } - if ((ntohl(bandwidth_in.value__) == 0) || - (ntohl(bandwidth_out.value__) == 0)) - { - GNUNET_break (0); - end_badly_now (); - return; - } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received 1st sugggestion for peer `%s' : `%s'\n", - GNUNET_i2s (&address->peer), (char *) address->address); - - first_suggestion = GNUNET_HELLO_address_copy (address); - first_address_suggested = GNUNET_YES; - - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Deleting 1st address for peer `%s' : `%s'\n", - GNUNET_i2s (&address->peer), - (char *) address->address); - if (0 == (strcmp ((char *) address->address, - "test"))) - { - GNUNET_assert (NULL != ar); - GNUNET_ATS_address_destroy (ar); - ar = NULL; - } - else - { - GNUNET_assert (NULL != ar2); - GNUNET_ATS_address_destroy (ar2); - ar2 = NULL; - } - - first_address_deleted = GNUNET_YES; - - return; - } - } - if (GNUNET_YES == first_address_deleted) - { - if (NULL == second_suggestion) - { - if ((NULL == address) || (NULL != session)) - { - GNUNET_break (0); - end_badly_now (); - return; - } - - if (0 != - memcmp (address->address, - first_suggestion->address, - (first_suggestion->address_length < address->address_length) - ? first_suggestion->address_length : address->address_length)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received 2nd sugggestion for peer `%s' : `%s'\n", - GNUNET_i2s (&address->peer), - (char *) address->address); - second_suggestion = GNUNET_HELLO_address_copy (address); - second_address_suggested = GNUNET_YES; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Deleting 2nd address for peer `%s' : `%s'\n", - GNUNET_i2s (&address->peer), - (char *) address->address); - if (NULL != ar) - { - GNUNET_assert (NULL == ar2); - GNUNET_ATS_address_destroy (ar); - ar = NULL; - } - else - { - GNUNET_assert (NULL != ar2); - GNUNET_ATS_address_destroy (ar2); - ar2 = NULL; - } - second_address_deleted = GNUNET_YES; - return; - } - } - } - if (GNUNET_YES == second_address_deleted) - { - /* Expecting disconnect */ - if ((ntohl(bandwidth_in.value__) == 0) && - (ntohl(bandwidth_out.value__) == 0)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS tells me to disconnect\n"); - GNUNET_SCHEDULER_add_now (&end, NULL); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Expected disconnect but received address `%s' with bandwidth \n", - (char *) address->address); - } - } -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if ((GNUNET_NO == addresses_added) && (value == 2)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "All addresses added, requesting....\n"); - /* We have 2 addresses, so we can request */ - addresses_added = GNUNET_YES; - GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); - } - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", mycfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - connect_ats = GNUNET_ATS_connectivity_init (mycfg); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Could not connect to ATS scheduling!\n"); - end_badly_now (); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, - "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding alternative address without session */ - test_session = NULL; - create_test_address (&alt_test_addr, "test", test_session, - "alt_test", strlen ("alt_test") + 1); - alt_test_hello_address.peer = p.id; - alt_test_hello_address.transport_name = alt_test_addr.plugin; - alt_test_hello_address.address = alt_test_addr.addr; - alt_test_hello_address.address_length = alt_test_addr.addr_len; - - - /* Adding address */ - ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, - test_ats_info, test_ats_count); - /* Adding alternative address */ - ar2 = GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL, - test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - char *sep; - char *src_filename = GNUNET_strdup (__FILE__); - char *test_filename = GNUNET_strdup (argv[0]); - const char *config_file; - char *solver; - - ret = 0; - - if (NULL == (sep = (strstr (src_filename, ".c")))) - { - GNUNET_break (0); - return -1; - } - sep[0] = '\0'; - - if (NULL != (sep = strstr (test_filename, ".exe"))) - sep[0] = '\0'; - - if (NULL == (solver = strstr (test_filename, src_filename))) - { - GNUNET_break (0); - return -1; - } - solver += strlen (src_filename) +1; - - if (0 == strcmp(solver, "proportional")) - { - config_file = "test_ats_solver_proportional.conf"; - } - else if (0 == strcmp(solver, "mlp")) - { - config_file = "test_ats_solver_mlp.conf"; - } - else if ((0 == strcmp(solver, "ril"))) - { - config_file = "test_ats_solver_ril.conf"; - } - else - { - GNUNET_break (0); - GNUNET_free (src_filename); - GNUNET_free (test_filename); - return 1; - } - - GNUNET_free (src_filename); - GNUNET_free (test_filename); - - if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", - config_file, &run, NULL )) - return GNUNET_SYSERR; - - return ret; -} - -/* end of file test_ats_solver_alternative_after_delete_address.c */ diff --git a/src/ats/test_ats_solver_request_and_add_address.c b/src/ats/test_ats_solver_request_and_add_address.c deleted file mode 100644 index 8514e8ddf..000000000 --- a/src/ats/test_ats_solver_request_and_add_address.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to connect to performance API\n"); - GNUNET_SCHEDULER_add_now (end_badly, NULL); - } - This file is part of GNUnet. - Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_solver_add_address.c - * @brief solver test: request address, add address and wait for suggest - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" -#include "gnunet_ats_service.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Connectivity handle - */ -static struct GNUNET_ATS_ConnectivityHandle *connect_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -static struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - - -static int -stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent); - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - if (NULL != connect_ats) - { - GNUNET_ATS_connectivity_done (connect_ats); - connect_ats = NULL; - } - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - - free_test_address (&test_addr); - - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end ( NULL, NULL); - ret = GNUNET_SYSERR; -} - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - - GNUNET_assert (NULL != address); - GNUNET_assert (NULL == session); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received sugggestion for peer `%s'\n", - GNUNET_i2s (&address->peer)); - - GNUNET_SCHEDULER_add_now (&end, NULL); -} - - -static int -stat_cb(void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", - subsystem,name, value); - return GNUNET_OK; -} - -static void -run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", mycfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - connect_ats = GNUNET_ATS_connectivity_init (mycfg); - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Request */ - GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); - - - /* Adding address */ - GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - char *sep; - char *src_filename = GNUNET_strdup (__FILE__); - char *test_filename = GNUNET_strdup (argv[0]); - char *config_file; - char *solver; - - ret = 0; - - if (NULL == (sep = (strstr (src_filename,".c")))) - { - GNUNET_break (0); - return -1; - } - sep[0] = '\0'; - - if (NULL != (sep = strstr (test_filename, ".exe"))) - sep[0] = '\0'; - - if (NULL == (solver = strstr (test_filename, src_filename))) - { - GNUNET_break (0); - return -1; - } - solver += strlen (src_filename) +1; - - if (0 == strcmp(solver, "proportional")) - { - config_file = "test_ats_solver_proportional.conf"; - } - else if (0 == strcmp(solver, "mlp")) - { - config_file = "test_ats_solver_mlp.conf"; - } - else if ((0 == strcmp(solver, "ril"))) - { - config_file = "test_ats_solver_ril.conf"; - } - else - { - GNUNET_break (0); - GNUNET_free (src_filename); - GNUNET_free (test_filename); - return 1; - } - - GNUNET_free (src_filename); - GNUNET_free (test_filename); - - if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", - config_file, &run, NULL )) - return GNUNET_SYSERR; - - return ret; -} - -/* end of file test_ats_solver_add_address.c */ diff --git a/src/ats/test_ats_solver_request_and_delete_address.c b/src/ats/test_ats_solver_request_and_delete_address.c deleted file mode 100644 index ac624f8ab..000000000 --- a/src/ats/test_ats_solver_request_and_delete_address.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. - */ -/** - * @file ats/test_ats_solver_request_and_delete_address.c - * @brief solver test: add address, request address, delete address and wait for disconnect - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" -#include "gnunet_testbed_service.h" -#include "gnunet_ats_service.h" -#include "test_ats_api_common.h" - -/** - * Timeout task - */ -static struct GNUNET_SCHEDULER_Task * die_task; - -/** - * Statistics handle - */ -static struct GNUNET_STATISTICS_Handle *stats; - -/** - * Scheduling handle - */ -static struct GNUNET_ATS_SchedulingHandle *sched_ats; - -/** - * Connectivity handle - */ -static struct GNUNET_ATS_ConnectivityHandle *connect_ats; - -/** - * Return value - */ -static int ret; - -/** - * Test address - */ -static struct Test_Address test_addr; - -/** - * Test peer - */ -static struct PeerContext p; - -/** - * HELLO address - */ -static struct GNUNET_HELLO_Address test_hello_address; - -/** - * Session - */ -static void *test_session; - -/** - * Test ats info - */ -struct GNUNET_ATS_Information test_ats_info[2]; - -/** - * Test ats count - */ -static uint32_t test_ats_count; - -/** - * The address we will delete. - */ -static struct GNUNET_ATS_AddressRecord *ar; - -static int address_deleted = GNUNET_NO; - - -static int -stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, - int is_persistent); - - -static void -end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - if (die_task != NULL) - { - GNUNET_SCHEDULER_cancel (die_task); - die_task = NULL; - } - - if (NULL != sched_ats) - { - GNUNET_ATS_scheduling_done (sched_ats); - sched_ats = NULL; - } - - if (NULL != connect_ats) - { - GNUNET_ATS_connectivity_done (connect_ats); - connect_ats = NULL; - } - GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); - if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - free_test_address (&test_addr); - ret = 0; -} - - -static void -end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - die_task = NULL; - end (NULL, NULL); - ret = GNUNET_SYSERR; -} - - -static void -address_suggest_cb (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Address *address, - struct Session *session, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) -{ - if (GNUNET_NO == address_deleted) - { - /* Expected address suggestion */ - GNUNET_assert (NULL != address); - GNUNET_assert (NULL == session); - GNUNET_assert (ntohl(bandwidth_in.value__) > 0); - GNUNET_assert (ntohl(bandwidth_out.value__) > 0); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received sugggestion for peer `%s', deleting address\n", - GNUNET_i2s (&address->peer)); - address_deleted = GNUNET_YES; - /* Destroying address and wait for disconnect suggestion */ - GNUNET_ATS_address_destroy (ar); - ar = NULL; - } - else - { - /* Expecting disconnect */ - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Received sugggestion for peer `%s': %u %u\n", - GNUNET_i2s (peer), - (unsigned int) ntohl (bandwidth_in.value__), - (unsigned int) ntohl (bandwidth_out.value__)); - - if ((ntohl(bandwidth_in.value__) == 0) && - (ntohl(bandwidth_out.value__) == 0)) - { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); - GNUNET_SCHEDULER_add_now (&end, NULL); - } - } -} - - -static int -stat_cb (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "ATS statistics: `%s' `%s' %llu\n", - subsystem, - name, - value); - if (NULL == sh) - sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); - return GNUNET_OK; -} - - -static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *mycfg, - struct GNUNET_TESTING_Peer *peer) -{ - die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); - stats = GNUNET_STATISTICS_create ("ats", mycfg); - GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); - - connect_ats = GNUNET_ATS_connectivity_init (mycfg); - - /* Connect to ATS scheduling */ - sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); - if (sched_ats == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); - GNUNET_SCHEDULER_add_now (&end_badly, NULL); - return; - } - - /* Set up peer */ - memset (&p.id, '1', sizeof (p.id)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", - GNUNET_i2s_full(&p.id)); - - /* Prepare ATS Information */ - test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); - test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); - test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); - test_ats_info[1].value = htonl(1); - test_ats_count = 2; - - /* Adding address without session */ - test_session = NULL; - create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); - test_hello_address.peer = p.id; - test_hello_address.transport_name = test_addr.plugin; - test_hello_address.address = test_addr.addr; - test_hello_address.address_length = test_addr.addr_len; - - /* Adding address */ - ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, - NULL, - test_ats_info, test_ats_count); -} - - -int -main (int argc, char *argv[]) -{ - char *sep; - char *src_filename = GNUNET_strdup (__FILE__); - char *test_filename = GNUNET_strdup (argv[0]); - char *config_file; - char *solver; - - ret = 0; - - if (NULL == (sep = (strstr (src_filename,".c")))) - { - GNUNET_break (0); - return -1; - } - sep[0] = '\0'; - - if (NULL != (sep = strstr (test_filename, ".exe"))) - sep[0] = '\0'; - - if (NULL == (solver = strstr (test_filename, src_filename))) - { - GNUNET_break (0); - return -1; - } - solver += strlen (src_filename) +1; - - if (0 == strcmp(solver, "proportional")) - { - config_file = "test_ats_solver_proportional.conf"; - } - else if (0 == strcmp(solver, "mlp")) - { - config_file = "test_ats_solver_mlp.conf"; - } - else if ((0 == strcmp(solver, "ril"))) - { - config_file = "test_ats_solver_ril.conf"; - } - else - { - GNUNET_break (0); - GNUNET_free (src_filename); - GNUNET_free (test_filename); - return 1; - } - - GNUNET_free (src_filename); - GNUNET_free (test_filename); - - if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", - config_file, &run, NULL )) - return GNUNET_SYSERR; - - return ret; -} - -/* end of file test_ats_solver_request_and_delete_address_proportional.c */ -- cgit v1.2.3