gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: ATS: Add first stub of test


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: ATS: Add first stub of test for new ATS API
Date: Wed, 23 Jan 2019 18:42:51 +0100

This is an automated email from the git hooks/post-receive script.

julius-buenger pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 546f01e20 ATS: Add first stub of test for new ATS API
546f01e20 is described below

commit 546f01e2008e79b6774fd69116f1387bc6ee0409
Author: Julius Bünger <address@hidden>
AuthorDate: Wed Jan 23 18:41:33 2019 +0100

    ATS: Add first stub of test for new ATS API
---
 src/ats/Makefile.am     |  13 +-
 src/ats/test_ats2_lib.c | 220 ++++++++++++++++++++
 src/ats/test_ats2_lib.h | 523 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 755 insertions(+), 1 deletion(-)

diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 147d371e6..f113d96e7 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -141,7 +141,8 @@ gnunet_service_ats_new_LDADD = \
 if HAVE_TESTING
 TESTING_TESTS = \
  test_ats_api_proportional \
- test_ats_reservation_api_proportional
+ test_ats_reservation_api_proportional \
+ test_ats2_lib
 if HAVE_EXPERIMENTAL
 TESTING_TESTS += \
  test_ats_api_ril
@@ -196,6 +197,16 @@ test_ats_api_mlp_LDADD = \
   $(top_builddir)/src/testing/libgnunettesting.la \
   libgnunetats.la
 
+test_ats2_lib_SOURCES = \
+ test_ats2_lib.c test_ats2_lib.h
+test_ats2_lib_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/hello/libgnunethello.la \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  libgnunetatsapplication.la \
+  libgnunetatstransport.la
+
+
 EXTRA_DIST = \
   ats.h ats2.h \
   plugin_ats2_common.c \
