GNUnet  0.11.x
gnunet-service-testbed.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2008--2013 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
31 #include "gnunet_core_service.h"
32 
33 #include "testbed.h"
34 #include "testbed_api.h"
35 #include "testbed_api_operations.h"
36 #include "testbed_api_hosts.h"
37 #include "gnunet_testing_lib.h"
39 
40 
44 #define LOG(kind, ...) \
45  GNUNET_log (kind, __VA_ARGS__)
46 
50 #define LOG_DEBUG(...) \
51  LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
52 
56 #define LIST_GROW_STEP 10
57 
58 
62 struct Route
63 {
67  uint32_t dest;
68 
72  uint32_t thru;
73 };
74 
75 
80 {
85 
90 
95 
100 
104  void *cls;
105 
110 
114  uint64_t operation_id;
115 
119  enum OperationType type;
120 };
121 
122 
127 {
132 
137 
142 
146  void *cb_cls;
147 
152 };
153 
154 
159 {
164 
168  uint64_t operation_id;
169 };
170 
171 
175 struct Peer
176 {
177  union
178  {
179  struct
180  {
185 
191 
196  } local;
197 
198  struct
199  {
203  struct Slave *slave;
204 
208  uint32_t remote_host_id;
211 
216 
220  uint32_t id;
221 
229  uint32_t reference_cnt;
230 
238  uint32_t destroy_flag;
239 };
240 
241 
245 struct Context
246 {
251 
255  char *master_ip;
256 
261 
265  uint32_t host_id;
266 };
267 
268 
273 {
277  char *name;
278 
282  uint32_t num_shared;
283 
287  uint32_t num_sharing;
288 };
289 
290 
291 struct RegisteredHostContext;
292 
293 
299 {
304 
309 
314 
319 
324 
328  uint64_t operation_id;
329 
333  uint32_t peer1;
334 
338  uint32_t peer2;
339 
343  uint32_t peer2_host_id;
344 };
345 
346 
352 {
357 
362 
367 
372 
376  enum RHCState
377  {
381  RHC_INIT = 0,
382 
386  RHC_DONE
387  } state;
388 };
389 
390 
395 {
400  unsigned int nslaves;
401 
406  int timeout;
407 };
408 
409 
414 
418 extern struct Context *GST_context;
419 
424 
429 
433 extern struct Peer **GST_peer_list;
434 
438 extern struct GNUNET_TESTBED_Host **GST_host_list;
439 
443 extern struct OperationQueue *GST_opq_openfds;
444 
448 extern struct GNUNET_TIME_Relative GST_timeout;
449 
453 extern unsigned int GST_peer_list_size;
454 
458 extern unsigned int GST_num_local_peers;
459 
463 extern unsigned int GST_host_list_size;
464 
468 extern char *GST_stats_dir;
469 
473 #define VALID_HOST_ID(id) \
474  (((id) < GST_host_list_size) && (NULL != GST_host_list[id]))
475 
479 #define VALID_PEER_ID(id) \
480  (((id) < GST_peer_list_size) && (NULL != GST_peer_list[id]))
481 
482 
494 #define GST_array_grow_large_enough(ptr, size, accommodate_size) \
495  do \
496  { \
497  unsigned int growth_size; \
498  GNUNET_assert (size <= accommodate_size); \
499  growth_size = size; \
500  while (growth_size <= accommodate_size) \
501  growth_size += LIST_GROW_STEP; \
502  GNUNET_array_grow (ptr, size, growth_size); \
503  GNUNET_assert (size > accommodate_size); \
504  } while (0)
505 
506 
512 void
513 GST_destroy_peer (struct Peer *peer);
514 
515 
519 void
520 GST_destroy_peers (void);
521 
522 
531 struct Route *
532 GST_find_dest_route (uint32_t host_id);
533 
534 
541 void
542 handle_overlay_connect (void *cls,
544 
545 
555 void
556 GST_queue_host_registration (struct Slave *slave,
558  void *cb_cls, struct GNUNET_TESTBED_Host *host);
559 
560 
567 void
569  const struct GNUNET_MessageHeader *msg);
570 
571 
578 void
580 
581 
585 void
586 GST_clear_fopcq (void);
587 
588 
596 void
598  uint64_t operation_id,
599  const char *emsg);
600 
601 
607 void
609 
610 
616 void
618 
619 
626 void
628  uint64_t operation_id);
629 
630 
638 int
640  const struct
642 
643 
650 void
652  const struct
654 
655 
663 int
664 check_peer_create (void *cls,
665  const struct GNUNET_TESTBED_PeerCreateMessage *msg);
666 
667 
674 void
675 handle_peer_create (void *cls,
676  const struct GNUNET_TESTBED_PeerCreateMessage *msg);
677 
678 
685 void
686 handle_peer_destroy (void *cls,
687  const struct GNUNET_TESTBED_PeerDestroyMessage *msg);
688 
689 
696 void
697 handle_peer_start (void *cls,
698  const struct GNUNET_TESTBED_PeerStartMessage *msg);
699 
700 
707 void
708 handle_peer_stop (void *cls,
709  const struct GNUNET_TESTBED_PeerStopMessage *msg);
710 
711 
718 void
719 handle_peer_get_config (void *cls,
720  const struct
722 
723 
730 void
731 handle_shutdown_peers (void *cls,
733 
734 
742 int
743 check_manage_peer_service (void *cls,
744  const struct
746 
747 
754 void
755 handle_manage_peer_service (void *cls,
756  const struct
758 
759 
767 int
768 check_peer_reconfigure (void *cls,
769  const struct
771 
772 
781 void
782 handle_peer_reconfigure (void *cls,
783  const struct
785 
786 
790 void
791 GST_free_mctxq (void);
792 
793 
797 void
798 GST_free_lcf (void);
799 
800 
804 void
805 GST_route_list_clear (void);
806 
807 
813 void
815 
816 
822 void
824 
825 
829 void
830 GST_free_occq (void);
831 
832 
836 void
837 GST_free_roccq (void);
838 
839 
843 void
844 GST_free_prcq (void);
845 
846 
852 void
853 GST_cache_init (unsigned int size);
854 
855 
859 void
860 GST_cache_clear (void);
861 
862 
869 const struct GNUNET_MessageHeader *
870 GST_cache_lookup_hello (const unsigned int peer_id);
871 
872 
880 void
881 GST_cache_add_hello (const unsigned int peer_id,
882  const struct GNUNET_MessageHeader *hello);
883 
884 
890 void
892 
893 
897 void
898 GST_stats_destroy (void);
899 
900 /* End of gnunet-service-testbed.h */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
const struct GNUNET_MessageHeader * GST_cache_lookup_hello(const unsigned int peer_id)
Looks up in the hello cache and returns the HELLO of the given peer.
void GST_forwarded_operation_reply_relay(void *cls, const struct GNUNET_MessageHeader *msg)
Callback to relay the reply msg of a forwarded operation back to the client.
void handle_overlay_connect(void *cls, const struct GNUNET_TESTBED_OverlayConnectMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT messages.
void GST_route_list_clear(void)
Cleans up the route list.
struct OperationQueue * GST_opq_openfds
Operation queue for open file descriptors.
void GST_free_mctxq(void)
Frees the ManageServiceContext queue.
int check_peer_reconfigure(void *cls, const struct GNUNET_TESTBED_PeerReconfigureMessage *msg)
Check #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages.
unsigned int GST_num_local_peers
The current number of peers running locally under this controller.
struct ForwardedOperationContext * fopcq_head
DLL head for forwarded operation contexts.
int check_remote_overlay_connect(void *cls, const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
Check GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT messages.
struct GNUNET_TESTBED_Host ** GST_host_list
Array of hosts.
void handle_peer_destroy(void *cls, const struct GNUNET_TESTBED_PeerDestroyMessage *msg)
Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages.
void GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize logging CPU and IO statisticfs.
struct Context * GST_context
The master context; generated with the first INIT message.
void GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client)
Notify peers subsystem that client disconnected.
struct GNUNET_TIME_Relative GST_timeout
Timeout for operations which may take some time.
struct Route * GST_find_dest_route(uint32_t host_id)
Finds the route with directly connected host as destination through which the destination host can be...
void GST_destroy_peers(void)
Stops and destroys all peers.
void handle_shutdown_peers(void *cls, const struct GNUNET_TESTBED_ShutdownPeersMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages.
unsigned int GST_host_list_size
The size of the host list.
void GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, uint64_t operation_id, const char *emsg)
Send operation failure message to client.
void handle_remote_overlay_connect(void *cls, const struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT messages.
void GST_cache_clear(void)
Clear cache.
void GST_stats_destroy(void)
Shutdown the status calls module.
void handle_peer_get_config(void *cls, const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg)
Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages.
void GST_cleanup_focc(struct ForwardedOverlayConnectContext *focc)
Cleans up ForwardedOverlayConnectContext.
void handle_manage_peer_service(void *cls, const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg)
Handler for GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE message.
void GST_free_lcf(void)
Cleans up the queue used for forwarding link controllers requests.
void GST_destroy_peer(struct Peer *peer)
Function to destroy a peer.
unsigned int GST_peer_list_size
The size of the peer list.
struct GNUNET_CONFIGURATION_Handle * GST_config
Our configuration.
void GST_queue_host_registration(struct Slave *slave, GNUNET_TESTBED_HostRegistrationCompletion cb, void *cb_cls, struct GNUNET_TESTBED_Host *host)
Adds a host registration's request to a slave's registration queue.
void handle_peer_start(void *cls, const struct GNUNET_TESTBED_PeerStartMessage *msg)
Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages.
void GST_free_roccq(void)
Clears all pending remote overlay connect contexts in queue.
void handle_peer_stop(void *cls, const struct GNUNET_TESTBED_PeerStopMessage *msg)
Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages.
struct ForwardedOperationContext * fopcq_tail
DLL tail for forwarded operation contexts.
void GST_process_next_focc(struct RegisteredHostContext *rhc)
Processes a forwarded overlay connect context in the queue of the given RegisteredHostContext.
void handle_peer_reconfigure(void *cls, const struct GNUNET_TESTBED_PeerReconfigureMessage *msg)
Handler for #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages.
void GST_notify_client_disconnect_oc(struct GNUNET_SERVICE_Client *client)
Notify OC subsystem that client disconnected.
void GST_forwarded_operation_timeout(void *cls)
Task to free resources when forwarded operation has been timedout.
int check_peer_create(void *cls, const struct GNUNET_TESTBED_PeerCreateMessage *msg)
Check #GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages.
void GST_clear_fopcq(void)
Clears the forwarded operations queue.
void GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, uint64_t operation_id)
Function to send generic operation success message to given client.
struct Peer ** GST_peer_list
A list of peers we know about.
void GST_cache_init(unsigned int size)
Initializes the cache.
void GST_free_prcq(void)
Cleans up the Peer reconfigure context list.
void handle_peer_create(void *cls, const struct GNUNET_TESTBED_PeerCreateMessage *msg)
Handler for #GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages.
void GST_free_occq(void)
Clears all pending overlay connect contexts in queue.
char * GST_stats_dir
The directory where to store load statistics data.
void GST_cache_add_hello(const unsigned int peer_id, const struct GNUNET_MessageHeader *hello)
Caches the HELLO of the given peer.
int check_manage_peer_service(void *cls, const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg)
Check GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE message.
void(* GNUNET_TESTBED_HostRegistrationCompletion)(void *cls, const char *emsg)
Callback which will be called to after a host registration succeeded or failed.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Context to hold data of peer.
char * master_ip
The network address of the master controller.
struct GNUNET_SERVICE_Client * client
The client handle associated with this context.
uint32_t host_id
Our host id according to this context.
struct GNUNET_TESTING_System * system
The TESTING system handle for starting peers locally.
Context information for operations forwarded to subcontrollers.
struct GNUNET_SCHEDULER_Task * timeout_task
Task ID for the timeout task.
struct ForwardedOperationContext * prev
The prev pointer for DLL.
enum OperationType type
The type of the operation which is forwarded.
struct OperationContext * opc
The generated operation context.
struct GNUNET_SERVICE_Client * client
The client to which we have to reply.
struct ForwardedOperationContext * next
The next pointer for DLL.
uint64_t operation_id
The id of the operation that has been forwarded.
Context information to used during operations which forward the overlay connect message.
struct RegisteredHostContext * rhc
Which host does this FOCC belong to?
uint64_t operation_id
The id of the operation which created this context information.
struct ForwardedOverlayConnectContext * next
next ForwardedOverlayConnectContext in the DLL
struct GNUNET_SERVICE_Client * client
The client handle.
uint32_t peer2_host_id
Id of the host where peer2 is running.
struct ForwardedOverlayConnectContext * prev
previous ForwardedOverlayConnectContext in the DLL
struct GNUNET_MessageHeader * orig_msg
A copy of the original overlay connect message.
Header for all communications.
Entry in list of pending tasks.
Definition: scheduler.c:135
Handle to a client that is connected to a service.
Definition: service.c:251
Opaque handle to a host running experiments managed by the testing framework.
Message to start/stop services of a peer.
Definition: testbed.h:706
Message sent from client to testing service to connect two peers.
Definition: testbed.h:376
Message sent from client to testing service to create (configure, but not start) a peer.
Definition: testbed.h:205
Message sent from client to testing service to destroy a (stopped) peer.
Definition: testbed.h:318
Message sent from client to testing service to obtain the configuration of a peer.
Definition: testbed.h:582
Message sent from client to testing service to reconfigure a (stopped) a peer.
Definition: testbed.h:241
Message sent from client to testing service to start a peer.
Definition: testbed.h:272
Message sent from client to testing service to stop a peer.
Definition: testbed.h:295
Message sent from host controller of a peer(A) to the host controller of another peer(B) to request B...
Definition: testbed.h:409
Shutdown peers message.
Definition: testbed.h:689
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:167
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:94
Time for relative time used by GNUnet, in microseconds.
Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler.
int timeout
Did we observe a timeout with respect to this operation at any of the slaves.
unsigned int nslaves
The number of slave we expect to hear from since we forwarded the GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOW...
A DLL of host registrations to be made.
struct GNUNET_TESTBED_Host * host
The host that has to be registered.
struct HostRegistration * prev
previous registration in the DLL
struct HostRegistration * next
next registration in the DLL
GNUNET_TESTBED_HostRegistrationCompletion cb
The callback to call after this registration's status is available.
void * cb_cls
The closure for the above callback.
Context information used while linking controllers.
uint64_t operation_id
The ID of the operation.
struct GNUNET_SERVICE_Client * client
The client which initiated the link controller operation.
Context information for GNUNET_TESTBED_Operation.
Definition: testbed_api.h:137
Queue of operations where we can only support a certain number of concurrent operations of a particul...
struct Slave * slave
The slave this peer is started through.
struct GNUNET_CONFIGURATION_Handle * cfg
The modified (by GNUNET_TESTING_peer_configure) configuration this peer is configured with.
uint32_t remote_host_id
The id of the remote host this peer is running on.
struct Peer::@56::@57 local
int is_remote
Is this peer locally created?
uint32_t destroy_flag
While destroying a peer, due to the fact that there could be references to this peer,...
struct GNUNET_TESTING_Peer * peer
The peer handle from testing API.
uint32_t reference_cnt
References to peers are using in forwarded overlay contexts and remote overlay connect contexts.
int is_running
Is the peer running.
uint32_t id
Our local reference id for this peer.
union Peer::@56 details
struct Peer::@56::@58 remote
This context information will be created for each host that is registered at slave controllers during...
enum RegisteredHostContext::RHCState state
struct GNUNET_TESTBED_Host * host
The host of the controller which has to connect to the above rhost.
struct ForwardedOverlayConnectContext * focc_dll_tail
Tail of the ForwardedOverlayConnectContext DLL.
struct ForwardedOverlayConnectContext * focc_dll_head
Head of the ForwardedOverlayConnectContext DLL.
struct GNUNET_TESTBED_Host * reg_host
The host which is being registered.
RHCState
Enumeration of states for this context.
@ RHC_DONE
State where we attempt to do the overlay connection again.
@ RHC_INIT
The initial state.
A routing entry.
uint32_t thru
The destination host is reachable thru.
uint32_t dest
destination host
The structure for identifying a shared service.
char * name
The name of the shared service.
uint32_t num_shared
Number of shared peers per instance of the shared service.
uint32_t num_sharing
Number of peers currently sharing the service.
Structure representing a connected(directly-linked) controller.
IPC messages between testing API and service ("controller")
Interface for functions internally exported from testbed_api.c.
internal API to access the 'hosts' subsystem
internal API to access the 'operations' subsystem
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.