GNUnet  0.20.0
transport_api_cmd_send_simple_performance.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 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 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
30 #include "transport-testing2.h"
31 #include "transport-testing-cmds.h"
32 
36 #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 
43 {
48 
53  const char *start_peer_label;
54 
59  const char *create_label;
60 
65 
69  unsigned int size;
70 
74  unsigned int max_send;
75 };
76 
77 struct MQWrapper
78 {
83 
88 
92  uint32_t num_send;
93 };
94 
99 static void
101 {
102  struct SendSimpleState *sss = cls;
103 
104  GNUNET_free (sss);
105 }
106 
107 
108 static void
110 {
111  struct MQWrapper *mq_wrapper = cls;
112  struct GNUNET_MQ_Envelope *env;
114  struct GNUNET_TIME_Absolute now;
115 
116  now = GNUNET_TIME_absolute_get ();
117  mq_wrapper->num_send++;
119  "Sending simple test message with size %u number %u with mq %p max %u\n",
120  mq_wrapper->sss->size,
121  mq_wrapper->num_send,
122  mq_wrapper->mq,
123  mq_wrapper->sss->max_send);
124 
125  env = GNUNET_MQ_msg_extra (test,
126  mq_wrapper->sss->size - sizeof(*test),
128  test->num = htonl (mq_wrapper->num_send);
129  test->time_send = GNUNET_TIME_absolute_hton (now);
130  memset (&test[1],
131  '1',
132  mq_wrapper->sss->size - sizeof(*test));
133  GNUNET_MQ_send (mq_wrapper->mq,
134  env);
135  if (mq_wrapper->sss->max_send > mq_wrapper->num_send)
137  else
138  GNUNET_TESTING_async_finish (&mq_wrapper->sss->ac);
139 }
140 
141 
142 static int
143 send_simple_cb (void *cls,
144  const struct GNUNET_ShortHashCode *key,
145  void *value)
146 {
147  struct SendSimplePerfState *sss = cls;
148  struct GNUNET_MQ_Handle *mq = value;
149  struct MQWrapper *mq_wrapper = GNUNET_new (struct MQWrapper);
150 
151  mq_wrapper->sss = sss;
152  mq_wrapper->mq = mq;
153  send_simple_single (mq_wrapper);
154 
155  return GNUNET_OK;
156 }
157 
158 
163 static void
164 send_simple_run (void *cls,
166 {
167  struct SendSimplePerfState *sss = cls;
168  const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
169  const struct GNUNET_TESTING_Command *peer1_cmd;
170  const struct GNUNET_TESTING_Command *system_cmd;
171  const struct GNUNET_TESTING_System *tl_system;
172 
173 
175  sss->start_peer_label);
177  &connected_peers_map);
178 
180  sss->create_label);
182  &tl_system);
183 
186  connected_peers_map, send_simple_cb,
187  sss);
188 }
189 
190 
193  const char *start_peer_label,
194  const char *create_label,
195  uint32_t num,
196  int size,
197  int max_send,
198  struct
200  topology)
201 {
202  struct SendSimplePerfState *sss;
203  struct GNUNET_TESTING_Command cmd;
204 
205  sss = GNUNET_new (struct SendSimplePerfState);
206  sss->start_peer_label = start_peer_label;
207  sss->create_label = create_label;
208  sss->topology = topology;
209  sss->size = size;
210  sss->max_send = max_send;
211 
212  cmd = GNUNET_TESTING_command_new (sss,
213  label,
216  NULL,
217  &sss->ac);
218  cmd.asynchronous_finish = GNUNET_YES;
219  return cmd;
220 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
enum GNUNET_TESTBED_TopologyOption topology
The topology to generate.
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait_test_system(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_System **ret)
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
static unsigned int size
Size of the "table".
Definition: peer.c:68
Internal representation of the hash map.
Handle to a message queue.
Definition: mq.c:87
A 256-bit hashcode.
State each asynchronous command must have in its closure.
A command to be run by the interpreter.
char label[127+1]
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
Time for absolute times used by GNUnet, in microseconds.
uint32_t num
Monotonically increasing counter throughout the test.
struct GNUNET_TIME_AbsoluteNBO time_send
Time this message was send via transport api.
struct GNUNET_MQ_Handle * mq
Message queue for a peer.
uint32_t num_send
Number of messages allready send.
struct SendSimplePerfState * sss
State of the command.
Struct to hold information for callbacks.
unsigned int size
Size of the message in bytes.
unsigned int max_send
Maximum number of messages per peer.
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
const char * create_label
Label of the cmd which started the test system.
struct GNUNET_TESTING_NetjailTopology * topology
The topology we get the connected nodes from.
const char * start_peer_label
Label of the cmd to start a peer.
Struct to hold information for callbacks.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_get_trait_connected_peers_map(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_CONTAINER_MultiShortmap **ret)
#define GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE
Message type used by #().
static void send_simple_single(void *cls)
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple_performance(const char *label, const char *start_peer_label, const char *create_label, uint32_t num, int size, int max_send, struct GNUNET_TESTING_NetjailTopology *topology)
static void send_simple_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will send a simple message to the connected peers.
static void send_simple_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
#define LOG(kind,...)
Generic logging shortcut.
static int send_simple_cb(void *cls, const struct GNUNET_ShortHashCode *key, void *value)