diff --git a/src/ats/test_ats2_lib.c b/src/ats/test_ats2_lib.c
new file mode 100644
index 000000000..a35b5bce6
--- /dev/null
+++ b/src/ats/test_ats2_lib.c
@@ -0,0 +1,220 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2010-2015 GNUnet e.V.
+
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     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
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * @file ats/test_ats2_lib.c
+ * @brief test ATS library with a generic interpreter for running ATS tests
+ * @author Julius Bünger
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_ats_application_service.h"
+#include "gnunet_ats_transport_service.h"
+#include "gnunet_testing_lib.h"
+
+/**
+ * @brief ATS Application Handle
+ *
+ * Handle to the application-side of ATS.
+ */
+static struct GNUNET_ATS_ApplicationHandle *ah;
+
+/**
+ * @brief ATS Transport Handle
+ *
+ * Handle to the transport-side of ATS.
+ */
+static struct GNUNET_ATS_TransportHandle *th;
+
+/**
+ * @brief Another (dummy) peer.
+ *
+ * Used as the peer ATS shall allocate bandwidth to.
+ */
+static struct GNUNET_PeerIdentity other_peer;
+
+/**
+ * @brief Handle to the session record
+ */
+static struct GNUNET_ATS_SessionRecord *sr;
+
+/**
+ * @brief Called whenever allocation changed
+ *
+ * Implements #GNUNET_ATS_AllocationCallback
+ *
+ * @param cls
+ * @param session
+ * @param bandwidth_out
+ * @param bandwidth_in
+ *
+ * @return 
+ */
+static void
+allocation_cb (void *cls,
+               struct GNUNET_ATS_Session *session,
+               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+               struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "allocation_cb() called\n");
+}
+
+
+/**
+ * @brief Called whenever suggestion is made
+ *
+ * Implements #GNUNET_ATS_SuggestionCallback
+ *
+ * @param cls
+ * @param pid
+ * @param address
+ */
+static void
+suggestion_cb (void *cls,
+               const struct GNUNET_PeerIdentity *pid,
+               const char *address)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggestion_cb() called\n");
+}
+
+
+/**
+ * @brief Initialise both 'sides' of ATS
+ *
+ * Initialises the application and transportation side of ATS.
+ */
+static void
+init_both (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  ah = GNUNET_ATS_application_init (cfg);
+  GNUNET_assert (NULL != ah);
+  th = GNUNET_ATS_transport_init (cfg,
+                                  allocation_cb,
+                                  NULL,
+                                  suggestion_cb,
+                                  NULL);
+  GNUNET_assert (NULL != ah);
+}
+
+
+/**
+ * @brief Disconnect both 'sides' of ATS
+ */
+static void
+finish_both (void)
+{
+  GNUNET_ATS_application_done (ah);
+  ah = NULL;
+  GNUNET_ATS_transport_done (th);
+  th = NULL;
+}
+
+
+/**
+ * @brief Provide information about the start of an imaginary connection
+ */
+static void
+provide_info_start (void)
+{
+  struct GNUNET_ATS_Properties prop =
+  {
+    .delay = GNUNET_TIME_UNIT_FOREVER_REL,
+    .goodput_out = 1048576,
+    .goodput_in = 1048576,
+    .utilization_out = 0,
+    .utilization_in = 0,
+    .distance = 0,
+    .mtu = UINT32_MAX,
+    .nt = GNUNET_NT_UNSPECIFIED,
+    .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
+  };
+
+  sr = GNUNET_ATS_session_add (th,
+                               &other_peer,
+                               "test-address",
+                               NULL,
+                               &prop);
+}
+
+
+/**
+ * @brief Provide information about the end of an imaginary connection
+ */
+static void
+provide_info_end (void)
+{
+  GNUNET_ATS_session_del (sr);
+}
+
+
+/**
+ * @brief Inform ATS about the need of a connection towards a peer
+ */
+static void
+get_suggestion (void)
+{
+  struct GNUNET_ATS_ApplicationSuggestHandle *ash;
+
+  ash = GNUNET_ATS_application_suggest (ah,
+                                        &other_peer,
+                                        GNUNET_MQ_PREFERENCE_NONE,
+                                        GNUNET_BANDWIDTH_VALUE_MAX);
+  GNUNET_ATS_application_suggest_cancel (ash);
+}
+
+
+/**
+ * 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)
+{
+  init_both (cfg);
+  provide_info_start ();
+  get_suggestion ();
+  provide_info_end ();
+  finish_both ();
+}
+
+
+/**
+ * @brief Starts the gnunet-testing peer
+ *
+ * @param argc
+ * @param argv[]
+ *
+ * @return 
+ */
+int
+main (int argc,
+      char *argv[])
+{
+  memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity));
+  return GNUNET_TESTING_peer_run ("test-ats2-lib",
+                                  "test_ats2_lib.conf",
+                                  &run, NULL);
+}
+
+
+
+/* end of test_ats2_lib.c */
diff --git a/src/ats/test_ats2_lib.h b/src/ats/test_ats2_lib.h
new file mode 100644
index 000000000..5c1518792
--- /dev/null
+++ b/src/ats/test_ats2_lib.h
@@ -0,0 +1,523 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2010-2015 GNUnet e.V.
+
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     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
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * @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_application_service.h"
+#include "gnunet_ats_transport_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,
+//
+//  /**
+//   * Reserve bandwidth, testing
+//   * #GNUNET_ATS_reserve_bandwidth().
+//   */
+//  CMD_RESERVE_BANDWIDTH,
+//
+//  /**
+//   * Wait for a bit.
+//   */
+//  CMD_SLEEP
+//
+//};
+//
+//
+///**
+// * 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;
+//
+//};
+//
+//
+///**
+// * Details for the #CMD_RESERVE_BANDWIDTH command.
+// */
+//struct CommandReserveBandwidth
+//{
+//  /**
+//   * For which peer do we reserve bandwidth?
+//   */
+//  unsigned int pid;
+//
+//  /**
+//   * How much should we try to reserve?
+//   */
+//  int32_t amount;
+//
+//  /**
+//   * Should we expect this to work or fail?
+//   * #GNUNET_YES: must work
+//   * #GNUNET_NO: may work or fail
+//   * #GNUNET_SYSERR: must fail
+//   */
+//  int expected_result;
+//
+//  /**
+//   * Location where we store the return value from
+//   * #GNUNET_ATS_reserve_bandwidth().
+//   */
+//  struct GNUNET_ATS_ReservationContext *rc;
+//
+//};
+//
+//
+///**
+// * Details for the #CMD_SLEEP command.
+// */
+//struct CommandSleep
+//{
+//  /**
+//   * How long should we wait before running the next command?
+//   */
+//  struct GNUNET_TIME_Relative delay;
+//};
+//
+//
+///**
+// * 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;
+//
+//    struct CommandReserveBandwidth reserve_bandwidth;
+//
+//    struct CommandSleep sleep;
+//
+//  } 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

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]